atsushieno / managed-midi

[Past project] Cross-platform MIDI processing library for mono and .NET (ALSA, CoreMIDI, Android, WinMM and UWP).
MIT License
194 stars 26 forks source link

How to decode and understand midi incoming messages #48

Closed eriveraa closed 5 years ago

eriveraa commented 5 years ago

Hi, i have this code (input port with an event attached): private void Result_MessageReceived(object sender, MidiReceivedEventArgs e) { var inputPort = (IMidiInput)sender; string debugMessage = $"Input from '{inputPort.Details.Name}' / Start: {e.Start} / Length: {e.Length} / Data: {e.Data[0]} {e.Data[1]} {e.Data[2]}"; Console.WriteLine(debugMessage); } How do i know what type of midi message is? (NoteOn, NoteOff, CC, etc.), how to extract the channel, the pitch and data values?. Please if you can refer to an example of code, it would be awesome. Thanks.

atsushieno commented 5 years ago

MidiEvent.Convert() might help it. IIRC it is still hacky when it receives sysex though.

eriveraa commented 5 years ago

Any other way than using MidiEvent.Conver() ? or example?

eriveraa commented 5 years ago

Please any help on how can i decode the messages?

atsushieno commented 5 years ago

You cannot find such examples in the source code because this repository is not for general-purpose "learning". MIDI is a common standard across various implementations and there are many good materials on the web (like, where you learned those terms "channel messages" and "system messages"). There is no point of making less-brushed up reference material in this repo, I'm not going to reinvent the wheel.

To identify message types, do basic logical calculations on the status bytes e.g. (evt.StatusByte & 0xF0) == 0xF0. You might find more hints if you have a look at how MidiEvent struct properties are implemented e.g. https://github.com/atsushieno/managed-midi/blob/master/Commons.Music.Midi.Shared/SMF.cs#L376