Skip to content

Commit

Permalink
MIKMIDIPacketListSizeForCommands() now accounts for the fact that on …
Browse files Browse the repository at this point in the history
…ARM the MIDIPackets in a MIDIPacketList are 4-byte aligned, and not packed as they are on X86/PowerPC.
  • Loading branch information
PatrickMIK committed Oct 9, 2024
1 parent c4011df commit 1447c9e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Source/MIKMIDICommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,26 @@ 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];

// Compute the total number of MIDI bytes in all commands
for (MIKMIDICommand *command in commands) {
packetListSize += [[command data] length];
}

#endif
return packetListSize;
}

Expand Down

1 comment on commit 1447c9e

@armadsen
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.