Exemplo n.º 1
0
        public void DrawCaption(string title, string urlHelp)
        {
            if (myStyle == null)
            {
                myStyle = new CustomStyle();
            }
            EditorGUILayout.BeginVertical(myStyle.LabelTitle);
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField(title);

            DrawHelp(urlHelp);

            EditorGUILayout.EndHorizontal();

            if (MidiPlayerGlobal.ImSFCurrent != null)
            {
                EditorGUILayout.LabelField(new GUIContent("SoundFont: " + MidiPlayerGlobal.ImSFCurrent.SoundFontName + " loaded", MidiPlayerGlobal.HelpDefSoundFont));
            }
            else if (MidiPlayerGlobal.CurrentMidiSet != null && MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo != null)
            {
                EditorGUILayout.LabelField(new GUIContent("SoundFont: " + MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.Name, MidiPlayerGlobal.HelpDefSoundFont));
            }
            else
            {
                ErrorNoSoundFont();
            }

            EditorGUILayout.EndVertical();
            //EditorGUILayout.Separator();
        }
Exemplo n.º 2
0
 static public void Display(string title, CustomStyle myStyle)
 {
     GUILayout.BeginHorizontal(myStyle.BacgDemos);
     if (buttonIconHome == null)
     {
         buttonIconHome = Resources.Load <Texture2D>("Textures/home");
     }
     if (GUILayout.Button(new GUIContent(buttonIconHome, "Go to main menu"), GUILayout.Width(60), GUILayout.Height(60)))
     {
         if (instance != null)
         {
             instance.GoToMainMenu();
         }
         else
         {
             Debug.LogWarning("Scene ScenesDemonstration is not loadded");
         }
     }
     GUILayout.Space(20);
     GUILayout.Label(title, myStyle.TitleLabel1, GUILayout.Height(60));
     GUILayout.Space(20);
     if (buttonIconMPTK == null)
     {
         buttonIconMPTK = Resources.Load <Texture2D>("Logo_MPTK");
     }
     if (GUILayout.Button(new GUIContent(buttonIconMPTK, "Go to web site"), GUILayout.Width(60), GUILayout.Height(60)))
     {
         Application.OpenURL("http://paxstellar.fr/setup-mptk-quick-start-v2/");
     }
     GUILayout.EndHorizontal();
 }
Exemplo n.º 3
0
        static public void Display(CustomStyle myStyle)
        {
            if (SoundFonts == null)
            {
                SoundFonts = MidiPlayerGlobal.MPTK_ListSoundFont;
            }

            if (SoundFonts != null)
            {
                GUILayout.Label("Select a soundfont", myStyle.TitleLabel3);
                foreach (string sfName in SoundFonts)
                {
                    GUI.color = Color.white;
                    if (sfName == MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.Name)
                    {
                        GUI.color = new Color(.7f, .9f, .7f, 1f);
                    }
                    if (GUILayout.Button(sfName))
                    {
                        MidiPlayerGlobal.MPTK_SelectSoundFont(sfName);
                    }
                }
                GUI.color = Color.white;
            }
            else
            {
                GUILayout.Label("No Soundfont found");
            }
        }
Exemplo n.º 4
0
 public void DrawAlertOnDefault()
 {
     if (myStyle == null)
     {
         myStyle = new CustomStyle();
     }
     EditorGUILayout.LabelField("Changing properties here are without any guarantee ! It's only for experimental use.", myStyle.LabelAlert);
 }
Exemplo n.º 5
0
        void OnGUI()
        {
            // Set custom Style. Good for background color 3E619800
            if (myStyle == null)
            {
                myStyle = new CustomStyle();
            }

            if (midiStreamPlayer != null)
            {
                scrollerWindow = GUILayout.BeginScrollView(scrollerWindow, false, false, GUILayout.Width(Screen.width));

                // If need, display the popup  before any other UI to avoid trigger it hidden
                PopBankInstrument.Draw(MidiPlayerGlobal.MPTK_ListBank, MidiPlayerGlobal.ImSFCurrent.DefaultBankNumber, myStyle);
                PopPatchInstrument.Draw(MidiPlayerGlobal.MPTK_ListPreset, CurrentPatchInstrument, myStyle);
                PopBankDrum.Draw(MidiPlayerGlobal.MPTK_ListBank, MidiPlayerGlobal.ImSFCurrent.DrumKitBankNumber, myStyle);
                PopPatchDrum.Draw(MidiPlayerGlobal.MPTK_ListPresetDrum, CurrentPatchDrum, myStyle);

                // MainMenu.Display("Test Midi Stream - A very simple Generated Music Stream ", myStyle);

                // Display soundfont available and select a new one
                //GUISelectSoundFont.Display(scrollerWindow, myStyle);

                // Select bank & Patch for Instrument
                // ----------------------------------
                //GUILayout.Space(spaceVertival);
                //GUILayout.Space(spaceVertival);
                GUILayout.BeginVertical(myStyle.BacgDemos);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Instrument: ", myStyle.TitleLabel3, GUILayout.Width(widthLabel));

                // Open the popup to select a bank
                if (GUILayout.Button(MidiPlayerGlobal.ImSFCurrent.DefaultBankNumber + " - Bank", GUILayout.Width(buttonWidth)))
                {
                    PopBankInstrument.Show = !PopBankInstrument.Show;
                }
                PopBankInstrument.Position(ref scrollerWindow);

                // Open the popup to select an instrument
                if (GUILayout.Button(
                        CurrentPatchInstrument.ToString() + " - " +
                        MidiPlayerGlobal.MPTK_GetPatchName(MidiPlayerGlobal.ImSFCurrent.DefaultBankNumber,
                                                           CurrentPatchInstrument),
                        GUILayout.Width(buttonWidth)))
                {
                    PopPatchInstrument.Show = !PopPatchInstrument.Show;
                }
                PopPatchInstrument.Position(ref scrollerWindow);

                GUILayout.EndHorizontal();
                GUILayout.EndScrollView();
            }
            else
            {
                GUILayout.Space(spaceVertival);
                GUILayout.Label("MidiStreamPlayer not defined, check hierarchy.", myStyle.TitleLabel3);
            }
        }
Exemplo n.º 6
0
        void OnGUI()
        {
            try
            {
                if (window == null)
                {
                    Init();
                }
                float startx = 5;
                float starty = 7;
                //Log.Write("test");

                if (myStyle == null)
                {
                    myStyle = new CustomStyle();
                }

                GUIContent content = new GUIContent()
                {
                    text = "Setup Midi files to play in your application - Version " + ToolsEditor.version, tooltip = ""
                };
                EditorGUI.LabelField(new Rect(startx, starty, 500, itemHeight), content, styleBold);

                if (GUI.Button(new Rect(startx + 410, starty - 5, 25, 25), buttonIconHelp))
                {
                    Application.OpenURL("https://paxstellar.fr/setup-mptk-add-midi-files-v2/");
                }

                GUI.color = ToolsEditor.ButtonColor;
                content   = new GUIContent()
                {
                    text = "Help & Contact", tooltip = "Get some help"
                };
                Rect rect = new Rect(window.position.size.x - buttonWidth - 5, starty, buttonWidth, buttonHeight);
                if (GUI.Button(rect, content))
                {
                    PopupWindow.Show(rect, new AboutMPTK());
                }

                starty += buttonHeight + espace;

                widthRight = window.position.size.x - widthLeft - 2 * espace - startx;
                heightList = window.position.size.y - 3 * espace - starty;

                ShowListMidiFiles(startx, starty + espace);
                ShowMidiAnalyse(startx + widthLeft + espace, starty + espace);
            }
            catch (ExitGUIException) { }
            catch (Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }
Exemplo n.º 7
0
 public void DrawAlertOnDefault()
 {
     if (myStyle == null)
     {
         myStyle = new CustomStyle();
     }
     EditorGUILayout.LabelField(
         "Changing properties here are without any guarantee!" +
         " To activate full stat, define these scripting symbols: " +
         "DEBUG_PERF_AUDIO, DEBUG_PERF_MIDI, DEBUG_STATUS_STAT"
         , myStyle.LabelAlert);
 }
Exemplo n.º 8
0
        static public void Display(Vector2 scrollerWindow, CustomStyle myStyle)
        {
            SoundFonts = new List <MPTKListItem>();
            foreach (string name in MidiPlayerGlobal.MPTK_ListSoundFont)
            {
                if (name == MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.Name)
                {
                    selectedSf = SoundFonts.Count;
                }
                SoundFonts.Add(new MPTKListItem()
                {
                    Index = SoundFonts.Count, Label = name
                });
            }

            if (PopSoundFont == null)
            {
                PopSoundFont = new PopupListItem()
                {
                    Title    = "Select A SoundFont",
                    OnSelect = SoundFontChanged,
                    ColCount = 1,
                    ColWidth = 500,
                }
            }
            ;

            if (SoundFonts != null)
            {
                PopSoundFont.Draw(SoundFonts, selectedSf, myStyle);
                GUILayout.BeginHorizontal(myStyle.BacgDemos);

                if (buttonIconNote == null)
                {
                    buttonIconNote = Resources.Load <Texture2D>("Textures/Note");
                }
                if (GUILayout.Button(new GUIContent(buttonIconNote, "Select A SoundFont"), GUILayout.Width(48), GUILayout.Height(48)))
                {
                    PopSoundFont.Show = !PopSoundFont.Show;
                }
                GUILayout.Space(20);
                GUILayout.Label("Current SoundFont: " + MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.Name, myStyle.TitleLabel2, GUILayout.Height(48));
                GUILayout.EndHorizontal();

                PopSoundFont.Position(ref scrollerWindow);
            }
            else
            {
                GUILayout.Label("No Soundfont found");
            }
        }
    }
Exemplo n.º 9
0
 public PopupListPatchs(string title, bool pselectable, List <string> data)
 {
     Content    = new GUIContent(title);
     Selectable = pselectable;
     if (MyStyle == null)
     {
         MyStyle = new CustomStyle();
     }
     Data       = data;
     CellStyle  = MyStyle.LabelList;
     TitleStyle = MyStyle.LabelTitle;
     //winHeight =(int)( Data.Count * CellStyle.CalcHeight(Content,300f)+ TitleStyle.CalcHeight(Content, 300f));
     winHeight = (int)((Data.Count + 2) * CellStyle.lineHeight + TitleStyle.lineHeight);
 }
Exemplo n.º 10
0
 static public void Display(string title, CustomStyle myStyle)
 {
     GUILayout.BeginHorizontal(myStyle.BacgDemos);
     if (buttonIconHome == null)
     {
         buttonIconHome = Resources.Load <Texture2D>("Textures/home");
     }
     if (GUILayout.Button(new GUIContent(buttonIconHome, "Go to main menu"), GUILayout.Width(48), GUILayout.Height(48)))
     {
         instance.GoToMainMenu();
     }
     GUILayout.Space(20);
     GUILayout.Label(title, myStyle.TitleLabel1, GUILayout.Height(48));
     GUILayout.EndHorizontal();
 }
Exemplo n.º 11
0
        static public void Display(string title, CustomStyle myStyle)
        {
            GUILayout.BeginHorizontal(myStyle.BacgDemos);
            if (buttonIconHome == null)
            {
                buttonIconHome = Resources.Load <Texture2D>("Textures/home");
            }
            if (buttonIconQuit == null)
            {
                buttonIconQuit = Resources.Load <Texture2D>("Textures/quit");
            }
            if (buttonIconMPTK == null)
            {
                buttonIconMPTK = Resources.Load <Texture2D>("Logo_MPTK");
            }

            if (GUILayout.Button(new GUIContent(buttonIconHome, "Go to main menu"), GUILayout.Width(60), GUILayout.Height(60)))
            {
                for (int i = 0; i < SceneManager.sceneCountInBuildSettings; i++)
                {
                    if (SceneUtility.GetScenePathByBuildIndex(i).Contains("ScenesDemonstration"))
                    {
                        MidiPlayerGlobal.MPTK_Stop();
                        SceneManager.LoadScene(i, LoadSceneMode.Single);
                        return;
                    }
                }
            }

            GUILayout.Space(20);
            GUILayout.Label(title, myStyle.TitleLabel1, GUILayout.Height(60));
            GUILayout.Space(20);

            if (GUILayout.Button(new GUIContent(buttonIconQuit, "Exit"), GUILayout.Width(60), GUILayout.Height(60)))
            {
                MidiPlayerGlobal.MPTK_Quit();
            }

            if (GUILayout.Button(new GUIContent(buttonIconMPTK, "Go to web site"), GUILayout.Width(60), GUILayout.Height(60)))
            {
                Application.OpenURL("https://paxstellar.fr/setup-mptk-quick-start-v2/");
            }
            GUILayout.EndHorizontal();
        }
Exemplo n.º 12
0
 public int Draw(CustomStyle myStyle)
 {
     if (DispatchPopupPatch)
     {
         if (Position.x < 0)
         {
             Position.x = 0;
         }
         if (Position.y < 0)
         {
             Position.y = 0;
         }
         GUILayout.Window(10, new Rect(Position, DefaultSize), DoMyWindow, "Select a patch",
                          myStyle.BackgWindow,
                          GUILayout.MaxWidth(Screen.width - Position.x - 30),
                          GUILayout.ExpandWidth(true),
                          GUILayout.MaxHeight(Screen.height - Position.y - 30),
                          GUILayout.ExpandHeight(true));
         //Debug.Log(Screen.height - position.y - 30);
     }
     return(Selected);
 }
