Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        private void detectDevice()
        {
            mutexDetectDevice.WaitOne();
            var devNum = Win32Midi.MidiInGetNumDevs();

            if (devNum != 0)
            {
                var res = Win32Midi.MidiInOpen(ref midiIn, 0, callbackPtr, (IntPtr)0, Win32Midi.CallbackFunction);
                if (res == Win32Midi.MMSysErrNoError)
                {
                    res = Win32Midi.MidiInStart(midiIn);
                }
                if (res != Win32Midi.MMSysErrNoError)
                {
                    var sb = new StringBuilder();
                    sb.Capacity = 1024;
                    Win32Midi.MidiInGetErrorText(res, sb, (uint)sb.Capacity);
                    Invoke(new addLogDelegate(addLog), sb.ToString());
                }
            }
            mutexDetectDevice.ReleaseMutex();
        }
Exemplo n.º 3
0
 private void FormMIDI2PC_FormClosed(object sender, FormClosedEventArgs e)
 {
     Win32Midi.MidiInStop(midiIn);
     Win32Midi.midiInClose(ref midiIn);
 }