46 for (
int i=0; i<other->size(); i++ ) {
47 ( *this ) << ( std::make_shared<Instrument>( ( *other )[i] ) );
71 XMLNode instrumentListNode = pNode->firstChildElement(
"instrumentList" );
72 if ( instrumentListNode.isNull() ) {
73 ERRORLOG(
"'instrumentList' node not found. Unable to load instrument list." );
77 auto pInstrumentList = std::make_shared<InstrumentList>();
78 XMLNode instrumentNode = instrumentListNode.firstChildElement(
"instrument" );
80 while ( !instrumentNode.isNull() ) {
83 ERRORLOG( QString(
"instrument nCount >= %1 (MAX_INSTRUMENTS), stop reading instruments" )
92 if ( pInstrument !=
nullptr ) {
93 ( *pInstrumentList ) << pInstrument;
96 ERRORLOG( QString(
"Unable to load instrument [%1]. The drumkit is corrupted. Skipping instrument" )
100 instrumentNode = instrumentNode.nextSiblingElement(
"instrument" );
104 ERRORLOG(
"Newly created instrument list does not contain any instruments. Aborting." );
108 return pInstrumentList;
115 assert( pInstrument );
116 assert( pInstrument->get_adsr() );
117 if ( pInstrument !=
nullptr && pInstrument->get_adsr() !=
nullptr ) {
118 pInstrument->save_to( &instruments_node, component_id, bRecentVersion, bFull );
133 if ( pOther !=
nullptr &&
size() == pOther->size() ) {
134 for (
int ii = 0; ii <
size(); ++ii ) {
135 if (
get( ii ).get() != pOther->get( ii ).get() ) {
147 if ( pOther !=
nullptr &&
size() == pOther->size() ) {
148 for (
int ii = 0; ii <
size(); ++ii ) {
149 if (
get( ii ).get() != pOther->get( ii ).get() ) {
181 ERRORLOG( QString(
"idx %1 out of [0;%2]" ).arg( idx ).arg(
size() ) );
202 ERRORLOG( QString(
"idx %1 out of [0;%2]" ).arg( idx ).arg(
size() ) );
264 if( idx_a == idx_b )
return;
275 if( idx_a == idx_b )
return;
282std::vector<std::shared_ptr<InstrumentList::Content>>
InstrumentList::summarizeContent(
const std::shared_ptr<std::vector<std::shared_ptr<DrumkitComponent>>> pDrumkitComponents )
const {
283 std::vector<std::shared_ptr<InstrumentList::Content>> results;
286 if ( ppInstrument !=
nullptr ) {
287 for (
const auto& ppInstrumentComponent : *ppInstrument->get_components() ) {
288 if ( ppInstrumentComponent !=
nullptr ) {
289 for (
const auto& ppInstrumentLayer : *ppInstrumentComponent ) {
290 if ( ppInstrumentLayer !=
nullptr ) {
291 auto pSample = ppInstrumentLayer->get_sample();
292 if ( pSample !=
nullptr ) {
296 QString sComponentName;
297 for (
const auto& ppDrumkitComponent : *pDrumkitComponents ) {
298 if ( ppInstrumentComponent->get_drumkit_componentID() ==
299 ppDrumkitComponent->get_id() ) {
301 sComponentName = ppDrumkitComponent->get_name();
307 sComponentName = pDrumkitComponents->front()->get_name();
310 results.push_back( std::make_shared<Content>(
311 ppInstrument->get_name(),
313 pSample->get_filename(),
314 pSample->get_filepath(),
315 pSample->getLicense()
331 WARNINGLOG(
"Same MIDI note assigned to every instrument. Assigning default values." );
345 notes.insert( instr->get_midi_out_note() );
347 return notes.size() == 1;
361 sOutput = QString(
"%1[InstrumentList]\n" ).arg( sPrefix );
363 if ( ii !=
nullptr ) {
364 sOutput.append( QString(
"%1" ).arg( ii->toQString( sPrefix + s, bShort ) ) );
368 sOutput = QString(
"[InstrumentList] " );
370 if ( ii !=
nullptr ) {
371 sOutput.append( QString(
"(%1: %2) " ).arg( ii->get_id() )
372 .arg( ii->get_name() ) );
394 sOutput = QString(
"\n" ).arg( sPrefix )
395 .append( QString(
"%1%2m_sInstrumentName: %3\n" ).arg( sPrefix ).arg( s ).arg(
m_sInstrumentName ) )
396 .append( QString(
"%1%2m_sComponentName: %3\n" ).arg( sPrefix ).arg( s ).arg(
m_sComponentName ) )
397 .append( QString(
"%1%2m_sSampleName: %3\n" ).arg( sPrefix ).arg( s ).arg(
m_sSampleName ) )
398 .append( QString(
"%1%2m_sFullSamplePath: %3\n" ).arg( sPrefix ).arg( s ).arg(
m_sFullSamplePath ) )
399 .append( QString(
"%1%2m_license: %3\n" ).arg(
m_license.
toQString( sPrefix + s, bShort ) ) );
403 .append( QString(
", m_sSampleName: %1\n" ).arg(
m_sSampleName ) )
415 if ( pInstrument->is_soloed() ) {
static QString sPrintIndention
String used to format the debugging string output of some core classes.
InstrumentList()
constructor
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
~InstrumentList()
destructor
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
void load_from(const QString &drumkit_path, const QString &instrument_name)
loads instrument from a given instrument within a given drumkit into a live Instrument object.
Wrapper class to help Hydrogen deal with the license information specified in a drumkit.
QString toQString(const QString &sPrefix="", bool bShort=true) const override
Formatted string version for debugging purposes.
XMLNode is a subclass of QDomNode with read and write values methods.
XMLNode createNode(const QString &name)
create a new XMLNode that has to be appended into de XMLDoc
#define MAX_INSTRUMENTS
Maximum number of instruments allowed in Hydrogen.
QString toQString(const QString &sPrefix="", bool bShort=true) const
QString m_sInstrumentName
QString m_sFullSamplePath