Пример #1
0
        public void MidiFileParameters(MidiFilePlayer instance)
        {
            instance.MPTK_PlayOnStart          = EditorGUILayout.Toggle(new GUIContent("Play At Startup", "Start playing Midi when the application starts"), instance.MPTK_PlayOnStart);
            instance.MPTK_StartPlayAtFirstNote = EditorGUILayout.Toggle(new GUIContent("Start Play From First Note", "Start playing Midi from the first note found in the midi"), instance.MPTK_StartPlayAtFirstNote);
            instance.MPTK_PauseOnFocusLoss     = EditorGUILayout.Toggle(new GUIContent("Pause When Focus Loss", "Pause when application loss the focus"), instance.MPTK_PauseOnFocusLoss);

            instance.MPTK_DirectSendToPlayer = EditorGUILayout.Toggle(new GUIContent("Send To Synth", "Midi events are send to the midi player directly"), instance.MPTK_DirectSendToPlayer);

            instance.MPTK_Loop = EditorGUILayout.Toggle(new GUIContent("Loop On Midi", "Enable loop on midi play"), instance.MPTK_Loop);

            if (EditorApplication.isPlaying)
            {
                EditorGUILayout.Separator();
                string infotime = "Real time from start and total duration regarding the current tempo";
                EditorGUILayout.LabelField(new GUIContent("Time", infotime), new GUIContent(instance.playTimeEditorModeOnly + " / " + instance.durationEditorModeOnly, infotime));

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(new GUIContent("Position", "Set real time position since the startup regarding the current tempo"));
                float currentPosition = (float)Math.Round(instance.MPTK_Position);
                float newPosition     = (float)Math.Round(EditorGUILayout.Slider(currentPosition, 0f, instance.MPTK_DurationMS));
                if (currentPosition != newPosition)
                {
                    // Avoid event as layout triggered when duration is changed
                    if (Event.current.type == EventType.Used)
                    {
                        //Debug.Log("New position " + currentPosition + " --> " + newPosition + " " + Event.current.type);
                        instance.MPTK_Position = newPosition;
                    }
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Separator();
                string infotick = "Tick count for start and total duration regardless the current tempo";
                EditorGUILayout.LabelField(new GUIContent("Ticks", infotick), new GUIContent(instance.MPTK_TickCurrent + " / " + instance.MPTK_TickLast, infotime));

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(new GUIContent("Position", "Set tick position since the startup regardless the current tempo"));
                long currenttick = instance.MPTK_TickCurrent;
                long ticks       = Convert.ToInt64(EditorGUILayout.Slider(currenttick, 0f, (float)instance.MPTK_TickLast));
                if (currenttick != ticks)
                {
                    // Avoid event as layout triggered when duration is changed
                    if (Event.current.type == EventType.Used)
                    {
                        //Debug.Log("New tick " + currenttick + " --> " + ticks + " " + Event.current.type);
                        instance.MPTK_TickCurrent = ticks;
                    }
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Separator();

                EditorGUILayout.BeginHorizontal();
                if (instance.MPTK_IsPlaying && !instance.MPTK_IsPaused)
                {
                    GUI.color = ToolsEditor.ButtonColor;
                }
                if (GUILayout.Button(new GUIContent("Play", "")))
                {
                    instance.MPTK_Play();
                }
                GUI.color = Color.white;

                if (instance.MPTK_IsPaused)
                {
                    GUI.color = ToolsEditor.ButtonColor;
                }
                if (GUILayout.Button(new GUIContent("Pause", "")))
                {
                    if (instance.MPTK_IsPaused)
                    {
                        //instance.MPTK_Play();
                        instance.MPTK_UnPause();
                    }
                    else
                    {
                        instance.MPTK_Pause();
                    }
                }
                GUI.color = Color.white;

                if (GUILayout.Button(new GUIContent("Stop", "")))
                {
                    instance.MPTK_Stop();
                }

                if (GUILayout.Button(new GUIContent("Restart", "")))
                {
                    instance.MPTK_RePlay();
                }
                EditorGUILayout.EndHorizontal();
#if MPTK_PRO
                if (!(instance is MidiExternalPlayer))
                {
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button(new GUIContent("Previous", "")))
                    {
                        instance.MPTK_Previous();
                    }
                    if (GUILayout.Button(new GUIContent("Next", "")))
                    {
                        instance.MPTK_Next();
                    }
                    EditorGUILayout.EndHorizontal();
                }
#endif
            }

            instance.showMidiParameter = DrawFoldoutAndHelp(instance.showMidiParameter, "Show Midi Parameters", "https://paxstellar.fr/midi-file-player-detailed-view-2/#Foldout-Midi-Parameters");
            if (instance.showMidiParameter)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(new GUIContent("Quantization", ""), GUILayout.Width(150));
                int newLevel = EditorGUILayout.Popup(instance.MPTK_Quantization, popupQuantization);
                if (newLevel != instance.MPTK_Quantization && newLevel >= 0 && newLevel < popupQuantization.Length)
                {
                    instance.MPTK_Quantization = newLevel;
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("Speed");
                float speed = EditorGUILayout.Slider(instance.MPTK_Speed, 0.1f, 10f);
                //          Debug.Log("New speed " + instance.MPTK_Speed + " --> " + speed + " " + Event.current.type);
                if (speed != instance.MPTK_Speed)
                {
                    //Debug.Log("New speed " + instance.MPTK_Speed + " --> " + speed + " " + Event.current.type);
                    instance.MPTK_Speed = speed;
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                instance.MPTK_EnableChangeTempo = EditorGUILayout.Toggle(new GUIContent("Tempo Change", "Enable midi event tempo change when playing."), instance.MPTK_EnableChangeTempo);
                EditorGUILayout.LabelField(new GUIContent("Current:" + Math.Round(instance.MPTK_Tempo, 0), "Current tempo defined in Midi"));
                EditorGUILayout.EndHorizontal();

                instance.MPTK_EnablePresetDrum = EditorGUILayout.Toggle(new GUIContent("Drum Preset Change", "Enable Preset change on the canal 10 for drum. By default disabled, could sometimes create bad sound with midi files not really compliant with the Midi norm."), instance.MPTK_EnablePresetDrum);
                instance.MPTK_KeepNoteOff      = EditorGUILayout.Toggle(new GUIContent("Keep Midi NoteOff", "Keep Midi NoteOff and NoteOn with Velocity=0 (need to restart the playing Midi)"), instance.MPTK_KeepNoteOff);
                instance.MPTK_LogEvents        = EditorGUILayout.Toggle(new GUIContent("Log Midi Events", "Log information about each midi events read."), instance.MPTK_LogEvents);
                EditorGUI.indentLevel--;
            }
        }
Пример #2
0
        public override void OnInspectorGUI()
        {
            try
            {
                //if (styleInfoMidi == null)
                //{
                //    styleInfoMidi = new GUIStyle(EditorStyles.textArea);
                //    styleInfoMidi.normal.textColor = new Color(0, 0, 0.99f);
                //    styleInfoMidi.alignment = TextAnchor.UpperLeft;
                //    //styleDragZone.border = new RectOffset(2, 2, 2, 2);
                //}



                GUI.changed = false;
                GUI.color   = Color.white;

                //Transform t = (Transform)target;
                //Debug.Log(t.localPosition+" " + t.position);

                //mDebug.Log(Event.current.type);
                Event e = Event.current;

                string soundFontSelected = "No SoundFont selected.";
                if (MidiPlayerGlobal.CurrentMidiSet != null && MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo != null)
                {
                    soundFontSelected = MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.Name;
                    EditorGUILayout.LabelField(new GUIContent("SoundFont: " + soundFontSelected, "Define SoundFont from the menu 'Tools/MPTK - SoundFont Setup' or alt-f"));
                    EditorGUILayout.Separator();

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(new GUIContent("Midi ", "Select Midi File to play"), GUILayout.Width(150));

                    //if (GUILayout.Button(new GUIContent("Refresh", "Reload all Midi from resource folder"))) MidiPlayerGlobal.CheckMidiSet();
                    if (MidiPlayerGlobal.CurrentMidiSet.MidiFiles != null && MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count > 0)
                    {
                        // Search index from midi name
                        int selectedMidi = instance.MPTK_MidiIndex;
                        if (selectedMidi < 0)
                        {
                            selectedMidi           = 0;
                            instance.MPTK_MidiName = MidiPlayerGlobal.CurrentMidiSet.MidiFiles[selectedMidi];
                        }
                        int newSelectMidi = EditorGUILayout.Popup(selectedMidi, MidiPlayerGlobal.CurrentMidiSet.MidiFiles.ToArray());
                        // Is midifile has changed ?
                        if (newSelectMidi != selectedMidi)
                        {
                            instance.MPTK_MidiIndex = newSelectMidi;
                            instance.MPTK_RePlay();
                        }
                    }
                    else
                    {
                        EditorGUILayout.LabelField("No Midi defined, go to menu 'Tools/MPTK - Midi File Setup' or alt-m");
                        instance.MPTK_MidiName = "";
                    }
                    EditorGUILayout.EndHorizontal();

                    float volume = EditorGUILayout.Slider(new GUIContent("Volume", "Set global volume for this midi playing"), instance.MPTK_Volume, 0f, 1f);
                    if (instance.MPTK_Volume != volume)
                    {
                        instance.MPTK_Volume = volume;
                    }


                    instance.MPTK_PlayOnStart        = EditorGUILayout.Toggle(new GUIContent("Play At Startup", "Start playing midi when the application starts"), instance.MPTK_PlayOnStart);
                    instance.MPTK_DirectSendToPlayer = EditorGUILayout.Toggle(new GUIContent("Direct send to player", "Midi events are send to the midi player directly"), instance.MPTK_DirectSendToPlayer);

                    EditorGUILayout.BeginHorizontal();
                    string tooltipDistance = "Playing is paused if distance between AudioListener and this component is greater than MaxDistance";
                    instance.MPTK_PauseOnDistance = EditorGUILayout.Toggle(new GUIContent("Pause With Distance", tooltipDistance), instance.MPTK_PauseOnDistance);
                    EditorGUILayout.LabelField(new GUIContent("Current:" + Math.Round(instance.distanceEditorModeOnly, 2), tooltipDistance));
                    EditorGUILayout.EndHorizontal();

                    float distance = EditorGUILayout.Slider(new GUIContent("Max Distance", tooltipDistance), instance.MPTK_MaxDistance, 0f, 500f);
                    if (instance.MPTK_MaxDistance != distance)
                    {
                        instance.MPTK_MaxDistance = distance;
                    }

                    instance.MPTK_Loop = EditorGUILayout.Toggle(new GUIContent("Loop", "Enable loop on midi play"), instance.MPTK_Loop);

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel("Speed");
                    float speed = EditorGUILayout.Slider(instance.MPTK_Speed, 0.1f, 5f);
                    if (instance.MPTK_Speed != speed)
                    {
                        instance.MPTK_Speed = speed;
                    }
                    EditorGUILayout.EndHorizontal();


                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel("Transpose");
                    instance.MPTK_Transpose = EditorGUILayout.IntSlider(instance.MPTK_Transpose, -24, 24);
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel("Release Time (sec.)");
                    instance.MPTK_TimeToRelease = EditorGUILayout.Slider(instance.MPTK_TimeToRelease, 0.05f, 1f);
                    EditorGUILayout.EndHorizontal();

                    instance.MPTK_LogWaves = EditorGUILayout.Toggle(new GUIContent("Log Waves", "Log information about wave for each notes played"), instance.MPTK_LogWaves);

                    if (EditorApplication.isPlaying)
                    {
                        EditorGUILayout.Separator();
                        EditorGUILayout.LabelField("Time", instance.playTimeEditorModeOnly + " / " + instance.durationEditorModeOnly);

                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.PrefixLabel("Position");
                        float pos = EditorGUILayout.Slider(instance.MPTK_Position, 0f, (float)instance.MPTK_Duration.TotalMilliseconds);
                        if (instance.MPTK_Position != pos)
                        {
                            instance.MPTK_Position = pos;
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();

                        if (instance.MPTK_IsPlaying && !instance.MPTK_IsPaused)
                        {
                            GUI.color = ToolsEditor.ButtonColor;
                        }
                        if (GUILayout.Button(new GUIContent("Play", "")))
                        {
                            instance.MPTK_Play();
                        }
                        GUI.color = Color.white;

                        if (instance.MPTK_IsPaused)
                        {
                            GUI.color = ToolsEditor.ButtonColor;
                        }
                        if (GUILayout.Button(new GUIContent("Pause", "")))
                        {
                            if (instance.MPTK_IsPaused)
                            {
                                instance.MPTK_Play();
                            }
                            else
                            {
                                instance.MPTK_Pause();
                            }
                        }
                        GUI.color = Color.white;

                        if (GUILayout.Button(new GUIContent("Stop", "")))
                        {
                            instance.MPTK_Stop();
                        }

                        if (GUILayout.Button(new GUIContent("Restart", "")))
                        {
                            instance.MPTK_RePlay();
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        if (GUILayout.Button(new GUIContent("Previous", "")))
                        {
                            instance.MPTK_Previous();
                        }
                        if (GUILayout.Button(new GUIContent("Next", "")))
                        {
                            instance.MPTK_Next();
                        }
                        EditorGUILayout.EndHorizontal();
                    }

                    showMidiParameter = EditorGUILayout.Foldout(showMidiParameter, "Show Midi Parameters");
                    if (showMidiParameter)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField(new GUIContent("Quantization", ""), GUILayout.Width(150));
                        int newLevel = EditorGUILayout.Popup(instance.MPTK_Quantization, popupQuantization);
                        if (newLevel != instance.MPTK_Quantization && newLevel >= 0 && newLevel < popupQuantization.Length)
                        {
                            instance.MPTK_Quantization = newLevel;
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.BeginHorizontal();
                        instance.MPTK_EnableChangeTempo = EditorGUILayout.Toggle(new GUIContent("Enable Tempo Change", "Enable midi event tempo change when playing"), instance.MPTK_EnableChangeTempo);
                        EditorGUILayout.LabelField(new GUIContent("Current:" + Math.Round(instance.MPTK_Tempo, 0), "Current tempo defined in Midi"));
                        EditorGUILayout.EndHorizontal();
                        instance.MPTK_EnablePanChange = EditorGUILayout.Toggle(new GUIContent("Enable Pan Change", "Enable midi event pan change when playing"), instance.MPTK_EnablePanChange);
                        instance.MPTK_KeepNoteOff     = EditorGUILayout.Toggle(new GUIContent("Keep Midi NoteOff", "Keep Midi NoteOff and NoteOn with Velocity=0 (need to restart the playing Midi)"), instance.MPTK_KeepNoteOff);
                        instance.MPTK_LogEvents       = EditorGUILayout.Toggle(new GUIContent("Log Midi Events", "Log information about each midi events read"), instance.MPTK_LogEvents);
                    }

                    showMidiInfo = EditorGUILayout.Foldout(showMidiInfo, "Show Midi Info");
                    if (showMidiInfo)
                    {
                        if (!string.IsNullOrEmpty(instance.MPTK_SequenceTrackName))
                        {
                            if (taSequence == null)
                            {
                                taSequence = new TextArea("Sequence");
                            }
                            taSequence.Display(instance.MPTK_SequenceTrackName);
                        }

                        if (!string.IsNullOrEmpty(instance.MPTK_ProgramName))
                        {
                            if (taProgram == null)
                            {
                                taProgram = new TextArea("Program");
                            }
                            taProgram.Display(instance.MPTK_ProgramName);
                        }

                        if (!string.IsNullOrEmpty(instance.MPTK_TrackInstrumentName))
                        {
                            if (taInstrument == null)
                            {
                                taInstrument = new TextArea("Instrument");
                            }
                            taInstrument.Display(instance.MPTK_TrackInstrumentName);
                        }

                        if (!string.IsNullOrEmpty(instance.MPTK_TextEvent))
                        {
                            if (taText == null)
                            {
                                taText = new TextArea("TextEvent");
                            }
                            taText.Display(instance.MPTK_TextEvent);
                        }

                        if (!string.IsNullOrEmpty(instance.MPTK_Copyright))
                        {
                            if (taCopyright == null)
                            {
                                taCopyright = new TextArea("Copyright");
                            }
                            taCopyright.Display(instance.MPTK_Copyright);
                        }
                    }

                    showEvents = EditorGUILayout.Foldout(showEvents, "Show Events");
                    if (showEvents)
                    {
                        EditorGUILayout.PropertyField(CustomEventStartPlayMidi);
                        EditorGUILayout.PropertyField(CustomEventListNotesEvent);
                        EditorGUILayout.PropertyField(CustomEventEndPlayMidi);
                        serializedObject.ApplyModifiedProperties();
                    }


                    //showDefault = EditorGUILayout.Foldout(showDefault, "Show default editor");
                    //if (showDefault) DrawDefaultInspector();
                }
                else
                {
                    EditorGUILayout.LabelField(new GUIContent("SoundFont: " + soundFontSelected, "Define SoundFont from the menu 'Tools/MPTK - SoundFont Setup' or alt-f"));
                    ToolsEditor.LoadMidiSet();
                    ToolsEditor.CheckMidiSet();
                }

                if (GUI.changed)
                {
                    EditorUtility.SetDirty(instance);
                }
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }