예제 #1
0
        public static void DisconnectDevice(MidiDevice connectedDevice)
        {
            if (midiDevice == null || connectedDevice == null)
            {
                return;
            }

            if (connectedDevice.isEditor)
            {
                for (int i = connectedEditorDevices.Count - 1; i >= 0; i--)
                {
                    if (connectedDevice.deviceId == connectedEditorDevices[i].deviceId)
                    {
                        connectedEditorDevices.RemoveAt(i);
                        break;
                    }
                }
            }
            else
            {
                for (int i = connectedDevices.Count - 1; i >= 0; i--)
                {
                    if (connectedDevice.deviceId == connectedDevices[i].deviceId)
                    {
                        connectedDevices.RemoveAt(i);
                        break;
                    }
                }
            }

            midiDevice.DisconnectDevice(connectedDevice.deviceId, connectedDevice.isEditor);
        }
예제 #2
0
        public static void Refresh()
        {
            if (midiDevice == null)
            {
                return;
            }

            deviceNames = new List <string>();
            for (int i = 0; i < midiDevice.GetDeviceCount(); i++)
            {
                deviceNames.Add(midiDevice.GetDeviceName(i));
            }

            if (midiEditorDevice != null)
            {
                connectedEditorDevices = new List <MidiDevice>();
                for (int i = 0; i < midiEditorDevice.GetConnectedDeviceCount(); i++)
                {
                    if (midiEditorDevice.GetConnectedDeviceIsEditor(i))
                    {
                        MidiDevice md = new MidiDevice();
                        md.name     = midiEditorDevice.GetConnectedDeviceName(i);
                        md.deviceId = midiEditorDevice.GetConnectedDeviceId(i);
                        md.isEditor = true;
                        connectedEditorDevices.Add(md);
                    }
                }
            }
        }
예제 #3
0
        public static MidiDevice ConnectDevice(int deviceIndex, bool editor = false)
        {
            if (midiDevice == null)
            {
                return(null);
            }

            foreach (MidiDevice md in MidiOUTPlugin.connectedDevices)
            {
                if (md.name == midiDevice.GetDeviceName(deviceIndex))
                {
                    Debug.LogError("Preventing infinite loop. To have same device connected as IN and OUT is not allowed.");
                    return(null);
                }
            }

            int deviceId = midiDevice.ConnectDevice(deviceIndex, editor);

            if (editor)
            {
                foreach (MidiDevice cd in connectedEditorDevices)
                {
                    if (deviceId == cd.deviceId)
                    {
                        Debug.LogError("Editor device already connected");
                        return(cd);
                    }
                }
            }
            else
            {
                foreach (MidiDevice cd in connectedDevices)
                {
                    if (deviceId == cd.deviceId)
                    {
                        Debug.LogError("Device already connected");
                        return(cd);
                    }
                }
            }

            MidiDevice connectedDevice = new MidiDevice
            {
                deviceId = deviceId,
                name     = GetDeviceName(deviceIndex),
                isEditor = editor
            };

            if (editor)
            {
                connectedEditorDevices.Add(connectedDevice);
            }
            else
            {
                connectedDevices.Add(connectedDevice);
            }

            return(connectedDevice);
        }
예제 #4
0
        public static void RestoreEditorConnections()
        {
            string names = EditorPrefs.GetString("MIDI_IN_NAMES", "").Trim();

            string[] midiInNames = string.IsNullOrEmpty(names) ? new string[0] : names.Split(';');

            foreach (string midiInName in midiInNames)
            {
                MidiDevice midiDevice = ConnectDeviceByName(midiInName, true);
                if (midiDevice == null)
                {
                    Debug.LogError("Could not conned midi in device : " + midiInName);
                }
            }
        }
예제 #5
0
        public static void DisconnectDeviceByName(string deviceName, bool editor = false)
        {
            if (midiDevice == null)
            {
                return;
            }

            MidiDevice disconnectDevice = null;

            if (editor)
            {
                for (int i = connectedEditorDevices.Count - 1; i >= 0; i--)
                {
                    if (deviceName == connectedEditorDevices[i].name)
                    {
                        disconnectDevice = connectedEditorDevices[i];
                        break;
                    }
                }
            }
            else
            {
                for (int i = connectedDevices.Count - 1; i >= 0; i--)
                {
                    if (deviceName == connectedDevices[i].name)
                    {
                        disconnectDevice = connectedDevices[i];
                        break;
                    }
                }
            }

            if (disconnectDevice != null)
            {
                DisconnectDevice(disconnectDevice);
            }
        }