From c5cebf0aeca2012bd9a3f60381a161b51b4e3aa3 Mon Sep 17 00:00:00 2001 From: Richie Date: Wed, 22 May 2024 15:06:32 +0100 Subject: [PATCH 1/3] fix for coremidi device index issues previously it was passing the pointer to i, which would be out of scope when events came in to ::read. We actually need to use the void * to hold the value of i, not a reference to i. Using reinterpret to overcome platform issues. NOTE : not tested as no suitable build environment here --- drivers/coremidi/midi_driver_coremidi.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/coremidi/midi_driver_coremidi.cpp b/drivers/coremidi/midi_driver_coremidi.cpp index 87fc7612f72c..f19743c038e5 100644 --- a/drivers/coremidi/midi_driver_coremidi.cpp +++ b/drivers/coremidi/midi_driver_coremidi.cpp @@ -39,9 +39,9 @@ void MIDIDriverCoreMidi::read(const MIDIPacketList *packet_list, void *read_proc_ref_con, void *src_conn_ref_con) { MIDIPacket *packet = const_cast(packet_list->packet); - int *device_index = static_cast(src_conn_ref_con); + intptr_t device_index = reinterpret_cast(src_conn_ref_con); for (UInt32 i = 0; i < packet_list->numPackets; i++) { - receive_input_packet(*device_index, packet->timeStamp, packet->data, packet->length); + receive_input_packet(device_index, packet->timeStamp, packet->data, packet->length); packet = MIDIPacketNext(packet); } } @@ -65,7 +65,7 @@ Error MIDIDriverCoreMidi::open() { for (int i = 0; i < sources; i++) { MIDIEndpointRef source = MIDIGetSource(i); if (source) { - MIDIPortConnectSource(port_in, source, static_cast(&i)); + MIDIPortConnectSource(port_in, source, reinterpret_cast(static_cast(i))); connected_sources.insert(i, source); } } From 1ce65162d83d0be9d6a555b78f2179aa55a4054b Mon Sep 17 00:00:00 2001 From: Richie Date: Wed, 22 May 2024 15:44:11 +0100 Subject: [PATCH 2/3] Update midi_driver_coremidi.cpp small tweak for possible loss of data warning --- drivers/coremidi/midi_driver_coremidi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/coremidi/midi_driver_coremidi.cpp b/drivers/coremidi/midi_driver_coremidi.cpp index f19743c038e5..07c59c7218d1 100644 --- a/drivers/coremidi/midi_driver_coremidi.cpp +++ b/drivers/coremidi/midi_driver_coremidi.cpp @@ -41,7 +41,7 @@ void MIDIDriverCoreMidi::read(const MIDIPacketList *packet_list, void *read_proc MIDIPacket *packet = const_cast(packet_list->packet); intptr_t device_index = reinterpret_cast(src_conn_ref_con); for (UInt32 i = 0; i < packet_list->numPackets; i++) { - receive_input_packet(device_index, packet->timeStamp, packet->data, packet->length); + receive_input_packet(static_cast(device_index), packet->timeStamp, packet->data, packet->length); packet = MIDIPacketNext(packet); } } From cbec5e85c0cb85f4dcfb7aa4e9290e56516f431a Mon Sep 17 00:00:00 2001 From: Richie Date: Wed, 22 May 2024 17:35:19 +0100 Subject: [PATCH 3/3] final tidy up remove casts from loop --- drivers/coremidi/midi_driver_coremidi.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/coremidi/midi_driver_coremidi.cpp b/drivers/coremidi/midi_driver_coremidi.cpp index 07c59c7218d1..030cdd75d8f4 100644 --- a/drivers/coremidi/midi_driver_coremidi.cpp +++ b/drivers/coremidi/midi_driver_coremidi.cpp @@ -39,9 +39,9 @@ void MIDIDriverCoreMidi::read(const MIDIPacketList *packet_list, void *read_proc_ref_con, void *src_conn_ref_con) { MIDIPacket *packet = const_cast(packet_list->packet); - intptr_t device_index = reinterpret_cast(src_conn_ref_con); + int device_index = static_cast(reinterpret_cast(src_conn_ref_con)); for (UInt32 i = 0; i < packet_list->numPackets; i++) { - receive_input_packet(static_cast(device_index), packet->timeStamp, packet->data, packet->length); + receive_input_packet(device_index, packet->timeStamp, packet->data, packet->length); packet = MIDIPacketNext(packet); } }