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

Raising event in C#

Topics: Getting Started
Apr 2, 2015 at 6:15 AM
I'm writing a win32 form based app that receives commands from my old Neve mixer board faders through a microcontroler I programmed that talks to the PC through an USB serial connexion. The Win32 app will translate these commands to control softwares like Cubase and RME TotalMix using midi data.

I have everything in MIDI.NET working, exept that I can't find a way to raise an event (send a Window's message) to my C# form to tell it that a sysex or short data has arrived. The delegate event handler mecanism works fine, exept when I call it from the LongData() and ShortData(). I guess it's because they are interrupt unmanaged pieces of code.

Additional note:
Since I'm quite new in C# and dotnet (I'm an old DOS C, C++ and ASM programmer), I found the following simple way to transfer sysex buffers to my app (a shared byte array "pointer"). Maybe you use another way to transfer the sysexs to the app, but I could not understand by looking at your samples. Here is my code:

public void LongData(MidiBufferStream buffer, long timestamp) {

    while (b != 0xF7) {
        b = buffer.ReadByte();
        buf[pos++] = (byte)b;    // byte buf[300] is a public  member of my instance of IMidiDataReceiver. 300 is enough for this app. 
     BufReady = true;
    OnMidiInEvent(this, MidiEventLongData); // this does not work in lonData()
Apr 2, 2015 at 1:54 PM
What does not work on raising the Event? What code is in OnMidiInEvent?

Also note that the LongData method is called on a separate thread. You could try to add the in the chain and then have a seperate loop that polls the arival of Midi In messages...