jdm555
jdm555

Reputation: 107

naudio Midi input - filter e.MidiEvent to just data2 parameter?

Writing an app that takes MIDI input using naudio. Managed to get midi input going and outputting fine to the console, but to use the data I need to be able to isolate parts of the data. My code is

    void midiIn_MessageReceived(object sender, MidiInMessageEventArgs e)
    {
        Console.WriteLine(e.MidiEvent);
    }

which writes the following line to the console.

0 ControlChange Ch: 1 Controller 48 Value 51

This is fine but how do I only get data2 (the value) to then pass on to something? I could do something awful like slice it up as a string but this is probably not the way forward...

Upvotes: 1

Views: 420

Answers (1)

CL.
CL.

Reputation: 180121

You have to get the MIDI message from the message information:

void midiIn_MessageReceived(object sender, MidiInMessageEventArgs e)
{
    MidiEvent me = e.MidiEvent;

Then you have to check for the correct message type:

    ControlChangeEvent cce = me as ControlChangeEvent;
    if (cce != null) {

And handle it:

        Console.WriteLine(cce.ControllerValue);
    }
}

Upvotes: 3

Related Questions