// private void OnLostFocus() // { //#if UNITY_2017_1_OR_NEWER // // Trig an error before v2017... // if (Application.isPlaying) // { // window.Close(); // } //#endif // } /// <summary> /// Reload data /// </summary> private void OnFocus() { // Load description of available soundfont try { ToolsEditor.LoadMidiSet(); ToolsEditor.CheckMidiSet(); if (MidiPlayerGlobal.ImSFCurrent != null) { KeepAllPatchs = MidiPlayerGlobal.ImSFCurrent.KeepAllPatchs; KeepAllZones = MidiPlayerGlobal.ImSFCurrent.KeepAllZones; RemoveUnusedWaves = MidiPlayerGlobal.ImSFCurrent.RemoveUnusedWaves; } // cause catch if call when playing (setup open on run mode) if (!Application.isPlaying) { AssetDatabase.Refresh(); } // Exec after Refresh, either cause errror ToolsEditor.LoadImSF(); } catch (Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
/// <summary> /// Reload data /// </summary> private void OnFocus() { // Load description of available soundfont try { MidiPlayerGlobal.InitPath(); //Debug.Log(MidiPlayerGlobal.ImSFCurrent == null ? "ImSFCurrent is null" : "ImSFCurrent:" + MidiPlayerGlobal.ImSFCurrent.SoundFontName); //Debug.Log(MidiPlayerGlobal.CurrentMidiSet == null ? "CurrentMidiSet is null" : "CurrentMidiSet" + MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.Name); //Debug.Log(MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo == null ? "ActiveSounFontInfo is null" : MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.Name); ToolsEditor.LoadMidiSet(); ToolsEditor.CheckMidiSet(); // cause catch if call when playing (setup open on run mode) try { if (!Application.isPlaying) { AssetDatabase.Refresh(); } } catch (Exception) { } // Exec after Refresh, either cause errror if (MidiPlayerGlobal.ImSFCurrent == null) { MidiPlayerGlobal.LoadCurrentSF(); } } catch (Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
void OnEnable() { try { instance = (MidiFileLoader)target; if (!Application.isPlaying) { // Load description of available soundfont if (MidiPlayerGlobal.CurrentMidiSet == null || MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo == null) { MidiPlayerGlobal.InitPath(); ToolsEditor.LoadMidiSet(); ToolsEditor.CheckMidiSet(); } } if (winSelectMidi != null) { //Debug.Log("OnEnable winSelectMidi " + winSelectMidi.Title); winSelectMidi.SelectedItem = instance.MPTK_MidiIndex; winSelectMidi.Repaint(); winSelectMidi.Focus(); } //EditorApplication.playModeStateChanged += EditorApplication_playModeStateChanged; } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
/// <summary> /// Add Midi files from a folder /// </summary> private static void AddMidiFromFolder() { try { string selectedFolder = EditorUtility.OpenFolderPanel("Import Midi from a folder", ToolsEditor.lastDirectoryMidi, ""); if (!string.IsNullOrEmpty(selectedFolder)) { ToolsEditor.lastDirectoryMidi = Path.GetDirectoryName(selectedFolder); string[] files = Directory.GetFiles(selectedFolder); foreach (string file in files) { if (file.EndsWith(".mid") || file.EndsWith(".midi")) { InsertMidiFIle(file); } } } AssetDatabase.Refresh(); ToolsEditor.LoadMidiSet(); ToolsEditor.CheckMidiSet(); AssetDatabase.Refresh(); } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
private void OnFocus() { // Load description of available soundfont try { ToolsEditor.LoadMidiSet(); ToolsEditor.CheckMidiSet(); AssetDatabase.Refresh(); } catch (Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
void OnEnable() { try { instance = (MidiStreamPlayer)target; // Load description of available soundfont if (MidiPlayerGlobal.CurrentMidiSet == null || MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo == null) { ToolsEditor.LoadMidiSet(); ToolsEditor.CheckMidiSet(); } } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
//static private GUIStyle styleInfoMidi; // PopupSelectMidi PopMidi; void OnEnable() { try { //Debug.Log("OnEnable MidiFilePlayerEditor"); CustomEventStartPlayMidi = serializedObject.FindProperty("OnEventStartPlayMidi"); CustomEventListNotesEvent = serializedObject.FindProperty("OnEventNotesMidi"); CustomEventEndPlayMidi = serializedObject.FindProperty("OnEventEndPlayMidi"); instance = (MidiFilePlayer)target; // Load description of available soundfont if (MidiPlayerGlobal.CurrentMidiSet == null || MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo == null) { ToolsEditor.LoadMidiSet(); ToolsEditor.CheckMidiSet(); } } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
/// <summary> /// Add a new Midi file from desktop /// </summary> private static void AddMidifile() { try { string selectedFile = EditorUtility.OpenFilePanelWithFilters("Open and import Midi file", ToolsEditor.lastDirectoryMidi, new string[] { "Midi files", "mid,midi", "Karoke files", "kar", "All", "*" }); if (!string.IsNullOrEmpty(selectedFile)) { // selectedFile contins also the folder ToolsEditor.lastDirectoryMidi = Path.GetDirectoryName(selectedFile); InsertMidiFIle(selectedFile); } AssetDatabase.Refresh(); ToolsEditor.LoadMidiSet(); ToolsEditor.CheckMidiSet(); AssetDatabase.Refresh(); ReadEvents(); } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
public static void ErrorNoMidiFile() { GUIStyle labError = new GUIStyle("Label"); labError.normal.background = SetColor(new Texture2D(2, 2), new Color(0.9f, 0.9f, 0.9f)); labError.normal.textColor = new Color(0.8f, 0.1f, 0.1f); labError.alignment = TextAnchor.MiddleLeft; labError.wordWrap = true; labError.fontSize = 12; Texture buttonIconFolder = Resources.Load <Texture2D>("Textures/question-mark"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(MidiPlayerGlobal.ErrorNoMidiFile, labError, GUILayout.Height(40f)); if (GUILayout.Button(new GUIContent(buttonIconFolder, "Help"), GUILayout.Width(40f), GUILayout.Height(40f))) { Application.OpenURL("https://paxstellar.fr/setup-mptk-quick-start-v2/"); } EditorGUILayout.EndHorizontal(); MidiPlayerGlobal.InitPath(); ToolsEditor.LoadMidiSet(); ToolsEditor.CheckMidiSet(); Debug.Log(MidiPlayerGlobal.ErrorNoMidiFile); }
void OnEnable() { try { instance = (MidiFilePlayer)target; //Debug.Log("MidiFilePlayerEditor OnEnable " + instance.MPTK_MidiIndex); //Debug.Log("OnEnable MidiFilePlayerEditor"); CustomEventStartPlayMidi = serializedObject.FindProperty("OnEventStartPlayMidi"); CustomEventListNotesEvent = serializedObject.FindProperty("OnEventNotesMidi"); CustomEventEndPlayMidi = serializedObject.FindProperty("OnEventEndPlayMidi"); if (!Application.isPlaying) { // Load description of available soundfont if (MidiPlayerGlobal.CurrentMidiSet == null || MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo == null) { MidiPlayerGlobal.InitPath(); ToolsEditor.LoadMidiSet(); ToolsEditor.CheckMidiSet(); } } if (winSelectMidi != null) { //Debug.Log("OnEnable winSelectMidi " + winSelectMidi.Title); winSelectMidi.SelectedItem = instance.MPTK_MidiIndex; winSelectMidi.Repaint(); winSelectMidi.Focus(); } //EditorApplication.playModeStateChanged += EditorApplication_playModeStateChanged; } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
public override void OnInspectorGUI() { try { GUI.changed = false; GUI.color = Color.white; //mDebug.Log(Event.current.type); string soundFontSelected = "No SoundFont selected."; if (MidiPlayerGlobal.CurrentMidiSet != null && MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo != null) { soundFontSelected = MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.Name; EditorGUILayout.LabelField(new GUIContent("SoundFont: " + soundFontSelected, "Define SoundFont from the menu 'Tools/MPTK - SoundFont Setup' or alt-f")); EditorGUILayout.Separator(); float volume = EditorGUILayout.Slider(new GUIContent("Volume", "Set global volume for this midi playing"), instance.MPTK_Volume, 0f, 1f); if (instance.MPTK_Volume != volume) { instance.MPTK_Volume = volume; } EditorGUILayout.BeginHorizontal(); string tooltipDistance = "Playing is paused if distance between AudioListener and this component is greater than MaxDistance"; instance.MPTK_PauseOnDistance = EditorGUILayout.Toggle(new GUIContent("Pause With Distance", tooltipDistance), instance.MPTK_PauseOnDistance); EditorGUILayout.LabelField(new GUIContent("Current:" + Math.Round(instance.distanceEditorModeOnly, 2), tooltipDistance)); EditorGUILayout.EndHorizontal(); float distance = EditorGUILayout.Slider(new GUIContent("Max Distance", tooltipDistance), instance.MPTK_MaxDistance, 0f, 500f); if (instance.MPTK_MaxDistance != distance) { instance.MPTK_MaxDistance = distance; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Transpose"); instance.MPTK_Transpose = EditorGUILayout.IntSlider(instance.MPTK_Transpose, -24, 24); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Release Time (sec.)"); instance.MPTK_TimeToRelease = EditorGUILayout.Slider(instance.MPTK_TimeToRelease, 0.05f, 1f); EditorGUILayout.EndHorizontal(); instance.MPTK_LogWaves = EditorGUILayout.Toggle(new GUIContent("Log Waves", "Log information about wave for each notes played"), instance.MPTK_LogWaves); } else { EditorGUILayout.LabelField(new GUIContent("SoundFont: " + soundFontSelected, "Define SoundFont from the menu 'Tools/MPTK - SoundFont Setup' or alt-f")); ToolsEditor.LoadMidiSet(); ToolsEditor.CheckMidiSet(); } if (GUI.changed) { EditorUtility.SetDirty(instance); } } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
public override void OnInspectorGUI() { try { //if (styleInfoMidi == null) //{ // styleInfoMidi = new GUIStyle(EditorStyles.textArea); // styleInfoMidi.normal.textColor = new Color(0, 0, 0.99f); // styleInfoMidi.alignment = TextAnchor.UpperLeft; // //styleDragZone.border = new RectOffset(2, 2, 2, 2); //} GUI.changed = false; GUI.color = Color.white; //Transform t = (Transform)target; //Debug.Log(t.localPosition+" " + t.position); //mDebug.Log(Event.current.type); Event e = Event.current; string soundFontSelected = "No SoundFont selected."; if (MidiPlayerGlobal.CurrentMidiSet != null && MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo != null) { soundFontSelected = MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.Name; EditorGUILayout.LabelField(new GUIContent("SoundFont: " + soundFontSelected, "Define SoundFont from the menu 'Tools/MPTK - SoundFont Setup' or alt-f")); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("Midi ", "Select Midi File to play"), GUILayout.Width(150)); //if (GUILayout.Button(new GUIContent("Refresh", "Reload all Midi from resource folder"))) MidiPlayerGlobal.CheckMidiSet(); if (MidiPlayerGlobal.CurrentMidiSet.MidiFiles != null && MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count > 0) { // Search index from midi name int selectedMidi = instance.MPTK_MidiIndex; if (selectedMidi < 0) { selectedMidi = 0; instance.MPTK_MidiName = MidiPlayerGlobal.CurrentMidiSet.MidiFiles[selectedMidi]; } int newSelectMidi = EditorGUILayout.Popup(selectedMidi, MidiPlayerGlobal.CurrentMidiSet.MidiFiles.ToArray()); // Is midifile has changed ? if (newSelectMidi != selectedMidi) { instance.MPTK_MidiIndex = newSelectMidi; instance.MPTK_RePlay(); } } else { EditorGUILayout.LabelField("No Midi defined, go to menu 'Tools/MPTK - Midi File Setup' or alt-m"); instance.MPTK_MidiName = ""; } EditorGUILayout.EndHorizontal(); float volume = EditorGUILayout.Slider(new GUIContent("Volume", "Set global volume for this midi playing"), instance.MPTK_Volume, 0f, 1f); if (instance.MPTK_Volume != volume) { instance.MPTK_Volume = volume; } instance.MPTK_PlayOnStart = EditorGUILayout.Toggle(new GUIContent("Play At Startup", "Start playing midi when the application starts"), instance.MPTK_PlayOnStart); instance.MPTK_DirectSendToPlayer = EditorGUILayout.Toggle(new GUIContent("Direct send to player", "Midi events are send to the midi player directly"), instance.MPTK_DirectSendToPlayer); EditorGUILayout.BeginHorizontal(); string tooltipDistance = "Playing is paused if distance between AudioListener and this component is greater than MaxDistance"; instance.MPTK_PauseOnDistance = EditorGUILayout.Toggle(new GUIContent("Pause With Distance", tooltipDistance), instance.MPTK_PauseOnDistance); EditorGUILayout.LabelField(new GUIContent("Current:" + Math.Round(instance.distanceEditorModeOnly, 2), tooltipDistance)); EditorGUILayout.EndHorizontal(); float distance = EditorGUILayout.Slider(new GUIContent("Max Distance", tooltipDistance), instance.MPTK_MaxDistance, 0f, 500f); if (instance.MPTK_MaxDistance != distance) { instance.MPTK_MaxDistance = distance; } instance.MPTK_Loop = EditorGUILayout.Toggle(new GUIContent("Loop", "Enable loop on midi play"), instance.MPTK_Loop); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Speed"); float speed = EditorGUILayout.Slider(instance.MPTK_Speed, 0.1f, 5f); if (instance.MPTK_Speed != speed) { instance.MPTK_Speed = speed; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Transpose"); instance.MPTK_Transpose = EditorGUILayout.IntSlider(instance.MPTK_Transpose, -24, 24); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Release Time (sec.)"); instance.MPTK_TimeToRelease = EditorGUILayout.Slider(instance.MPTK_TimeToRelease, 0.05f, 1f); EditorGUILayout.EndHorizontal(); instance.MPTK_LogWaves = EditorGUILayout.Toggle(new GUIContent("Log Waves", "Log information about wave for each notes played"), instance.MPTK_LogWaves); if (EditorApplication.isPlaying) { EditorGUILayout.Separator(); EditorGUILayout.LabelField("Time", instance.playTimeEditorModeOnly + " / " + instance.durationEditorModeOnly); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Position"); float pos = EditorGUILayout.Slider(instance.MPTK_Position, 0f, (float)instance.MPTK_Duration.TotalMilliseconds); if (instance.MPTK_Position != pos) { instance.MPTK_Position = pos; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (instance.MPTK_IsPlaying && !instance.MPTK_IsPaused) { GUI.color = ToolsEditor.ButtonColor; } if (GUILayout.Button(new GUIContent("Play", ""))) { instance.MPTK_Play(); } GUI.color = Color.white; if (instance.MPTK_IsPaused) { GUI.color = ToolsEditor.ButtonColor; } if (GUILayout.Button(new GUIContent("Pause", ""))) { if (instance.MPTK_IsPaused) { instance.MPTK_Play(); } else { instance.MPTK_Pause(); } } GUI.color = Color.white; if (GUILayout.Button(new GUIContent("Stop", ""))) { instance.MPTK_Stop(); } if (GUILayout.Button(new GUIContent("Restart", ""))) { instance.MPTK_RePlay(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Previous", ""))) { instance.MPTK_Previous(); } if (GUILayout.Button(new GUIContent("Next", ""))) { instance.MPTK_Next(); } EditorGUILayout.EndHorizontal(); } showMidiParameter = EditorGUILayout.Foldout(showMidiParameter, "Show Midi Parameters"); if (showMidiParameter) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("Quantization", ""), GUILayout.Width(150)); int newLevel = EditorGUILayout.Popup(instance.MPTK_Quantization, popupQuantization); if (newLevel != instance.MPTK_Quantization && newLevel >= 0 && newLevel < popupQuantization.Length) { instance.MPTK_Quantization = newLevel; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); instance.MPTK_EnableChangeTempo = EditorGUILayout.Toggle(new GUIContent("Enable Tempo Change", "Enable midi event tempo change when playing"), instance.MPTK_EnableChangeTempo); EditorGUILayout.LabelField(new GUIContent("Current:" + Math.Round(instance.MPTK_Tempo, 0), "Current tempo defined in Midi")); EditorGUILayout.EndHorizontal(); instance.MPTK_EnablePanChange = EditorGUILayout.Toggle(new GUIContent("Enable Pan Change", "Enable midi event pan change when playing"), instance.MPTK_EnablePanChange); instance.MPTK_KeepNoteOff = EditorGUILayout.Toggle(new GUIContent("Keep Midi NoteOff", "Keep Midi NoteOff and NoteOn with Velocity=0 (need to restart the playing Midi)"), instance.MPTK_KeepNoteOff); instance.MPTK_LogEvents = EditorGUILayout.Toggle(new GUIContent("Log Midi Events", "Log information about each midi events read"), instance.MPTK_LogEvents); } showMidiInfo = EditorGUILayout.Foldout(showMidiInfo, "Show Midi Info"); if (showMidiInfo) { if (!string.IsNullOrEmpty(instance.MPTK_SequenceTrackName)) { if (taSequence == null) { taSequence = new TextArea("Sequence"); } taSequence.Display(instance.MPTK_SequenceTrackName); } if (!string.IsNullOrEmpty(instance.MPTK_ProgramName)) { if (taProgram == null) { taProgram = new TextArea("Program"); } taProgram.Display(instance.MPTK_ProgramName); } if (!string.IsNullOrEmpty(instance.MPTK_TrackInstrumentName)) { if (taInstrument == null) { taInstrument = new TextArea("Instrument"); } taInstrument.Display(instance.MPTK_TrackInstrumentName); } if (!string.IsNullOrEmpty(instance.MPTK_TextEvent)) { if (taText == null) { taText = new TextArea("TextEvent"); } taText.Display(instance.MPTK_TextEvent); } if (!string.IsNullOrEmpty(instance.MPTK_Copyright)) { if (taCopyright == null) { taCopyright = new TextArea("Copyright"); } taCopyright.Display(instance.MPTK_Copyright); } } showEvents = EditorGUILayout.Foldout(showEvents, "Show Events"); if (showEvents) { EditorGUILayout.PropertyField(CustomEventStartPlayMidi); EditorGUILayout.PropertyField(CustomEventListNotesEvent); EditorGUILayout.PropertyField(CustomEventEndPlayMidi); serializedObject.ApplyModifiedProperties(); } //showDefault = EditorGUILayout.Foldout(showDefault, "Show default editor"); //if (showDefault) DrawDefaultInspector(); } else { EditorGUILayout.LabelField(new GUIContent("SoundFont: " + soundFontSelected, "Define SoundFont from the menu 'Tools/MPTK - SoundFont Setup' or alt-f")); ToolsEditor.LoadMidiSet(); ToolsEditor.CheckMidiSet(); } if (GUI.changed) { EditorUtility.SetDirty(instance); } } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
/// <summary> /// Display, add, remove Soundfont /// </summary> /// <param name="localstartX"></param> /// <param name="localstartY"></param> private void ShowListSoundFonts(float localstartX, float localstartY, float width, float height) { try { Rect zone = new Rect(localstartX, localstartY, width, height); GUI.color = new Color(.8f, .8f, .8f, 1f); GUI.Box(zone, ""); GUI.color = Color.white; if (MidiPlayerGlobal.CurrentMidiSet != null && MidiPlayerGlobal.CurrentMidiSet.SoundFonts != null) { string caption = "SoundFont available"; if (MidiPlayerGlobal.CurrentMidiSet.SoundFonts.Count == 0) { caption = "No SoundFont available yet"; MidiPlayerGlobal.ImSFCurrent = null; } GUIContent content = new GUIContent() { text = caption, tooltip = "Each SoundFonts contains a set of bank of sound. \nOnly one SoundFont can be active at the same time for the midi player" }; EditorGUI.LabelField(new Rect(localstartX + xpostitlebox, localstartY + ypostitlebox, 300, itemHeight), content, styleBold); Rect rect = new Rect(width - buttonWidth, localstartY + ypostitlebox, buttonWidth, buttonHeight); #if MPTK_PRO if (GUI.Button(rect, "Add SoundFont")) { //if (EditorUtility.DisplayDialog("Import SoundFont", "This action could take time, do you confirm ?", "Ok", "Cancel")) { SoundFontOptim.AddSoundFont(); scrollPosSoundFont = Vector2.zero; KeepAllPatchs = false; KeepAllZones = false; //listPatchs = PatchOptim.PatchUsed(); } } #else if (GUI.Button(rect, "Add SoundFont [PRO]")) { try { PopupWindow.Show(rect, new GetVersionPro()); } catch (Exception) { // generate some weird exception ... } } #endif Rect listVisibleRect = new Rect(localstartX, localstartY + itemHeight, width - 5, height - itemHeight - 5); Rect listContentRect = new Rect(0, 0, width - 20, MidiPlayerGlobal.CurrentMidiSet.SoundFonts.Count * itemHeight + 5); scrollPosSoundFont = GUI.BeginScrollView(listVisibleRect, scrollPosSoundFont, listContentRect); float boxY = 0; for (int i = 0; i < MidiPlayerGlobal.CurrentMidiSet.SoundFonts.Count; i++) { SoundFontInfo sf = MidiPlayerGlobal.CurrentMidiSet.SoundFonts[i]; GUI.color = new Color(.7f, .7f, .7f, 1f); float boxX = 5; GUI.Box(new Rect(boxX, boxY + 5, width - 30, itemHeight), ""); GUI.color = Color.white; content = new GUIContent() { text = sf.Name, tooltip = "" }; EditorGUI.LabelField(new Rect(boxX, boxY + 9, 200, itemHeight), content); if (sf.Name == MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.Name) { GUI.color = ToolsEditor.ButtonColor; } boxX += 200 + espace; if (GUI.Button(new Rect(boxX, boxY + 9, 80, buttonHeight), "Select")) { #if MPTK_PRO OptimInfo = new BuilderInfo(); #endif MidiPlayerGlobal.CurrentMidiSet.SetActiveSoundFont(i); string soundPath = Path.Combine(Application.dataPath + "/", MidiPlayerGlobal.PathToSoundfonts); soundPath = Path.Combine(soundPath + "/", sf.Name); ToolsEditor.LoadImSF(soundPath, sf.Name); MidiPlayerGlobal.CurrentMidiSet.Save(); if (MidiPlayerGlobal.ImSFCurrent != null) { KeepAllPatchs = MidiPlayerGlobal.ImSFCurrent.KeepAllPatchs; KeepAllZones = MidiPlayerGlobal.ImSFCurrent.KeepAllZones; RemoveUnusedWaves = MidiPlayerGlobal.ImSFCurrent.RemoveUnusedWaves; if (Application.isPlaying) { MidiPlayerGlobal.MPTK_SelectSoundFont(null); } } //listPatchs = PatchOptim.PatchUsed(); } boxX += 80 + espace; GUI.color = Color.white; rect = new Rect(boxX, boxY + 9, 80, buttonHeight); if (GUI.Button(rect, "Remove")) { #if MPTK_PRO OptimInfo = new BuilderInfo(); string soundFontPath = Path.Combine(Application.dataPath + "/", MidiPlayerGlobal.PathToSoundfonts); string path = Path.Combine(soundFontPath, sf.Name); if (!string.IsNullOrEmpty(path) && EditorUtility.DisplayDialog("Delete SoundFont", "Are you sure to delete all the content of this folder ? " + path, "ok", "cancel")) { try { Directory.Delete(path, true); File.Delete(path + ".meta"); } catch (Exception ex) { Debug.Log("Remove SF " + ex.Message); } AssetDatabase.Refresh(); ToolsEditor.CheckMidiSet(); } #else try { PopupWindow.Show(rect, new GetVersionPro()); } catch (Exception) { // generate some weird exception ... } #endif } GUI.color = Color.white; //boxX = 5; //boxY += itemHeight; //if (MidiPlayerGlobal.ImSFCurrent.WaveSize < 1000000) // strSize = Math.Round((double)MidiPlayerGlobal.ImSFCurrent.WaveSize / 1000d).ToString() + " Ko"; //else // strSize = Math.Round((double)MidiPlayerGlobal.ImSFCurrent.WaveSize / 1000000d).ToString() + " Mo"; //string.Format("Patch count: {0} Wave count:{1} Wave size:{2}", MidiPlayerGlobal.ImSFCurrent.PatchCount, MidiPlayerGlobal.ImSFCurrent.WaveCount, strSize); //content = new GUIContent() { text = sf.Name, tooltip = "" }; //EditorGUI.LabelField(new Rect(boxX, boxY + 9, 200, itemHeight), content); boxY += itemHeight; } GUI.EndScrollView(); } } catch (Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
/// <summary> /// Display, add, remove Midi file /// </summary> /// <param name="startX"></param> /// <param name="startY"></param> private void ShowListMidiFiles(float startX, float startY, float width, float height) { try { Event e = Event.current; if (e.type == EventType.KeyDown) { //Debug.Log("Ev.KeyDown: " + e); if (e.keyCode == KeyCode.DownArrow || e.keyCode == KeyCode.UpArrow || e.keyCode == KeyCode.End || e.keyCode == KeyCode.Home) { if (e.keyCode == KeyCode.End) { IndexEditItem = MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count - 1; } if (e.keyCode == KeyCode.Home) { IndexEditItem = 0; } if (e.keyCode == KeyCode.DownArrow) { IndexEditItem++; if (IndexEditItem >= MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count) { IndexEditItem = 0; } } if (e.keyCode == KeyCode.UpArrow) { IndexEditItem--; if (IndexEditItem < 0) { IndexEditItem = MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count - 1; } } SetMidiSelectedVisible(); ReadEvents(); GUI.changed = true; Repaint(); } } if (columnSF == null) { columnSF = new ToolsEditor.DefineColumn[2]; columnSF[0].Width = 60; columnSF[0].Caption = "Index"; columnSF[0].PositionCaption = 10f; columnSF[1].Width = 300; columnSF[1].Caption = "Midi Name"; columnSF[1].PositionCaption = 5f; //columnSF[2].Width = 70; columnSF[2].Caption = "Read"; columnSF[2].PositionCaption = 0f; //columnSF[3].Width = 60; columnSF[3].Caption = "Remove"; columnSF[3].PositionCaption = -9f; } GUI.Box(new Rect(startX, startY, width, height), "", stylePanel); float localstartX = 0; float localstartY = 0; GUIContent content = new GUIContent() { text = MidiPlayerGlobal.CurrentMidiSet.MidiFiles == null || MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count == 0 ? "No Midi file available" : "Midi files available", tooltip = "" }; localstartX += xpostitlebox; localstartY += ypostitlebox; GUI.Label(new Rect(startX + localstartX + 5, startY + localstartY, 160, titleHeight), content, styleBold); string searchMidi = EditorGUI.TextField(new Rect(startX + localstartX + 5 + 170 + espace, startY + localstartY - 2, 225, titleHeight), "Search in list:"); if (!string.IsNullOrEmpty(searchMidi)) { int index = MidiPlayerGlobal.CurrentMidiSet.MidiFiles.FindIndex(s => s.ToLower().Contains(searchMidi.ToLower())); if (index >= 0) { IndexEditItem = index; SetMidiSelectedVisible(); ReadEvents(); } } localstartY += titleHeight; if (GUI.Button(new Rect(startX + localstartX + width - 65, startY + localstartY - 18, 35, 35), buttonIconHelp)) { Application.OpenURL("https://paxstellar.fr/setup-mptk-add-midi-files-v2/"); } if (GUI.Button(new Rect(startX + localstartX + espace, startY + localstartY, buttonLargeWidth, buttonHeight), "Add a Midi File")) { AddMidifile(); } if (GUI.Button(new Rect(startX + localstartX + 2 * espace + buttonLargeWidth, startY + localstartY, buttonLargeWidth, buttonHeight), "Add All Midi from a Folder")) { AddMidiFromFolder(); } if (IndexEditItem >= 0 && IndexEditItem < MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count) { if (GUI.Button(new Rect(startX + localstartX + 7 * espace + 2 * buttonLargeWidth, startY + localstartY, 30, buttonHeight), new GUIContent(buttonIconDelete, $"Remove {MidiPlayerGlobal.CurrentMidiSet.MidiFiles[IndexEditItem]}"))) { if (EditorUtility.DisplayDialog( "Remove Midi File", $"Remove {MidiPlayerGlobal.CurrentMidiSet.MidiFiles[IndexEditItem]}", "ok", "cancel")) { DeleteResource(MidiLoad.BuildOSPath(MidiPlayerGlobal.CurrentMidiSet.MidiFiles[IndexEditItem])); AssetDatabase.Refresh(); ToolsEditor.LoadMidiSet(); ToolsEditor.CheckMidiSet(); AssetDatabase.Refresh(); } } } localstartY += buttonHeight + espace; // Draw title list box GUI.Box(new Rect(startX + localstartX + espace, startY + localstartY, width - 35, itemHeight), "", styleListTitle); float boxX = startX + localstartX + espace; foreach (ToolsEditor.DefineColumn column in columnSF) { GUI.Label(new Rect(boxX + column.PositionCaption, startY + localstartY, column.Width, itemHeight), column.Caption, styleLabelLeft); boxX += column.Width; } localstartY += itemHeight + espace; if (MidiPlayerGlobal.CurrentMidiSet.MidiFiles != null) { listMidiVisibleRect = new Rect(startX + localstartX, startY + localstartY - 6, width - 10, height - localstartY); Rect listMidiContentRect = new Rect(0, 0, width - 25, MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count * itemHeight + 5); scrollPosMidiFile = GUI.BeginScrollView(listMidiVisibleRect, scrollPosMidiFile, listMidiContentRect, false, true); //Debug.Log($"scrollPosMidiFile:{scrollPosMidiFile.y} listVisibleRect:{listMidiVisibleRect.height} listContentRect:{listMidiContentRect.height}"); float boxY = 0; // Loop on each midi // ----------------- for (int i = 0; i < MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count; i++) { boxX = 5; if (GUI.Button(new Rect(espace, boxY, width - 35, itemHeight), "", IndexEditItem == i ? styleListRowSelected : styleListRow)) { IndexEditItem = i; ReadEvents(); } // col 0 - Index float colw = columnSF[0].Width; EditorGUI.LabelField(new Rect(boxX + 1, boxY + 2, colw, itemHeight - 5), i.ToString(), styleLabelCenter); boxX += colw; // col 1 - Name colw = columnSF[1].Width; content = new GUIContent() { text = MidiPlayerGlobal.CurrentMidiSet.MidiFiles[i], tooltip = MidiPlayerGlobal.CurrentMidiSet.MidiFiles[i] }; EditorGUI.LabelField(new Rect(boxX + 5, boxY + 2, colw, itemHeight - 5), content, styleLabelLeft); boxX += colw; // col 2 - Select //colw = columnSF[2].Width; //if (GUI.Button(new Rect(boxX, boxY + 3, 30, buttonHeight), new GUIContent(buttonIconView, "Read Midi events"))) //{ // IndexEditItem = i; // ReadEvents(); //} //boxX += colw; // col 3 - remove //colw = columnSF[3].Width; //if (GUI.Button(new Rect(boxX, boxY + 3, 30, buttonHeight), new GUIContent(buttonIconDelete, "Remove Midi File"))) //{ // DeleteResource(MidiLoad.BuildOSPath(MidiPlayerGlobal.CurrentMidiSet.MidiFiles[i])); // AssetDatabase.Refresh(); // ToolsEditor.LoadMidiSet(); // ToolsEditor.CheckMidiSet(); // AssetDatabase.Refresh(); //} //boxX += colw; boxY += itemHeight - 1; } GUI.EndScrollView(); } } catch (Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
/// <summary> /// Display, add, remove Midi file /// </summary> /// <param name="localstartX"></param> /// <param name="localstartY"></param> private void ShowListMidiFiles(float localstartX, float localstartY) { try { Rect zone = new Rect(localstartX, localstartY, widthLeft, heightList); GUI.color = new Color(.8f, .8f, .8f, 1f); GUI.Box(zone, ""); GUI.color = Color.white; string caption = "Midi file available"; if (MidiPlayerGlobal.CurrentMidiSet.MidiFiles == null || MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count == 0) { caption = "No Midi file available yet"; ScanInfo = new BuilderInfo(); } GUIContent content = new GUIContent() { text = caption, tooltip = "" }; EditorGUI.LabelField(new Rect(localstartX + xpostitlebox, localstartY + ypostitlebox, 300, itemHeight), content, styleBold); if (GUI.Button(new Rect(widthLeft - buttonWidth - espace, localstartY + ypostitlebox, buttonWidth, buttonHeight), "Add Midi file")) { AddMidifile(); } if (MidiPlayerGlobal.CurrentMidiSet.MidiFiles != null) { Rect listVisibleRect = new Rect(localstartX, localstartY + itemHeight, widthLeft - 5, heightList - itemHeight - 5); Rect listContentRect = new Rect(0, 0, widthLeft - 20, MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count * itemHeight + 5); scrollPosMidiFile = GUI.BeginScrollView(listVisibleRect, scrollPosMidiFile, listContentRect); float boxY = 0; for (int i = 0; i < MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count; i++) { GUI.color = new Color(.7f, .7f, .7f, 1f); float boxX = 5; GUI.Box(new Rect(boxX, boxY + 5, widthLeft - 30, itemHeight), ""); GUI.color = Color.white; content = new GUIContent() { text = i.ToString() + " - " + MidiPlayerGlobal.CurrentMidiSet.MidiFiles[i], tooltip = MidiPlayerGlobal.CurrentMidiSet.MidiFiles[i] }; EditorGUI.LabelField(new Rect(boxX, boxY + 9, 200, itemHeight), content); boxX += 285 + espace; if (GUI.Button(new Rect(boxX, boxY + 9, 80, buttonHeight), "Analyse")) { ScanInfo = new BuilderInfo(); midifile = MidiPlayerGlobal.CurrentMidiSet.MidiFiles[i]; ScanInfo.Add(midifile); MidiScan.GeneralInfo(midifile, ScanInfo); scrollPosAnalyze = Vector2.zero; } boxX += 80 + espace; GUI.color = Color.white; if (GUI.Button(new Rect(boxX, boxY + 9, 80, buttonHeight), "Remove")) { if (!string.IsNullOrEmpty(MidiPlayerGlobal.CurrentMidiSet.MidiFiles[i])) { DeleteResource(MidiLoad.BuildOSPath(MidiPlayerGlobal.CurrentMidiSet.MidiFiles[i])); AssetDatabase.Refresh(); ToolsEditor.CheckMidiSet(); } } boxY += itemHeight; } GUI.EndScrollView(); } } catch (Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
/// <summary> /// Add a new Midi file from desktop /// </summary> private static void AddMidifile() { try { string selectedFile = EditorUtility.OpenFilePanelWithFilters("Open and import Midi file", ToolsEditor.lastDirectoryMidi, new string[] { "Midi files", "mid,midi", "Karoke files", "kar", "All", "*" }); if (!string.IsNullOrEmpty(selectedFile)) { ToolsEditor.lastDirectoryMidi = Path.GetDirectoryName(selectedFile); // Build path to midi folder string pathMidiFile = Path.Combine(Application.dataPath, MidiPlayerGlobal.PathToMidiFile); if (!Directory.Exists(pathMidiFile)) { Directory.CreateDirectory(pathMidiFile); } try { MidiLoad midifile = new MidiLoad(); if (!midifile.MPTK_LoadFile(selectedFile)) { EditorUtility.DisplayDialog("Midi Not Loaded", "Try to open " + selectedFile + "\nbut this file is not a valid midi file", "ok"); return; } } catch (Exception ex) { Debug.LogWarningFormat("{0} {1}", selectedFile, ex.Message); return; } string filename = Path.GetFileNameWithoutExtension(selectedFile); //foreach (char c in filename) Debug.Log(string.Format("{0} {1}", c, (int)c)); foreach (char i in Path.GetInvalidFileNameChars()) { filename = filename.Replace(i, '_'); } string filenameToSave = Path.Combine(pathMidiFile, filename + MidiPlayerGlobal.ExtensionMidiFile); filenameToSave = filenameToSave.Replace('(', '_'); filenameToSave = filenameToSave.Replace(')', '_'); filenameToSave = filenameToSave.Replace('#', '_'); filenameToSave = filenameToSave.Replace('$', '_'); // Create a copy of the midi file in MPTK resources File.Copy(selectedFile, filenameToSave, true); if (MidiPlayerGlobal.CurrentMidiSet.MidiFiles == null) { MidiPlayerGlobal.CurrentMidiSet.MidiFiles = new List <string>(); } // Add midi file to the list string midiname = Path.GetFileNameWithoutExtension(selectedFile); if (MidiPlayerGlobal.CurrentMidiSet.MidiFiles.FindIndex(s => s == midiname) < 0) { MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Add(midiname); MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Sort(); MidiPlayerGlobal.CurrentMidiSet.Save(); } indexEditItem = MidiPlayerGlobal.CurrentMidiSet.MidiFiles.FindIndex(s => s == midiname); } AssetDatabase.Refresh(); ToolsEditor.LoadMidiSet(); ToolsEditor.CheckMidiSet(); AssetDatabase.Refresh(); ReadEvents(); } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
/// <summary> /// Display, add, remove Midi file /// </summary> /// <param name="localstartX"></param> /// <param name="localstartY"></param> private void ShowListMidiFiles(float localstartX, float localstartY) { try { Rect zone = new Rect(localstartX, localstartY, widthLeft, heightList); GUI.color = new Color(.8f, .8f, .8f, 1f); GUI.Box(zone, ""); GUI.color = Color.white; string caption = "Midi file available"; if (MidiPlayerGlobal.CurrentMidiSet.MidiFiles == null || MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count == 0) { caption = "No Midi file available yet"; } GUIContent content = new GUIContent() { text = caption, tooltip = "" }; EditorGUI.LabelField(new Rect(localstartX + xpostitlebox, localstartY + ypostitlebox, 300, itemHeight), content, styleBold); if (indexEditItem >= 0 && indexEditItem < MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count && !string.IsNullOrEmpty(MidiPlayerGlobal.CurrentMidiSet.MidiFiles[indexEditItem])) { string name = MidiPlayerGlobal.CurrentMidiSet.MidiFiles[indexEditItem]; if (name.Length > 10) { name = name.Substring(0, 10); } string midiselected = "'" + indexEditItem + "-" + name + "'"; if (GUI.Button(new Rect(localstartX + xpostitlebox + 150, localstartY + ypostitlebox, buttonWidth, buttonHeight), "Remove " + midiselected)) { DeleteResource(MidiLoad.BuildOSPath(MidiPlayerGlobal.CurrentMidiSet.MidiFiles[indexEditItem])); AssetDatabase.Refresh(); ToolsEditor.LoadMidiSet(); ToolsEditor.CheckMidiSet(); AssetDatabase.Refresh(); } } if (GUI.Button(new Rect(widthLeft - buttonWidth - espace, localstartY + ypostitlebox, buttonWidth, buttonHeight), "Add Midi file")) { AddMidifile(); } if (MidiPlayerGlobal.CurrentMidiSet.MidiFiles != null) { Rect listVisibleRect = new Rect(localstartX, localstartY + itemHeight, widthLeft - 5, heightList - itemHeight - 5); Rect listContentRect = new Rect(0, 0, widthLeft - 20, MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count * itemHeight + 5); scrollPosMidiFile = GUI.BeginScrollView(listVisibleRect, scrollPosMidiFile, listContentRect); float boxY = 0; for (int i = 0; i < MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count; i++) { //GUI.color = new Color(.7f, .7f, .7f, 1f); float boxX = 5; content = new GUIContent() { text = i.ToString() + " - " + MidiPlayerGlobal.CurrentMidiSet.MidiFiles[i], tooltip = MidiPlayerGlobal.CurrentMidiSet.MidiFiles[i] }; if (indexEditItem == i) { GUI.color = new Color(.7f, .7f, .7f, 1f); } else { GUI.color = Color.white; } GUI.Box(new Rect(boxX, boxY + 5, widthLeft - 30, itemHeight), ""); if (GUI.Button(new Rect(boxX + 5, boxY + 9, widthLeft - 30, itemHeight), content, myStyle.BtListNormal)) { indexEditItem = i; ReadEvents(); } boxY += itemHeight; } GUI.EndScrollView(); } } catch (Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }