hydrogen 1.2.6
InstrumentList Class Reference

InstrumentList is a collection of instruments used within a song, a drumkit, ... More...

#include <InstrumentList.h>

Inheritance diagram for InstrumentList:
Object< InstrumentList > Base

Data Structures

struct  Content
 

Public Member Functions

 InstrumentList ()
 constructor
 
 InstrumentList (std::shared_ptr< InstrumentList > other)
 copy constructor
 
 ~InstrumentList ()
 destructor
 
void add (std::shared_ptr< Instrument > instrument)
 add an instrument to the list
 
std::vector< std::shared_ptr< Instrument > >::iterator begin ()
 Iteration.
 
std::shared_ptr< Instrumentdel (int idx)
 remove the instrument at a given index, does not delete it
 
std::shared_ptr< Instrumentdel (std::shared_ptr< Instrument > instrument)
 remove an instrument from the list, does not delete it
 
std::vector< std::shared_ptr< Instrument > >::iterator end ()
 
std::shared_ptr< Instrumentfind (const int i)
 find an instrument within the instruments
 
std::shared_ptr< Instrumentfind (const QString &name)
 find an instrument within the instruments
 
std::shared_ptr< InstrumentfindMidiNote (const int note)
 find an instrument which play the given midi note
 
void fix_issue_307 ()
 Fix GitHub issue #307, so called "Hi Bongo fiasco".
 
std::shared_ptr< Instrumentget (int idx) const
 get an instrument from the list
 
bool has_all_midi_notes_same () const
 Check if all instruments have assigned the same MIDI out note.
 
int index (std::shared_ptr< Instrument > instrument)
 get the index of an instrument within the instruments
 
void insert (int idx, std::shared_ptr< Instrument > instrument)
 insert an instrument into the list
 
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
 
bool isAnyInstrumentSoloed ()
 Check if any instrument in the list is solo'd.
 
void load_samples (float fBpm=120)
 Calls the Instrument::load_samples() member function of all Instruments in __instruments.
 
void move (int idx_a, int idx_b)
 move an instrument from a position to another
 
bool operator!= (std::shared_ptr< InstrumentList > pOther) const
 
void operator<< (std::shared_ptr< Instrument > instrument)
 add an instrument to the list
 
bool operator== (std::shared_ptr< InstrumentList > pOther) const
 Superficial comparison check.
 
std::shared_ptr< Instrumentoperator[] (int idx)
 get an instrument from the list
 
void save_to (XMLNode *node, int component_id, bool bRecentVersion=true, bool bFull=false)
 save the instrument list within the given XMLNode
 
void set_default_midi_out_notes ()
 Set each instrument consecuteve MIDI out notes, starting from 36.
 
int size () const
 returns the numbers of instruments
 
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 associated samples.
 
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.
 
void unload_samples ()
 Calls the Instrument::unload_samples() member function of all Instruments in __instruments.
 
- Public Member Functions inherited from Object< InstrumentList >
 Object ()
 
 Object (const Object< InstrumentList > &other)
 
- Public Member Functions inherited from Base
 Base ()
 
 Base (const Base &other)
 
virtual const char * class_name () const
 
void logBacktrace () const
 Print the current stack at point into the debug log.
 
void Print (bool bShort=true) const
 Prints content of toQString() via DEBUGLOG.
 

Static Public Member Functions

static std::shared_ptr< InstrumentListload_from (XMLNode *node, const QString &sDrumkitPath, const QString &sDrumkitName, const License &license=License(), bool *pLegacyFormatEncountered=nullptr, bool bSilent=false)
 load an instrument list from an XMLNode
 
- Static Public Member Functions inherited from Base
static const char * _class_name ()
 return the class name
 
static QString base_clock (const QString &sMsg)
 Measures the current time and stores it in __last_clock.
 
static QString base_clock_in (const QString &sMsg)
 
static int bootstrap (Logger *logger, bool count=false)
 must be called before any Object instantiation !
 
static bool count_active ()
 
static int getAliveObjectCount ()
 
static object_map_t getObjectMap ()
 
static Loggerlogger ()
 return the logger instance
 
static int objects_count ()
 
static void printObjectMapDiff (object_map_t map)
 Creates the difference between a snapshot of the object map and its current state and prints it to std::cout.
 
static void set_count (bool flag)
 enable/disable class instances counting
 
static void write_objects_map_to (std::ostream &out, object_map_t *map=nullptr)
 output the full objects map to a given ostream
 
