Exemplo n.º 1
0
        public static IReadOnlyList <MidiDevice> GetLaunchpads()
        {
            var devices       = new List <WinmmMidiDevice>();
            int inDeviceCount = NativeMethods.midiInGetNumDevs();

            for (uint i = 0; i < inDeviceCount; i++)
            {
                var caps = new MIDIINCAPS();
                if (NativeMethods.midiInGetDevCaps(i, ref caps, MIDIINCAPS.Size) <= 0)
                {
                    continue;
                }

                foreach (var deviceType in DeviceInfo.SupportedDevices)
                {
                    if (caps.szPname.Contains(deviceType.MidiName))
                    {
                        devices.Add(new WinmmMidiDevice(caps.szPname, caps.szPname, deviceType.Type));
                    }
                }
            }
            return(devices);
        }
Exemplo n.º 2
0
        protected override bool ConnectInternal(bool isNormal)
        {
            int  inDeviceCount = NativeMethods.midiInGetNumDevs();
            uint?inDeviceId    = null;

            for (uint i = 0; i < inDeviceCount; i++)
            {
                var caps = new MIDIINCAPS();
                NativeMethods.midiInGetDevCaps(i, ref caps, MIDIINCAPS.Size);
                if (caps.szPname == Id)
                {
                    inDeviceId = i;
                    break;
                }
            }
            if (inDeviceId == null)
            {
                return(false);
            }

            int  outDeviceCount = NativeMethods.midiOutGetNumDevs();
            uint?outDeviceId    = null;

            for (uint i = 0; i < outDeviceCount; i++)
            {
                var caps = new MIDIOUTCAPS();
                NativeMethods.midiOutGetDevCaps(i, ref caps, MIDIOUTCAPS.Size);
                if (caps.szPname == Id.Replace("MIDIIN", "MIDIOUT"))
                {
                    outDeviceId = i;
                    break;
                }
            }
            if (outDeviceId == null)
            {
                return(false);
            }

            if (NativeMethods.midiInOpen(out var inDeviceHandle, inDeviceId.Value, _inputCallback, 0, 0x00030000) != 0)
            {
                return(false);
            }
            if (NativeMethods.midiOutOpen(out var outDeviceHandle, outDeviceId.Value, _outputCallback, 0, 0x00030000) != 0)
            {
                return(false);
            }
            if (NativeMethods.midiInStart(inDeviceHandle) != 0)
            {
                return(false);
            }

            _outBuffer = new MidiBuffer(outDeviceHandle, SysEx.MaxMessageLength);

            _inDeviceId      = inDeviceId.Value;
            _outDeviceId     = outDeviceId.Value;
            _inDeviceHandle  = inDeviceHandle;
            _outDeviceHandle = outDeviceHandle;
            _inputCallback   = InputEvent;
            _outputCallback  = OutputEvent;

            _inputClosed.Reset();
            _outputClosed.Reset();

            return(true);
        }
Exemplo n.º 3
0
 public static extern int midiInGetDevCaps(uint uDeviceID, ref MIDIINCAPS lpMidiInCaps, uint cbMidiInCaps);