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();
            }
        }
Example #2
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();
            }
        }