コード例 #1
0
    static void AutoInit()
    {
        if (!MidiINPlugin.initialized)
        {
            EditorDispatcher.StartThread((a) => {
                MidiINPlugin.Init();
                MidiINPlugin.Refresh();
                EditorDispatcher.Dispatch((b) => {
                    MidiINPlugin.RestoreEditorConnections();
                    midiINInitialized = true;
                }, new { a = "" });
            }, new { a = "" });
        }
        else
        {
            midiINInitialized = true;
        }

        if (!MidiOUTPlugin.initialized)
        {
            EditorDispatcher.StartThread((a) => {
                MidiOUTPlugin.Init();
                MidiOUTPlugin.Refresh();
                EditorDispatcher.Dispatch((b) => {
                    MidiOUTPlugin.RestoreEditorConnections();
                    midiOUTInitialized = true;
                }, new { a = "" });
            }, new { a = "" });
        }
        else
        {
            midiOUTInitialized = true;
        }

        EditorApplication.update -= EditorUpdate;
        EditorApplication.update += EditorUpdate;
    }
コード例 #2
0
 public static void RefreshMidiIO()
 {
     MidiINPlugin.Refresh();
     MidiOUTPlugin.Refresh();
 }
コード例 #3
0
    void DrawINOUT()
    {
        backgroundColor = GUI.backgroundColor;

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

        if (count == 0)
        {
            EditorGUILayout.HelpBox("No MIDI connection found!!!", MessageType.Info);
        }

        float selectionHeight = count * (lineHeight + 5);
        float dialogHeight    = selectionHeight + 65;

        Rect defaultRect = new Rect(0, 0, window.position.width, dialogHeight);

        GUI.BeginGroup(defaultRect);

        float width     = defaultRect.width;
        float halfWidth = width / 2f;

        GUI.Box(new Rect(-5f, -5f, defaultRect.width + 10, defaultRect.height + 10), "");

        GUILayout.BeginHorizontal();
        GUILayout.Box("Midi IN", GUILayout.Width(halfWidth));
        GUILayout.Box("Midi OUT", GUILayout.Width(halfWidth));
        GUILayout.EndHorizontal();

        GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(5));

        bool exists = false;

        for (int i = 0; i < count; i++)
        {
            GUILayout.BeginHorizontal();
            if (i < MidiINPlugin.deviceNames.Count)
            {
                exists = false;
                foreach (MidiDevice inDevice in MidiINPlugin.connectedEditorDevices)
                {
                    if (MidiINPlugin.deviceNames [i] == inDevice.name)
                    {
                        exists = true;
                        break;
                    }
                }
                GUI.backgroundColor = exists ? Color.green : backgroundColor;
                if (GUILayout.Button(MidiINPlugin.deviceNames [i], GUILayout.Width(halfWidth), GUILayout.Height(lineHeight)))
                {
                    if (exists)
                    {
                        MidiINPlugin.DisconnectDeviceByName(MidiINPlugin.deviceNames [i], true);
                    }
                    else
                    {
                        MidiINPlugin.ConnectDevice(i, true);
                    }
                    MidiINPlugin.StoreEditorConnections();
                }
                GUI.backgroundColor = backgroundColor;
            }
            else
            {
                GUILayout.Label("", GUILayout.Width(halfWidth), GUILayout.Height(lineHeight));
            }

            if (i < MidiOUTPlugin.deviceNames.Count)
            {
                exists = false;
                foreach (MidiDevice outDevice in MidiOUTPlugin.connectedEditorDevices)
                {
                    if (MidiOUTPlugin.deviceNames [i] == outDevice.name)
                    {
                        exists = true;
                        break;
                    }
                }
                GUI.backgroundColor = exists ? Color.green : backgroundColor;
                if (GUILayout.Button(MidiOUTPlugin.deviceNames [i], GUILayout.Width(halfWidth), GUILayout.Height(lineHeight)))
                {
                    if (exists)
                    {
                        MidiOUTPlugin.DisconnectDeviceByName(MidiOUTPlugin.deviceNames [i], true);
                    }
                    else
                    {
                        MidiOUTPlugin.ConnectDevice(i, true);
                    }
                    MidiOUTPlugin.StoreEditorConnections();
                }
                GUI.backgroundColor = backgroundColor;
            }
            else
            {
                GUILayout.Label("", GUILayout.Width(halfWidth), GUILayout.Height(lineHeight));
            }

            GUILayout.EndHorizontal();
        }

        GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(5));

        GUILayout.BeginHorizontal();

        if (GUILayout.Button("Refresh", GUILayout.Width(halfWidth)))
        {
            MidiINPlugin.Refresh();
            MidiOUTPlugin.Refresh();
        }

        if (GUILayout.Button("Reset", GUILayout.Width(halfWidth)))
        {
            MidiOut.AllSoundOff();
            MidiOut.ResetAllControllers();
        }

        GUILayout.EndHorizontal();

        GUI.EndGroup();
    }