static void write_objects_map_to_cerr ()
 output objects map to stderr
 

Private Attributes

std::vector< std::shared_ptr< Instrument > > __instruments
 the list of instruments
 

Additional Inherited Members

- Static Public Attributes inherited from Base
static QString sPrintIndention = " "
 String used to format the debugging string output of some core classes.
 
- Protected Member Functions inherited from Object< InstrumentList >
 ~Object ()
 
- Protected Member Functions inherited from Base
 ~Base ()
 
- Static Protected Member Functions inherited from Base
static void registerClass (const char *name, const atomic_obj_cpt_t *counters)
 
- Static Protected Attributes inherited from Base
static bool __count = false
 should we count class instances
 
static timeval __last_clock = { 0, 0 }
 
static Logger__logger = nullptr
 
static bool bLogColors = true
 

Detailed Description

InstrumentList is a collection of instruments used within a song, a drumkit, ...

Definition at line 42 of file InstrumentList.h.

Constructor & Destructor Documentation

◆ InstrumentList() [1/2]

constructor

Definition at line 39 of file InstrumentList.cpp.

◆ ~InstrumentList()

destructor

Definition at line 52 of file InstrumentList.cpp.

◆ InstrumentList() [2/2]

InstrumentList ( std::shared_ptr< InstrumentList > other)

copy constructor

Parameters
other

Definition at line 43 of file InstrumentList.cpp.

Member Function Documentation

◆ add()

void add ( std::shared_ptr< Instrument > instrument)

add an instrument to the list

Parameters
instrumenta pointer to the instrument to add

Definition at line 165 of file InstrumentList.cpp.

◆ begin()

std::vector< std::shared_ptr< Instrument > >::iterator begin ( )

Iteration.

Definition at line 386 of file InstrumentList.cpp.

◆ del() [1/2]

std::shared_ptr< Instrument > del ( int idx)

remove the instrument at a given index, does not delete it

Parameters
idxthe index
Returns
a pointer to the removed instrument

Definition at line 246 of file InstrumentList.cpp.

◆ del() [2/2]

std::shared_ptr< Instrument > del ( std::shared_ptr< Instrument > instrument)

remove an instrument from the list, does not delete it

Parameters
instrumentthe instrument to be removed
Returns
a pointer to the removed instrument, 0 if not found

Definition at line 254 of file InstrumentList.cpp.

◆ end()

std::vector< std::shared_ptr< Instrument > >::iterator end ( )

Definition at line 390 of file InstrumentList.cpp.

◆ find() [1/2]

std::shared_ptr< Instrument > find ( const int i)

find an instrument within the instruments

Parameters
ithe id of the instrument to find
Returns
0 if not found

Definition at line 222 of file InstrumentList.cpp.

◆ find() [2/2]

std::shared_ptr< Instrument > find ( const QString & name)

find an instrument within the instruments

Parameters
namethe name of the instrument to find
Returns
0 if not found

Definition at line 230 of file InstrumentList.cpp.

◆ findMidiNote()

std::shared_ptr< Instrument > findMidiNote ( const int note)

find an instrument which play the given midi note

Parameters
notethe Midi note of the instrument to find
Returns
0 if not found

Definition at line 238 of file InstrumentList.cpp.

◆ fix_issue_307()

void fix_issue_307 ( )

Fix GitHub issue #307, so called "Hi Bongo fiasco".

Check whether the same MIDI note is assignedto every instrument - that condition makes MIDI export unusable. When so, assign each instrument consecutive MIDI note starting from 36.

Definition at line 333 of file InstrumentList.cpp.

◆ get()

std::shared_ptr< Instrument > get ( int idx) const

get an instrument from the list

Parameters
idxthe index to get the instrument from

Definition at line 204 of file InstrumentList.cpp.

◆ has_all_midi_notes_same()

bool has_all_midi_notes_same ( ) const

Check if all instruments have assigned the same MIDI out note.

Definition at line 341 of file InstrumentList.cpp.

◆ index()

int index ( std::shared_ptr< Instrument > instrument)

get the index of an instrument within the instruments

Parameters
instrumenta pointer to the instrument to find
Returns
-1 if not found

Definition at line 214 of file InstrumentList.cpp.

◆ insert()

void insert ( int idx,
std::shared_ptr< Instrument > instrument )

insert an instrument into the list

Parameters
idxthe index to insert the instrument at
instrumenta pointer to the instrument to add

Definition at line 174 of file InstrumentList.cpp.

