Browse Source

Allow midi::Output::channel to be set to -1, which disables automatically setting outbound MIDI messages.

tags/v2.0.0
Andrew Belt 4 years ago
parent
commit
b4d66ae15f
2 changed files with 14 additions and 11 deletions
  1. +5
    -4
      include/midi.hpp
  2. +9
    -7
      src/midi.cpp

+ 5
- 4
include/midi.hpp View File

@@ -144,10 +144,11 @@ struct OutputDevice : Device {
////////////////////

struct Port {
/* For MIDI output, the channel to output messages.
For MIDI input, the channel to filter.
Set to -1 to allow all MIDI channels (for input).
Zero indexed.
/** For MIDI output, the channel to automatically set outbound messages.
If -1, the channel is not overwritten and must be set by MIDI generator.

For MIDI input, messages will be filtered by the channel.
If -1, all MIDI channels pass through.
*/
int channel = -1;



+ 9
- 7
src/midi.cpp View File

@@ -28,17 +28,19 @@ void InputDevice::unsubscribe(Input* input) {
}

void InputDevice::onMessage(const Message &message) {
// Set timestamp if unset
// Set timestamp to now if unset
Message msg = message;
if (msg.timestamp < 0)
msg.timestamp = system::getNanoseconds();

for (Input* input : subscribed) {
// We're probably in the MIDI driver's thread, so set the Rack context.
contextSet(input->context);
// Filter channel
if (input->channel < 0 || msg.getStatus() == 0xf || msg.getChannel() == input->channel) {
input->onMessage(msg);
}
// Filter channel if message is not a system MIDI message
if (msg.getStatus() != 0xf && input->channel >= 0 && msg.getChannel() != input->channel)
continue;
// Pass message to Input port
input->onMessage(msg);
}
}

@@ -223,9 +225,9 @@ void Output::sendMessage(const Message &message) {
if (!outputDevice)
return;

// Set channel
// Set channel if message is not a system MIDI message
Message msg = message;
if (msg.getStatus() != 0xf) {
if (msg.getStatus() != 0xf && channel >= 0) {
msg.setChannel(channel);
}
// DEBUG("sendMessage %02x %02x %02x", msg.cmd, msg.data1, msg.data2);


Loading…
Cancel
Save