This project has moved and is read-only. For the latest updates, please go here.

Need more granular info from NoteEvent

May 21, 2007 at 4:24 PM
Mark,

This is a very useful library and I'm so glad to find it! I've been hunting for a simple MIDI event library for .NET for a long time. I'm writing a free music education application in VB.

I've figured out from your MidiIn demo how to get the ToString() value from a MIDI event, which has the info I need, but it's strung together with other stuff I don't. Here's what I'm getting:

0 NoteOff Ch: 1 E3 Vel:122

What I need is just the "E3" noteName or, better yet, the MIDI note number. Here's my code for the event handling:

Private Sub messageReceived(ByVal sender As Object, ByVal e As MidiInMessageEventArgs)
contentArea.InnerHtml = e.MidiEvent.ToString
End Sub


Can you help me get the note name or the MIDI note number out of the event?

Thanks!
-- D
May 21, 2007 at 8:53 PM
you need to check what type the MidiEvent is. If it is a NoteOn event, then you can cast it to NoteOnEvent, which will give you access to all the parameters you need.

Mark
May 22, 2007 at 3:11 PM
Mark,

Thanks for that! That solves my problem. But I'm using an ugly string-based method of determining if we have "NoteOn". Is there an elegant way to tell from the MidiInMessageEventArgs or from the MidiEvent itself?

Thanks to you, I got a working prototype of my application up and running in one day. :-)

-- D
May 22, 2007 at 8:19 PM
Have a look at the midiEvent.CommandCode property - it will tell you what you need to know

Mark
May 22, 2007 at 9:41 PM
Thanks again, Mark. I understand now how it works... You find out the type of event, then recast as an event of that type to get the full properties.

Nice work!

-- D