Exemplo n.º 13
0
        void OnGUI()
        {
            try
            {
                //Debug.Log("ongui");
                KeepOpen = true;
                list     = new List <MPTKListItem>();
                foreach (string midiname in MidiPlayerGlobal.CurrentMidiSet.MidiFiles)
                {
                    list.Add(new MPTKListItem()
                    {
                        Label = midiname, Index = list.Count
                    });
                }
                ColWidth           = 250;
                ColHeight          = 30;
                calculatedColCount = 3;
                EspaceX            = 5;
                EspaceY            = 5;
                TitleHeight        = 30;
                countRow           = (int)((float)list.Count / (float)calculatedColCount + 1f);
                resizedWidth       = (int)SelectWindow.position.size.x;;
                resizedHeight      = (int)SelectWindow.position.size.y;

                if (myStyle == null)
                {
                    myStyle = new CustomStyle();
                }

                DrawWindow();
            }
            catch (Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }
Exemplo n.º 14
0
        public void SynthParameters(MidiSynth instance, SerializedObject sobject)
        {
            showSynthParameter = EditorGUILayout.Foldout(showSynthParameter, "Show Synth Parameters");
            if (showSynthParameter)
            {
                EditorGUI.indentLevel++;

                //EditorGUILayout.BeginHorizontal();
                //EditorGUILayout.PrefixLabel(new GUIContent("Cutoff Volume", "Level of volume when the sound is cut. Could be usefull on weak device to rise this value, but sound experience is less good. "));
                //instance.CutoffVolume = EditorGUILayout.Slider((float)instance.CutoffVolume*1000f, 0.1f, 5f)/1000f;
                //EditorGUILayout.EndHorizontal();

                GUIContent labelCore = new GUIContent("Core Player", "Play music with a non Unity thread. Change this properties only when not running");
                if (!EditorApplication.isPlaying)
                {
                    instance.MPTK_CorePlayer = EditorGUILayout.Toggle(labelCore, instance.MPTK_CorePlayer);
                }
                else
                {
                    EditorGUILayout.LabelField(labelCore, new GUIContent(instance.MPTK_CorePlayer ? "True" : "False"));
                }

                showUnitySynthParameter = EditorGUILayout.Foldout(showUnitySynthParameter, "Show Unity Audio Parameters");
                if (showUnitySynthParameter)
                {
                    EditorGUI.indentLevel++;
                    if (myStyle == null)
                    {
                        myStyle = new CustomStyle();
                    }
                    EditorGUILayout.LabelField("Changing synth rate and buffer size can produce unexpected effect according to the hardware. Save your work before!", myStyle.LabelAlert);

                    synthRateLabel[0] = "Default: " + AudioSettings.outputSampleRate + " Hz";
                    int indexrate = EditorGUILayout.IntPopup("Rate Synth Output", instance.MPTK_IndexSynthRate, synthRateLabel, synthRateIndex);
                    if (indexrate != instance.MPTK_IndexSynthRate)
                    {
                        instance.MPTK_IndexSynthRate = indexrate;
                    }

                    int bufferLenght;
                    int numBuffers;
                    AudioSettings.GetDSPBufferSize(out bufferLenght, out numBuffers);
                    synthBufferSizeLabel[0] = "Default: " + bufferLenght;
                    int indexBuffSize = EditorGUILayout.IntPopup("Buffer Synth Size", instance.MPTK_IndexSynthBuffSize, synthBufferSizeLabel, synthBufferSizeIndex);
                    if (indexBuffSize != instance.MPTK_IndexSynthBuffSize)
                    {
                        instance.MPTK_IndexSynthBuffSize = indexBuffSize;
                    }
                    EditorGUI.indentLevel--;
                }

                instance.MPTK_LogWave = EditorGUILayout.Toggle(new GUIContent("Log Waves", "Log information about wave found 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);

                //EditorGUILayout.BeginHorizontal();
                //EditorGUILayout.PrefixLabel(new GUIContent("Release Time Minimum", "A default release time is defined at the preset level in the SoundFont. Setting a minimum time (100 nano seconds) to avoid abrupt sound stop and remove unpleasant sound. 50ms is a good tradoff for most of the case."));
                //instance.MPTK_ReleaseTimeMin = (uint)EditorGUILayout.IntSlider((int)instance.MPTK_ReleaseTimeMin, 0, 5000000);
                //EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space();
                instance.MPTK_ApplyFilter = EditorGUILayout.Toggle(new GUIContent("Apply Filter", "Low pass filter is defined in each preset of the SoudFont. Uncheck to gain some % CPU on weak device."), instance.MPTK_ApplyFilter);
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(new GUIContent("Offset Filter Freq.", "Offset on the SF frequency set for this preset. 1000 seems a good value with the Unity filter ..."));
                instance.FilterOffset = EditorGUILayout.Slider(instance.FilterOffset, -2000f, 3000f);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space();
                instance.MPTK_ApplyReverb = EditorGUILayout.Toggle(new GUIContent("Apply Reverb", "Reverb is defined in each preset of the SoudFont."), instance.MPTK_ApplyReverb);
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(new GUIContent("Supersede Reverb", "If greater than 0, this parameter supersedes the value found in SF. 0:low dry signal 1: high dry signal"));
                instance.ReverbMix = EditorGUILayout.Slider(instance.ReverbMix, 0f, 1f);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space();
                instance.MPTK_ApplyChorus = EditorGUILayout.Toggle(new GUIContent("Apply Chorus", "Chorus is defined in each preset of the SoudFont."), instance.MPTK_ApplyChorus);
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(new GUIContent("Supersede Chorus", "If greater than 0, this parameter supersedes the value found in SF. 0:low original signal 1: high original signal"));
                instance.ChorusMix = EditorGUILayout.Slider(instance.ChorusMix, 0f, 1f);
                EditorGUILayout.EndHorizontal();

                showSynthEvents = EditorGUILayout.Foldout(showSynthEvents, "Show Synth Events");
                if (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--;
            }
        }
Exemplo n.º 15
0
        public void Draw(List <MPTKListItem> plist, int pselected, CustomStyle style)
        {
            list         = plist;
            selectedItem = pselected;
            myStyle      = style;
            if (Show)
            {
                realItemCount = 0;
                foreach (MPTKListItem item in list)
                {
                    if (item != null && (string.IsNullOrWhiteSpace(filterItem) || item.Label.ToLower().Contains(filterItem.ToLower())))
                    {
                        realItemCount++;
                    }
                }

                // Min, one column
                if (realItemCount < 3)
                {
                    realItemCount = 3;
                }
                if (ColCount < 1)
                {
                    ColCount = 1;
                }
                if (ColWidth < 20)
                {
                    ColWidth = 20;
                }
                if (ColHeight < 10)
                {
                    ColHeight = 10;
                }

                calculatedColCount = realItemCount < ColCount ? realItemCount : ColCount;
                countRow           = calculatedColCount > 1 ? (int)((float)realItemCount / (float)calculatedColCount + 1f) : realItemCount;

                // Try to fit all col without H scroll
                resizedWidth = calculatedColCount * (ColWidth + EspaceX) + EspaceX;
                if (resizedWidth < 100)
                {
                    resizedWidth = 100;
                }
                if (resizedHeight < 35)
                {
                    resizedHeight = 35;
                }

                // Try to fit all row without V scroll
                resizedHeight  = countRow * ColHeight + EspaceY;
                resizedHeight += TitleHeight + 2 * EspaceY;
                if (resizedHeight > Screen.height)
                {
                    resizedHeight = Screen.height;
                }

                windowRect.width  = resizedWidth;
                windowRect.height = resizedHeight;
                windowRect        = GUI.Window(10, windowRect, DrawWindow, "", myStyle.BackgPopupList);
            }
        }
Exemplo n.º 16
0
        public void Draw(List <MPTKListItem> plist, int pselected, CustomStyle style)
        {
            list         = plist;
            selectedItem = pselected;
            myStyle      = style;
            if (Show)
            {
                // Min, one column
                if (ColCount < 1)
                {
                    ColCount = 1;
                }

                if (ColWidth < 20)
                {
                    ColWidth = 20;
                }

                if (ColHeight < 10)
                {
                    ColHeight = 10;
                }

                if (list.Count < ColCount)
                {
                    calculatedColCount = list.Count;
                }
                else
                {
                    calculatedColCount = ColCount;
                }

                if (calculatedColCount > 1)
                {
                    countRow = (int)((float)list.Count / (float)calculatedColCount + 1f);
                }
                else
                {
                    countRow = list.Count;
                }


                if (Width < 0)
                {
                    // Try to fit all col without H scroll
                    resizedWidth = calculatedColCount * (ColWidth + EspaceX) + 5 * EspaceX;
                }
                else
                {
                    resizedWidth = Width;
                }

                if (Height < 0)
                {
                    // Try to fit all row without V scroll
                    resizedHeight = countRow * ColHeight + EspaceY;
                }
                else
                {
                    resizedHeight = Height;
                }

                resizedHeight += TitleHeight + 2 * EspaceY;

                if (positionbt.x + resizedWidth > Screen.width)
                {
                    // popup right out of the screen
                    positionbt.x = Screen.width - resizedWidth;
                }

                if (positionbt.y + resizedHeight > Screen.height)
                {
                    // popup bottom out of the screen
                    positionbt.y = Screen.height - resizedHeight;
                }

                if (positionbt.x < 0)
                {
                    // Popup left out of the screen
                    positionbt.x = 0;
                }

                if (positionbt.y < 0)
                {
                    // Popup top out of the screen
                    positionbt.y = 0;
                }

                // Popup too big for screen, resize ...
                if (resizedWidth >= Screen.width)
                {
                    positionbt.x = 0;
                    resizedWidth = Screen.width;
                }

                if (resizedHeight >= Screen.height)
                {
                    positionbt.y  = 0;
                    resizedHeight = Screen.height;
                }

                if (resizedWidth < 100)
                {
                    resizedWidth = 100;
                }

                if (resizedHeight < 35)
                {
                    resizedHeight = 35;
                }

                GUI.Window(10, new Rect(positionbt, new Vector2(resizedWidth, resizedHeight)), DrawWindow, "", myStyle.BackgPopupList);
            }
        }
Exemplo n.º 17
0
        //static public float _ratioHalfTone = 0.0594630943592952645618252949463f;

        static public void DisplayInfoSynth(MidiSynth synth, int width, CustomStyle myStyle)
        {
            string info;

            GUILayout.BeginHorizontal(GUILayout.Width(width));
            GUILayout.Label("Synthesizer statistics", myStyle.TitleLabel3, GUILayout.Width(150));
            if (GUILayout.Button("Reset Stat", GUILayout.Width(100)))
            {
                synth.MPTK_ResetStat();
            }
            GUILayout.EndHorizontal();
            info  = string.Format("Mode:\t{0}\tRate:{1}\tBuffer:{2}\tDSP:{3,-5:F2} ms\n", synth.MPTK_CorePlayer ? "Core" : "AudioSource", synth.OutputRate, synth.DspBufferSize, Math.Round(synth.StatDeltaAudioFilterReadMS, 2));
            info += string.Format("Voice:\tPlayed:{0,-4}\tFree:{1,-4}\tActive:{2,-4}\tReused:{3} %\n",
                                  synth.MPTK_StatVoicePlayed, synth.MPTK_StatVoiceCountFree,
                                  synth.MPTK_StatVoiceCountActive, Mathf.RoundToInt(synth.MPTK_StatVoiceRatioReused));

#if DEBUG_STATUS_STAT
            if (synth.StatusStat != null && synth.StatusStat.Length >= (int)fluid_voice_status.FLUID_VOICE_OFF + 2)
            {
                info += string.Format("\t\tSustain:{0,-4}\tRelease:{1,-4}\n\n",
                                      synth.StatusStat[(int)fluid_voice_status.FLUID_VOICE_SUSTAINED],
                                      synth.StatusStat[(int)fluid_voice_status.FLUID_VOICE_OFF + 1]
                                      );
            }
#endif
            if (synth.StatAudioFilterReadMA != null)
            {
                info += string.Format("Stat Synth:\tSample:{0,-5:F2} ms\tMini:{1,-5:F2}\tMaxi:{2,-5:F2}\tAvg:{3,-5:F2}\n",
                                      Math.Round(synth.StatAudioFilterReadMS, 2),
                                      synth.StatAudioFilterReadMIN < double.MaxValue ? Math.Round(synth.StatAudioFilterReadMIN, 2) : 0,
                                      Math.Round(synth.StatAudioFilterReadMAX, 2),
                                      Math.Round(synth.StatAudioFilterReadAVG, 2));
            }

            if (synth.StatDspLoadMAX != 0f)
            {
                info += string.Format("\tLoad:{0} %\tMini:{1,-5:F2}\tMaxi:{2,-5:F2}\tAvg:{3,-5:F2}",//\tLong Avg:{3,-5:F2}",
                                      Math.Round(synth.StatDspLoadPCT, 2),
                                      Math.Round(synth.StatDspLoadMIN, 2),
                                      Math.Round(synth.StatDspLoadMAX, 2),
                                      Math.Round(synth.StatDspLoadAVG, 2));
            }
            //Math.Round(synth.StatDspLoadLongAVG, 1));
            else
            {
                info += string.Format("\tDSP Load:{0} % ", Math.Round(synth.StatDspLoadPCT, 1));
            }

            if (synth.StatDspLoadPCT >= 100f)
            {
                info += string.Format("\n\t<color=red>\tDSP Load over 100%</color>");
            }
            else if (synth.StatDspLoadPCT >= synth.MaxDspLoad)
            {
                info += string.Format("\n\t<color=orange>\tDSP Load over {0}%</color>", synth.MaxDspLoad);
            }
            else
            {
                info += "\n";
            }

            // Available only when a file Midi reader is enabled
            if (synth.StatDeltaThreadMidiMA != null && synth.StatDeltaThreadMidiMIN < double.MaxValue)
            {
                info += string.Format("\nStat Sequencer:\tDelta:{0,-5:F2} ms\tMini:{1,-5:F2}\tMaxi:{2,-5:F2}\tAvg:{3,-5:F2}\n",
                                      Math.Round(synth.StatDeltaThreadMidiMS, 2),
                                      synth.StatDeltaThreadMidiMIN < double.MaxValue ? Math.Round(synth.StatDeltaThreadMidiMIN, 2) : 0,
                                      Math.Round(synth.StatDeltaThreadMidiMAX, 2),
                                      Math.Round(synth.StatDeltaThreadMidiAVG, 2));
                info += string.Format("\tRead:{0,-5:F2} ms\tTreat:{1,-5:F2}\tMaxi:{2,-5:F2}",
                                      Math.Round(synth.StatReadMidiMS, 2),
                                      Math.Round(synth.StatProcessMidiMS, 2),
                                      Math.Round(synth.StatProcessMidiMAX, 2));
            }

            //#if !UNITY_ANDROID
            //#endif
            GUILayout.Label(info, myStyle.TextFieldMultiCourier);
        }
Exemplo n.º 18
0
        void OnGUI()
        {
            if (!HelperDemo.CheckSFExists())
            {
                return;
            }
            // Set custom Style. Good for background color 3E619800
            if (myStyle == null)
            {
                myStyle = new CustomStyle();
            }

            if (midiStreamPlayer != null)
            {
                //GUILayout.BeginArea(new Rect(0, 0, 1080, 2280));
                scrollerWindow = GUILayout.BeginScrollView(scrollerWindow, false, false, GUILayout.Width(Screen.width));

                // If need, display the popup  before any other UI to avoid trigger it hidden
                PopBankInstrument.Draw(MidiPlayerGlobal.MPTK_ListBank, MidiPlayerGlobal.ImSFCurrent.DefaultBankNumber, myStyle);
                PopPatchInstrument.Draw(MidiPlayerGlobal.MPTK_ListPreset, CurrentPreset, myStyle);
                PopBankDrum.Draw(MidiPlayerGlobal.MPTK_ListBank, MidiPlayerGlobal.ImSFCurrent.DrumKitBankNumber, myStyle);
                PopPatchDrum.Draw(MidiPlayerGlobal.MPTK_ListPresetDrum, CurrentPatchDrum, myStyle);

                MainMenu.Display("Test Midi Stream - A very simple Generated Music Stream ", myStyle);

                // Display soundfont available and select a new one
                GUISelectSoundFont.Display(scrollerWindow, myStyle);

                // Select bank & Patch for Instrument
                // ----------------------------------
                //GUILayout.Space(spaceVertival);
                //GUILayout.Space(spaceVertival);
                GUILayout.BeginVertical(myStyle.BacgDemos);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Instrument", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));

                // Open the popup to select a bank
                if (GUILayout.Button(MidiPlayerGlobal.ImSFCurrent.DefaultBankNumber + " - Bank", GUILayout.Width(buttonWidth)))
                {
                    PopBankInstrument.Show = !PopBankInstrument.Show;
                }
                PopBankInstrument.Position(ref scrollerWindow);

                // Open the popup to select an instrument
                if (GUILayout.Button(
                        CurrentPreset.ToString() + " - " +
                        MidiPlayerGlobal.MPTK_GetPatchName(MidiPlayerGlobal.ImSFCurrent.DefaultBankNumber,
                                                           CurrentPreset),
                        GUILayout.Width(buttonWidth)))
                {
                    PopPatchInstrument.Show = !PopPatchInstrument.Show;
                }
                PopPatchInstrument.Position(ref scrollerWindow);

                GUILayout.EndHorizontal();

                // Select bank & Patch for Drum
                // ----------------------------
                GUILayout.Space(spaceVertival);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Drum", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));

                // Open the popup to select a bank for drum
                if (GUILayout.Button(MidiPlayerGlobal.ImSFCurrent.DrumKitBankNumber + " - Bank", GUILayout.Width(buttonWidth)))
                {
                    PopBankDrum.Show = !PopBankDrum.Show;
                }
                PopBankDrum.Position(ref scrollerWindow);

                // Open the popup to select an instrument for drum
                if (GUILayout.Button(
                        CurrentPatchDrum.ToString() + " - " +
                        MidiPlayerGlobal.MPTK_GetPatchName(MidiPlayerGlobal.ImSFCurrent.DrumKitBankNumber, CurrentPatchDrum),
                        GUILayout.Width(buttonWidth)))
                {
                    PopPatchDrum.Show = !PopPatchDrum.Show;
                }
                PopPatchDrum.Position(ref scrollerWindow);
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal(GUILayout.Width(350));
                GUILayout.Label("One Shot", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));
                if (GUILayout.Button("Play", myStyle.BtStandard, GUILayout.Width(buttonWidth * 0.666f)))
                {
                    PlayOneNote();
                }
                if (GUILayout.Button("Stop", myStyle.BtStandard, GUILayout.Width(buttonWidth * 0.666f)))
                {
                    StopOneNote();
                }
                if (GUILayout.Button("Clear", myStyle.BtStandard, GUILayout.Width(buttonWidth * 0.666f)))
                {
                    midiStreamPlayer.MPTK_ClearAllSound(true);
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal(GUILayout.Width(350));
                GUILayout.Label("Loop Notes", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));
                if (GUILayout.Button("Start / Stop", IsplayingLoopNotes ? myStyle.BtSelected : myStyle.BtStandard, GUILayout.Width(buttonWidth * 0.666f)))
                {
                    IsplayingLoopNotes = !IsplayingLoopNotes;
                }
                StartNote = (int)Slider("From", StartNote, 0, 127, true, 50);
                EndNote   = (int)Slider("To", EndNote, 0, 127, true, 50);
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal(GUILayout.Width(350));
                GUILayout.Label("Loop Presets", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));
                if (GUILayout.Button("Start / Stop", IsplayingLoopPresets ? myStyle.BtSelected : myStyle.BtStandard, GUILayout.Width(buttonWidth * 0.666f)))
                {
                    IsplayingLoopPresets = !IsplayingLoopPresets;
                }
                StartPreset = (int)Slider("From", StartPreset, 0, 127, true, 50);
                EndPreset   = (int)Slider("To", EndPreset, 0, 127, true, 50);
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal(GUILayout.Width(500));
                CurrentNote   = (int)Slider("Current note", CurrentNote, 0, 127);
                CurrentPreset = (int)Slider("Current preset", CurrentPreset, 0, 127, true);
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal();
                GUILayout.Label(" ", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));
                //if (MidiPlayerGlobal.ImSFCurrent.DrumKitBankNumber >= 0)
                DrumKit      = GUILayout.Toggle(DrumKit, "Drum Kit", GUILayout.Width(120));
                RandomPlay   = GUILayout.Toggle(RandomPlay, "Random", GUILayout.Width(120));
                ChordPlay    = GUILayout.Toggle(ChordPlay, "Chord Play", GUILayout.Width(120));
                ArpeggioPlay = GUILayout.Toggle(ArpeggioPlay, "Arpeggio Play", GUILayout.Width(120));
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal(GUILayout.Width(350));
                GUILayout.Label("Voices Statistics ", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));
                GUILayout.Label(string.Format("Played:{0}   Free:{1}   Active:{2}   Reused:{3} %",
                                              midiStreamPlayer.MPTK_StatVoicePlayed, midiStreamPlayer.MPTK_StatVoiceCountFree, midiStreamPlayer.MPTK_StatVoiceCountActive, Mathf.RoundToInt(midiStreamPlayer.MPTK_StatVoiceRatioReused)),
                                myStyle.TitleLabel3, GUILayout.Width(500));

                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal(GUILayout.Width(350));
                DelayTimeChange = Slider("Delay note", DelayTimeChange, 0.001f, 10f);
                DeltaDelay      = Slider("Delta delay", DeltaDelay, -10f, 100f, true, 80);
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal(GUILayout.Width(350));
                midiStreamPlayer.MPTK_Volume = Slider("Volume", midiStreamPlayer.MPTK_Volume, 0, 1);
                float pitchChange = Slider("Pitch", PitchChange, 0, 127, true, 80);
                if (pitchChange != PitchChange)
                {
                    LastTimePitchChange = Time.realtimeSinceStartup;
                    PitchChange         = pitchChange;
                    //Debug.Log("Slider " + PitchChange);
                    midiStreamPlayer.MPTK_PlayEvent(new MPTKEvent()
                    {
                        Command = MPTKCommand.PitchWheelChange, Value = (int)PitchChange << 7, Channel = StreamChannel
                    });
                }

                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal(GUILayout.Width(350));
                midiStreamPlayer.MPTK_Transpose = (int)Slider("Transpose", midiStreamPlayer.MPTK_Transpose, -24, 24);
                GUILayout.Space(spaceHorizontal);
                Velocity = (int)Slider("Velocity", (int)Velocity, 0f, 127f, true, 80);
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal(GUILayout.Width(350));
                int panChange = (int)Slider("Panoramic", PanChange, 0, 127);
                if (panChange != PanChange)
                {
                    PanChange = panChange;
                    midiStreamPlayer.MPTK_PlayEvent(new MPTKEvent()
                    {
                        Command = MPTKCommand.ControlChange, Controller = MPTKController.Pan, Value = PanChange, Channel = StreamChannel
                    });
                }
                GUILayout.Space(spaceHorizontal);
                midiStreamPlayer.ReverbMix = Slider("Reverb", midiStreamPlayer.ReverbMix, 0, 1, true, 80);
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal(GUILayout.Width(350));
                int modChange = (int)Slider("Modulation", ModChange, 0, 127);
                if (modChange != ModChange)
                {
                    ModChange = modChange;
                    midiStreamPlayer.MPTK_PlayEvent(new MPTKEvent()
                    {
                        Command = MPTKCommand.ControlChange, Controller = MPTKController.Modulation, Value = ModChange, Channel = StreamChannel
                    });
                }
                GUILayout.Space(spaceHorizontal);
                int expChange = (int)Slider("Expression", ExpChange, 0, 127, true, 80);
                if (expChange != ExpChange)
                {
                    ExpChange = expChange;
                    midiStreamPlayer.MPTK_PlayEvent(new MPTKEvent()
                    {
                        Command = MPTKCommand.ControlChange, Controller = MPTKController.Expression, Value = ExpChange, Channel = StreamChannel
                    });
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                //GUILayout.BeginHorizontal(GUILayout.Width(350));
                //GUILayout.Label(" ", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));
                //midiStreamPlayer.MPTK_WeakDevice = GUILayout.Toggle(midiStreamPlayer.MPTK_WeakDevice, "Weak Device", GUILayout.Width(widthLabel));
                //GUILayout.EndHorizontal();


                // end zone des parametres
                GUILayout.EndVertical();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginVertical(myStyle.BacgDemos);
                GUILayout.Label("Go to your Hierarchy, select GameObject MidiStreamPlayer: inspector contains a lot of parameters to control the sound.", myStyle.TitleLabel2);
                GUILayout.EndVertical();

                GUILayout.EndScrollView();
            }
            else
            {
                GUILayout.Space(spaceVertival);
                GUILayout.Label("MidiStreamPlayer not defined, check hierarchy.", myStyle.TitleLabel3);
            }
            //GUILayout.EndArea();
        }
        void OnGUI()
        {
            if (!HelperDemo.CheckSFExists())
            {
                return;
            }

            // Set custom Style. Good for background color 3E619800
            if (myStyle == null)
            {
                myStyle = new CustomStyle();
            }

            if (midiFilePlayer != null)
            {
                scrollerWindow = GUILayout.BeginScrollView(scrollerWindow, false, false, GUILayout.Width(Screen.width));

                // Display popup in first to avoid activate other layout behind
                PopMidi.Draw(MidiPlayerGlobal.MPTK_ListMidi, midiFilePlayer.MPTK_MidiIndex, myStyle);

                MainMenu.Display("Test Midi File Player Scripting - Demonstrate how to use the MPTK API to Play Midi", myStyle);

                GUISelectSoundFont.Display(scrollerWindow, myStyle);

                //
                // Left column: Midi action
                // ------------------------

                GUILayout.BeginHorizontal();

                GUILayout.BeginVertical(myStyle.BacgDemos, GUILayout.Width(450));
                // Open the popup to select a midi
                if (GUILayout.Button("Current Midi file: '" + midiFilePlayer.MPTK_MidiName + (midiFilePlayer.MPTK_IsPlaying ? "' is playing" : "' is not playing"), GUILayout.Width(500), GUILayout.Height(40)))
                {
                    PopMidi.Show = !PopMidi.Show;
                }
                PopMidi.Position(ref scrollerWindow);

                GUILayout.Space(20);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Time Position: " + midiFilePlayer.MPTK_PlayTime, myStyle.TitleLabel3, GUILayout.Width(220));
                double currentposition = midiFilePlayer.MPTK_Position / 1000d;
                double position        = GUILayout.HorizontalSlider((float)currentposition, 0f, (float)midiFilePlayer.MPTK_Duration.TotalSeconds, GUILayout.Width(buttonWidth));
                if (position != currentposition)
                {
                    midiFilePlayer.MPTK_Position = position * 1000d;
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(20);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Tick Position: " + midiFilePlayer.MPTK_TickCurrent + " / " + midiFilePlayer.MPTK_TickLast, myStyle.TitleLabel3, GUILayout.Width(220));
                long tick = (long)GUILayout.HorizontalSlider((float)midiFilePlayer.MPTK_TickCurrent, 0f, (float)midiFilePlayer.MPTK_TickLast, GUILayout.Width(buttonWidth));
                if (tick != midiFilePlayer.MPTK_TickCurrent)
                {
                    midiFilePlayer.MPTK_TickCurrent = tick;
                }
                GUILayout.EndHorizontal();

                // Define the global volume
                GUILayout.Space(20);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Global Volume: " + Math.Round(midiFilePlayer.MPTK_Volume, 2), myStyle.TitleLabel3, GUILayout.Width(220));
                midiFilePlayer.MPTK_Volume = GUILayout.HorizontalSlider(midiFilePlayer.MPTK_Volume * 100f, 0f, 100f, GUILayout.Width(buttonWidth)) / 100f;
                GUILayout.EndHorizontal();

                // Transpose each note
                GUILayout.Space(20);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Note Transpose: " + midiFilePlayer.MPTK_Transpose, myStyle.TitleLabel3, GUILayout.Width(220));
                midiFilePlayer.MPTK_Transpose = (int)GUILayout.HorizontalSlider((float)midiFilePlayer.MPTK_Transpose, -24f, 24f, GUILayout.Width(buttonWidth));
                GUILayout.EndHorizontal();

                // Random playing ?
                GUILayout.Space(20);
                GUILayout.BeginHorizontal();
                IsRandomPlay = GUILayout.Toggle(IsRandomPlay, "  Random Play Midi", GUILayout.Width(220));
                midiFilePlayer.MPTK_WeakDevice = GUILayout.Toggle(midiFilePlayer.MPTK_WeakDevice, "Weak Device", GUILayout.Width(220));
                GUILayout.EndHorizontal();
                GUILayout.Space(20);

                // Play/Pause/Stop/Restart actions on midi
                GUILayout.BeginHorizontal(GUILayout.Width(500));
                if (midiFilePlayer.MPTK_IsPlaying && !midiFilePlayer.MPTK_IsPaused)
                {
                    GUI.color = ButtonColor;
                }
                if (GUILayout.Button(new GUIContent("Play", "")))
                {
                    midiFilePlayer.MPTK_Play();
                }
                GUI.color = Color.white;

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

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

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

                // Previous and Next button action on midi
                GUILayout.BeginHorizontal(GUILayout.Width(500));
                if (GUILayout.Button(new GUIContent("Previous", "")))
                {
                    midiFilePlayer.MPTK_Previous();
                    CurrentIndexPlaying = midiFilePlayer.MPTK_MidiIndex;
                }
                if (GUILayout.Button(new GUIContent("Next", "")))
                {
                    midiFilePlayer.MPTK_Next();
                    CurrentIndexPlaying = midiFilePlayer.MPTK_MidiIndex;
                    Debug.Log("MPTK_Next - CurrentIndexPlaying " + CurrentIndexPlaying);
                }
                GUILayout.EndHorizontal();
                GUILayout.EndVertical();

                if (!string.IsNullOrEmpty(infoMidi) || !string.IsNullOrEmpty(infoLyrics) || !string.IsNullOrEmpty(infoCopyright) || !string.IsNullOrEmpty(infoSeqTrackName))
                {
                    //
                    // Right Column: midi infomation, lyrics, ...
                    // ------------------------------------------
                    GUILayout.BeginVertical(myStyle.BacgDemos);
                    if (!string.IsNullOrEmpty(infoMidi))
                    {
                        scrollPos1 = GUILayout.BeginScrollView(scrollPos1, false, true);//, GUILayout.Height(heightLyrics));
                        GUILayout.Label(infoMidi, myStyle.TextFieldMultiLine);
                        GUILayout.EndScrollView();
                    }
                    GUILayout.Space(5);
                    if (!string.IsNullOrEmpty(infoLyrics))
                    {
                        //Debug.Log(scrollPos + " " + countline+ " " + myStyle.TextFieldMultiLine.CalcHeight(new GUIContent(lyrics), 400));
                        //float heightLyrics = myStyle.TextFieldMultiLine.CalcHeight(new GUIContent(infoLyrics), 400);
                        //scrollPos.y = - 340;
                        //if (heightLyrics > 200) heightLyrics = 200;
                        scrollPos2 = GUILayout.BeginScrollView(scrollPos2, false, true);//, GUILayout.Height(heightLyrics));
                        GUILayout.Label(infoLyrics, myStyle.TextFieldMultiLine);
                        GUILayout.EndScrollView();
                        //if (GUILayout.Button(new GUIContent("Add", ""))) lyrics += "\ntestest testetst";
                    }
                    GUILayout.Space(5);
                    if (!string.IsNullOrEmpty(infoCopyright))
                    {
                        scrollPos3 = GUILayout.BeginScrollView(scrollPos3, false, true);
                        GUILayout.Label(infoCopyright, myStyle.TextFieldMultiLine);
                        GUILayout.EndScrollView();
                    }
                    GUILayout.Space(5);
                    if (!string.IsNullOrEmpty(infoSeqTrackName))
                    {
                        scrollPos4 = GUILayout.BeginScrollView(scrollPos4, false, true);
                        GUILayout.Label(infoSeqTrackName, myStyle.TextFieldMultiLine);
                        GUILayout.EndScrollView();
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal(myStyle.BacgDemos);
                GUILayout.Label("Go to your Hierarchy, select GameObject MidiFilePlayer: inspector contains a lot of parameters to control the sound.", myStyle.TitleLabel2);
                GUILayout.EndHorizontal();


                GUILayout.EndScrollView();
            }
        }
Exemplo n.º 20
0
        void OnGUI()
        {
            if (!HelperDemo.CheckSFExists())
            {
                return;
            }

            // Set custom Style. Good for background color 3E619800
            if (myStyle == null)
            {
                myStyle = new CustomStyle();
            }

            if (butCentered == null)
            {
                butCentered           = new GUIStyle("Button");
                butCentered.alignment = TextAnchor.MiddleCenter;
                butCentered.fontSize  = 16;
            }

            if (labCentered == null)
            {
                labCentered           = new GUIStyle("Label");
                labCentered.alignment = TextAnchor.MiddleCenter;
                labCentered.fontSize  = 16;
            }

            if (MidiLoader != null)
            {
                scrollerWindow = GUILayout.BeginScrollView(scrollerWindow, false, false, GUILayout.Width(Screen.width));

                // Display popup in first to avoid activate other layout behind
                PopMidi.Draw(MidiPlayerGlobal.MPTK_ListMidi, MidiIndex, myStyle);

                MainMenu.Display("Test Midi File Loader - Demonstrate how to use the MPTK API to load a Midi file", myStyle);

                //
                // Left column: Midi action and info
                // ---------------------------------

                GUILayout.BeginHorizontal();
                GUILayout.BeginVertical(myStyle.BacgDemos, GUILayout.Width(450));

                GUILayout.BeginHorizontal();
                // Open the popup to select a midi
                if (GUILayout.Button("Select And Load Midi File", GUILayout.Height(40)))
                {
                    PopMidi.Show = !PopMidi.Show;
                }
                PopMidi.Position(ref scrollerWindow);

                if (GUILayout.Button(new GUIContent("Read Events", ""), GUILayout.Height(40)))
                {
                    infoEvents = new List <string>();
                    List <MPTKEvent> events = MidiLoader.MPTK_ReadMidiEvents(StartTicks, EndTicks);
                    foreach (MPTKEvent evt in events)
                    {
                        infoEvents.Add(evt.ToString());
                    }
                }
                GUILayout.EndHorizontal();

                string midiname = "no midi defined";
                if (MidiIndex >= 0 && MidiPlayerGlobal.MPTK_ListMidi != null && MidiIndex < MidiPlayerGlobal.MPTK_ListMidi.Count)
                {
                    midiname = MidiPlayerGlobal.MPTK_ListMidi[MidiIndex].Label;
                }
                GUILayout.Label("Current Midi file: " + midiname, myStyle.TitleLabel3);

                GUILayout.Space(10);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Read Midi Events from: " + StartTicks, myStyle.TitleLabel3, GUILayout.Width(220));
                StartTicks = (long)GUILayout.HorizontalSlider((float)StartTicks, 0f, (float)MidiLoader.MPTK_TickLast, GUILayout.Width(buttonWidth));
                GUILayout.EndHorizontal();

                GUILayout.Space(10);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Read Midi Events to: " + EndTicks, myStyle.TitleLabel3, GUILayout.Width(220));
                EndTicks = (long)GUILayout.HorizontalSlider((float)EndTicks, 0f, (float)MidiLoader.MPTK_TickLast, GUILayout.Width(buttonWidth));
                GUILayout.EndHorizontal();

                GUILayout.Space(10);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Duration in seconds: ", myStyle.TitleLabel3, GUILayout.Width(220));
                GUILayout.Label(MidiLoader.MPTK_Duration.TotalSeconds.ToString(), myStyle.TitleLabel3);
                GUILayout.EndHorizontal();

                GUILayout.Space(10);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Beat per Measure: ", myStyle.TitleLabel3, GUILayout.Width(220));
                GUILayout.Label(MidiLoader.MPTK_NumberBeatsMeasure.ToString());
                GUILayout.EndHorizontal();

                GUILayout.Space(10);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Quarter per Beat: ", myStyle.TitleLabel3, GUILayout.Width(220));
                GUILayout.Label(MidiLoader.MPTK_NumberQuarterBeat.ToString(), myStyle.TitleLabel3);
                GUILayout.EndHorizontal();

                GUILayout.Space(10);
                GUILayout.BeginHorizontal();
                GUILayout.Label("MPTK_InitialTempo: ", myStyle.TitleLabel3, GUILayout.Width(220));
                GUILayout.Label(Convert.ToInt32(MidiLoader.MPTK_InitialTempo).ToString(), myStyle.TitleLabel3);
                GUILayout.EndHorizontal();

                // End left column
                GUILayout.EndVertical();

                if (infoEvents != null && infoEvents.Count > 0)
                {
                    GUILayout.BeginVertical(myStyle.BacgDemos, GUILayout.Width(650));

                    //
                    // Right Column: midi infomation, lyrics, ...
                    // ------------------------------------------
                    GUILayout.BeginHorizontal(myStyle.BacgDemos);

                    if (GUILayout.Button("<<", butCentered, GUILayout.Height(40)))
                    {
                        PageToDisplay = 0;
                    }
                    if (GUILayout.Button("<", butCentered, GUILayout.Height(40)))
                    {
                        PageToDisplay--;
                    }
                    GUILayout.Label("page " + (PageToDisplay + 1).ToString() + " / " + (infoEvents.Count / MAXLINEPAGE + 1).ToString(), labCentered, GUILayout.Width(150), GUILayout.Height(40));
                    if (GUILayout.Button(">", butCentered, GUILayout.Height(40)))
                    {
                        PageToDisplay++;
                    }
                    if (GUILayout.Button(">>", butCentered, GUILayout.Height(40)))
                    {
                        PageToDisplay = infoEvents.Count / MAXLINEPAGE;
                    }

                    GUILayout.EndHorizontal();

                    if (PageToDisplay < 0)
                    {
                        PageToDisplay = 0;
                    }
                    if (PageToDisplay * MAXLINEPAGE > infoEvents.Count)
                    {
                        PageToDisplay = infoEvents.Count / MAXLINEPAGE;
                    }

                    string infoToDisplay = "";
                    for (int i = PageToDisplay * MAXLINEPAGE; i < (PageToDisplay + 1) * MAXLINEPAGE; i++)
                    {
                        if (i < infoEvents.Count)
                        {
                            infoToDisplay += infoEvents[i];
                        }
                    }

                    GUILayout.BeginHorizontal();

                    scrollPos = GUILayout.BeginScrollView(scrollPos, false, false);//, GUILayout.Height(heightLyrics));
                    GUILayout.Label(infoToDisplay, myStyle.TextFieldMultiLine);
                    GUILayout.EndScrollView();

                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();

                GUILayout.EndScrollView();
            }
        }
Exemplo n.º 21
0
        void OnGUI()
        {
            // Set custom Style. Good for background color 3E619800
            if (customSkin != null)
            {
                GUI.skin = customSkin;
            }
            if (myStyle == null)
            {
                myStyle = new CustomStyle();
            }

            scrollerWindow = GUILayout.BeginScrollView(scrollerWindow, false, false, GUILayout.Width(Screen.width));


            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            GUILayout.Label(Header, GUILayout.Width(Header.width));
            GUILayout.Label("MPTK Demonstration - Have a look to the scenes !", myStyle.TitleLabel1, GUILayout.Height(Header.height));
            GUILayout.EndHorizontal();
            bool header = true;

            foreach (Demonstrator demo in Demonstrator.Demos)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(20);
                GUILayout.Label(demo.Title, header ? myStyle.LabelTitle : myStyle.LabelZone, GUILayout.Width(widthColTitle), GUILayout.Height(height));
                if (!header)
                {
                    if (GUILayout.Button("Go", GUILayout.Width(widthColGo), GUILayout.Height(height)))
                    {
                        int index = SceneUtility.GetBuildIndexByScenePath(demo.SceneName);
                        if (index < 0)
                        {
                            if (demo.Pro)
                            {
                                Debug.LogWarning("Available with the Pro verion. Have a look to menu Tools to get the pro version or https://assetstore.unity.com/packages/tools/audio/midi-tool-kit-pro-115331");
                            }
                            else
                            {
                                Debug.LogWarning("Scene " + demo.SceneName + " not found");
                            }
                        }
                        else
                        {
                            SceneManager.LoadScene(index, LoadSceneMode.Single);
                        }
                    }
                }
                else
                {
                    GUILayout.Label("Load", myStyle.LabelTitle, GUILayout.Width(widthColGo), GUILayout.Height(height));
                }

                GUILayout.Label(demo.Description, header ? myStyle.LabelTitle : myStyle.LabelZone, GUILayout.Width(widthColDescription), GUILayout.Height(height));
                GUILayout.Label(demo.SceneName, header ? myStyle.LabelTitle : myStyle.LabelZone, GUILayout.Width(widthColSceneName), GUILayout.Height(height));
                GUILayout.Label(demo.ScripName, header ? myStyle.LabelTitle : myStyle.LabelZone, GUILayout.Width(widthColScript), GUILayout.Height(height));
                GUILayout.Label(demo.Version, header ? myStyle.LabelTitle : myStyle.LabelZoneCentered, GUILayout.Width(widthColVersion), GUILayout.Height(height));
                GUILayout.EndHorizontal();
                header = false;
            }

            GUILayout.EndScrollView();
        }
Exemplo n.º 22
0
        void OnGUI()
        {
            if (!HelperDemo.CheckSFExists())
            {
                return;
            }

            // Set custom Style. Good for background color 3E619800
            if (myStyle == null)
            {
                myStyle = new CustomStyle();
            }

            if (midiStreamPlayer != null)
            {
                scrollerWindow = GUILayout.BeginScrollView(scrollerWindow, false, false, GUILayout.Width(Screen.width));

                // If need, display the popup  before any other UI to avoid trigger it hidden
                PopBankInstrument.Draw(MidiPlayerGlobal.MPTK_ListBank, MidiPlayerGlobal.ImSFCurrent.DefaultBankNumber, myStyle);
                PopPatchInstrument.Draw(MidiPlayerGlobal.MPTK_ListPreset, CurrentPatchInstrument, myStyle);
                PopBankDrum.Draw(MidiPlayerGlobal.MPTK_ListBank, MidiPlayerGlobal.ImSFCurrent.DrumKitBankNumber, myStyle);
                PopPatchDrum.Draw(MidiPlayerGlobal.MPTK_ListPresetDrum, CurrentPatchDrum, myStyle);

                MainMenu.Display("Test Midi Stream - A very simple Generated Music Stream ", myStyle);

                // Display soundfont available and select a new one
                GUISelectSoundFont.Display(scrollerWindow, myStyle);

                // Select bank & Patch for Instrument
                // ----------------------------------
                //GUILayout.Space(spaceVertival);
                //GUILayout.Space(spaceVertival);
                GUILayout.BeginVertical(myStyle.BacgDemos);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Instrument: ", myStyle.TitleLabel3, GUILayout.Width(widthLabel));

                // Open the popup to select a bank
                if (GUILayout.Button(MidiPlayerGlobal.ImSFCurrent.DefaultBankNumber + " - Bank", GUILayout.Width(buttonWidth)))
                {
                    PopBankInstrument.Show = !PopBankInstrument.Show;
                }
                PopBankInstrument.Position(ref scrollerWindow);

                // Open the popup to select an instrument
                if (GUILayout.Button(
                        CurrentPatchInstrument.ToString() + " - " +
                        MidiPlayerGlobal.MPTK_GetPatchName(MidiPlayerGlobal.ImSFCurrent.DefaultBankNumber,
                                                           CurrentPatchInstrument),
                        GUILayout.Width(buttonWidth)))
                {
                    PopPatchInstrument.Show = !PopPatchInstrument.Show;
                }
                PopPatchInstrument.Position(ref scrollerWindow);

                GUILayout.EndHorizontal();

                // Select bank & Patch for Drum
                // ----------------------------
                GUILayout.Space(spaceVertival);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Drum: ", myStyle.TitleLabel3, GUILayout.Width(widthLabel));

                // Open the popup to select a bank for drum
                if (GUILayout.Button(MidiPlayerGlobal.ImSFCurrent.DrumKitBankNumber + " - Bank", GUILayout.Width(buttonWidth)))
                {
                    PopBankDrum.Show = !PopBankDrum.Show;
                }
                PopBankDrum.Position(ref scrollerWindow);

                // Open the popup to select an instrument for drum
                if (GUILayout.Button(
                        CurrentPatchDrum.ToString() + " - " +
                        MidiPlayerGlobal.MPTK_GetPatchName(MidiPlayerGlobal.ImSFCurrent.DrumKitBankNumber, CurrentPatchDrum),
                        GUILayout.Width(buttonWidth)))
                {
                    PopPatchDrum.Show = !PopPatchDrum.Show;
                }
                PopPatchDrum.Position(ref scrollerWindow);

                GUILayout.EndHorizontal();
                GUILayout.Space(spaceVertival);
                GUILayout.BeginHorizontal(GUILayout.Width(350));
                if (GUILayout.Button("Play Loop", IsplayingLoop ? myStyle.BtSelected : myStyle.BtStandard, GUILayout.Width(buttonWidth * 0.666f)))
                {
                    IsplayingLoop = !IsplayingLoop;
                }
                if (GUILayout.Button("Play One Shot", myStyle.BtStandard, GUILayout.Width(buttonWidth * 0.666f)))
                {
                    PlayOneNote();
                }
                if (GUILayout.Button("Stop One Shot", myStyle.BtStandard, GUILayout.Width(buttonWidth * 0.666f)))
                {
                    StopOneNote();
                }
                if (GUILayout.Button("Clear", myStyle.BtStandard, GUILayout.Width(buttonWidth * 0.666f)))
                {
                    midiStreamPlayer.MPTK_ClearAllSound(true);
                }

                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);
                midiStreamPlayer.MPTK_Volume = Slider("Volume", midiStreamPlayer.MPTK_Volume, 0, 1);

                GUILayout.Space(spaceVertival);
                GUILayout.BeginHorizontal(GUILayout.Width(350));
                DelayTimeChange = Slider("Delay note", DelayTimeChange, 0.1f, 10f);
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);
                GUILayout.BeginHorizontal(GUILayout.Width(500));
                StartNote = (int)Slider("Start note", StartNote, 0, 127);
                GUILayout.Space(spaceHorizontal);
                EndNote = (int)Slider("End note", EndNote, 0, 127);
                GUILayout.Space(spaceHorizontal);
                CurrentNote = (int)Slider("Current note", CurrentNote, 0, 127);
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);
                GUILayout.BeginHorizontal(GUILayout.Width(350));
                midiStreamPlayer.MPTK_Transpose = (int)Slider("Transpose", midiStreamPlayer.MPTK_Transpose, -24, 24);
                GUILayout.Space(spaceHorizontal);
                Velocity = (int)Slider("Velocity", (int)Velocity, 0f, 127f);
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);
                GUILayout.BeginHorizontal(GUILayout.Width(350));
                int panChange = (int)Slider("Panoramic", PanChange, 0, 127);
                if (panChange != PanChange)
                {
                    PanChange = panChange;
                    midiStreamPlayer.MPTK_PlayEvent(new MPTKEvent()
                    {
                        Command = MPTKCommand.ControlChange, Controller = MPTKController.Pan, Value = PanChange, Channel = StreamChannel
                    });
                }

                GUILayout.Space(spaceHorizontal);
                midiStreamPlayer.ReverbMix = Slider("Reverb", midiStreamPlayer.ReverbMix, 0, 1);
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);
                GUILayout.BeginHorizontal(GUILayout.Width(350));

                int modChange = (int)Slider("Modulation", ModChange, 0, 127);
                if (modChange != ModChange)
                {
                    ModChange = modChange;
                    midiStreamPlayer.MPTK_PlayEvent(new MPTKEvent()
                    {
                        Command = MPTKCommand.ControlChange, Controller = MPTKController.Modulation, Value = ModChange, Channel = StreamChannel
                    });
                }
                GUILayout.Space(spaceHorizontal);
                int expChange = (int)Slider("Expression", ExpChange, 0, 127);
                if (expChange != ExpChange)
                {
                    ExpChange = expChange;
                    midiStreamPlayer.MPTK_PlayEvent(new MPTKEvent()
                    {
                        Command = MPTKCommand.ControlChange, Controller = MPTKController.Expression, Value = ExpChange, Channel = StreamChannel
                    });
                }
                GUILayout.EndHorizontal();


                GUILayout.Space(spaceVertival);
                GUILayout.BeginHorizontal();
                RandomPlay = GUILayout.Toggle(RandomPlay, "   Random Play", GUILayout.Width(widthLabel));
                if (MidiPlayerGlobal.ImSFCurrent.DrumKitBankNumber >= 0)
                {
                    bool newDrumKit = GUILayout.Toggle(DrumKit, "   Drum Kit", GUILayout.Width(widthLabel));
                    if (newDrumKit != DrumKit)
                    {
                        DrumKit = newDrumKit;
                        if (DrumKit)
                        {
                            // Set canal to dedicated drum canal (9 if canal start from 0, canal 10 is displayed in log)
                            StreamChannel = 9;
                        }
                        else
                        {
                            StreamChannel = 0;
                        }
                        CurrentPatchInstrument = 0;
                    }
                }
                midiStreamPlayer.MPTK_WeakDevice = GUILayout.Toggle(midiStreamPlayer.MPTK_WeakDevice, "   Weak Device", GUILayout.Width(widthLabel));
                GUILayout.EndHorizontal();
                GUILayout.Space(spaceVertival);
                GUILayout.EndVertical();

                GUILayout.BeginVertical(myStyle.BacgDemos);
                GUILayout.Label("Go to your Hierarchy, select GameObject MidiStreamPlayer: inspector contains a lot of parameters to control the sound.", myStyle.TitleLabel2);
                GUILayout.EndVertical();

                GUILayout.EndScrollView();
            }
            else
            {
                GUILayout.Space(spaceVertival);
                GUILayout.Label("MidiStreamPlayer not defined, check hierarchy.", myStyle.TitleLabel3);
            }
        }
