Skip to content

Commit

Permalink
Use "MIDI 2.0" checkbox for toggling MIDIEventList vs MIDIPacketList …
Browse files Browse the repository at this point in the history
…code paths.
  • Loading branch information
SolfaMode committed Sep 29, 2024
1 parent 9405a78 commit 34a5517
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/framework/midi/internal/platform/osx/coremidioutport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,27 +307,32 @@ Ret CoreMidiOutPort::sendEvent(const Event& e)
OSStatus result;
MIDITimeStamp timeStamp = AudioGetCurrentHostTime();

if (__builtin_available(macOS 11.0, *)) {
MIDIProtocolID protocolId = kMIDIProtocol_2_0; // configuration()->useMIDI20Output() ? m_core->destinationProtocolId : kMIDIProtocol_1_0;
// Note: there could be three cases: MIDI2+MIDIEventList, MIDI1+MIDIEventList, MIDI1+MIDIPacketList.
// But we only maintain 2 code paths and may drop configuration()->useMIDI20Output() and MIDIPacketList later.

ByteCount wordCount = e.midi20WordCount();
if (wordCount == 0) {
LOG_MIDI_W() << "Failed to send message for event: " << e.to_string();
return make_ret(Err::MidiSendError, "failed send message. unknown word count");
}
LOG_MIDI_D() << "Sending MIDIEventList event: " << e.to_string();
if (supportsMIDI20Output() && configuration()->useMIDI20Output()) {
if (__builtin_available(macOS 11.0, *)) {
MIDIProtocolID protocolId = kMIDIProtocol_2_0;

MIDIEventList eventList;
MIDIEventPacket* packet = MIDIEventListInit(&eventList, protocolId);
ByteCount wordCount = e.midi20WordCount();
if (wordCount == 0) {
LOG_MIDI_W() << "Failed to send message for event: " << e.to_string();
return make_ret(Err::MidiSendError, "failed send message. unknown word count");
}
LOG_MIDI_D() << "Sending MIDIEventList event: " << e.to_string();

if (e.messageType() == Event::MessageType::ChannelVoice20 && e.opcode() == muse::midi::Event::Opcode::NoteOn
&& e.velocity() < 128) {
LOG_MIDI_W() << "Detected low MIDI 2.0 ChannelVoiceMessage velocity.";
}
MIDIEventList eventList;
MIDIEventPacket* packet = MIDIEventListInit(&eventList, protocolId);

MIDIEventListAdd(&eventList, sizeof(eventList), packet, timeStamp, wordCount, e.rawData());
if (e.messageType() == Event::MessageType::ChannelVoice20 && e.opcode() == muse::midi::Event::Opcode::NoteOn
&& e.velocity() < 128) {
LOG_MIDI_W() << "Detected low MIDI 2.0 ChannelVoiceMessage velocity.";
}

MIDIEventListAdd(&eventList, sizeof(eventList), packet, timeStamp, wordCount, e.rawData());

result = MIDISendEventList(m_core->outputPort, m_core->destinationId, &eventList);
result = MIDISendEventList(m_core->outputPort, m_core->destinationId, &eventList);
}
} else {
const std::vector<Event> events = e.toMIDI10();

Expand Down

0 comments on commit 34a5517

Please sign in to comment.