Exemple #1
0
        public bool OpenMidiOut()
        {
            int         outDeviceID = -1;
            MidiDevices devices     = new MidiDevices();
            int         Idx         = 0;

            foreach (string devName in devices.OutDevices)
            {
                if (devName == this.DeviceName)
                {
                    outDeviceID = Idx;
                    break;
                }
                Idx++;
            }
            if (outDeviceID == -1)
            {
                DebugMsg(Direction.Out, Status.Error, "MidiOutOpen Error: Unable to find " + DeviceName + " output device.");
                return(false);
            }
            else
            {
                int result = WinMM.MidiOutOpen(out midi_out_handle, (uint)outDeviceID, IntPtr.Zero, IntPtr.Zero, WinMM.MidiOutOpenFlags.Null);
                if (result != 0)
                {
                    StringBuilder error_text = new StringBuilder(256);
                    WinMM.MidiInGetErrorText(result, error_text, 256);
                    DebugMsg(Direction.Out, Status.Error, "MidiOutOpen Error:", error_text.ToString());
                    return(false);
                }
                DebugMsg(Direction.Out, Status.Open);
                return(true);
            }
        }
Exemple #2
0
        public bool OpenMidiIn(int deviceIndex, string deviceName)
        {
            DeviceIndex     = deviceIndex;
            this.DeviceName = deviceName;
            //this.VFOSelect = 0;
            callback = new WinMM.MidiInCallback(InCallback);
            int result = WinMM.MidiInOpen(out midi_in_handle, (uint)DeviceIndex, callback, IntPtr.Zero,
                                          WinMM.MidiInOpenFlags.Function | WinMM.MidiInOpenFlags.MidiIoStatus);

            if (result != 0)
            {
                StringBuilder error_text = new StringBuilder(256);
                WinMM.MidiInGetErrorText(result, error_text, 256);
                DebugMsg(Direction.In, Status.Error, "MidiInOpen Error: ", error_text.ToString());
                return(false);
            }

            /*
             * for (int i = 0; i < 3; i++)
             * {
             *  result = AddSysExBuffer(midi_in_handle);
             *  if (result != 0)
             *  {
             *      StringBuilder error_text = new StringBuilder(256);
             *      WinMM.MidiInGetErrorText(result, error_text, 256);
             *      DebugMsg(Direction.In, Status.Error, "AddSysExBuffer Error:", error_text.ToString());
             *      return false;
             *  }
             * }
             */
            result = WinMM.MidiInStart(midi_in_handle);
            if (result != 0)
            {
                StringBuilder error_text = new StringBuilder(256);
                WinMM.MidiInGetErrorText(result, error_text, 256);
                DebugMsg(Direction.In, Status.Error, "MidiInStart Error:", error_text.ToString());
                return(false);
            }
            // Try and open Midi Out and send a reset.
            if (OpenMidiOut())
            {
                SendMsg(0x0F, 0x0F, 0, 0);
            }


            DebugMsg(Direction.In, Status.Open);
            return(true);
        }