Exemplo n.º 23
0
        static public void Display(Vector2 scrollerWindow, CustomStyle myStyle)
        {
            SoundFonts = new List <MPTKListItem>();
            foreach (string name in MidiPlayerGlobal.MPTK_ListSoundFont)
            {
                if (MidiPlayerGlobal.CurrentMidiSet != null && MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo != null && name == MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.Name)
                {
                    selectedSf = SoundFonts.Count;
                }
                SoundFonts.Add(new MPTKListItem()
                {
                    Index = SoundFonts.Count, Label = name
                });
            }

            if (PopSoundFont == null)
            {
                PopSoundFont = new PopupListItem()
                {
                    Title    = "Select A SoundFont",
                    OnSelect = SoundFontChanged,
                    ColCount = 1,
                    ColWidth = 500,
                }
            }
            ;

            if (SoundFonts != null)
            {
                PopSoundFont.Draw(SoundFonts, selectedSf, myStyle);
                GUILayout.BeginHorizontal(myStyle.BacgDemos);

                if (buttonIconNote == null)
                {
                    buttonIconNote = Resources.Load <Texture2D>("Textures/Note");
                }
                if (GUILayout.Button(new GUIContent(buttonIconNote, "Select A SoundFont"), GUILayout.Width(60), GUILayout.Height(60)))
                {
                    PopSoundFont.Show = !PopSoundFont.Show;
                }
                GUILayout.Space(20);
                if (MidiPlayerGlobal.ImSFCurrent != null)
                {
                    if (MidiPlayerGlobal.ImSFCurrent.LiveSF)
                    {
                        GUILayout.Label("Live SoundFont: " + MidiPlayerGlobal.ImSFCurrent.SoundFontName, myStyle.TitleLabel2, GUILayout.Height(60));
                    }
                    else
                    {
                        GUILayout.Label("Current SoundFont: " + MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.Name, myStyle.TitleLabel2, GUILayout.Height(60));
                    }
                    GUILayout.Label(string.Format("Load Time:{0} s    Samples:{1} s    Count Presets:{2}   Samples:{3}",
                                                  Math.Round(MidiPlayerGlobal.MPTK_TimeToLoadSoundFont.TotalSeconds, 3),
                                                  Math.Round(MidiPlayerGlobal.MPTK_TimeToLoadWave.TotalSeconds, 3),
                                                  MidiPlayerGlobal.MPTK_CountPresetLoaded,
                                                  MidiPlayerGlobal.MPTK_CountWaveLoaded),
                                    myStyle.TitleLabel2, GUILayout.Height(60));
                }
                else
                {
                    GUILayout.Label("No SoundFont loaded", myStyle.TitleLabel2, GUILayout.Height(60));
                }

                GUILayout.EndHorizontal();

                PopSoundFont.Position(ref scrollerWindow);
            }
            else
            {
                GUILayout.Label("No SoundFont found");
            }
        }
    }
        void OnGUI()
        {
            // Set custom Style. Good for background color 3E619800
            if (customSkin != null)
            {
                GUI.skin = customSkin;
            }
            if (myStyle == null)
            {
                myStyle = new CustomStyle();
            }

            float maxwidth = Screen.width / 2;

            if (maxwidth < 300)
            {
                maxwidth = 300;
            }

            if (midiFilePlayer != null)
            {
                GUILayout.BeginArea(new Rect(25, 30, maxwidth, 600));

                GUILayout.Label("Test Midi File Player Scripting - Demonstrate how to use the MPTK API to plays Midi", myStyle.TitleLabel1);
                if (GUILayout.Button(new GUIContent("Return to menu", "")))
                {
                    GoMainMenu.Go();
                }
                GUILayout.Space(20);

                GUISelectSoundFont.Display(myStyle);

                // Status and current position of the midi playing
                GUILayout.Space(20);
                GUILayout.Label("Current midi '" + midiFilePlayer.MPTK_MidiName + "'" + (midiFilePlayer.MPTK_IsPlaying ? " is playing" : "is not playing"), myStyle.TitleLabel3);
                float currentposition = midiFilePlayer.MPTK_Position / 1000f;
                float position        = GUILayout.HorizontalSlider(currentposition, 0f, (float)midiFilePlayer.MPTK_Duration.TotalSeconds);
                if (position != currentposition)
                {
                    midiFilePlayer.MPTK_Position = position * 1000f;
                }

                // Define the global volume
                GUILayout.Space(20);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Global Volume: " + Math.Round(midiFilePlayer.MPTK_Volume, 2), myStyle.TitleLabel3, GUILayout.Width(200));
                midiFilePlayer.MPTK_Volume = GUILayout.HorizontalSlider(midiFilePlayer.MPTK_Volume * 100f, 0f, 100f) / 100f;
                GUILayout.EndHorizontal();

                // Transpose each note
                GUILayout.Space(20);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Note Transpose: " + midiFilePlayer.MPTK_Transpose, myStyle.TitleLabel3, GUILayout.Width(200));
                midiFilePlayer.MPTK_Transpose = (int)GUILayout.HorizontalSlider((float)midiFilePlayer.MPTK_Transpose, -24f, 24f);
                GUILayout.EndHorizontal();

                // Time before a note is stop after note off
                GUILayout.Space(20);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Note Release Time: " + Math.Round(midiFilePlayer.MPTK_TimeToRelease, 2), myStyle.TitleLabel3, GUILayout.Width(200));
                midiFilePlayer.MPTK_TimeToRelease = GUILayout.HorizontalSlider(midiFilePlayer.MPTK_TimeToRelease, 0.05f, 1f);
                GUILayout.EndHorizontal();

                // Random playing ?
                GUILayout.Space(20);
                IsRandomPlay = GUILayout.Toggle(IsRandomPlay, "  Random Play Midi");
                GUILayout.Space(20);

                // Play/Pause/Stop/Restart actions on midi
                GUILayout.BeginHorizontal();
                if (midiFilePlayer.MPTK_IsPlaying && !midiFilePlayer.MPTK_IsPaused)
                {
                    GUI.color = ButtonColor;
                }
                if (GUILayout.Button(new GUIContent("Play", "")))
                {
                    midiFilePlayer.MPTK_Play();
                }
                GUI.color = Color.white;

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

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

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

                // Previous and Next button action on midi
                GUILayout.BeginHorizontal();
                if (GUILayout.Button(new GUIContent("Previous", "")))
                {
                    midiFilePlayer.MPTK_Previous();
                }
                if (GUILayout.Button(new GUIContent("Next", "")))
                {
                    midiFilePlayer.MPTK_Next();
                }
                GUILayout.EndHorizontal();

                GUILayout.Label("Go to your Hierarchy, select GameObject MidiFilePlayer, inspector contains more parameters to control your Midi player.");

                GUILayout.EndArea();
            }
        }
