View Issue Details

IDProjectCategoryView StatusLast Update
0035750FPCPackagespublic2021-01-02 16:27
Reporterjosh Assigned To 
Status newResolutionopen 
Summary0035750: MidiPacket and MidiPacketList Size if differnece between carbon and cocoa.
DescriptionWHen using CoreMidi services cia MidiService; all works fine under Carbon; as the STructure of The Midi Packet matches the data stream.
When the same code is used when using 64bot cocoa; then the data being received into the packet is corrupted and invalid.

After checking the Size of the Packet Record is larger when running under cocoa.
The record is 268 bytes under carbon; but 272bytes when compiled for cocoa.

Sorroundinng the Definition with
{$packrecords 4}
Appears to solve the problem; but need to check for any knock on effects.

In MidiServices around line 565
{$packrecords 4}
MIDIPacket = record
        timeStamp: MIDITimeStamp;
        length: UInt16;
        data: packed array [0..255] of Byte;

and around midipacketlist
{$packrecords 4}
MIDIPacketList = record
        numPackets: UInt32;
        packet: array [0..0] of MIDIPacket;

Discussion here.,45782.0.html
TagsNo tags attached.
Fixed in Revision
Attached Files


Thaddy de Koning

2019-06-22 10:22

reporter   ~0116831

Last edited: 2019-06-22 10:35

View 5 revisions

Packrecords 4 is wrong as I already explained on the forum. Should be packrecords 1.
The issue at hand is simply a natural alignment issue if the pack size is wrong.
If the pack size is one, the records are equal on all platforms.
Midi is a streaming protocol and does not allow slack space.
Anything else is misinformation.

On the forum I provided a link to the official midi specification, just in case.

This is not a bug, but programmer error.

Benjamin Rosseaux

2021-01-02 06:48

reporter   ~0128013

@Thaddy Sorry, but {$packrecords 4} is right here (or a packed record together with a AlignmentDummy UInt16 after the length UInt16). I've tested with my own pascal-native cross-platform Mini-DAW (Digital Audio Workstation), which I'm developing in the moment. You are probably confusing API data structures (here CoreMIDI) with the MIDI specification of the MIDI bytestream.

Bart Broersma

2021-01-02 12:41

reporter   ~0128016

About which Lazarus package is this?

jamie philbrook

2021-01-02 14:53

reporter   ~0128018

This looks like the old age problem of variable length streaming where the last field needs a name without storage in the record.

Seems like I remember coming up with a hack that would solve this and also others using a blank Record at the end..

 AName :REcord end;

 This does not take any space for the record but does provide a pointer to the start of trailing data.

Bart Broersma

2021-01-02 16:26

reporter   ~0128025

This seems to be about MIDIServices.pas.
So, this is an FPC issue, not a Lazarus issue.
Moving to FPC.
@Josh: please take proper care where (which project and category) you file a bugreport next time.

Issue History

Date Modified Username Field Change
2019-06-22 08:49 josh New Issue
2019-06-22 10:22 Thaddy de Koning Note Added: 0116831
2019-06-22 10:23 Thaddy de Koning Note Edited: 0116831 View Revisions
2019-06-22 10:24 Thaddy de Koning Note Edited: 0116831 View Revisions
2019-06-22 10:34 Thaddy de Koning Note Edited: 0116831 View Revisions
2019-06-22 10:35 Thaddy de Koning Note Edited: 0116831 View Revisions
2021-01-02 06:48 Benjamin Rosseaux Note Added: 0128013
2021-01-02 12:41 Bart Broersma Status new => feedback
2021-01-02 12:41 Bart Broersma LazTarget => -
2021-01-02 12:41 Bart Broersma Note Added: 0128016
2021-01-02 14:53 jamie philbrook Note Added: 0128018
2021-01-02 16:26 Bart Broersma Note Added: 0128025
2021-01-02 16:26 Bart Broersma Status feedback => new
2021-01-02 16:27 Bart Broersma Project Packages => FPC