示例#1
0
 public static void Close(MIDIType Type)
 {
     if (Type == MIDIType.Serial) UtilitySerial.CloseCOM();
     else if (Type == MIDIType.MIDI_IN && midiIn != null) { midiIn.Stop(); midiIn.Close(); midiIn.Dispose(); midiIn = null; midiIn_Name = null; }
     else if (Type == MIDIType.MIDI_OUT && midiOut != null) { midiOut.Close(); midiOut.Dispose(); midiOut = null; midiOut_Name = null; }
 }
示例#2
0
        public static bool OpenMIDI(MIDIType Type, string Data)
        {
            //midiType = Type;
            try
            {
                if (Type == MIDIType.Serial)
                {
                    UtilitySerial.OpenCOM(Data);

                    if (UtilitySerial.IsOpen)
                    {
                        UtilitySerial.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived);
                        return true;
                    }
                }
                else if (Type == MIDIType.MIDI_IN)
                {
                    for (int i = 0; i < MidiInEx.NumberOfDevices; i++)
                        if (MidiInEx.DeviceInfo(i).ProductName == Data)
                        {
                            midiIn = new MidiInEx(i);
                            midiIn.ErrorReceived += new EventHandler<MidiInMessageEventArgs>(midiIn_ErrorReceived);
                            midiIn.MessageReceived += new EventHandler<MidiInMessageEventArgs>(midiIn_MessageReceived);
                            midiIn.Start();
                            midiIn_Name = MidiInEx.DeviceInfo(i).ProductName;
                            return true;
                        }
                }
                else if (Type == MIDIType.MIDI_OUT)
                {
                    for (int i = 0; i < MidiOutEx.NumberOfDevices; i++)
                        if (MidiOutEx.DeviceInfo(i).ProductName == Data)
                        {
                            midiOut = new MidiOutEx(i);
                            midiOut_Name = MidiOutEx.DeviceInfo(i).ProductName;
                            return true;
                        }
                }
                return false;
            }
            catch (Exception exc)
            {
                return false;
            }
        }