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); } }
public override void OnInspectorGUI() { try { GUI.changed = false; GUI.color = Color.white; styleBold = new GUIStyle("Label") { fontSize = 12, fontStyle = FontStyle.Bold }; string soundFontSelected = "No SoundFont selected."; if (MidiPlayerGlobal.CurrentMidiSet != null && MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo != null) { soundFontSelected = MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.Name; EditorGUILayout.LabelField(new GUIContent("SoundFont: " + MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.Name, "Define SoundFont from the menu 'Tools/MPTK - SoundFont Setup' or alt-f")); // EditorGUILayout.Separator(); instance.MidiStreamPlayer = (MidiStreamPlayer)EditorGUILayout.ObjectField(new GUIContent("Midi Stream Player"), instance.MidiStreamPlayer, typeof(MidiStreamPlayer), true); ObjType = instance.GetType(); instance.MeasureLength = UtToolsEditor.IntSlider("Mesure Length", "Quarter number per measure", "MeasureLength", instance.MeasureLength, ObjType); instance.QuarterPerMinute = UtToolsEditor.IntSlider("Quarter Per Minute", "Quarter Per Minute", "QuarterPerMinute", instance.QuarterPerMinute, ObjType); // // Running // if (Application.isPlaying) { EditorGUILayout.LabelField(new GUIContent("Measure", ""), new GUIContent(string.Format("{0,3:000}.{1,2:00}.{2,2:00}", InfinityMusic.instance.IndexMeasure + 1, InfinityMusic.instance.IndexQuarterMeasure + 1, InfinityMusic.instance.IndexSixteenthMeasure + 1), ""), styleBold); } // // Actions // if (Application.isPlaying) { instance.SongName = EditorGUILayout.TextField(new GUIContent("Song Name", ""), instance.SongName); instance.Description = EditorGUILayout.TextArea(instance.Description); EditorGUILayout.Space(); EditorGUILayout.LabelField(new GUIContent("Song", "")); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("New"), GUILayout.ExpandWidth(true))) { if (EditorUtility.DisplayDialog("New Song", "Erase current song ?", "Ok", "Cancel")) { InfinityMusic.UtNewSong(); } } if (GUILayout.Button(new GUIContent("Save"), GUILayout.ExpandWidth(true))) { string path = Path.Combine(Application.dataPath, MidiPlayerGlobal.PathToSong); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string filepath = EditorUtility.SaveFilePanel("Save Song", path, null, MidiPlayerGlobal.ExtensionSong); if (!string.IsNullOrEmpty(filepath)) { SaveLoad.UtSave(filepath); } } if (GUILayout.Button(new GUIContent("Open"), GUILayout.ExpandWidth(true))) { string path = EditorUtility.OpenFilePanel("Open Song", Path.Combine(Application.dataPath, MidiPlayerGlobal.PathToSong), MidiPlayerGlobal.ExtensionSong); if (!string.IsNullOrEmpty(path)) { InfinityMusic.UtNewSong(); SaveLoad.UtLoad(path); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.LabelField(new GUIContent("Create components", "")); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Math Motif", ""), GUILayout.ExpandWidth(true))) { UtComponent.UtNew(UtComponent.Component.Motif); } if (GUILayout.Button(new GUIContent("Cadence", ""), GUILayout.ExpandWidth(true))) { UtComponent.UtNew(UtComponent.Component.Cadence); } EditorGUILayout.EndHorizontal(); } else { //if (GUILayout.Button(new GUIContent("View folder", ""), GUILayout.ExpandWidth(false))) // EditorUtility.RevealInFinder(UtGlobal.BuildPathConfig(null)); } } else { EditorGUILayout.LabelField(new GUIContent("SoundFont: " + soundFontSelected, "Define SoundFont from the menu 'Tools/MPTK - SoundFont Setup' or alt-f")); ToolsEditor.LoadMidiSet(); ToolsEditor.CheckMidiSet(); } showDefault = EditorGUILayout.Foldout(showDefault, "Show default editor"); if (showDefault) { DrawDefaultInspector(); } if (GUI.changed) { EditorUtility.SetDirty(instance); } } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }