commit 3c4ad99a891f0595c5fe9d1e552d81bf1277c38f
parent ac803f5991e1adac6581658a346250d4246e59b6
Author: falkTX <falktx@falktx.com>
Date: Mon, 19 Sep 2022 10:04:57 +0100
Deal with Bitwig buggy behaviour regarding MIDI notes
Diffstat:
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/distrho/src/DistrhoPluginCLAP.cpp b/distrho/src/DistrhoPluginCLAP.cpp
@@ -870,11 +870,20 @@ public:
{
const clap_event_header_t* const event = inputEvents->get(inputEvents, i);
- // event->time
switch (event->type)
{
case CLAP_EVENT_NOTE_ON:
+ #if DISTRHO_PLUGIN_WANT_MIDI_INPUT
+ // BUG: even though we only report CLAP_NOTE_DIALECT_MIDI as supported, Bitwig sends us this anyway
+ addNoteEvent(static_cast<const clap_event_note_t*>(static_cast<const void*>(event)), true);
+ #endif
+ break;
case CLAP_EVENT_NOTE_OFF:
+ #if DISTRHO_PLUGIN_WANT_MIDI_INPUT
+ // BUG: even though we only report CLAP_NOTE_DIALECT_MIDI as supported, Bitwig sends us this anyway
+ addNoteEvent(static_cast<const clap_event_note_t*>(static_cast<const void*>(event)), false);
+ #endif
+ break;
case CLAP_EVENT_NOTE_CHOKE:
case CLAP_EVENT_NOTE_END:
case CLAP_EVENT_NOTE_EXPRESSION:
@@ -1126,7 +1135,22 @@ public:
// ----------------------------------------------------------------------------------------------------------------
#if DISTRHO_PLUGIN_WANT_MIDI_INPUT
- void addMidiEvent(const clap_event_midi_t* const event)
+ void addNoteEvent(const clap_event_note_t* const event, const bool isOn) noexcept
+ {
+ DISTRHO_SAFE_ASSERT_UINT_RETURN(event->port_index == 0, event->port_index,);
+
+ if (fMidiEventCount == kMaxMidiEvents)
+ return;
+
+ MidiEvent& midiEvent(fMidiEvents[fMidiEventCount++]);
+ midiEvent.frame = event->header.time;
+ midiEvent.size = 3;
+ midiEvent.data[0] = (isOn ? 0x90 : 0x80) | (event->channel & 0x0F);
+ midiEvent.data[1] = std::max(0, std::min(127, static_cast<int>(event->key)));
+ midiEvent.data[2] = std::max(0, std::min(127, static_cast<int>(event->velocity * 127 + 0.5)));
+ }
+
+ void addMidiEvent(const clap_event_midi_t* const event) noexcept
{
DISTRHO_SAFE_ASSERT_UINT_RETURN(event->port_index == 0, event->port_index,);