Beispiel #1
0
    IEnumerator ConnectMidiOnStart()
    {
        yield return(new WaitUntil(() =>
                                   MIDI.initialized
                                   ));

        try
        {
            for (int i = 0; i < MidiOUTPlugin.GetDeviceCount(); i++)
            {
                var deviceName = MidiOUTPlugin.GetDeviceName(i);
                MidiOUTPlugin.DisconnectDeviceByName(deviceName);
                //Debug.Log($"DisconnectMidiOut {deviceName}");
            }

            for (int i = 0; i < MidiINPlugin.GetDeviceCount(); i++)
            {
                var deviceName = MidiINPlugin.GetDeviceName(i);
                if (!deviceName.Contains("Session"))
                {
                    MidiINPlugin.ConnectDeviceByName(deviceName);
                    //Debug.Log($"ConnectMidiIn {deviceName}");
                    break;
                }
            }
        }
        catch (Exception e)
        {
            Debug.LogWarning("ConnectMidiOnStart " + e);
        }
    }
    IEnumerator GetMidiOutIe()
    {
        yield return(new WaitUntil(() =>
                                   MIDI.initialized
                                   ));


        listConnectedMidiOut = new List <string>();
        //Debug.Log("MidiOUTPlugin.connectedDevices " + MidiOUTPlugin.connectedDevices.Count);
        foreach (MidiDevice md in MidiOUTPlugin.connectedDevices)
        {
            listConnectedMidiOut.Add(md.name);
            //Debug.Log("MidiINPlugin.connectedDevices " + md.name);
        }

        //Debug.LogWarning("GetMidiOutIe");
        foreach (Transform child in PanelMidiOut.transform)
        {
            Destroy(child.gameObject);
        }

        var buttonNoMidi = Instantiate(ButtonMidi, Vector3.zero, Quaternion.identity);

        buttonNoMidi.transform.SetParent(PanelMidiOut.transform);
        buttonNoMidi.transform.localScale = Vector3.one;
        buttonNoMidi.name = "OUT No Midi Out Detected";
        buttonNoMidi.GetComponentInChildren <Text>().text = "No Midi Out Detected";
        var color = buttonNoMidi.GetComponent <Image>().color;

        color.a = 0.2f;
        buttonNoMidi.GetComponent <Image>().color = color;


        for (int i = 0; i < MidiOUTPlugin.GetDeviceCount(); i++)
        {
            if (MidiOUTPlugin.GetDeviceName(i).Contains("Session"))
            {
                continue;
            }

            buttonNoMidi.SetActive(false);
            var button = Instantiate(ButtonMidi, Vector3.zero, Quaternion.identity);
            button.transform.SetParent(PanelMidiOut.transform);
            button.transform.localScale = Vector3.one;
            button.GetComponentInChildren <Text>().text = MidiOUTPlugin.GetDeviceName(i).Trim();

            if (listConnectedMidiOut.Contains(MidiOUTPlugin.GetDeviceName(i)))
            {
                button.name = "OUT DISCONNECT " + MidiOUTPlugin.GetDeviceName(i);
                color       = button.GetComponent <Image>().color;
                color.a     = 1f;
                button.GetComponent <Image>().color = color;
            }
            else
            {
                button.name = "OUT CONNECT " + MidiOUTPlugin.GetDeviceName(i);
                color       = button.GetComponent <Image>().color;
                color.a     = 0.2f;
                button.GetComponent <Image>().color = color;
            }

            //Debug.LogWarning(i + ". GetMidiOutIe " + MidiOUTPlugin.GetDeviceName(i) + "");
        }
    }
Beispiel #3
0
    void Init()
    {
        foreach (MidiSelectionUIDeviceButton button in INs)
        {
            Destroy(button.gameObject);
        }

        INs = new List <MidiSelectionUIDeviceButton> ();

        foreach (MidiSelectionUIDeviceButton button in OUTs)
        {
            Destroy(button.gameObject);
        }

        OUTs = new List <MidiSelectionUIDeviceButton> ();

        int count = MidiINPlugin.deviceNames.Count > MidiOUTPlugin.deviceNames.Count ? MidiINPlugin.deviceNames.Count : MidiOUTPlugin.deviceNames.Count;

        _minHeight = count * (int)PREFAB_MidiDeviceButton.GetComponent <LayoutElement> ().preferredHeight + 100;

        if (_minHeight < minHeight)
        {
            _minHeight = minHeight;
        }

        _minWidth = minWidth;

        for (int i = 0; i < MidiINPlugin.GetDeviceCount(); i++)
        {
            var go = Instantiate(PREFAB_MidiDeviceButton);

            go.transform.SetParent(inPanel, false);
            MidiSelectionUIDeviceButton button = go.GetComponent <MidiSelectionUIDeviceButton> ();
            button.device          = MidiSelectionUIDeviceButton.Device.IN;
            button.midiSelectionUI = this;
            button.text.text       = MidiINPlugin.GetDeviceName(i);

            bool connected = false;

            foreach (MidiDevice device in MidiINPlugin.connectedDevices)
            {
                if (device.name == button.text.text)
                {
                    connected = true;
                }
            }

            button.connected = connected;

            if (connected)
            {
                button.image.color = connectedColor;
            }
            else
            {
                button.image.color = disconnectedColor;
            }

            INs.Add(button);

            int preferredWidth = (int)button.text.preferredWidth;
            if (preferredWidth > _minWidth / 2)
            {
                _minWidth = 2 * preferredWidth;
            }
        }

        for (int i = 0; i < MidiOUTPlugin.GetDeviceCount(); i++)
        {
            var go = Instantiate(PREFAB_MidiDeviceButton);
            go.transform.SetParent(outPanel, false);
            MidiSelectionUIDeviceButton button = go.GetComponent <MidiSelectionUIDeviceButton> ();
            button.device          = MidiSelectionUIDeviceButton.Device.OUT;
            button.midiSelectionUI = this;
            button.text.text       = MidiOUTPlugin.GetDeviceName(i);

            bool connected = false;

            foreach (MidiDevice device in MidiOUTPlugin.connectedDevices)
            {
                if (device.name == button.text.text)
                {
                    connected = true;
                }
            }

            button.connected = connected;

            if (connected)
            {
                button.image.color = connectedColor;
            }
            else
            {
                button.image.color = disconnectedColor;
            }

            OUTs.Add(button);

            int preferredWidth = (int)button.text.preferredWidth;
            if (preferredWidth > _minWidth / 2)
            {
                _minWidth = 2 * preferredWidth;
            }
        }

        _minWidth += 2 * widthMargin;
        //_minHeight += 2 * heightMargin;

        midiPanel.SetSize(new Vector2(_minWidth, _minHeight));
    }