/// <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); } }
/// <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> /// 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); } }