Exemplo n.º 25
0
        void OnGUI()
        {
            // Set custom Style. Good for background color 3E619800
            if (myStyle == null)
            {
                myStyle = new CustomStyle();
            }

            scrollerWindow = GUILayout.BeginScrollView(scrollerWindow, false, false, GUILayout.Width(Screen.width));

            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            GUILayout.Label(Header, GUILayout.Width(Header.width));
            GUILayout.Space(40);
            if (!MsgScene.gameObject.activeInHierarchy)
            {
                GUI.color = Color.black;
                GUILayout.BeginVertical();
                GUILayout.Label("MPTK Demonstration - Have a look to the demo scenes and the documentation!", myStyle.TitleLabel1, GUILayout.Height(Header.height / 2));
                GUI.color = Color.white;
                GUILayout.Space(20);
                if (GUILayout.Button("MPTK WebSite: quick start, API, doc, ...", myStyle.BtSelected, GUILayout.Width(400), GUILayout.Height(Header.height / 2 - 20)))
                {
                    Application.OpenURL("https://paxstellar.fr/midi-player-tool-kit-for-unity-v2/");
                }
                GUILayout.EndVertical();
            }

            GUILayout.EndHorizontal();
            GUILayout.Space(20);
            bool header = true;

            if (!MsgScene.gameObject.activeInHierarchy)
            {
                foreach (Demonstrator demo in Demonstrator.Demos)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(20);
                    //GUILayout.Label(demo.Title, header ? myStyle.LabelTitle : myStyle.LabelZone, GUILayout.Width(widthColTitle), GUILayout.Height(height));
                    if (!header)
                    {
                        if (GUILayout.Button(demo.Title, myStyle.BtSelected, GUILayout.Width(widthColGo), GUILayout.Height(height)))
                        {
                            for (int i = 1; i < SceneManager.sceneCountInBuildSettings; i++)
                            {
                                Debug.Log(SceneUtility.GetScenePathByBuildIndex(i));
                            }

                            int index = SceneUtility.GetBuildIndexByScenePath(demo.SceneName);
                            if (index < 0)
                            {
                                if (demo.Pro)
                                {
                                    Debug.Log("Available with the Pro vervion.");
                                }

                                Debug.LogWarning("Scene " + demo.SceneName + " not found");
                                MsgScene.gameObject.SetActive(true);
                            }
                            else
                            {
                                SceneManager.LoadScene(index, LoadSceneMode.Single);
                            }
                        }
                    }
                    else
                    {
                        GUILayout.Label("Load", myStyle.LabelTitle, GUILayout.Width(widthColGo), GUILayout.Height(height));
                    }

                    GUILayout.Label(demo.Description, header ? myStyle.LabelTitle : myStyle.LabelZone, GUILayout.Width(widthColDescription), GUILayout.Height(height));
                    GUILayout.Label(demo.SceneName, header ? myStyle.LabelTitle : myStyle.LabelZone, GUILayout.Width(widthColSceneName), GUILayout.Height(height));
                    GUILayout.Label(demo.ScripName, header ? myStyle.LabelTitle : myStyle.LabelZone, GUILayout.Width(widthColScript), GUILayout.Height(height));
                    GUILayout.Label(demo.Version, header ? myStyle.LabelTitle : myStyle.LabelZoneCentered, GUILayout.Width(widthColVersion), GUILayout.Height(height));
                    GUILayout.EndHorizontal();
                    header = false;
                }
            }
            GUILayout.EndScrollView();
        }