◆ is_valid_index()

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

Parameters
idxthe index of the instrument

Definition at line 193 of file InstrumentList.cpp.

◆ isAnyInstrumentSoloed()

bool isAnyInstrumentSoloed ( )

Check if any instrument in the list is solo'd.

Definition at line 417 of file InstrumentList.cpp.

◆ load_from()

std::shared_ptr< InstrumentList > load_from ( XMLNode * node,
const QString & sDrumkitPath,
const QString & sDrumkitName,
const License & license = License(),
bool * pLegacyFormatEncountered = nullptr,
bool bSilent = false )
static

load an instrument list from an XMLNode

Parameters
nodethe XMLDode to read from
sDrumkitPaththe directory holding the Drumkit
sDrumkitNamename of the Drumkit found in sDrumkitPath
licenseLicense assigned to all Samples that will be loaded. If empty, the license will be read from dk_path.
pLegacyFormatEncounteredwill be set to true is any of the XML elements requires legacy format support and left untouched otherwise.
bSilentif set to true, all log messages except of errors and warnings are suppressed.
Returns
a new InstrumentList instance

Definition at line 70 of file InstrumentList.cpp.

◆ load_samples()

void load_samples ( float fBpm = 120)

Calls the Instrument::load_samples() member function of all Instruments in __instruments.

Definition at line 56 of file InstrumentList.cpp.

◆ move()

void move ( int idx_a,
int idx_b )

move an instrument from a position to another

Parameters
idx_athe start index
idx_bthe finish index

Definition at line 276 of file InstrumentList.cpp.

◆ operator!=()

bool operator!= ( std::shared_ptr< InstrumentList > pOther) const

Definition at line 151 of file InstrumentList.cpp.

◆ operator<<()

void operator<< ( std::shared_ptr< Instrument > instrument)

add an instrument to the list

Parameters
instrumenta pointer to the instrument to add

Definition at line 128 of file InstrumentList.cpp.

◆ operator==()

bool operator== ( std::shared_ptr< InstrumentList > pOther) const

Superficial comparison check.

If it succeeds, both objects are identical. If it fails, however, they are not guarantued to be not identical.

Definition at line 137 of file InstrumentList.cpp.

◆ operator[]()

std::shared_ptr< Instrument > operator[] ( int idx)

get an instrument from the list

Parameters
idxthe index to get the instrument from

Definition at line 183 of file InstrumentList.cpp.

◆ save_to()

void save_to ( XMLNode * node,
int component_id,
bool bRecentVersion = true,
bool bFull = false )

save the instrument list within the given XMLNode

Parameters
nodethe XMLNode to feed
component_idIdentifier of the corresponding component.
bRecentVersionWhether the drumkit format should be supported by Hydrogen 0.9.7 or higher (whether it should be composed of DrumkitComponents).
bFullWhether to write all parameters of the contained Sample as well. This will be done when storing an Instrument as part of a Song but not when storing as part of a Drumkit.

Definition at line 116 of file InstrumentList.cpp.

◆ set_default_midi_out_notes()

void set_default_midi_out_notes ( )

Set each instrument consecuteve MIDI out notes, starting from 36.

Definition at line 355 of file InstrumentList.cpp.

◆ size()

int size ( ) const
inline

returns the numbers of instruments

Definition at line 264 of file InstrumentList.h.

◆ summarizeContent()

std::vector< std::shared_ptr< InstrumentList::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 associated samples.

Definition at line 287 of file InstrumentList.cpp.

◆ swap()

void swap ( int idx_a,
int idx_b )

swap the instruments of two different indexes

Parameters
idx_athe first index
idx_bthe second index

Definition at line 265 of file InstrumentList.cpp.

◆ toQString()

QString toQString ( const QString & sPrefix = "",
bool bShort = true ) const
overridevirtual

Formatted string version for debugging purposes.

Parameters
sPrefixString prefix which will be added in front of every new line
bShortInstead of the whole content of all classes stored as members just a single unique identifier will be displayed without line breaks.
Returns
String presentation of current object.

Reimplemented from Base.

Definition at line 362 of file InstrumentList.cpp.

◆ unload_samples()

void unload_samples ( )

Calls the Instrument::unload_samples() member function of all Instruments in __instruments.

Definition at line 63 of file InstrumentList.cpp.

Field Documentation

◆ __instruments

std::vector<std::shared_ptr<Instrument> > __instruments
private

the list of instruments

Definition at line 259 of file InstrumentList.h.