From a4c146850c661f0e4cf12bd352383882a13702ad Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 15 Mar 2013 02:33:51 +0000 Subject: [PATCH] Implement MAP_PROGRAM_CHANGES on plugins; fix VST program changes --- source/backend/native/zynaddsubfx.cpp | 10 ++++++--- source/backend/plugin/DssiPlugin.cpp | 4 ++-- source/backend/plugin/FluidSynthPlugin.cpp | 4 ++-- source/backend/plugin/LinuxSamplerPlugin.cpp | 4 ++-- source/backend/plugin/NativePlugin.cpp | 4 ++-- source/backend/plugin/VstPlugin.cpp | 22 +++++--------------- 6 files changed, 20 insertions(+), 28 deletions(-) diff --git a/source/backend/native/zynaddsubfx.cpp b/source/backend/native/zynaddsubfx.cpp index 6981d2998..d5370bd89 100644 --- a/source/backend/native/zynaddsubfx.cpp +++ b/source/backend/native/zynaddsubfx.cpp @@ -174,14 +174,16 @@ protected: if (program >= BANK_SIZE) return; - const std::string bankdir(kMaster->bank.banks[bank].dir); + const std::string& bankdir(kMaster->bank.banks[bank].dir); if (! bankdir.empty()) { pthread_mutex_lock(&kMaster->mutex); kMaster->bank.loadbank(bankdir); - kMaster->bank.loadfromslot(program, kMaster->part[0]); + + for (int i=0; i < NUM_MIDI_PARTS; i++) + kMaster->bank.loadfromslot(program, kMaster->part[i]); pthread_mutex_unlock(&kMaster->mutex); } @@ -192,7 +194,9 @@ protected: void activate() { - kMaster->setController(0, MIDI_CONTROL_ALL_SOUND_OFF, 0); + // broken + //for (int i=0; i < NUM_MIDI_PARTS; i++) + // kMaster->setController(0, MIDI_CONTROL_ALL_SOUND_OFF, 0); } void process(float**, float** const outBuffer, const uint32_t frames, const uint32_t midiEventCount, const MidiEvent* const midiEvents) diff --git a/source/backend/plugin/DssiPlugin.cpp b/source/backend/plugin/DssiPlugin.cpp index 6497ac2bd..43796d1fc 100644 --- a/source/backend/plugin/DssiPlugin.cpp +++ b/source/backend/plugin/DssiPlugin.cpp @@ -1178,12 +1178,12 @@ public: } case kEngineControlEventTypeMidiBank: - if (event.channel == kData->ctrlChannel) + if (event.channel == kData->ctrlChannel && (fOptions & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0) nextBankId = ctrlEvent.param; break; case kEngineControlEventTypeMidiProgram: - if (event.channel == kData->ctrlChannel) + if (event.channel == kData->ctrlChannel && (fOptions & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0) { const uint32_t nextProgramId = ctrlEvent.param; diff --git a/source/backend/plugin/FluidSynthPlugin.cpp b/source/backend/plugin/FluidSynthPlugin.cpp index 388375ad6..9ba7ce180 100644 --- a/source/backend/plugin/FluidSynthPlugin.cpp +++ b/source/backend/plugin/FluidSynthPlugin.cpp @@ -1065,12 +1065,12 @@ public: } case kEngineControlEventTypeMidiBank: - if (event.channel < 16) + if (event.channel < 16 && (fOptions & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0) nextBankIds[event.channel] = ctrlEvent.param; break; case kEngineControlEventTypeMidiProgram: - if (event.channel < 16) + if (event.channel < 16 && (fOptions & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0) { const uint32_t bankId = nextBankIds[event.channel]; const uint32_t progId = ctrlEvent.param; diff --git a/source/backend/plugin/LinuxSamplerPlugin.cpp b/source/backend/plugin/LinuxSamplerPlugin.cpp index d372f398e..d1724ee28 100644 --- a/source/backend/plugin/LinuxSamplerPlugin.cpp +++ b/source/backend/plugin/LinuxSamplerPlugin.cpp @@ -656,12 +656,12 @@ public: } case kEngineControlEventTypeMidiBank: - if (event.channel == kData->ctrlChannel) + if (event.channel == kData->ctrlChannel && (fOptions & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0) nextBankId = ctrlEvent.param; break; case kEngineControlEventTypeMidiProgram: - if (event.channel == kData->ctrlChannel) + if (event.channel == kData->ctrlChannel && (fOptions & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0) { const uint32_t nextProgramId = ctrlEvent.param; diff --git a/source/backend/plugin/NativePlugin.cpp b/source/backend/plugin/NativePlugin.cpp index ba109d69e..dc62bd170 100644 --- a/source/backend/plugin/NativePlugin.cpp +++ b/source/backend/plugin/NativePlugin.cpp @@ -1347,12 +1347,12 @@ public: } case kEngineControlEventTypeMidiBank: - if (event.channel == kData->ctrlChannel) + if (event.channel == kData->ctrlChannel && (fOptions & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0) nextBankId = ctrlEvent.param; break; case kEngineControlEventTypeMidiProgram: - if (event.channel == kData->ctrlChannel) + if (event.channel == kData->ctrlChannel && (fOptions & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0) { const uint32_t nextProgramId = ctrlEvent.param; diff --git a/source/backend/plugin/VstPlugin.cpp b/source/backend/plugin/VstPlugin.cpp index 8fd461d88..81aa258ed 100644 --- a/source/backend/plugin/VstPlugin.cpp +++ b/source/backend/plugin/VstPlugin.cpp @@ -1070,10 +1070,6 @@ public: uint32_t startTime = 0; uint32_t timeOffset = 0; - uint32_t nextBankId = 0; - if (kData->midiprog.current >= 0 && kData->midiprog.count > 0) - nextBankId = kData->midiprog.data[kData->midiprog.current].bank; - for (i=0; i < nEvents; i++) { const EngineEvent& event = kData->event.portIn->getEvent(i); @@ -1095,7 +1091,6 @@ public: fMidiEventCount = 0; } - nextBankId = 0; timeOffset = time; } else @@ -1203,23 +1198,16 @@ public: } case kEngineControlEventTypeMidiBank: - if (event.channel == kData->ctrlChannel) - nextBankId = ctrlEvent.param; break; case kEngineControlEventTypeMidiProgram: - if (event.channel == kData->ctrlChannel) + if (event.channel == kData->ctrlChannel && (fOptions & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0) { - const uint32_t nextProgramId = ctrlEvent.param; - - for (k=0; k < kData->midiprog.count; k++) + if (ctrlEvent.param < kData->prog.count) { - if (kData->midiprog.data[k].bank == nextBankId && kData->midiprog.data[k].program == nextProgramId) - { - setMidiProgram(k, false, false, false); - postponeRtEvent(kPluginPostRtEventMidiProgramChange, k, 0, 0.0f); - break; - } + setProgram(ctrlEvent.param, false, false, false); + postponeRtEvent(kPluginPostRtEventMidiProgramChange, ctrlEvent.param, 0, 0.0f); + break; } } break;