private void MidiChanged(object tag, int midiindex)
 {
     //Debug.Log("MidiChanged " + midiindex + " for " + tag);
     instance.MPTK_MidiIndex = midiindex;
     instance.MPTK_RePlay();
     MidiCommonEditor.SetSceneChangedIfNeed(instance, true);
 }
Пример #2
0
        public override void OnInspectorGUI()
        {
            try
            {
                GUI.changed = false;
                GUI.color   = Color.white;
                if (commonEditor == null)
                {
                    commonEditor = ScriptableObject.CreateInstance <MidiCommonEditor>();
                }

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

                commonEditor.DrawCaption("Midi Stream Player - Create your music with your algo", "https://paxstellar.fr/midi-file-player-detailed-view-2-2/");
                commonEditor.AllPrefab(instance);
                commonEditor.SynthParameters(instance, serializedObject);
#if SHOWDEFAULT
                instance.showDefault = EditorGUILayout.Foldout(instance.showDefault, "Show default editor");
                if (instance.showDefault)
                {
                    EditorGUI.indentLevel++;
                    commonEditor.DrawAlertOnDefault();
                    DrawDefaultInspector();
                    EditorGUI.indentLevel--;
                }
#endif
                MidiCommonEditor.SetSceneChangedIfNeed(instance, GUI.changed);
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }
Пример #3
0
 static public bool DrawFoldoutAndHelp(bool state, string title, string urlHelp)
 {
     EditorGUILayout.BeginHorizontal();
     state = EditorGUILayout.Foldout(state, title);
     MidiCommonEditor.DrawHelp(urlHelp);
     EditorGUILayout.EndHorizontal();
     return(state);
 }
Пример #4
0
        public override void OnInspectorGUI()
        {
            try
            {
                GUI.changed = false;
                GUI.color   = Color.white;

                if (MidiPlayerGlobal.CurrentMidiSet != null || MidiPlayerGlobal.CurrentMidiSet.MidiFiles == null || MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count == 0)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(new GUIContent("Select Midi ", "Select Midi File to play"), GUILayout.Width(150));

                    if (GUILayout.Button(new GUIContent(instance.MPTK_MidiIndex + " - " + instance.MPTK_MidiName, "Selected Midi File to load"), GUILayout.Height(30)))
                    {
                        InitWinSelectMidi(instance.MPTK_MidiIndex, MidiChanged);
                    }
                    EditorGUILayout.EndHorizontal();

                    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);

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

                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    MidiCommonEditor.ErrorNoMidiFile();
                }

                MidiCommonEditor.SetSceneChangedIfNeed(instance, GUI.changed);
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }
        public override void OnInspectorGUI()
        {
            try
            {
                GUI.changed = false;
                GUI.color   = Color.white;
                if (commonEditor == null)
                {
                    commonEditor = ScriptableObject.CreateInstance <MidiCommonEditor>();
                }

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

                string soundFontSelected = "No SoundFont selected.";
                if (MidiPlayerGlobal.CurrentMidiSet != null && MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo != null)
                {
                    soundFontSelected = MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.Name;
                    EditorGUILayout.LabelField(new GUIContent("SoundFont: " + soundFontSelected, MidiPlayerGlobal.HelpDefSoundFont));
                    EditorGUILayout.Separator();

                    commonEditor.AllPrefab(instance);
                    commonEditor.SynthParameters(instance, serializedObject);
                }
                else
                {
                    MidiCommonEditor.ErrorNoSoundFont();
                }
#if SHOWDEFAULT
                showDefault = EditorGUILayout.Foldout(showDefault, "Show default editor");
                if (showDefault)
                {
                    EditorGUI.indentLevel++;
                    commonEditor.DrawAlertOnDefault();
                    DrawDefaultInspector();
                    EditorGUI.indentLevel--;
                }
#endif
                MidiCommonEditor.SetSceneChangedIfNeed(instance, GUI.changed);
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }
Пример #6
0
        public override void OnInspectorGUI()
        {
            try
            {
                //DrawHeader();
                GUI.changed = false;
                GUI.color   = Color.white;
                if (commonEditor == null)
                {
                    commonEditor = ScriptableObject.CreateInstance <MidiCommonEditor>();
                }

                Event e = Event.current;

                commonEditor.DrawCaption("Midi File Player - Play Midi from the MPTK Repository", "https://paxstellar.fr/midi-file-player-detailed-view-2/");

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

                if (MidiPlayerGlobal.CurrentMidiSet.MidiFiles != null && MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count > 0)
                {
                    if (GUILayout.Button(new GUIContent(instance.MPTK_MidiIndex + " - " + instance.MPTK_MidiName, "Selected Midi File to play"), GUILayout.Height(30)))
                    {
                        InitWinSelectMidi(instance.MPTK_MidiIndex, MidiChanged);
                    }
                }
                else
                {
                    EditorGUILayout.LabelField(MidiPlayerGlobal.ErrorNoMidiFile);
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();

                commonEditor.AllPrefab(instance);
                commonEditor.MidiFileParameters(instance);
                instance.showEvents = MidiCommonEditor.DrawFoldoutAndHelp(instance.showEvents, "Show Midi Events", "https://paxstellar.fr/midi-file-player-detailed-view-2/#Foldout-Events");
                if (instance.showEvents)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(CustomEventStartPlayMidi);
                    EditorGUILayout.PropertyField(CustomEventListNotesEvent);
                    EditorGUILayout.PropertyField(CustomEventEndPlayMidi);
                    serializedObject.ApplyModifiedProperties();
                    EditorGUI.indentLevel--;
                }
                commonEditor.MidiFileInfo(instance);
                commonEditor.SynthParameters(instance, serializedObject);

#if SHOWDEFAULT
                instance.showDefault = EditorGUILayout.Foldout(instance.showDefault, "Show default editor");
                if (instance.showDefault)
                {
                    EditorGUI.indentLevel++;
                    commonEditor.DrawAlertOnDefault();
                    DrawDefaultInspector();
                    EditorGUI.indentLevel--;
                }
#endif
                MidiCommonEditor.SetSceneChangedIfNeed(instance, GUI.changed);
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }
Пример #7
0
        public void SynthParameters(MidiSynth instance, SerializedObject sobject)
        {
            instance.showSynthParameter = DrawFoldoutAndHelp(instance.showSynthParameter, "Show Synth Parameters", "https://paxstellar.fr/midi-file-player-detailed-view-2/#Foldout-Synth-Parameters");
            if (instance.showSynthParameter)
            {
                EditorGUI.indentLevel++;

                GUIContent labelCore   = new GUIContent("Core Player", "Play music with a non Unity thread. Change this properties only when not running");
                string     labelRate   = "Rate Synth Output";
                string     labelBuffer = "Buffer Synth Size";
                instance.showUnitySynthParameter = DrawFoldoutAndHelp(instance.showUnitySynthParameter, "Show Unity Audio Parameters", "https://paxstellar.fr/midi-file-player-detailed-view-2/#Foldout-Audio-Parameters");
                if (instance.showUnitySynthParameter)
                {
                    EditorGUI.indentLevel++;
                    if (myStyle == null)
                    {
                        myStyle = new CustomStyle();
                    }
                    EditorGUILayout.LabelField("With Core Player checked (fluidsynth mode), the synthesizer is working on a thread apart from the main Unity thread. Accuracy is much better. The legacy mode which is using many AudioSource will be removed with the next major version.", myStyle.LabelGreen);
                    if (!EditorApplication.isPlaying)
                    {
                        instance.MPTK_CorePlayer = EditorGUILayout.Toggle(labelCore, instance.MPTK_CorePlayer);
                    }
                    else
                    {
                        EditorGUILayout.LabelField(labelCore, new GUIContent(instance.MPTK_CorePlayer ? "True" : "False"));
                    }

                    if (NoErrorValidator.CantChangeAudioConfiguration)
                    {
                        EditorGUILayout.LabelField("Warning: Audio configuration change is disabled on this platform.", myStyle.LabelAlert);
                    }
                    else if (instance.MPTK_CorePlayer)
                    {
                        EditorGUILayout.Space();
                        EditorGUILayout.LabelField("Changing synthesizer rate and buffer size can produce unexpected effect according to the hardware. Save your work before!", myStyle.LabelGreen);
                        EditorGUILayout.Space();
                        if (!EditorApplication.isPlaying)
                        {
                            EditorGUILayout.LabelField("Increase the rate to get a better sound.", myStyle.LabelGreen);
                            synthRateLabel[0] = "Default: " + AudioSettings.outputSampleRate + " Hz";
                            int indexrate = EditorGUILayout.IntPopup(labelRate, instance.MPTK_IndexSynthRate, synthRateLabel, synthRateIndex);
                            if (indexrate != instance.MPTK_IndexSynthRate)
                            {
                                instance.MPTK_IndexSynthRate = indexrate;
                            }
                            EditorGUILayout.Space();
                        }
                        else
                        {
                            EditorGUILayout.LabelField(labelRate, instance.OutputRate.ToString());
                        }

                        if (!EditorApplication.isPlaying)
                        {
                            EditorGUILayout.LabelField("Decrease the buffer size to get a more accurate playing.", myStyle.LabelGreen);
                            int bufferLenght;
                            int numBuffers;
                            AudioSettings.GetDSPBufferSize(out bufferLenght, out numBuffers);
                            synthBufferSizeLabel[0] = "Default: " + bufferLenght;
                            int indexBuffSize = EditorGUILayout.IntPopup(labelBuffer, instance.MPTK_IndexSynthBuffSize, synthBufferSizeLabel, synthBufferSizeIndex);
                            if (indexBuffSize != instance.MPTK_IndexSynthBuffSize)
                            {
                                instance.MPTK_IndexSynthBuffSize = indexBuffSize;
                            }
                            EditorGUILayout.Space();
                        }
                        else
                        {
                            EditorGUILayout.LabelField(labelBuffer, instance.DspBufferSize.ToString());
                        }

                        EditorGUILayout.Space();
                        EditorGUILayout.LabelField("Interpolation is the core of the synth process. Linear is a good balacing between quality and performance", myStyle.LabelGreen);
                        instance.InterpolationMethod = (fluid_interp)EditorGUILayout.IntPopup("Interpolation Method", (int)instance.InterpolationMethod, synthInterpolationLabel, synthInterpolationIndex);
                    }
                    else
                    {
                        EditorGUILayout.LabelField("Warning: with non core mode, all voices will be played in separate Audio Source. SoundFont synth is not fully implemented. This mode will be removed with a future version.", myStyle.LabelAlert);
                    }

                    EditorGUI.indentLevel--;
                }

                instance.MPTK_LogWave = EditorGUILayout.Toggle(new GUIContent("Log Samples", "Log information about sample played for a NoteOn event."), instance.MPTK_LogWave);

                //instance.MPTK_PlayOnlyFirstWave = EditorGUILayout.Toggle(new GUIContent("Play Only First Wave", "Some Instrument in Preset are using more of one wave at the same time. If checked, play only the first wave, usefull on weak device, but sound experience is less good."), instance.MPTK_PlayOnlyFirstWave);
                //instance.MPTK_WeakDevice = EditorGUILayout.Toggle(new GUIContent("Weak Device", "Playing Midi files with WeakDevice activated could cause some bad interpretation of Midi Event, consequently bad sound."), instance.MPTK_WeakDevice);
                instance.MPTK_EnablePanChange = EditorGUILayout.Toggle(new GUIContent("Pan Change", "Enable midi event pan change when playing. Uncheck if you want to manage Pan in your application."), instance.MPTK_EnablePanChange);

                instance.MPTK_ApplyRealTimeModulator = EditorGUILayout.Toggle(new GUIContent("Apply Modulator", "Real-Time change Modulator from Midi and ADSR enveloppe Modulator parameters from SoundFont could have an impact on CPU. Initial value of Modulator set at Note On are keep. Uncheck to gain some % CPU on weak device."), instance.MPTK_ApplyRealTimeModulator);
                instance.MPTK_ApplyModLfo            = EditorGUILayout.Toggle(new GUIContent("Apply Mod LFO", "LFO modulation are defined in SoudFont. Uncheck to gain some % CPU on weak device."), instance.MPTK_ApplyModLfo);
                instance.MPTK_ApplyVibLfo            = EditorGUILayout.Toggle(new GUIContent("Apply Vib LFO", "LFO vibrato are defined in SoudFont. Uncheck to gain some % CPU on weak device."), instance.MPTK_ApplyVibLfo);

                instance.showSoundFontEffect = MidiCommonEditor.DrawFoldoutAndHelp(instance.showSoundFontEffect, "Show SoundFont Effect Parameters", "https://paxstellar.fr/midi-file-player-detailed-view-2/#Foldout-SoundFont-Effects");
                if (instance.showSoundFontEffect)
#if MPTK_PRO
                { CommonProEditor.EffectSoundFontParameters(instance, myStyle); }
#else
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.LabelField("[Available with MPTK Pro] These effects will be applied independently on each voices. Effects values are defined in the SoundFont, so limited modification can't be applied.", myStyle.LabelGreen);
                    EditorGUI.indentLevel--;
                }
#endif

                instance.showUnitySynthEffect = MidiCommonEditor.DrawFoldoutAndHelp(instance.showUnitySynthEffect, "Show Unity Effect Parameters", "https://paxstellar.fr/midi-file-player-detailed-view-2/#Foldout-Unity-Effects");
                if (instance.showUnitySynthEffect)
#if MPTK_PRO
                { CommonProEditor.EffectUnityParameters(instance, myStyle); }
#else
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.LabelField("[Available with MPTK Pro] These effects will be applied to all voices processed by the current MPTK gameObject. You can add multiple MPTK gameObjects to apply for different effects.", myStyle.LabelGreen);
                    EditorGUI.indentLevel--;
                }
#endif
                instance.showUnityPerformanceParameter = DrawFoldoutAndHelp(instance.showUnityPerformanceParameter, "Show Performance Parameters", "https://paxstellar.fr/midi-file-player-detailed-view-2/#Foldout-Performance");
                if (instance.showUnityPerformanceParameter)
                {
                    EditorGUI.indentLevel++;
                    instance.waitThreadMidi    = EditorGUILayout.IntSlider(new GUIContent("Thread Midi Delay", "Delay in milliseconds between call to the midi sequencer"), instance.waitThreadMidi, 1, 30);
                    instance.MaxDspLoad        = EditorGUILayout.IntSlider(new GUIContent("Max Level DSP Load", "When DSP is over the 'Max Level DSP Load' (by default 50%), some actions are taken on current playing voices for better performance"), (int)instance.MaxDspLoad, 0, 100);
                    instance.DevicePerformance = EditorGUILayout.IntSlider(new GUIContent("Device Performance", "Define amount of cleaning of the voice. 1 for weak device and high cleaning. If <=25 some voice could be stopped."), instance.DevicePerformance, 1, 100);
                    EditorGUI.indentLevel--;
                }

                instance.showSynthEvents = MidiCommonEditor.DrawFoldoutAndHelp(instance.showSynthEvents, "Show Synth Unity Events", "https://paxstellar.fr/midi-file-player-detailed-view-2/#Foldout-Synth-Unity-Events");
                if (instance.showSynthEvents)
                {
                    EditorGUI.indentLevel++;
                    if (CustomEventSynthAwake == null)
                    {
                        CustomEventSynthAwake = sobject.FindProperty("OnEventSynthAwake");
                    }
                    EditorGUILayout.PropertyField(CustomEventSynthAwake);

                    if (CustomEventSynthStarted == null)
                    {
                        CustomEventSynthStarted = sobject.FindProperty("OnEventSynthStarted");
                    }
                    EditorGUILayout.PropertyField(CustomEventSynthStarted);

                    sobject.ApplyModifiedProperties();
                    EditorGUI.indentLevel--;
                }
                EditorGUI.indentLevel--;
            }
        }
        public override void OnInspectorGUI()
        {
            try
            {
                GUI.changed = false;
                GUI.color   = Color.white;
                if (commonEditor == null)
                {
                    commonEditor = ScriptableObject.CreateInstance <MidiCommonEditor>();
                }

                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, MidiPlayerGlobal.HelpDefSoundFont));
                    EditorGUILayout.Separator();

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

                    if (MidiPlayerGlobal.CurrentMidiSet.MidiFiles != null && MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count > 0)
                    {
                        if (GUILayout.Button(new GUIContent(instance.MPTK_MidiIndex + " - " + instance.MPTK_MidiName, "Selected Midi File to play"), GUILayout.Height(30)))
                        {
                            InitWinSelectMidi(instance.MPTK_MidiIndex, MidiChanged);
                        }
                    }
                    else
                    {
                        EditorGUILayout.LabelField(MidiPlayerGlobal.ErrorNoMidiFile);
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.Space();

                    commonEditor.AllPrefab(instance);
                    commonEditor.MidiFileParameters(instance);
                    showEvents = EditorGUILayout.Foldout(showEvents, "Show Midi Events");
                    if (showEvents)
                    {
                        EditorGUILayout.PropertyField(CustomEventStartPlayMidi);
                        EditorGUILayout.PropertyField(CustomEventListNotesEvent);
                        EditorGUILayout.PropertyField(CustomEventEndPlayMidi);
                        serializedObject.ApplyModifiedProperties();
                    }
                    commonEditor.MidiFileInfo(instance);
                    commonEditor.SynthParameters(instance, serializedObject);

#if SHOWDEFAULT
                    showDefault = EditorGUILayout.Foldout(showDefault, "Show default editor");
                    if (showDefault)
                    {
                        DrawDefaultInspector();
                    }
#endif
                }
                else
                {
                    MidiCommonEditor.ErrorNoSoundFont();
                }

                MidiCommonEditor.SetSceneChangedIfNeed(instance, GUI.changed);
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }