From c1d2d4b24e8a460b3de8d323929a81ca5c20ea0c Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 28 Apr 2013 06:12:23 +0100 Subject: [PATCH] Send 128 notes-off when OPTION_SEND_ALL_SOUND_OFF is off --- source/backend/plugin/DssiPlugin.cpp | 23 +++++--- source/backend/plugin/FluidSynthPlugin.cpp | 15 ++--- source/backend/plugin/LadspaPlugin.cpp | 4 +- source/backend/plugin/LinuxSamplerPlugin.cpp | 13 ++-- source/backend/plugin/Lv2Plugin.cpp | 62 ++++++++++++++++---- source/backend/plugin/NativePlugin.cpp | 24 +++++--- source/backend/plugin/VstPlugin.cpp | 16 +++-- source/utils/CarlaBridgeUtils.hpp | 15 ++--- 8 files changed, 122 insertions(+), 50 deletions(-) diff --git a/source/backend/plugin/DssiPlugin.cpp b/source/backend/plugin/DssiPlugin.cpp index ef73e3e88..0fb1c7731 100644 --- a/source/backend/plugin/DssiPlugin.cpp +++ b/source/backend/plugin/DssiPlugin.cpp @@ -419,8 +419,8 @@ public: clearBuffers(); - const float sampleRate = (float)kData->engine->getSampleRate(); - const uint32_t portCount = static_cast(fDescriptor->PortCount); + const float sampleRate(static_cast(kData->engine->getSampleRate())); + const uint32_t portCount(static_cast(fDescriptor->PortCount)); uint32_t aIns, aOuts, mIns, params, j; aIns = aOuts = mIns = params = 0; @@ -989,7 +989,6 @@ public: if (kData->needsReset) { - // TODO! if (fOptions & PLUGIN_OPTION_SEND_ALL_SOUND_OFF) { for (unsigned char j=0, l=MAX_MIDI_CHANNELS; j < MAX_MIDI_CHANNELS; ++j) @@ -999,17 +998,27 @@ public: fMidiEvents[j].type = SND_SEQ_EVENT_CONTROLLER; fMidiEvents[j].data.control.channel = j; - fMidiEvents[j].data.control.param = MIDI_CONTROL_ALL_SOUND_OFF; + fMidiEvents[j].data.control.param = MIDI_CONTROL_ALL_NOTES_OFF; fMidiEvents[j+l].type = SND_SEQ_EVENT_CONTROLLER; fMidiEvents[j+l].data.control.channel = j; - fMidiEvents[j+l].data.control.param = MIDI_CONTROL_ALL_NOTES_OFF; + fMidiEvents[j+l].data.control.param = MIDI_CONTROL_ALL_SOUND_OFF; } midiEventCount = MAX_MIDI_CHANNELS*2; } - else + else if (kData->ctrlChannel >= 0 && kData->ctrlChannel < MAX_MIDI_CHANNELS) { + for (unsigned char j=0; j < MAX_MIDI_NOTE; ++j) + { + carla_zeroStruct(fMidiEvents[j]); + + fMidiEvents[j].type = SND_SEQ_EVENT_NOTEOFF; + fMidiEvents[j].data.note.channel = kData->ctrlChannel; + fMidiEvents[j].data.note.note = j; + } + + midiEventCount = MAX_MIDI_NOTE; } if (kData->latency > 0) @@ -1219,8 +1228,8 @@ public: { if (! allNotesOffSent) { - sendMidiAllNotesOffToCallback(); allNotesOffSent = true; + sendMidiAllNotesOffToCallback(); } postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_ACTIVE, 0, 0.0f); diff --git a/source/backend/plugin/FluidSynthPlugin.cpp b/source/backend/plugin/FluidSynthPlugin.cpp index 3a4d93369..99f25d411 100644 --- a/source/backend/plugin/FluidSynthPlugin.cpp +++ b/source/backend/plugin/FluidSynthPlugin.cpp @@ -923,22 +923,23 @@ public: if (kData->needsReset) { - // TODO if (fOptions & PLUGIN_OPTION_SEND_ALL_SOUND_OFF) { - for (int c=0; c < MAX_MIDI_CHANNELS; c++) + for (int c=0; c < MAX_MIDI_CHANNELS; ++c) { #ifdef FLUIDSYNTH_VERSION_NEW_API fluid_synth_all_notes_off(fSynth, c); fluid_synth_all_sounds_off(fSynth, c); #else - fluid_synth_cc(f_synth, c, MIDI_CONTROL_ALL_SOUND_OFF, 0); - fluid_synth_cc(f_synth, c, MIDI_CONTROL_ALL_NOTES_OFF, 0); + fluid_synth_cc(fSynth, c, MIDI_CONTROL_ALL_SOUND_OFF, 0); + fluid_synth_cc(fSynth, c, MIDI_CONTROL_ALL_NOTES_OFF, 0); #endif } } - else + else if (kData->ctrlChannel >= 0 && kData->ctrlChannel < MAX_MIDI_CHANNELS) { + for (k=0; k < MAX_MIDI_NOTE; ++k) + fluid_synth_noteoff(fSynth, kData->ctrlChannel, k); } kData->needsReset = false; @@ -1140,8 +1141,8 @@ public: { if (! allNotesOffSent) { - sendMidiAllNotesOffToCallback(); allNotesOffSent = true; + sendMidiAllNotesOffToCallback(); } postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_ACTIVE, 0, 0.0f); @@ -1163,8 +1164,8 @@ public: { if (! allNotesOffSent) { - sendMidiAllNotesOffToCallback(); allNotesOffSent = true; + sendMidiAllNotesOffToCallback(); } if (fOptions & PLUGIN_OPTION_SEND_ALL_SOUND_OFF) diff --git a/source/backend/plugin/LadspaPlugin.cpp b/source/backend/plugin/LadspaPlugin.cpp index a2a7f13a9..c72971985 100644 --- a/source/backend/plugin/LadspaPlugin.cpp +++ b/source/backend/plugin/LadspaPlugin.cpp @@ -411,8 +411,8 @@ public: clearBuffers(); - const float sampleRate = (float)kData->engine->getSampleRate(); - const uint32_t portCount = static_cast(fDescriptor->PortCount); + const float sampleRate(static_cast(kData->engine->getSampleRate())); + const uint32_t portCount(static_cast(fDescriptor->PortCount)); uint32_t aIns, aOuts, params, j; aIns = aOuts = params = 0; diff --git a/source/backend/plugin/LinuxSamplerPlugin.cpp b/source/backend/plugin/LinuxSamplerPlugin.cpp index 39b79cde4..66ff5b38d 100644 --- a/source/backend/plugin/LinuxSamplerPlugin.cpp +++ b/source/backend/plugin/LinuxSamplerPlugin.cpp @@ -522,17 +522,18 @@ public: if (kData->needsReset) { - // TODO if (fOptions & PLUGIN_OPTION_SEND_ALL_SOUND_OFF) { for (k=0, i=MAX_MIDI_CHANNELS; k < MAX_MIDI_CHANNELS; ++k) { - fMidiInputPort->DispatchControlChange(MIDI_CONTROL_ALL_SOUND_OFF, 0, k, 0); - fMidiInputPort->DispatchControlChange(MIDI_CONTROL_ALL_NOTES_OFF, 0, k, 0); + fMidiInputPort->DispatchControlChange(MIDI_CONTROL_ALL_NOTES_OFF, 0, k); + fMidiInputPort->DispatchControlChange(MIDI_CONTROL_ALL_SOUND_OFF, 0, k); } } - else + else if (kData->ctrlChannel >= 0 && kData->ctrlChannel < MAX_MIDI_CHANNELS) { + for (k=0; k < MAX_MIDI_NOTE; ++k) + fMidiInputPort->DispatchNoteOff(k, 0, kData->ctrlChannel); } kData->needsReset = false; @@ -733,8 +734,8 @@ public: { if (! allNotesOffSent) { - sendMidiAllNotesOffToCallback(); allNotesOffSent = true; + sendMidiAllNotesOffToCallback(); } postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_ACTIVE, 0, 0.0f); @@ -750,8 +751,8 @@ public: { if (! allNotesOffSent) { - sendMidiAllNotesOffToCallback(); allNotesOffSent = true; + sendMidiAllNotesOffToCallback(); } } diff --git a/source/backend/plugin/Lv2Plugin.cpp b/source/backend/plugin/Lv2Plugin.cpp index 1ff9a79e5..e8a11ec47 100644 --- a/source/backend/plugin/Lv2Plugin.cpp +++ b/source/backend/plugin/Lv2Plugin.cpp @@ -1262,8 +1262,8 @@ public: clearBuffers(); - const float sampleRate = (float)kData->engine->getSampleRate(); - const uint32_t portCount = fRdfDescriptor->PortCount; + const float sampleRate(static_cast(kData->engine->getSampleRate())); + const uint32_t portCount(static_cast(fRdfDescriptor->PortCount)); uint32_t aIns, aOuts, cvIns, cvOuts, params, j; aIns = aOuts = cvIns = cvOuts = params = 0; @@ -2278,15 +2278,57 @@ public: if (kData->needsReset) { - // TODO! - if (fOptions & PLUGIN_OPTION_SEND_ALL_SOUND_OFF) + k = fEventsIn.ctrlIndex; + uint8_t midiData[3] = { 0 }; + + if (fEventsIn.ctrl->type & CARLA_EVENT_TYPE_MIDI) { - //for (unsigned char j=0, l=MAX_MIDI_CHANNELS; j < MAX_MIDI_CHANNELS; ++j) + if (fOptions & PLUGIN_OPTION_SEND_ALL_SOUND_OFF) { + for (k=0, i=MAX_MIDI_CHANNELS; k < MAX_MIDI_CHANNELS; ++k) + { + midiData[0] = MIDI_STATUS_CONTROL_CHANGE + k; + midiData[1] = MIDI_CONTROL_ALL_NOTES_OFF; + + if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_ATOM) + lv2_atom_buffer_write(&evInAtomIters[k], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); + + else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_EVENT) + lv2_event_write(&evInEventIters[k], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); + + else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_MIDI_LL) + lv2midi_put_event(&evInMidiStates[k], 0, 3, midiData); + + midiData[0] = MIDI_STATUS_CONTROL_CHANGE + k; + midiData[1] = MIDI_CONTROL_ALL_SOUND_OFF; + + if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_ATOM) + lv2_atom_buffer_write(&evInAtomIters[k], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); + + else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_EVENT) + lv2_event_write(&evInEventIters[k], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); + + else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_MIDI_LL) + lv2midi_put_event(&evInMidiStates[k], 0, 3, midiData); + } + } + else if (kData->ctrlChannel >= 0 && kData->ctrlChannel < MAX_MIDI_CHANNELS) + { + for (k=0; k < MAX_MIDI_NOTE; ++k) + { + midiData[0] = MIDI_STATUS_NOTE_OFF + kData->ctrlChannel; + midiData[1] = k; + + if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_ATOM) + lv2_atom_buffer_write(&evInAtomIters[k], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); + + else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_EVENT) + lv2_event_write(&evInEventIters[k], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); + + else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_MIDI_LL) + lv2midi_put_event(&evInMidiStates[k], 0, 3, midiData); + } } - } - else - { } if (kData->latency > 0) @@ -2487,7 +2529,7 @@ public: CARLA_ASSERT(note.channel >= 0 && note.channel < MAX_MIDI_CHANNELS); - uint8_t midiEvent[3] = { 0 }; + uint8_t midiEvent[3]; midiEvent[0] = (note.velo > 0) ? MIDI_STATUS_NOTE_ON : MIDI_STATUS_NOTE_OFF; midiEvent[0] += note.channel; midiEvent[1] = note.note; @@ -2700,8 +2742,8 @@ public: { if (! allNotesOffSent) { - sendMidiAllNotesOffToCallback(); allNotesOffSent = true; + sendMidiAllNotesOffToCallback(); } postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_ACTIVE, 0, 0.0f); diff --git a/source/backend/plugin/NativePlugin.cpp b/source/backend/plugin/NativePlugin.cpp index 19bc00da4..584db3750 100644 --- a/source/backend/plugin/NativePlugin.cpp +++ b/source/backend/plugin/NativePlugin.cpp @@ -1193,24 +1193,34 @@ public: if (kData->needsReset) { - // TODO! if (fOptions & PLUGIN_OPTION_SEND_ALL_SOUND_OFF) { for (k=0, i=MAX_MIDI_CHANNELS; k < MAX_MIDI_CHANNELS; ++k) { fMidiEvents[k].data[0] = MIDI_STATUS_CONTROL_CHANGE + k; - fMidiEvents[k].data[1] = MIDI_CONTROL_ALL_SOUND_OFF; - fMidiEvents[k].size = 2; + fMidiEvents[k].data[1] = MIDI_CONTROL_ALL_NOTES_OFF; + fMidiEvents[k].data[2] = 0; + fMidiEvents[k].size = 3; fMidiEvents[k+i].data[0] = MIDI_STATUS_CONTROL_CHANGE + k; - fMidiEvents[k+i].data[1] = MIDI_CONTROL_ALL_NOTES_OFF; - fMidiEvents[k+i].size = 2; + fMidiEvents[k+i].data[1] = MIDI_CONTROL_ALL_SOUND_OFF; + fMidiEvents[k+i].data[2] = 0; + fMidiEvents[k+i].size = 3; } fMidiEventCount = MAX_MIDI_CHANNELS*2; } - else + else if (kData->ctrlChannel >= 0 && kData->ctrlChannel < MAX_MIDI_CHANNELS) { + for (k=0; k < MAX_MIDI_NOTE; ++k) + { + fMidiEvents[k].data[0] = MIDI_STATUS_NOTE_OFF + kData->ctrlChannel; + fMidiEvents[k].data[1] = k; + fMidiEvents[k].data[2] = 0; + fMidiEvents[k].size = 3; + } + + fMidiEventCount = MAX_MIDI_NOTE; } kData->needsReset = false; @@ -1452,8 +1462,8 @@ public: { if (! allNotesOffSent) { - sendMidiAllNotesOffToCallback(); allNotesOffSent = true; + sendMidiAllNotesOffToCallback(); } postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_ACTIVE, 0, 0.0f); diff --git a/source/backend/plugin/VstPlugin.cpp b/source/backend/plugin/VstPlugin.cpp index 2621f5435..1a2f8bb1c 100644 --- a/source/backend/plugin/VstPlugin.cpp +++ b/source/backend/plugin/VstPlugin.cpp @@ -1004,7 +1004,6 @@ public: if (kData->needsReset) { - // TODO! if (fOptions & PLUGIN_OPTION_SEND_ALL_SOUND_OFF) { for (k=0, i=MAX_MIDI_CHANNELS; k < MAX_MIDI_CHANNELS; ++k) @@ -1012,7 +1011,7 @@ public: fMidiEvents[k].type = kVstMidiType; fMidiEvents[k].byteSize = sizeof(VstMidiEvent); fMidiEvents[k].midiData[0] = MIDI_STATUS_CONTROL_CHANGE + k; - fMidiEvents[k].midiData[1] = MIDI_CONTROL_ALL_SOUND_OFF; + fMidiEvents[k].midiData[1] = MIDI_CONTROL_ALL_NOTES_OFF; fMidiEvents[k+i].type = kVstMidiType; fMidiEvents[k+i].byteSize = sizeof(VstMidiEvent); @@ -1022,8 +1021,17 @@ public: fMidiEventCount = MAX_MIDI_CHANNELS*2; } - else + else if (kData->ctrlChannel >= 0 && kData->ctrlChannel < MAX_MIDI_CHANNELS) { + for (k=0; k < MAX_MIDI_NOTE; ++k) + { + fMidiEvents[k].type = kVstMidiType; + fMidiEvents[k].byteSize = sizeof(VstMidiEvent); + fMidiEvents[k].midiData[0] = MIDI_STATUS_NOTE_OFF + kData->ctrlChannel; + fMidiEvents[k].midiData[1] = k; + } + + fMidiEventCount = MAX_MIDI_NOTE; } if (kData->latency > 0) @@ -1287,8 +1295,8 @@ public: { if (! allNotesOffSent) { - sendMidiAllNotesOffToCallback(); allNotesOffSent = true; + sendMidiAllNotesOffToCallback(); } postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_ACTIVE, 0, 0.0f); diff --git a/source/utils/CarlaBridgeUtils.hpp b/source/utils/CarlaBridgeUtils.hpp index eb6aacd23..0b0333ea0 100644 --- a/source/utils/CarlaBridgeUtils.hpp +++ b/source/utils/CarlaBridgeUtils.hpp @@ -54,13 +54,14 @@ enum PluginBridgeInfoType { enum PluginBridgeOpcode { kPluginBridgeOpcodeNull = 0, kPluginBridgeOpcodeReadyWait = 1, - kPluginBridgeOpcodeSetBufferSize = 2, - kPluginBridgeOpcodeSetSampleRate = 3, - kPluginBridgeOpcodeSetParameter = 4, - kPluginBridgeOpcodeSetProgram = 5, - kPluginBridgeOpcodeSetMidiProgram = 6, - kPluginBridgeOpcodeProcess = 7, - kPluginBridgeOpcodeQuit = 8 + kPluginBridgeOpcodeSetBufferSize = 2, // int + kPluginBridgeOpcodeSetSampleRate = 3, // float + kPluginBridgeOpcodeSetParameter = 4, // int, float + kPluginBridgeOpcodeSetProgram = 5, // int + kPluginBridgeOpcodeSetMidiProgram = 6, // int + kPluginBridgeOpcodeMidiEvent = 7, // int, char, ... (int = size, max 4) + kPluginBridgeOpcodeProcess = 8, + kPluginBridgeOpcodeQuit = 9 }; /*!