public void OnGUI() { try { if (customSkin != null) { GUI.skin = customSkin; } if (myStyle == null) { myStyle = new CustomStyle(); } GUI.changed = false; GUI.color = Color.white; //GUIStyle styleBold; //styleBold = new GUIStyle("Label") //{ // fontSize = 12, // fontStyle = FontStyle.Bold //}; float widthSelectSong = 200; float buttonHeight = 30; float buttonWidth = 200; float listHeight = 150; float maxwidth = Screen.width / 2; if (maxwidth < 300) { maxwidth = 300; } if (MidiPlayerGlobal.CurrentMidiSet != null && MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo != null) { GUILayout.BeginArea(new Rect(25, 30, maxwidth, 600)); GUILayout.Label("InfinityMusic - Music generated by an algo", myStyle.TitleLabel1); if (GUILayout.Button(new GUIContent("Return to menu", ""))) { GoMainMenu.Go(); } GUILayout.Space(20); GUISelectSoundFont.Display(myStyle); GUILayout.Space(20); GUILayout.Label( string.Format("Measure {0,3:000}.{1,2:00}.{2,2:00}", InfinityMusic.instance.IndexMeasure + 1, InfinityMusic.instance.IndexQuarterMeasure + 1, InfinityMusic.instance.IndexSixteenthMeasure + 1), myStyle.TitleLabel2); GUILayout.Space(20); GUILayout.BeginHorizontal(); SelectSong(widthSelectSong, listHeight); GUILayout.BeginVertical(); if (GUILayout.Button("New", GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight))) { GuiMessage = null; InfinityMusic.UtNewSong(); instance.SongName = ""; } if (GUILayout.Button("Open", GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight))) { if (string.IsNullOrEmpty(SelectedSongName)) { GuiMessage = "Select a song name"; } else { GuiMessage = null; string path = Path.Combine(Application.dataPath, MidiPlayerGlobal.PathToSong); string filepath = Path.Combine(path, SelectedSongName + "." + MidiPlayerGlobal.ExtensionSong); if (!string.IsNullOrEmpty(filepath)) { instance.SongName = SelectedSongName; InfinityMusic.UtNewSong(); SaveLoad.UtLoad(filepath); } } } instance.SongName = GUILayout.TextField(instance.SongName, GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight)); if (GUILayout.Button("Save", GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight))) { if (string.IsNullOrEmpty(instance.SongName)) { GuiMessage = "Set a name for this song"; } else { GuiMessage = null; string path = Path.Combine(Application.dataPath, MidiPlayerGlobal.PathToSong); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string filepath = Path.Combine(path, instance.SongName + "." + MidiPlayerGlobal.ExtensionSong); if (!string.IsNullOrEmpty(filepath)) { SaveLoad.UtSave(filepath); } } } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.BeginVertical(); if (!string.IsNullOrEmpty(GuiMessage)) { GUI.color = Color.red; GUILayout.Label(GuiMessage, myStyle.TitleLabel2); GUI.color = Color.white; } GUILayout.Label("Go to your Hierarchy and select InfinityMusic:", myStyle.TitleLabel2); GUILayout.Label(" - Add MathMotif or Cadence components by clicking on button.", myStyle.TitleLabel2); GUILayout.Label(" - Select created components MathMotif or Cadence under InfinityMusic.", myStyle.TitleLabel2); GUILayout.Label(" - Change parameters in inspector to change melody.", myStyle.TitleLabel2); GUILayout.EndVertical(); } else { GUILayout.Label(new GUIContent("SoundFont: no soundfont selected", "Define SoundFont from the menu 'Tools/MPTK - SoundFont Setup' or alt-f")); } GUILayout.EndArea(); } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
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(); } }