Browse Source

Deal with Bitwig buggy behaviour regarding MIDI notes

pull/321/merge
falkTX 2 years ago
parent
commit
3c4ad99a89
1 changed files with 26 additions and 2 deletions
  1. +26
    -2
      distrho/src/DistrhoPluginCLAP.cpp

+ 26
- 2
distrho/src/DistrhoPluginCLAP.cpp View File

@@ -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,);



Loading…
Cancel
Save