hydrogen 1.2.3
InstrumentList.h
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2024 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY, without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
23#ifndef H2C_INSTRUMENT_LIST_H
24#define H2C_INSTRUMENT_LIST_H
25
26#include <vector>
27#include <memory>
28#include <core/License.h>
29#include <core/Object.h>
30
31namespace H2Core
32{
33
34class XMLNode;
35class Instrument;
36class DrumkitComponent;
37
42class InstrumentList : public H2Core::Object<InstrumentList>
43{
45 public:
46
47 struct Content {
53
54 Content( const QString& sInstrumentName,
55 const QString& sComponentName,
56 const QString& sSampleName,
57 const QString& sFullSamplePath,
58 const License& license ) :
59 m_sInstrumentName( sInstrumentName ),
60 m_sComponentName( sComponentName ),
61 m_sSampleName( sSampleName ),
62 m_sFullSamplePath( sFullSamplePath ),
63 m_license( license ) {
64 };
65
66 QString toQString( const QString& sPrefix = "", bool bShort = true ) const;
67 };
68
77 InstrumentList( std::shared_ptr<InstrumentList> other );
78
80 int size() const;
85 void operator<<( std::shared_ptr<Instrument> instrument );
90 std::shared_ptr<Instrument> operator[]( int idx );
96 bool operator==( std::shared_ptr<InstrumentList> pOther ) const;
97 bool operator!=( std::shared_ptr<InstrumentList> pOther ) const;
102 void add( std::shared_ptr<Instrument> instrument );
108 void insert( int idx, std::shared_ptr<Instrument> instrument );
109
115 bool is_valid_index( int idx ) const;
120 std::shared_ptr<Instrument> get( int idx ) const;
126 std::shared_ptr<Instrument> del( int idx );
132 std::shared_ptr<Instrument> del( std::shared_ptr<Instrument> instrument );
138 int index( std::shared_ptr<Instrument> instrument );
144 std::shared_ptr<Instrument> find( const int i );
150 std::shared_ptr<Instrument> find( const QString& name );
156 std::shared_ptr<Instrument> findMidiNote( const int note );
162 void swap( int idx_a, int idx_b );
168 void move( int idx_a, int idx_b );
169
173 void load_samples( float fBpm = 120 );
177 void unload_samples();
191 void save_to( XMLNode* node, int component_id, bool bRecentVersion = true, bool bFull = false );
204 static std::shared_ptr<InstrumentList> load_from( XMLNode* node,
205 const QString& sDrumkitPath,
206 const QString& sDrumkitName,
207 const License& license = License(),
208 bool bSilent = false );
213 std::vector<std::shared_ptr<Content>> summarizeContent( const std::shared_ptr<std::vector<std::shared_ptr<DrumkitComponent>>> pDrumkitComponents ) const;
214
223 void fix_issue_307();
224
229 bool has_all_midi_notes_same() const;
230
244 QString toQString( const QString& sPrefix = "", bool bShort = true ) const override;
245
247 std::vector<std::shared_ptr<Instrument>>::iterator begin();
248 std::vector<std::shared_ptr<Instrument>>::iterator end();
249
252
253 private:
254 std::vector<std::shared_ptr<Instrument>> __instruments;
255};
256
257// DEFINITIONS
258
259inline int InstrumentList::size() const
260{
261 return __instruments.size();
262}
263
264};
265
266#endif // H2C_INSTRUMENT_LIST_H
267
268/* vim: set softtabstop=4 noexpandtab: */
#define H2_OBJECT(name)
Definition Object.h:224
InstrumentList is a collection of instruments used within a song, a drumkit, ...
void insert(int idx, std::shared_ptr< Instrument > instrument)
insert an instrument into the list
int index(std::shared_ptr< Instrument > instrument)
get the index of an instrument within the instruments
void add(std::shared_ptr< Instrument > instrument)
add an instrument to the list
std::vector< std::shared_ptr< Instrument > >::iterator end()
std::shared_ptr< Instrument > operator[](int idx)
get an instrument from the list
bool has_all_midi_notes_same() const
Check if all instruments have assigned the same MIDI out note.
std::shared_ptr< Instrument > findMidiNote(const int note)
find an instrument which play the given midi note
void move(int idx_a, int idx_b)
move an instrument from a position to another
bool is_valid_index(int idx) const
check if there is a idx is a valid index for this list without throwing an error messaage
void load_samples(float fBpm=120)
Calls the Instrument::load_samples() member function of all Instruments in __instruments.
std::shared_ptr< Instrument > find(const int i)
find an instrument within the instruments
std::shared_ptr< Instrument > get(int idx) const
get an instrument from the list
void fix_issue_307()
Fix GitHub issue #307, so called "Hi Bongo fiasco".
std::vector< std::shared_ptr< Instrument > >::iterator begin()
Iteration.
void operator<<(std::shared_ptr< Instrument > instrument)
add an instrument to the list
void swap(int idx_a, int idx_b)
swap the instruments of two different indexes
QString toQString(const QString &sPrefix="", bool bShort=true) const override
Formatted string version for debugging purposes.
std::vector< std::shared_ptr< Content > > summarizeContent(const std::shared_ptr< std::vector< std::shared_ptr< DrumkitComponent > > > pDrumkitComponents) const
Returns vector of lists containing instrument name, component name, file name, the license of all ass...
std::shared_ptr< Instrument > del(int idx)
remove the instrument at a given index, does not delete it
void set_default_midi_out_notes()
Set each instrument consecuteve MIDI out notes, starting from 36.
bool isAnyInstrumentSoloed()
Check if any instrument in the list is solo'd.
void unload_samples()
Calls the Instrument::unload_samples() member function of all Instruments in __instruments.
bool operator==(std::shared_ptr< InstrumentList > pOther) const
Superficial comparison check.
std::vector< std::shared_ptr< Instrument > > __instruments
the list of instruments
void save_to(XMLNode *node, int component_id, bool bRecentVersion=true, bool bFull=false)
save the instrument list within the given XMLNode
static std::shared_ptr< InstrumentList > load_from(XMLNode *node, const QString &sDrumkitPath, const QString &sDrumkitName, const License &license=License(), bool bSilent=false)
load an instrument list from an XMLNode
int size() const
returns the numbers of instruments
bool operator!=(std::shared_ptr< InstrumentList > pOther) const
Wrapper class to help Hydrogen deal with the license information specified in a drumkit.
Definition License.h:48
XMLNode is a subclass of QDomNode with read and write values methods.
Definition Xml.h:39
QString toQString(const QString &sPrefix="", bool bShort=true) const
Content(const QString &sInstrumentName, const QString &sComponentName, const QString &sSampleName, const QString &sFullSamplePath, const License &license)