Add MIDI controller device index to InputEventMIDI.device property.
It is possible to query the OS for the connected MIDI controllers, but the event messages' device field was not being used. This implements controller index being sent in InputEventMIDI messages in the device property, matching the index from OS.get_connected_midi_inputs(). Based on the work done by @ramdor. Closes godotengine/godot-proposals#7733 Co-authored-by: Richie <richie_github@grange-lane.co.uk>
This commit is contained in:
@ -82,13 +82,13 @@ size_t MIDIDriverALSAMidi::msg_expected_data(uint8_t status_byte) {
|
||||
}
|
||||
|
||||
void MIDIDriverALSAMidi::InputConnection::parse_byte(uint8_t byte, MIDIDriverALSAMidi &driver,
|
||||
uint64_t timestamp) {
|
||||
uint64_t timestamp, int device_index) {
|
||||
switch (msg_category(byte)) {
|
||||
case MessageCategory::RealTime:
|
||||
// Real-Time messages are single byte messages that can
|
||||
// occur at any point.
|
||||
// We pass them straight through.
|
||||
driver.receive_input_packet(timestamp, &byte, 1);
|
||||
driver.receive_input_packet(device_index, timestamp, &byte, 1);
|
||||
break;
|
||||
|
||||
case MessageCategory::Data:
|
||||
@ -100,7 +100,7 @@ void MIDIDriverALSAMidi::InputConnection::parse_byte(uint8_t byte, MIDIDriverALS
|
||||
|
||||
// Forward a complete message and reset relevant state.
|
||||
if (received_data == expected_data) {
|
||||
driver.receive_input_packet(timestamp, buffer, received_data + 1);
|
||||
driver.receive_input_packet(device_index, timestamp, buffer, received_data + 1);
|
||||
received_data = 0;
|
||||
|
||||
if (msg_category(buffer[0]) != MessageCategory::Voice) {
|
||||
@ -130,13 +130,13 @@ void MIDIDriverALSAMidi::InputConnection::parse_byte(uint8_t byte, MIDIDriverALS
|
||||
expected_data = msg_expected_data(byte);
|
||||
skipping_sys_ex = false;
|
||||
if (expected_data == 0) {
|
||||
driver.receive_input_packet(timestamp, &byte, 1);
|
||||
driver.receive_input_packet(device_index, timestamp, &byte, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int MIDIDriverALSAMidi::InputConnection::read_in(MIDIDriverALSAMidi &driver, uint64_t timestamp) {
|
||||
int MIDIDriverALSAMidi::InputConnection::read_in(MIDIDriverALSAMidi &driver, uint64_t timestamp, int device_index) {
|
||||
int ret;
|
||||
do {
|
||||
uint8_t byte = 0;
|
||||
@ -147,7 +147,7 @@ int MIDIDriverALSAMidi::InputConnection::read_in(MIDIDriverALSAMidi &driver, uin
|
||||
ERR_PRINT("snd_rawmidi_read error: " + String(snd_strerror(ret)));
|
||||
}
|
||||
} else {
|
||||
parse_byte(byte, driver, timestamp);
|
||||
parse_byte(byte, driver, timestamp, device_index);
|
||||
}
|
||||
} while (ret > 0);
|
||||
|
||||
@ -165,7 +165,7 @@ void MIDIDriverALSAMidi::thread_func(void *p_udata) {
|
||||
size_t connection_count = md->connected_inputs.size();
|
||||
|
||||
for (size_t i = 0; i < connection_count; i++) {
|
||||
connections[i].read_in(*md, timestamp);
|
||||
connections[i].read_in(*md, timestamp, (int)i);
|
||||
}
|
||||
|
||||
md->unlock();
|
||||
|
||||
Reference in New Issue
Block a user