From 1447c9e6acfdc58472dba738e919f88de6beb93f Mon Sep 17 00:00:00 2001 From: Patrick Machielse Date: Wed, 9 Oct 2024 19:28:09 +0200 Subject: [PATCH] MIKMIDIPacketListSizeForCommands() now accounts for the fact that on ARM the MIDIPackets in a MIDIPacketList are 4-byte aligned, and not packed as they are on X86/PowerPC. --- Source/MIKMIDICommand.m | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Source/MIKMIDICommand.m b/Source/MIKMIDICommand.m index 36ee1fd..ff02a5c 100644 --- a/Source/MIKMIDICommand.m +++ b/Source/MIKMIDICommand.m @@ -384,6 +384,18 @@ ByteCount MIKMIDIPacketListSizeForCommands(NSArray *commands) return 0; } +#if defined(__arm__) || defined(__aarch64__) + // [4-byte aligned] + // Compute the size of static members of MIDIPacketList + ByteCount packetListSize = offsetof(MIDIPacketList, packet); + + for (MIKMIDICommand *command in commands) { + // Compute the size of MIDIPacket + ByteCount packetSize = offsetof(MIDIPacket, data) + command.data.length; + packetListSize += 4 * ((packetSize + 3) / 4); + } +#else + // [packed] // Compute the size of static members of MIDIPacketList and (MIDIPacket * [commands count]) ByteCount packetListSize = offsetof(MIDIPacketList, packet) + offsetof(MIDIPacket, data) * [commands count]; @@ -391,7 +403,7 @@ ByteCount MIKMIDIPacketListSizeForCommands(NSArray *commands) for (MIKMIDICommand *command in commands) { packetListSize += [[command data] length]; } - +#endif return packetListSize; }