Exemplo n.º 26
0
        void OnGUI()
        {
            //if (!HelperDemo.CheckSFExists()) return;
            // Set custom Style. Good for background color 3E619800
            if (myStyle == null)
            {
                myStyle = new CustomStyle();
            }

            if (midiStreamPlayer != null)
            {
                //GUILayout.BeginArea(new Rect(0, 0, 1080, 2280));
                scrollerWindow = GUILayout.BeginScrollView(scrollerWindow, false, false, GUILayout.Width(Screen.width));

                // If need, display the popup  before any other UI to avoid trigger it hidden
                if (HelperDemo.CheckSFExists())
                {
                    PopBankInstrument.Draw(MidiPlayerGlobal.MPTK_ListBank, MidiPlayerGlobal.ImSFCurrent.DefaultBankNumber, myStyle);
                    PopPatchInstrument.Draw(MidiPlayerGlobal.MPTK_ListPreset, CurrentPreset, myStyle);
                    PopBankDrum.Draw(MidiPlayerGlobal.MPTK_ListBank, MidiPlayerGlobal.ImSFCurrent.DrumKitBankNumber, myStyle);
                    PopPatchDrum.Draw(MidiPlayerGlobal.MPTK_ListPresetDrum, CurrentPatchDrum, myStyle);

                    MainMenu.Display("Test Midi Stream - A very simple Generated Music Stream ", myStyle);

                    // Display soundfont available and select a new one
                    GUISelectSoundFont.Display(scrollerWindow, myStyle);

                    // Select bank & Patch for Instrument
                    // ----------------------------------
                    //GUILayout.Space(spaceVertival);
                    //GUILayout.Space(spaceVertival);
                    GUILayout.BeginVertical(myStyle.BacgDemos);
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Instrument", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));

                    // Open the popup to select a bank
                    if (GUILayout.Button(MidiPlayerGlobal.ImSFCurrent.DefaultBankNumber + " - Bank", GUILayout.Width(buttonWidth)))
                    {
                        PopBankInstrument.Show = !PopBankInstrument.Show;
                    }
                    PopBankInstrument.Position(ref scrollerWindow);

                    // Open the popup to select an instrument
                    if (GUILayout.Button(
                            CurrentPreset.ToString() + " - " +
                            MidiPlayerGlobal.MPTK_GetPatchName(MidiPlayerGlobal.ImSFCurrent.DefaultBankNumber,
                                                               CurrentPreset),
                            GUILayout.Width(buttonWidth)))
                    {
                        PopPatchInstrument.Show = !PopPatchInstrument.Show;
                    }
                    PopPatchInstrument.Position(ref scrollerWindow);
                    StreamChannel = (int)Slider("Channel", StreamChannel, 0, 15, true, 100);

                    GUILayout.EndHorizontal();

                    // Select bank & Patch for Drum
                    // ----------------------------
                    GUILayout.Space(spaceVertival);
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Drum", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));

                    // Open the popup to select a bank for drum
                    if (GUILayout.Button(MidiPlayerGlobal.ImSFCurrent.DrumKitBankNumber + " - Bank", GUILayout.Width(buttonWidth)))
                    {
                        PopBankDrum.Show = !PopBankDrum.Show;
                    }
                    PopBankDrum.Position(ref scrollerWindow);

                    // Open the popup to select an instrument for drum
                    if (GUILayout.Button(
                            CurrentPatchDrum.ToString() + " - " +
                            MidiPlayerGlobal.MPTK_GetPatchName(MidiPlayerGlobal.ImSFCurrent.DrumKitBankNumber, CurrentPatchDrum),
                            GUILayout.Width(buttonWidth)))
                    {
                        PopPatchDrum.Show = !PopPatchDrum.Show;
                    }
                    PopPatchDrum.Position(ref scrollerWindow);
                    GUILayout.EndHorizontal();
                }
                else
                {
                    GUILayout.BeginVertical(myStyle.BacgDemos);
                }

                GUILayout.Space(spaceVertival);

                HelperDemo.DisplayInfoSynth(midiStreamPlayer, 500, myStyle);

                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal(GUILayout.Width(350));
                GUILayout.Label("One Shot", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));
                if (GUILayout.Button("Play", myStyle.BtStandard, GUILayout.Width(buttonWidth * 0.666f)))
                {
                    Play(true);
                }

                if (GUILayout.Button("Stop", myStyle.BtStandard, GUILayout.Width(buttonWidth * 0.666f)))
                {
                    StopOneNote();
#if MPTK_PRO
                    StopChord();
#endif
                }
                if (GUILayout.Button("Clear", myStyle.BtStandard, GUILayout.Width(buttonWidth * 0.666f)))
                {
                    midiStreamPlayer.MPTK_ClearAllSound(true);
                    // midiStreamPlayer.MPTK_InitSynth();
                }
                if (GUILayout.Button("Re-init", myStyle.BtStandard, GUILayout.Width(buttonWidth * 0.666f)))
                {
                    midiStreamPlayer.MPTK_InitSynth();
                    CurrentPreset = CurrentPatchDrum = 0;
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal(GUILayout.Width(500));
                CurrentNote = (int)Slider("Note", CurrentNote, 0, 127);
                int preset = (int)Slider("Preset", CurrentPreset, 0, 127, true);
                if (preset != CurrentPreset)
                {
                    CurrentPreset = preset;
                    midiStreamPlayer.MPTK_PlayEvent(new MPTKEvent()
                    {
                        Command = MPTKCommand.PatchChange,
                        Value   = CurrentPreset,
                        Channel = StreamChannel,
                    });
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal(GUILayout.Width(350));
                GUILayout.Label("Loop Notes", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));
                if (GUILayout.Button("Start / Stop", IsplayingLoopNotes ? myStyle.BtSelected : myStyle.BtStandard, GUILayout.Width(buttonWidth * 0.666f)))
                {
                    IsplayingLoopNotes = !IsplayingLoopNotes;
                }
                StartNote = (int)Slider("From", StartNote, 0, 127, true, 50);
                EndNote   = (int)Slider("To", EndNote, 0, 127, true, 50);
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal(GUILayout.Width(350));
                GUILayout.Label("Loop Presets", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));
                if (GUILayout.Button("Start / Stop", IsplayingLoopPresets ? myStyle.BtSelected : myStyle.BtStandard, GUILayout.Width(buttonWidth * 0.666f)))
                {
                    IsplayingLoopPresets = !IsplayingLoopPresets;
                }
                StartPreset = (int)Slider("From", StartPreset, 0, 127, true, 50);
                EndPreset   = (int)Slider("To", EndPreset, 0, 127, true, 50);
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);
#if DEBUG_MULTI
                GUILayout.BeginHorizontal();
                GUILayout.Label(" ", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));
                CountNoteToPlay = (int)Slider("Play Multiple Notes", CountNoteToPlay, 1, 200, false, 70);
                GUILayout.EndHorizontal();
