diff --git a/source/backend/engine/CarlaEngineJack.cpp b/source/backend/engine/CarlaEngineJack.cpp index 53d06d608..0f0ee6f7f 100644 --- a/source/backend/engine/CarlaEngineJack.cpp +++ b/source/backend/engine/CarlaEngineJack.cpp @@ -1275,6 +1275,8 @@ protected: if (MIDI_IS_STATUS_CONTROL_CHANGE(midiStatus)) { + CARLA_ASSERT(jackEvent.size == 2 || jackEvent.size == 3); + const uint8_t midiControl = jackEvent.buffer[1]; engineEvent->type = kEngineEventTypeControl; @@ -1300,6 +1302,8 @@ protected: } else { + CARLA_ASSERT(jackEvent.size == 3); + const uint8_t midiValue = jackEvent.buffer[2]; engineEvent->ctrl.type = kEngineControlEventTypeParameter; @@ -1309,6 +1313,8 @@ protected: } else if (MIDI_IS_STATUS_PROGRAM_CHANGE(midiStatus)) { + CARLA_ASSERT(jackEvent.size == 2); + const uint8_t midiProgram = jackEvent.buffer[1]; engineEvent->type = kEngineEventTypeControl; @@ -1320,10 +1326,11 @@ protected: { engineEvent->type = kEngineEventTypeMidi; - carla_copy(engineEvent->midi.data, jackEvent.buffer, jackEvent.size); - engineEvent->midi.data[0] = midiStatus; engineEvent->midi.size = static_cast(jackEvent.size); + + if (jackEvent.size > 1) + carla_copy(engineEvent->midi.data+1, jackEvent.buffer+1, jackEvent.size-1); } if (engineEventIndex >= INTERNAL_EVENT_COUNT) @@ -1539,7 +1546,7 @@ protected: PortNameToId portNameId(groupId, portId, portName, fullPortName); fUsedPortNames.removeOne(portNameId); - callback(CALLBACK_PATCHBAY_PORT_REMOVED, 0, portId, 0, 0.0f, nullptr); + callback(CALLBACK_PATCHBAY_PORT_REMOVED, 0, portId, 0, 0.0f, fullPortName); } } diff --git a/source/backend/plugin/Lv2Plugin.cpp b/source/backend/plugin/Lv2Plugin.cpp index 3adde331f..8052269b6 100644 --- a/source/backend/plugin/Lv2Plugin.cpp +++ b/source/backend/plugin/Lv2Plugin.cpp @@ -2782,6 +2782,23 @@ public: postponeRtEvent(kPluginPostRtEventParameterChange, static_cast(k), 0, value); } + if ((fOptions & PLUGIN_OPTION_SEND_CONTROL_CHANGES) != 0 && ctrlEvent.param <= 0x5F) + { + uint8_t midiData[3]; + midiData[0] = MIDI_STATUS_CONTROL_CHANGE + i; + midiData[1] = ctrlEvent.param; + midiData[2] = ctrlEvent.value*127.0f; + + if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_ATOM) + lv2_atom_buffer_write(&evInAtomIters[fEventsIn.ctrlIndex], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); + + else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_EVENT) + lv2_event_write(&evInEventIters[fEventsIn.ctrlIndex], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); + + else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_MIDI_LL) + lv2midi_put_event(&evInMidiStates[fEventsIn.ctrlIndex], 0, 3, midiData); + } + break; } @@ -2810,19 +2827,21 @@ public: case kEngineControlEventTypeAllSoundOff: if (fOptions & PLUGIN_OPTION_SEND_ALL_SOUND_OFF) { + const uint32_t mtime(sampleAccurate ? startTime : time); + uint8_t midiData[3]; midiData[0] = MIDI_STATUS_CONTROL_CHANGE + i; midiData[1] = MIDI_CONTROL_ALL_SOUND_OFF; midiData[2] = 0; if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_ATOM) - lv2_atom_buffer_write(&evInAtomIters[fEventsIn.ctrlIndex], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); + lv2_atom_buffer_write(&evInAtomIters[fEventsIn.ctrlIndex], mtime, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_EVENT) - lv2_event_write(&evInEventIters[fEventsIn.ctrlIndex], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); + lv2_event_write(&evInEventIters[fEventsIn.ctrlIndex], mtime, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_MIDI_LL) - lv2midi_put_event(&evInMidiStates[fEventsIn.ctrlIndex], 0, 3, midiData); + lv2midi_put_event(&evInMidiStates[fEventsIn.ctrlIndex], mtime, 3, midiData); } break; @@ -2835,19 +2854,21 @@ public: sendMidiAllNotesOffToCallback(); } + const uint32_t mtime(sampleAccurate ? startTime : time); + uint8_t midiData[3]; midiData[0] = MIDI_STATUS_CONTROL_CHANGE + i; midiData[1] = MIDI_CONTROL_ALL_NOTES_OFF; midiData[2] = 0; if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_ATOM) - lv2_atom_buffer_write(&evInAtomIters[fEventsIn.ctrlIndex], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); + lv2_atom_buffer_write(&evInAtomIters[fEventsIn.ctrlIndex], mtime, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_EVENT) - lv2_event_write(&evInEventIters[fEventsIn.ctrlIndex], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); + lv2_event_write(&evInEventIters[fEventsIn.ctrlIndex], mtime, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_MIDI_LL) - lv2midi_put_event(&evInMidiStates[fEventsIn.ctrlIndex], 0, 3, midiData); + lv2midi_put_event(&evInMidiStates[fEventsIn.ctrlIndex], mtime, 3, midiData); } break; }