private void FormMIDI2PC_Load(object sender, EventArgs e)
        {
            callbackDelegate = new Win32Midi.MidiInProc(callback);
            callbackPtr      = (IntPtr)Marshal.GetFunctionPointerForDelegate(callbackDelegate);

            uint uDevicesSum = Win32Midi.MidiInGetNumDevs();

            lblMes.Text = "Devices-sum:" + uDevicesSum.ToString();
            Win32Midi.MidiInCaps getMidiInCap = new Win32Midi.MidiInCaps();
            for (uint i = 0; i < uDevicesSum; i++)
            {
                Win32Midi.MidiInGetDevCaps(i, ref getMidiInCap, Win32Midi.MaxPNameLen);
                int Version1 = (int)getMidiInCap.vDriverVersion >> 8 & 0xff;
                int Version2 = (int)getMidiInCap.vDriverVersion & 0xff;
                lblInCaps.Text = i.ToString() +
                                 ": Mid:0x" + getMidiInCap.wMid.ToString("X4") +
                                 "    Pid:0x" + getMidiInCap.wPid.ToString("X4") +
                                 "    DriverVersion: V" + Version1.ToString() + "." + Version2.ToString() +
                                 "    Pname:" + getMidiInCap.szPname.ToString() +
                                 "    Support:0x" + getMidiInCap.dwSupport.ToString("X2");
                if (i < uDevicesSum - 1)
                {
                    lblInCaps.Text += "\n";
                }
            }

            new Thread(new ThreadStart(detectDevice)).Start();
        }
Exemple #2
0
    public MidiInputDevice(uint deviceIndex)
    {
        var info = new Info(deviceIndex);

        Name = info.Name;

        SynchronizationContext = SynchronizationContext.Current;
        if (SynchronizationContext == null)
        {
            throw new InvalidOperationException("No synchronization context");
        }

        Callback = _MidiCallback;
        var openResult = Win32Midi.midiInOpen(out Handle, new UIntPtr(deviceIndex), Callback, UIntPtr.Zero, Win32Midi.MidiOpenFlags.CALLBACK_FUNCTION);

        if (openResult != Win32Midi.MMRESULT.MMSYSERR_NOERROR)
        {
            throw new Exception("Opening midi input device failed with " + openResult.ToString());
        }

        Win32Midi.midiInStart(Handle);
    }