#endif

                GUILayout.BeginHorizontal();
                GUILayout.Label(" ", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));
                //if (MidiPlayerGlobal.ImSFCurrent.DrumKitBankNumber >= 0)
                bool newDrumKit = GUILayout.Toggle(DrumKit, "Drum Kit", GUILayout.Width(120));
                if (newDrumKit != DrumKit)
                {
                    DrumKit = newDrumKit;
                    // Set canal to dedicated drum canal 9
                    StreamChannel = DrumKit  ? 9 : 0;
                }
                RandomPlay   = GUILayout.Toggle(RandomPlay, "Random", GUILayout.Width(120));
                ChordPlay    = GUILayout.Toggle(ChordPlay, "Play Chord", GUILayout.Width(120));
                ChordLibPlay = GUILayout.Toggle(ChordLibPlay, "Play Chord Lib", GUILayout.Width(120));
                GUILayout.EndHorizontal();

#if MPTK_PRO
                if (ChordPlay)
                {
                    GUILayout.BeginVertical(myStyle.BacgDemos1);
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Chord from Degree", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));
                    CountNoteChord = (int)Slider("Count", CountNoteChord, 2, 17, false, 70);
                    DegreeChord    = (int)Slider("Degree", DegreeChord, 1, 7, false, 70);
                    ArpeggioPlay   = (int)Slider("Arpeggio (ms)", ArpeggioPlay, 0, 500, false, 70);
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Label(" ", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));
                    int range = (int)Slider("Range", RangeChord, 0, MPTKRangeLib.RangeCount - 1, false, 70);
                    if (RangeChord != range)
                    {
                        RangeChord = range;
                        midiStreamPlayer.MPTK_RangeSelected = RangeChord;
                    }
                    GUILayout.Label(midiStreamPlayer.MPTK_RangeName, myStyle.TitleLabel3, GUILayout.MaxWidth(200));
                    GUILayout.Label("See file GammeDefinition.csv in folder Resources/GeneratorTemplate", myStyle.TitleLabel3, GUILayout.Width(500));
                    GUILayout.EndHorizontal();
                    GUILayout.EndVertical();
                }

                if (ChordLibPlay)
                {
                    GUILayout.BeginVertical(myStyle.BacgDemos1);
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Chord from Lib", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));
                    CurrentChord = (int)Slider("Chord", CurrentChord, 0, MPTKChordLib.ChordCount - 1, false, 70);
                    GUILayout.Label(MPTKChordLib.Chords[CurrentChord].Name, myStyle.TitleLabel3, GUILayout.MaxWidth(200));
                    GUILayout.Label("See file ChordLib.csv in folder Resources/GeneratorTemplate", myStyle.TitleLabel3, GUILayout.Width(500));
                    GUILayout.EndHorizontal();
                    GUILayout.EndVertical();
                }
