示例#1
0
    public MIDIdevice Connect(midiComponentInterface _interface, int ID, bool input)
    {
        DeviceBase d;

        if (input)
        {
            d = InputDevice.InstalledDevices[ID];
        }
        else
        {
            d = OutputDevice.InstalledDevices[ID];
        }

        MIDIdevice midOut = getConnectedDevice(d);

        bool success = false;

        if (midOut == null)
        {
            try {
                if (input)
                {
                    (d as InputDevice).Open();
                    (d as InputDevice).StartReceiving(null);
                    midOut = new MIDIdevice(d, true);
                    connectedInputDevices.Add(midOut);
                    success = true;
                }
                else
                {
                    (d as OutputDevice).Open();
                    midOut = new MIDIdevice(d, false);
                    connectedOutputDevices.Add(midOut);
                    success = true;
                }
            } catch {
                Debug.Log("FAIL...");
            }
        }
        else
        {
            success = true;
        }

        if (success)
        {
            if (input)
            {
                midOut.addInterface(_interface);
                (d as InputDevice).NoteOn        += new InputDevice.NoteOnHandler(_interface.InputNoteOn);
                (d as InputDevice).NoteOff       += new InputDevice.NoteOffHandler(_interface.InputNoteOff);
                (d as InputDevice).ControlChange += new InputDevice.ControlChangeHandler(_interface.InputControlChange);
            }
        }

        return(midOut);
    }
示例#2
0
    public void Disconnect(MIDIdevice m, bool input, midiComponentInterface _interface = null)
    {
        if (input)
        {
            if (!connectedInputDevices.Contains(m))
            {
                return;
            }

            if (_interface != null)
            {
                m.removeInterface(_interface);
                (m.getDevice() as InputDevice).NoteOn        -= new InputDevice.NoteOnHandler(_interface.InputNoteOn);
                (m.getDevice() as InputDevice).NoteOff       -= new InputDevice.NoteOffHandler(_interface.InputNoteOff);
                (m.getDevice() as InputDevice).ControlChange -= new InputDevice.ControlChangeHandler(_interface.InputControlChange);
            }
            else
            {
                for (int i = 0; i < m._interfaceList.Count; i++)
                {
                    (m.getDevice() as InputDevice).NoteOn        -= new InputDevice.NoteOnHandler(m._interfaceList[i].InputNoteOn);
                    (m.getDevice() as InputDevice).NoteOff       -= new InputDevice.NoteOffHandler(m._interfaceList[i].InputNoteOff);
                    (m.getDevice() as InputDevice).ControlChange -= new InputDevice.ControlChangeHandler(m._interfaceList[i].InputControlChange);
                }


                (m.getDevice() as InputDevice).StopReceiving();
                (m.getDevice() as InputDevice).Close();
                (m.getDevice() as InputDevice).RemoveAllEventHandlers();
                connectedInputDevices.Remove(m);
            }
        }
        else
        {
            if (!connectedOutputDevices.Contains(m))
            {
                return;
            }

            if (_interface == null)
            {
                (m.getDevice() as OutputDevice).Close();
                connectedOutputDevices.Remove(m);
            }
        }
    }
示例#3
0
    public void outputNote(MIDIdevice _dev, bool on, int ID, int channel)
    {
        if (_dev.input)
        {
            Debug.Log("problem");
            return;
        }

        if (on)
        {
            (_dev.getDevice() as OutputDevice).SendNoteOn((Channel)channel, (Pitch)ID, 127);
        }
        else
        {
            (_dev.getDevice() as OutputDevice).SendNoteOff((Channel)channel, (Pitch)ID, 127);
        }
    }
示例#4
0
    public void outputCC(MIDIdevice _dev, int val, int ID, int channel)
    {
        if (_dev.input)
        {
            Debug.Log("problem");
            return;
        }
        Channel c1 = (Channel)channel;
        Control c2 = (Control)ID;
        string  s  = c2.ToString();

        if (c2.IsValid())
        {
            (_dev.getDevice() as OutputDevice).SendControlChange(c1, c2, val);
        }
        else
        {
            Debug.Log("problem b");
        }
    }
示例#5
0
    void TryConnect(int index, string name)
    {
        string     s = "Connecting";
        MIDIdevice lastMidiDevice = curMIDIdevice;

        curMIDIdevice = MIDImaster.instance.Connect(this, index, input);
        statusText.gameObject.SetActive(true);
        if (lastMidiDevice != curMIDIdevice && lastMidiDevice != null)
        {
            MIDImaster.instance.Disconnect(lastMidiDevice, input, this);
        }

        if (curMIDIdevice != null)
        {
            connectedDevice = name;
            s = "CONNECTED!";
            statusLightMat.SetColor("_TintColor", connectedColor);
            statusText.text = s;
        }
        else
        {
            connectedDevice = "";
            s = "Connection failed\nDevice may be connected to other software.";
            statusLightMat.SetColor("_TintColor", disconnectedColor);
            statusText.text = s;
        }

        if (gameObject.activeSelf)
        {
            if (_textKillRoutine != null)
            {
                StopCoroutine(_textKillRoutine);
            }
            _textKillRoutine = StartCoroutine(TextKillRoutine());
        }
    }