Midibuffer troubles on linux

Here's the background.

I'm serialising a midi buffer and sending it as a UPD datagram from a Mac to a Linux machine. To serialize the midibuffer I am copying the data from the MidiBuffer's Array<uint8> data member into a MemoryBlock using copyFrom() like so:

data.copyFrom((void *) midiMessages->data.getRawDataPointer(), getMidiDataOffset(), midiMessages->data.size() * sizeof(uint8));

then deserialising like so:

buffer.data = Array<uint8>(this->header.midiData, this->header.midiDataSize); ​

This works on the mac internally. It works sending from a mac to a mac. 

But mac to linux gives me garbage on the linux end. Midi notes are not parsed or recognized.

Sending the same Datagram message from linux back to the mac deserialises fine though.

This is leading me to believe that the serialisation is ok, and that something about the MidiBuffer's Array<uint8> structure is funny on Linux.


Anyone got any tips for me where to look or what to test next?

FWIW none of that stuff is platform-specific. If it's getting messed up then it's most likely somewhere else in your code that's corrupting it.

But do pay attention to the very clear comment saying that you shouldn't rely on the format of that Array to be consistent - it could change at any time and could vary between platforms (although currently it doesn't)

Yup! problem was in my code. My offsets were using data that had varying sizes on different platforms. Fixed that and everything works great. 

Thanks for the reassurance.

I saw the comment saying i shouldn't rely on the data format in the MidiBuffer and am aware that might change. Any suggestion how one could quickly serialise a MidiBuffer? The AudioSampleBuffer copyFrom() , getReadPointer() and setDataToReferTo() are very helpfull for this kind of thing. With MidiBuffer you are sort of stuck with the Array<uint8> data member and the very clear warning that this is bad. 



The only 100% safe way would be to iterate the buffer, and store each message's data in whatever format you choose.