Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for CoreMIDI midi message format #19

Closed
plaukiu opened this issue Nov 2, 2022 · 2 comments
Closed

Support for CoreMIDI midi message format #19

plaukiu opened this issue Nov 2, 2022 · 2 comments

Comments

@plaukiu
Copy link

plaukiu commented Nov 2, 2022

Hi. Great work.

It would be nice if midly could parse MIDI messages received live within CoreMIDI framework, which uses uses 32-bit integers instead of 8-bit integers for its MIDI message packets.

@kovaxis
Copy link
Owner

kovaxis commented Jan 1, 2023

Helllo! Sorry for the late reply.

I am not familiar with the CoreMIDI framework or how are messages encoded in that context.

However, after some quick googling, I believe messages arrive as a single u32 per message, am I correct? I am basing myself off of this piece of code:

let words = Mirror(reflecting: packet.words).children
words.forEach { word in
    let uint32 = word.value as! UInt32
    guard uint32 > 0 else { return }
    midiPacket = MidiPacket(
        first: UInt8((uint32 & 0xFF000000) >> 24),
        second: UInt8((uint32 & 0x00FF0000) >> 16),
        third: UInt8((uint32 & 0x0000FF00) >> 8),
        fourth: UInt8(uint32 & 0x000000FF))        
}

In this case, CoreMIDI would basically encode a big endian 4-byte buffer in a uint32. You can parse this format using LiveEvent::parse(&int.to_be_bytes()).

Is my understanding correct?

@kovaxis
Copy link
Owner

kovaxis commented Jul 18, 2023

I'm assuming it's correct. If it turns out it isn't, please reopen this issue.

@kovaxis kovaxis closed this as completed Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants