diff options
author | JP Cimalando <jpcima@users.noreply.github.com> | 2018-07-03 18:50:49 +0200 |
---|---|---|
committer | JP Cimalando <jpcima@users.noreply.github.com> | 2018-07-03 19:49:00 +0200 |
commit | eecf8221aeac7097b971d585140850d45271e7a0 (patch) | |
tree | f34817c9d2878a89880d376a2ee5e68fae0cb7a5 | |
parent | 96960d1dd9ff21adfc4e5171f4a6ef4f2a3e57a6 (diff) | |
download | libADLMIDI-eecf8221aeac7097b971d585140850d45271e7a0.tar.gz libADLMIDI-eecf8221aeac7097b971d585140850d45271e7a0.tar.bz2 libADLMIDI-eecf8221aeac7097b971d585140850d45271e7a0.zip |
embedded bank loading API into multi-bank
-rw-r--r-- | include/adlmidi.h | 2 | ||||
-rw-r--r-- | src/adlmidi.cpp | 35 |
2 files changed, 35 insertions, 2 deletions
diff --git a/include/adlmidi.h b/include/adlmidi.h index a1289a0..348b15c 100644 --- a/include/adlmidi.h +++ b/include/adlmidi.h @@ -149,6 +149,8 @@ extern int adl_getNextBank(struct ADL_MIDIPlayer *device, ADL_Bank *bank); extern int adl_getInstrument(struct ADL_MIDIPlayer *device, const ADL_Bank *bank, unsigned index, ADL_Instrument *ins); /* Sets the nth intrument in the bank [0..127]. */ extern int adl_setInstrument(struct ADL_MIDIPlayer *device, ADL_Bank *bank, unsigned index, const ADL_Instrument *ins); +/* Loads the melodic or percussive part of the nth embedded bank. */ +extern int adl_loadEmbeddedBank(struct ADL_MIDIPlayer *device, ADL_Bank *bank, int num); #endif /* defined(ADLMIDI_UNSTABLE_API) */ /*Sets number of 4-operator channels between all chips. diff --git a/src/adlmidi.cpp b/src/adlmidi.cpp index 32872ef..6252df3 100644 --- a/src/adlmidi.cpp +++ b/src/adlmidi.cpp @@ -123,8 +123,8 @@ ADLMIDI_EXPORT int adl_setBank(ADL_MIDIPlayer *device, int bank) ADL_UNUSED(bank); MidiPlayer *play = GET_MIDI_PLAYER(device); play->setErrorString("This build of libADLMIDI has no embedded banks. " - "Please load bank by using of adl_openBankFile() or " - "adl_openBankData() functions instead of adl_setBank()"); + "Please load banks by using adl_openBankFile() or " + "adl_openBankData() functions instead of adl_setBank()."); return -1; #else const uint32_t NumBanks = static_cast<uint32_t>(maxAdlBanks()); @@ -304,6 +304,37 @@ ADLMIDI_EXPORT int adl_setInstrument(ADL_MIDIPlayer *device, ADL_Bank *bank, uns return 0; } +ADLMIDI_EXPORT int adl_loadEmbeddedBank(struct ADL_MIDIPlayer *device, ADL_Bank *bank, int num) +{ + if(!device) + return -1; + MidiPlayer *play = GET_MIDI_PLAYER(device); + if (!play) + return -1; + +#ifdef DISABLE_EMBEDDED_BANKS + ADL_UNUSED(bank); + ADL_UNUSED(num); + play->setErrorString("This build of libADLMIDI has no embedded banks. " + "Please load banks by using adl_openBankFile() or " + "adl_openBankData() functions instead of adl_loadEmbeddedBank()."); + return -1; +#else + if(num < 0 || num >= maxAdlBanks()) + return -1; + + OPL3::BankMap::iterator it = OPL3::BankMap::iterator::from_ptrs(bank->pointer); + size_t id = it->first; + + for (unsigned i = 0; i < 128; ++i) { + size_t insno = i + ((id & OPL3::PercussionTag) ? 128 : 0); + size_t adlmeta = ::banks[num][insno]; + it->second.ins[i] = adlinsdata2(::adlins[adlmeta]); + } + return 0; +#endif +} + ADLMIDI_EXPORT int adl_setNumFourOpsChn(ADL_MIDIPlayer *device, int ops4) { if(!device) |