#else
                if (ChordPlay || ChordLibPlay)
                {
                    GUILayout.BeginVertical(myStyle.BacgDemos1);
                    GUILayout.Space(spaceVertival);
                    GUILayout.Label("Chord and Range are available only with MPTK PRO", myStyle.TitleLabel3);
                    GUILayout.Space(spaceVertival);
                    GUILayout.EndVertical();
                }
#endif
                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal(GUILayout.Width(350));
                Frequency    = Slider("Frequency", Frequency, 0.05f, 10f);
                NoteDuration = Slider("Duration", NoteDuration, -1f, 100f, true, 80);
                NoteDelay    = Slider("Delay", NoteDelay, 0f, 10f, true, 80);
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal(GUILayout.Width(350));
                midiStreamPlayer.MPTK_Volume = Slider("Volume", midiStreamPlayer.MPTK_Volume, 0, 1);
                float pitchChange = Slider("Pitch", PitchChange, 0, 127, true, 80);
                if (pitchChange != PitchChange)
                {
                    LastTimePitchChange = Time.realtimeSinceStartup;
                    PitchChange         = pitchChange;
                    //Debug.Log("Slider " + PitchChange);
                    midiStreamPlayer.MPTK_PlayEvent(new MPTKEvent()
                    {
                        Command = MPTKCommand.PitchWheelChange, Value = (int)PitchChange << 7, Channel = StreamChannel
                    });
                }

                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal(GUILayout.Width(350));
                midiStreamPlayer.MPTK_Transpose = (int)Slider("Transpose", midiStreamPlayer.MPTK_Transpose, -24, 24);
                GUILayout.Space(spaceHorizontal);
                Velocity = (int)Slider("Velocity", (int)Velocity, 0f, 127f, true, 80);
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal(GUILayout.Width(350));
                int panChange = (int)Slider("Panoramic", PanChange, 0, 127);
                if (panChange != PanChange)
                {
                    PanChange = panChange;
                    midiStreamPlayer.MPTK_PlayEvent(new MPTKEvent()
                    {
                        Command = MPTKCommand.ControlChange, Controller = MPTKController.Pan, Value = PanChange, Channel = StreamChannel
                    });
                }
                //GUILayout.Space(spaceHorizontal);
                //midiStreamPlayer.ReverbMix = Slider("Reverb", midiStreamPlayer.ReverbMix, 0, 1, true, 80);
                //GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginHorizontal(GUILayout.Width(350));
                int modChange = (int)Slider("Modulation", ModChange, 0, 127);
                if (modChange != ModChange)
                {
                    ModChange = modChange;
                    midiStreamPlayer.MPTK_PlayEvent(new MPTKEvent()
                    {
                        Command = MPTKCommand.ControlChange, Controller = MPTKController.Modulation, Value = ModChange, Channel = StreamChannel
                    });
                }
                GUILayout.Space(spaceHorizontal);
                int expChange = (int)Slider("Expression", ExpChange, 0, 127, true, 80);
                if (expChange != ExpChange)
                {
                    ExpChange = expChange;
                    midiStreamPlayer.MPTK_PlayEvent(new MPTKEvent()
                    {
                        Command = MPTKCommand.ControlChange, Controller = MPTKController.Expression, Value = ExpChange, Channel = StreamChannel
                    });
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(spaceVertival);

                //GUILayout.BeginHorizontal(GUILayout.Width(350));
                //GUILayout.Label(" ", myStyle.TitleLabel3, GUILayout.Width(widthFirstCol));
                //midiStreamPlayer.MPTK_WeakDevice = GUILayout.Toggle(midiStreamPlayer.MPTK_WeakDevice, "Weak Device", GUILayout.Width(widthLabel));
                //GUILayout.EndHorizontal();


                // end zone des parametres
                GUILayout.EndVertical();

                GUILayout.Space(spaceVertival);

                GUILayout.BeginVertical(myStyle.BacgDemos);
                GUILayout.Label("Go to your Hierarchy, select GameObject MidiStreamPlayer: inspector contains a lot of parameters to control the sound.", myStyle.TitleLabel2);
                GUILayout.EndVertical();

                GUILayout.EndScrollView();
            }
            else
            {
                GUILayout.Space(spaceVertival);
                GUILayout.Label("MidiStreamPlayer not defined, check hierarchy.", myStyle.TitleLabel3);
            }
            //GUILayout.EndArea();
        }
Exemplo n.º 27
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--;
            }
        }
        void OnGUI()
        {
            int spaceV = 10;

            if (!HelperDemo.CheckSFExists())
            {
                return;
            }

            // Set custom Style. Good for background color 3E619800
            if (myStyle == null)
            {
                myStyle = new CustomStyle();
            }

            if (midiFilePlayer != null)
            {
                scrollerWindow = GUILayout.BeginScrollView(scrollerWindow, false, false, GUILayout.Width(Screen.width));

                // Display popup in first to avoid activate other layout behind
                PopMidi.Draw(MidiPlayerGlobal.MPTK_ListMidi, midiFilePlayer.MPTK_MidiIndex, myStyle);

                MainMenu.Display("Test Midi File Player Scripting - Demonstrate how to use the MPTK API to Play Midi", myStyle);

                GUISelectSoundFont.Display(scrollerWindow, myStyle);

                //
                // Left column: Midi action
                // ------------------------

                GUILayout.BeginHorizontal();

                GUILayout.BeginVertical(myStyle.BacgDemos, GUILayout.Width(550));
                // Open the popup to select a midi
                if (GUILayout.Button("Current Midi file: '" + midiFilePlayer.MPTK_MidiName + (midiFilePlayer.MPTK_IsPlaying ? "' is playing" : "' is not playing"), GUILayout.Width(500), GUILayout.Height(40)))
                {
                    PopMidi.Show = !PopMidi.Show;
                }
                PopMidi.Position(ref scrollerWindow);

                GUILayout.Space(spaceV);
                string playTime     = string.Format("{0:00}:{1:00}:{2:00}:{3:000}", midiFilePlayer.MPTK_PlayTime.Hours, midiFilePlayer.MPTK_PlayTime.Minutes, midiFilePlayer.MPTK_PlayTime.Seconds, midiFilePlayer.MPTK_PlayTime.Milliseconds);
                string realDuration = string.Format("{0:00}:{1:00}:{2:00}:{3:000}", midiFilePlayer.MPTK_RealDuration.Hours, midiFilePlayer.MPTK_RealDuration.Minutes, midiFilePlayer.MPTK_RealDuration.Seconds, midiFilePlayer.MPTK_RealDuration.Milliseconds);

                GUILayout.Label(string.Format("Time from start playing {0} / {1}", playTime, realDuration), myStyle.TitleLabel3, GUILayout.Width(400));

#if TestWithLocalTime
                TimeSpan localDeltaMidi = DateTime.Now - localStartTimeMidi;
                GUILayout.Label(string.Format("Debug Time start local  {0} {1:F3} {2}",
                                              string.Format("{0:00}:{1:00}:{2:00}:{3:000}",
                                                            localDeltaMidi.Hours, localDeltaMidi.Minutes, localDeltaMidi.Seconds, localDeltaMidi.Milliseconds),
                                              (midiFilePlayer.MPTK_PlayTime - localDeltaMidi).TotalSeconds, midiFilePlayer.OutputRate), myStyle.TitleLabel3, GUILayout.Width(400));
#endif

                //GUILayout.Space(spaceV);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Time Position: " + playTime, myStyle.TitleLabel3, GUILayout.Width(220));
                double currentPosition = Math.Round(midiFilePlayer.MPTK_Position / 1000d, 2);
                double newPosition     = Math.Round(GUILayout.HorizontalSlider((float)currentPosition, 0f, (float)midiFilePlayer.MPTK_Duration.TotalSeconds, GUILayout.Width(buttonWidth)), 2);
                if (newPosition != currentPosition)
                {
                    Debug.Log("New position " + currentPosition + " --> " + newPosition + " " + Event.current.type);
                    midiFilePlayer.MPTK_Position = newPosition * 1000d;
                }
                GUILayout.EndHorizontal();


                //GUILayout.Space(spaceV);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Tick Position: " + midiFilePlayer.MPTK_TickCurrent + " / " + midiFilePlayer.MPTK_TickLast, myStyle.TitleLabel3, GUILayout.Width(220));
                long tick = (long)GUILayout.HorizontalSlider((float)midiFilePlayer.MPTK_TickCurrent, 0f, (float)midiFilePlayer.MPTK_TickLast, GUILayout.Width(buttonWidth));
                if (tick != midiFilePlayer.MPTK_TickCurrent)
                {
                    midiFilePlayer.MPTK_TickCurrent = tick;
                }
                GUILayout.EndHorizontal();

                // Define the global volume
                GUILayout.Space(spaceV);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Global Volume: " + Math.Round(midiFilePlayer.MPTK_Volume, 2), myStyle.TitleLabel3, GUILayout.Width(220));
                midiFilePlayer.MPTK_Volume = GUILayout.HorizontalSlider(midiFilePlayer.MPTK_Volume * 100f, 0f, 100f, GUILayout.Width(buttonWidth)) / 100f;
                GUILayout.EndHorizontal();

                // Transpose each note
                GUILayout.Space(spaceV);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Note Transpose: " + midiFilePlayer.MPTK_Transpose, myStyle.TitleLabel3, GUILayout.Width(220));
                midiFilePlayer.MPTK_Transpose = (int)GUILayout.HorizontalSlider((float)midiFilePlayer.MPTK_Transpose, -24f, 24f, GUILayout.Width(buttonWidth));
                GUILayout.EndHorizontal();

                // Transpose each note
                GUILayout.Space(spaceV);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Speed: " + Math.Round(midiFilePlayer.MPTK_Speed, 2), myStyle.TitleLabel3, GUILayout.Width(220));
                midiFilePlayer.MPTK_Speed = GUILayout.HorizontalSlider((float)midiFilePlayer.MPTK_Speed, 0.1f, 5f, GUILayout.Width(buttonWidth));
                GUILayout.EndHorizontal();


                GUILayout.Space(spaceV);
                GUILayout.BeginHorizontal(GUILayout.Width(350));
                GUILayout.Label("Voices Statistics ", myStyle.TitleLabel3, GUILayout.Width(220));
                GUILayout.Label(string.Format("Played:{0,-4}   Free:{1,-3}   Active:{2,-3}   Reused:{3} %",
                                              midiFilePlayer.MPTK_StatVoicePlayed, midiFilePlayer.MPTK_StatVoiceCountFree, midiFilePlayer.MPTK_StatVoiceCountActive, Mathf.RoundToInt(midiFilePlayer.MPTK_StatVoiceRatioReused)),
                                myStyle.TitleLabel3, GUILayout.Width(330));
                GUILayout.EndHorizontal();

                // Enable or disable channel
                GUILayout.Space(spaceV);
                GUILayout.Label("Channel / Preset, enable or disable channel: ", myStyle.TitleLabel3, GUILayout.Width(400));

                GUILayout.BeginHorizontal();
                for (int channel = 0; channel < midiFilePlayer.MPTK_ChannelCount(); channel++)
                {
                    bool state = GUILayout.Toggle(midiFilePlayer.MPTK_ChannelEnableGet(channel), string.Format("{0} / {1}", channel + 1, midiFilePlayer.MPTK_ChannelPresetGetIndex(channel)), GUILayout.Width(65));
                    if (state != midiFilePlayer.MPTK_ChannelEnableGet(channel))
                    {
                        midiFilePlayer.MPTK_ChannelEnableSet(channel, state);
                        Debug.LogFormat("Channel {0} state:{1}, preset:{2}", channel + 1, state, midiFilePlayer.MPTK_ChannelPresetGetName(channel) ?? "not set");
                    }

                    if (channel == 7)
                    {
                        // Create a new line ...
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                    }
                }
                GUILayout.EndHorizontal();

                // Random playing ?
                GUILayout.Space(spaceV);
                GUILayout.BeginHorizontal();
                IsRandomPlay = GUILayout.Toggle(IsRandomPlay, "  Random Play Midi", GUILayout.Width(220));

                // Weak device ?
                //midiFilePlayer.MPTK_WeakDevice = GUILayout.Toggle(midiFilePlayer.MPTK_WeakDevice, "Weak Device", GUILayout.Width(220));
                GUILayout.EndHorizontal();
                GUILayout.Space(spaceV);

                // Play/Pause/Stop/Restart actions on midi
                GUILayout.BeginHorizontal(GUILayout.Width(500));
                if (midiFilePlayer.MPTK_IsPlaying && !midiFilePlayer.MPTK_IsPaused)
                {
                    GUI.color = ButtonColor;
                }
                if (GUILayout.Button(new GUIContent("Play", "")))
                {
                    midiFilePlayer.MPTK_Play();
                }
                GUI.color = Color.white;

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

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

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

                // Previous and Next button action on midi
                GUILayout.BeginHorizontal(GUILayout.Width(500));
                if (GUILayout.Button(new GUIContent("Previous", "")))
                {
                    midiFilePlayer.MPTK_Previous();
                    CurrentIndexPlaying = midiFilePlayer.MPTK_MidiIndex;
                }
                if (GUILayout.Button(new GUIContent("Next", "")))
                {
                    midiFilePlayer.MPTK_Next();
                    CurrentIndexPlaying = midiFilePlayer.MPTK_MidiIndex;
                    Debug.Log("MPTK_Next - CurrentIndexPlaying " + CurrentIndexPlaying);
                }
                GUILayout.EndHorizontal();
                GUILayout.EndVertical();

                if (!string.IsNullOrEmpty(infoMidi) || !string.IsNullOrEmpty(infoLyrics) || !string.IsNullOrEmpty(infoCopyright) || !string.IsNullOrEmpty(infoSeqTrackName))
                {
                    //
                    // Right Column: midi infomation, lyrics, ...
                    // ------------------------------------------
                    GUILayout.BeginVertical(myStyle.BacgDemos);
                    if (!string.IsNullOrEmpty(infoMidi))
                    {
                        scrollPos1 = GUILayout.BeginScrollView(scrollPos1, false, true);//, GUILayout.Height(heightLyrics));
                        GUILayout.Label(infoMidi, myStyle.TextFieldMultiLine);
                        GUILayout.EndScrollView();
                    }
                    GUILayout.Space(5);
                    if (!string.IsNullOrEmpty(infoLyrics))
                    {
                        //Debug.Log(scrollPos + " " + countline+ " " + myStyle.TextFieldMultiLine.CalcHeight(new GUIContent(lyrics), 400));
                        //float heightLyrics = myStyle.TextFieldMultiLine.CalcHeight(new GUIContent(infoLyrics), 400);
                        //scrollPos.y = - 340;
                        //if (heightLyrics > 200) heightLyrics = 200;
                        scrollPos2 = GUILayout.BeginScrollView(scrollPos2, false, true);//, GUILayout.Height(heightLyrics));
                        GUILayout.Label(infoLyrics, myStyle.TextFieldMultiLine);
                        GUILayout.EndScrollView();
                        //if (GUILayout.Button(new GUIContent("Add", ""))) lyrics += "\ntestest testetst";
                    }
                    GUILayout.Space(5);
                    if (!string.IsNullOrEmpty(infoCopyright))
                    {
                        scrollPos3 = GUILayout.BeginScrollView(scrollPos3, false, true);
                        GUILayout.Label(infoCopyright, myStyle.TextFieldMultiLine);
                        GUILayout.EndScrollView();
                    }
                    GUILayout.Space(5);
                    if (!string.IsNullOrEmpty(infoSeqTrackName))
                    {
                        scrollPos4 = GUILayout.BeginScrollView(scrollPos4, false, true);
                        GUILayout.Label(infoSeqTrackName, myStyle.TextFieldMultiLine);
                        GUILayout.EndScrollView();
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal(myStyle.BacgDemos);
                GUILayout.Label("Go to your Hierarchy, select GameObject MidiFilePlayer: inspector contains a lot of parameters to control the sound.", myStyle.TitleLabel2);
                GUILayout.EndHorizontal();


                GUILayout.EndScrollView();
            }
        }
Exemplo n.º 29
0
        void OnGUI()
        {
            // Set custom Style. Good for background color 3E619800
            if (customSkin != null)
            {
                GUI.skin = customSkin;
            }
            if (myStyle == null)
            {
                myStyle = new CustomStyle();
            }

            float maxwidth = Screen.width / 2;

            if (maxwidth < 300)
            {
                maxwidth = 300;
            }

            if (midiStreamPlayer != null)
            {
                GUILayout.BeginArea(new Rect(25, 30, maxwidth, 600));

                GUILayout.Label("Test Midi Stream - A very simple music stream generated", myStyle.TitleLabel1);
                if (GUILayout.Button(new GUIContent("Return to menu", "")))
                {
                    GoMainMenu.Go();
                }
                GUILayout.Space(20);

                GUISelectSoundFont.Display(myStyle);

                GUILayout.Space(20);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Global Volume: " + Math.Round(midiStreamPlayer.MPTK_Volume, 2), myStyle.TitleLabel3, GUILayout.Width(200));
                midiStreamPlayer.MPTK_Volume = GUILayout.HorizontalSlider(midiStreamPlayer.MPTK_Volume * 100f, 0f, 100f) / 100f;
                GUILayout.EndHorizontal();

                GUILayout.Space(20);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Note Transpose: " + midiStreamPlayer.MPTK_Transpose, myStyle.TitleLabel3, GUILayout.Width(200));
                midiStreamPlayer.MPTK_Transpose = (int)GUILayout.HorizontalSlider((float)midiStreamPlayer.MPTK_Transpose, -24f, 24f);
                GUILayout.EndHorizontal();

                GUILayout.Space(20);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Note Velocity: " + Velocity, myStyle.TitleLabel3, GUILayout.Width(200));
                Velocity = (int)GUILayout.HorizontalSlider((int)Velocity, 0f, 127f);
                GUILayout.EndHorizontal();

                GUILayout.Space(20);
                GUILayout.BeginHorizontal();
                GUILayout.Label("Note Release Time: " + Math.Round(midiStreamPlayer.MPTK_TimeToRelease, 2), myStyle.TitleLabel3, GUILayout.Width(200));
                midiStreamPlayer.MPTK_TimeToRelease = GUILayout.HorizontalSlider(midiStreamPlayer.MPTK_TimeToRelease, 0.05f, 1f);
                GUILayout.EndHorizontal();

                GUILayout.Space(20);

                GUILayout.BeginHorizontal();
                RandomPlay = GUILayout.Toggle(RandomPlay, "   Random Play", GUILayout.Width(200));
                DrumKit    = GUILayout.Toggle(DrumKit, "   Drum Kit", GUILayout.Width(200));


                if (MidiPlayerGlobal.MPTK_ListPreset != null && MidiPlayerGlobal.MPTK_ListPreset.Count > 0)
                {
                    if (!RandomPlay && DrumKit)
                    {
                        if (MidiPlayerGlobal.MPTK_ListDrum != null && CurrentNote < MidiPlayerGlobal.MPTK_ListDrum.Count)
                        {
                            // Display the drum playing (each key is a different drum in midi norm)
                            GUILayout.Label("Drum:" + MidiPlayerGlobal.MPTK_ListDrum[CurrentNote], myStyle.TitleLabel3);
                        }
                        else
                        {
                            GUILayout.Label("No Drumkit found in your SoundFont for key " + CurrentNote, myStyle.TitleLabel3);
                        }
                    }
                    else
                    {
                        if (CurrentPatch >= 0 && CurrentPatch < MidiPlayerGlobal.MPTK_ListPreset.Count)
                        {
                            // Open the popup to select an instrument
                            if (GUILayout.Button(MidiPlayerGlobal.MPTK_ListPreset[CurrentPatch]))
                            {
                                PopPatch.Selected           = CurrentPatch;
                                PopPatch.DispatchPopupPatch = !PopPatch.DispatchPopupPatch;
                            }

                            // If need, display the popup to select an instrument
                            CurrentPatch = PopPatch.Draw(myStyle);


                            Event e = Event.current;
                            if (e.type == EventType.Repaint)
                            {
                                // Get the position of the button to set the position popup near the button : same X and above
                                Rect lastRect = GUILayoutUtility.GetLastRect();
                                // Don't forget that the window can be scrolled !
                                PopPatch.Position = new Vector2(
                                    lastRect.x - scroller.x,
                                    lastRect.y - PopPatch.RealRect.height - lastRect.height - scroller.y);
                            }
                        }
                        else
                        {
                            GUILayout.Label("Patch: " + CurrentPatch + " Nothing found", myStyle.TitleLabel3);
                        }
                    }
                    GUILayout.EndHorizontal();
                }

                GUILayout.Space(20);
                GUILayout.Label("Go to your Hierarchy, select GameObject TestMidiStream: inspector contains some parameters to control your generator.", myStyle.TitleLabel3);

                GUILayout.EndArea();
            }
        }