/// <summary> /// Display optimization log /// </summary> /// <param name="localstartX"></param> /// <param name="localstartY"></param> private void ShowLogOptim(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; float posx = localstartX; GUI.Label(new Rect(posx + espace, localstartY + espace, 40, buttonHeight), new GUIContent("Logs:"), styleBold); posx += 40; float btw = 25f; if (GUI.Button(new Rect(posx + espace, localstartY + espace, btw, buttonHeight), new GUIContent(buttonIconSave, "Save Log"))) { // Save log file if (LogInfo != null) { string filenamelog = string.Format("SoundFontSetupLog {0} {1} .txt", MidiPlayerGlobal.ImSFCurrent.SoundFontName, DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss")); using (System.IO.StreamWriter file = new System.IO.StreamWriter(Path.Combine(Application.persistentDataPath, filenamelog))) foreach (string line in LogInfo.Infos) { file.WriteLine(line); } } } if (GUI.Button(new Rect(posx + 2f * espace + btw, localstartY + espace, btw, buttonHeight), new GUIContent(buttonIconFolders, "Open Logs Folder"))) { Application.OpenURL(Application.persistentDataPath); } if (GUI.Button(new Rect(posx + 3f * espace + 2f * btw, localstartY + espace, btw, buttonHeight), new GUIContent(buttonIconDelete, "Clear Logs"))) { LogInfo = new BuilderInfo(); } #if MPTK_PRO if (LogInfo != null && LogInfo.Count > 0) { float heightLine = styleRichText.lineHeight * 1.2f; Rect listVisibleRect = new Rect(espace, localstartY + buttonHeight + espace, width - 5, height - 25); Rect listContentRect = new Rect(0, 0, 2 * width, LogInfo.Count * heightLine + 5); scrollPosOptim = GUI.BeginScrollView(listVisibleRect, scrollPosOptim, listContentRect); GUI.color = Color.white; float labelY = -heightLine; foreach (string s in LogInfo.Infos) { EditorGUI.LabelField(new Rect(localstartX, labelY += heightLine, width * 2, heightLine), s, styleRichText); } if (MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo != null && MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.PatchCount == 0) { float xpos = 0; float ypos = labelY + 2 * heightLine; EditorGUI.LabelField(new Rect(xpos, ypos, 450, itemHeight), "No patchs and waves has been yet extracted from the Soundfont.", styleRed); ypos += itemHeight / 1f; EditorGUI.LabelField(new Rect(xpos, ypos, 450, itemHeight), "On the right panel:", styleRed); ypos += itemHeight / 2f; EditorGUI.LabelField(new Rect(xpos, ypos, 450, itemHeight), " Select banks you want to keep.", styleRed); ypos += itemHeight / 2f; EditorGUI.LabelField(new Rect(xpos, ypos, 450, itemHeight), " Select default bank for instruments and drums kit.", styleRed); ypos += itemHeight / 1f; EditorGUI.LabelField(new Rect(xpos, ypos, 450, itemHeight), "Click on button:", styleRed); ypos += itemHeight / 2f; EditorGUI.LabelField(new Rect(xpos, ypos, 450, itemHeight), " 'Optimize from Midi file list' to keep only patchs required or", styleRed); ypos += itemHeight / 2f; EditorGUI.LabelField(new Rect(xpos, ypos, 450, itemHeight), " 'Extract all Patchs & Waves' to keep all patchs of selected banks.", styleRed); ypos += itemHeight; } GUI.EndScrollView(); } #endif } catch (Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
void OnGUI() { try { if (window == null) { Init(); } if (LogInfo == null) { LogInfo = new BuilderInfo(); } float startx = 5; float starty = 7; if (styleRowListNormal == null) { styleRowListNormal = new GUIStyle("box"); } if (styleRowListSelected == null) { styleRowListSelected = new GUIStyle("box"); styleRowListSelected.normal.background = ToolsEditor.SetColor(new Texture2D(2, 2), new Color(.6f, .8f, .6f, 1f)); } GUIContent content = new GUIContent() { text = "Setup SoundFont - Version " + ToolsEditor.version, tooltip = "" }; EditorGUI.LabelField(new Rect(startx, starty, 500, itemHeight), content, styleBold); if (GUI.Button(new Rect(startx + 370, starty - 5, 25, 25), buttonIconHelp)) { //CreateWave createwave = new CreateWave(); //string path = System.IO.Path.Combine(MidiPlayerGlobal.MPTK_PathToResources, "unitySample") + ".wav"; ////string path = "unitySample.wav"; //HiSample sample = new HiSample(); ////sample.LoopStart = sample.LoopEnd = 0; //byte[] data = new byte[10000]; //for (int i = 0; i < data.Length; i++) data[i] = (byte)255; //sample.SampleRate = 44100; //sample.End = (uint)data.Length/2; //createwave.Build(path, sample, data); Application.OpenURL("https://paxstellar.fr/setup-mptk-add-soundfonts-v2/"); } GUI.color = ToolsEditor.ButtonColor; content = new GUIContent() { text = "Help & Contact", tooltip = "Get some help" }; // Set position of the button Rect rect = new Rect(window.position.size.x - buttonLargeWidth - 5, starty, buttonLargeWidth, buttonHeight); if (GUI.Button(rect, content)) { PopupWindow.Show(rect, new AboutMPTK()); } starty += buttonHeight + espace; widthRight = window.position.size.x - widthLeft - 2 * espace - startx; //widthRight = window.position.size.x / 2f - espace; //widthLeft = window.position.size.x / 2f - espace; heightLeftBottom = window.position.size.y - heightLeftTop - 3 * espace - starty; heightRightBottom = window.position.size.y - heightRightTop - 3 * espace - starty; // Display list of soundfont already loaded ShowListSoundFonts(startx, starty, widthLeft, heightLeftTop); ShowListBanks(startx + widthLeft + espace, starty, widthRight, heightRightTop); ShowExtractOptim(startx + widthLeft + espace, starty + heightRightTop + espace, widthRight, heightRightBottom + espace); ShowLogOptim(startx, starty + espace + heightLeftTop, widthLeft, heightLeftBottom + espace); } catch (ExitGUIException) { } catch (Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
void OnGUI() { try { if (window == null) { Init(); } if (LogInfo == null) { LogInfo = new BuilderInfo(); } float startx = 5; float starty = 7; if (styleRowListNormal == null) { styleRowListNormal = new GUIStyle("box"); } if (styleRowListSelected == null) { styleRowListSelected = new GUIStyle("box"); styleRowListSelected.normal.background = ToolsEditor.SetColor(new Texture2D(2, 2), new Color(.6f, .8f, .6f, 1f)); } GUIContent content = new GUIContent() { text = "Setup SoundFont in your application - Version " + ToolsEditor.version, tooltip = "" }; EditorGUI.LabelField(new Rect(startx, starty, 500, itemHeight), content, styleBold); GUI.color = ToolsEditor.ButtonColor; content = new GUIContent() { text = "Help & Contact", tooltip = "Get some help" }; // Set position of the button Rect rect = new Rect(window.position.size.x - buttonLargeWidth - 5, starty, buttonLargeWidth, buttonHeight); if (GUI.Button(rect, content)) { PopupWindow.Show(rect, new AboutMPTK()); } starty += buttonHeight + espace; widthRight = window.position.size.x - widthLeft - 2 * espace - startx; //widthRight = window.position.size.x / 2f - espace; //widthLeft = window.position.size.x / 2f - espace; heightLeftBottom = window.position.size.y - heightLeftTop - 3 * espace - starty; heightRightBottom = window.position.size.y - heightRightTop - 3 * espace - starty; // Display list of soundfont already loaded ShowListSoundFonts(startx, starty, widthLeft, heightLeftTop); ShowListBanks(startx + widthLeft + espace, starty, widthRight, heightRightTop); ShowExtractOptim(startx + widthLeft + espace, starty + heightRightTop + espace, widthRight, heightRightBottom + espace); ShowLogOptim(startx, starty + espace + heightLeftTop, widthLeft, heightLeftBottom + espace); } catch (ExitGUIException) { } catch (Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
/// <summary> /// Return information about a midifile : patch change, copyright, ... /// </summary> /// <param name="pathfilename"></param> /// <param name="Info"></param> static public void GeneralInfo(string pathfilename, BuilderInfo Info) { try { int NumberBeatsMeasure; int NumberQuarterBeat; Debug.Log("Open midifile :" + pathfilename); MidiLoad midifile = new MidiLoad(); midifile.MPTK_Load(pathfilename); if (midifile != null) { Info.Add(string.Format("Format: {0}", midifile.midifile.FileFormat)); Info.Add(string.Format("Tracks: {0}", midifile.midifile.Tracks)); Info.Add(string.Format("Ticks Quarter Note: {0}", midifile.midifile.DeltaTicksPerQuarterNote)); //if (false) { foreach (TrackMidiEvent trackEvent in midifile.MidiSorted) { if (trackEvent.Event.CommandCode == MidiCommandCode.NoteOn) { // Not used //if (((NoteOnEvent)trackEvent.Event).OffEvent != null) //{ // //infoTrackMidi[e.Channel].Events.Add((NoteOnEvent)e); // NoteOnEvent noteon = (NoteOnEvent)trackEvent.Event; //} } else if (trackEvent.Event.CommandCode == MidiCommandCode.NoteOff) { //Debug.Log("NoteOff"); } else if (trackEvent.Event.CommandCode == MidiCommandCode.ControlChange) { // Not used //ControlChangeEvent controlchange = (ControlChangeEvent)e; //Debug.Log(string.Format("CtrlChange Track:{0} Channel:{1,2:00} {2}", track, e.Channel, controlchange.ToString())); } else if (trackEvent.Event.CommandCode == MidiCommandCode.PatchChange) { PatchChangeEvent change = (PatchChangeEvent)trackEvent.Event; Info.Add(BuildInfoTrack(trackEvent) + string.Format("PatchChange {0,3:000} {1}", change.Patch, PatchChangeEvent.GetPatchName(change.Patch)), 2); } else if (trackEvent.Event.CommandCode == MidiCommandCode.MetaEvent) { MetaEvent meta = (MetaEvent)trackEvent.Event; switch (meta.MetaEventType) { case MetaEventType.SetTempo: TempoEvent tempo = (TempoEvent)meta; Info.Add(BuildInfoTrack(trackEvent) + string.Format("SetTempo Tempo:{0} MicrosecondsPerQuarterNote:{1}", Math.Round(tempo.Tempo, 0), tempo.MicrosecondsPerQuarterNote), 2); //tempo.Tempo break; case MetaEventType.TimeSignature: TimeSignatureEvent timesig = (TimeSignatureEvent)meta; // Numerator: counts the number of beats in a measure. // For example a numerator of 4 means that each bar contains four beats. // Denominator: number of quarter notes in a beat.0=ronde, 1=blanche, 2=quarter, 3=eighth, etc. // Set default value NumberBeatsMeasure = timesig.Numerator; NumberQuarterBeat = System.Convert.ToInt32(System.Math.Pow(2, timesig.Denominator)); Info.Add(BuildInfoTrack(trackEvent) + string.Format("TimeSignature Beats Measure:{0} Beat Quarter:{1}", NumberBeatsMeasure, NumberQuarterBeat), 2); break; case MetaEventType.SequenceTrackName: // Sequence / Track Name case MetaEventType.ProgramName: case MetaEventType.TrackInstrumentName: // Track instrument name case MetaEventType.TextEvent: // Text event case MetaEventType.Copyright: // Copyright Info.Add(BuildInfoTrack(trackEvent) + ((TextEvent)meta).Text, 1); break; case MetaEventType.Lyric: // lyric case MetaEventType.Marker: // marker case MetaEventType.CuePoint: // cue point case MetaEventType.DeviceName: //Info.Add(BuildInfoTrack(trackEvent) + string.Format("{0} '{1}'", meta.MetaEventType.ToString(), ((TextEvent)meta).Text)); break; } } else { // Other midi event //Debug.Log(string.Format("Track:{0} Channel:{1,2:00} CommandCode:{2,3:000} AbsoluteTime:{3,6:000000}", track, e.Channel, e.CommandCode.ToString(), e.AbsoluteTime)); } } } //else DebugMidiSorted(midifile.MidiSorted); } else { Info.Add("Error reading midi file"); } } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
/// <summary> /// Display optimization /// </summary> /// <param name="localstartX"></param> /// <param name="localstartY"></param> private void ShowOptim(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; string tooltip = "Remove all banks and Presets not used in the Midi file list"; GUIContent content; if (MidiPlayerGlobal.ImSFCurrent != null) { float xpos = localstartX + xpostitlebox; float ypos = localstartY + ypostitlebox; content = new GUIContent() { text = "Extract Patchs & Waves from " + MidiPlayerGlobal.ImSFCurrent.SoundFontName, tooltip = tooltip }; EditorGUI.LabelField(new Rect(xpos, ypos, 380 + 85, itemHeight), content, styleBold); ypos += itemHeight;// + espace; if (MidiPlayerGlobal.ImSFCurrent.PatchCount == 0 || MidiPlayerGlobal.ImSFCurrent.WaveCount == 0) { EditorGUI.LabelField(new Rect(xpos, ypos, 380 + 85, itemHeight), "No patchs and waves has been yet extracted from the Soundfont.", styleRed); ypos += itemHeight / 1f; // + espace; EditorGUI.LabelField(new Rect(xpos, ypos, 380 + 85, itemHeight), "On the right panel, select one bank for instruments and", styleRed); ypos += itemHeight / 2f; // + espace; EditorGUI.LabelField(new Rect(xpos, ypos, 380 + 85, itemHeight), "optional, one bank for drums kit, others banks will be removed.", styleRed); ypos += itemHeight / 1f; // + espace; EditorGUI.LabelField(new Rect(xpos, ypos, 380 + 85, itemHeight), "Then, choose between 'Optimize from Midi file list'", styleRed); ypos += itemHeight / 2f; // + espace; EditorGUI.LabelField(new Rect(xpos, ypos, 380 + 85, itemHeight), "or 'Extract all Patchs & Waves' with the buttons below.", styleRed); ypos += itemHeight;// + espace; } else { string infoSf = string.Format("Patch count: {0} Wave count:{1} Wave size:{2}", MidiPlayerGlobal.ImSFCurrent.PatchCount, MidiPlayerGlobal.ImSFCurrent.WaveCount, (MidiPlayerGlobal.ImSFCurrent.WaveSize < 1000000) ? Math.Round((double)MidiPlayerGlobal.ImSFCurrent.WaveSize / 1000d).ToString() + " Ko" : Math.Round((double)MidiPlayerGlobal.ImSFCurrent.WaveSize / 1000000d).ToString() + " Mo" ); EditorGUI.LabelField(new Rect(xpos, ypos, 380 + 85, itemHeight), infoSf); ypos += 2 * heightLine; } int widthCheck = 110; /* * KeepAllZones = GUI.Toggle(new Rect(xpos, ypos, widthCheck, itemHeight), KeepAllZones, new GUIContent("Keep all Zones", "Keep all Waves associated with a Patch regardless of notes and velocities played in Midi files.\n Usefull if you want transpose Midi files.")); * xpos += widthCheck + espace; * KeepAllPatchs = GUI.Toggle(new Rect(xpos, ypos, widthCheck, itemHeight), KeepAllPatchs, new GUIContent("Keep all Patchs", "Keep all Patchs and waves found in the SoundFont selected.\nWarning : a huge volume of files coud be created")); * xpos += widthCheck + +2 * espace; * RemoveUnusedWaves = GUI.Toggle(new Rect(xpos, ypos, widthCheck + 40, itemHeight), RemoveUnusedWaves, new GUIContent("Remove unused waves", "If check, keep only waves used by your midi files")); * ypos += itemHeight;// + espace; */ // Always true RemoveUnusedWaves = true; xpos = localstartX + xpostitlebox; Rect rect = new Rect(xpos, ypos, widthCheck * 2 + espace, buttonHeight); #if MPTK_PRO if (GUI.Button(rect, new GUIContent("Optimize from Midi file list", "Your list of Midi files will be scanned to identify patchs and zones useful"))) { KeepAllPatchs = false; KeepAllZones = false; OptimInfo = new BuilderInfo(); SoundFontOptim.OptimizeSFFromMidiFiles(OptimInfo, KeepAllPatchs, KeepAllZones, RemoveUnusedWaves); //listPatchs = PatchOptim.PatchUsed(); } xpos += 3 * espace + 2 * widthCheck; rect = new Rect(xpos, ypos, buttonWidth, buttonHeight); if (GUI.Button(rect, new GUIContent("Extract all Patchs & Waves", "All patchs and waves will be extracted from the Soundfile"))) { KeepAllPatchs = true; KeepAllZones = true; OptimInfo = new BuilderInfo(); SoundFontOptim.OptimizeSFFromMidiFiles(OptimInfo, KeepAllPatchs, KeepAllZones, RemoveUnusedWaves); //listPatchs = PatchOptim.PatchUsed(); } #else if (GUI.Button(rect, new GUIContent("Optimize from Midi file list [PRO]", "You need to setup some midi files before to launch ths optimization"))) { PopupWindow.Show(rect, new GetVersionPro()); } xpos += 3 * espace + 2 * widthCheck; rect = new Rect(xpos, ypos, buttonWidth, buttonHeight); if (GUI.Button(rect, new GUIContent("Extract all Patchs & Waves [PRO]", ""))) { PopupWindow.Show(rect, new GetVersionPro()); } #endif ypos += itemHeight + espace; if (MidiPlayerGlobal.ImSFCurrent.PatchCount != 0 && MidiPlayerGlobal.ImSFCurrent.WaveCount != 0) { // // Show patch list // xpos = localstartX + xpostitlebox; EditorGUI.LabelField(new Rect(xpos, ypos, 380, itemHeight), "List of available Patchs:"); ypos += itemHeight / 2f; List <string> patchList = new List <string>(); for (int i = 0; i < MidiPlayerGlobal.MPTK_ListPreset.Count; i++) { if (!string.IsNullOrEmpty(MidiPlayerGlobal.MPTK_ListPreset[i])) { patchList.Add(string.Format("Instrument - Patch: [{0:000}] {1}", i, MidiPlayerGlobal.MPTK_ListPreset[i])); } } for (int i = 0; i < MidiPlayerGlobal.MPTK_ListDrum.Count; i++) { if (!string.IsNullOrEmpty(MidiPlayerGlobal.MPTK_ListDrum[i])) { patchList.Add(string.Format("Drum - Midi note: [{0:000}] {1}", i, MidiPlayerGlobal.MPTK_ListDrum[i])); } } float heightAvailable = height - (ypos - (localstartY + ypostitlebox)) - 16; Rect listVisibleRect = new Rect(localstartX, ypos, width - 5, heightAvailable); GUI.color = new Color(.8f, .8f, .8f, 1f); GUI.Box(new Rect(localstartX + 5, ypos + 5, width - 30, heightAvailable - 4), ""); Rect listContentRect = new Rect(0, 0, width - 20, patchList.Count * itemHeight + 5); scrollPosListPatchs = GUI.BeginScrollView(listVisibleRect, scrollPosListPatchs, listContentRect); float boxY = 0; foreach (string patchInfo in patchList) { 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; EditorGUI.LabelField(new Rect(boxX, boxY + 9, 300, itemHeight), patchInfo); boxY += itemHeight; } GUI.EndScrollView(); ypos += heightAvailable + heightLine; //List<PatchOptim> listPatchs = PatchOptim.PatchUsed(); //float heightAvailable = height - (ypos - (localstartY + ypostitlebox)) - 15 - 4 * heightLine; //Rect listVisibleRect = new Rect(localstartX, ypos, width - 5, heightAvailable); //Rect listContentRect = new Rect(0, 0, width - 20, listPatchs.Count * itemHeight + 5); //scrollPosListPatchs = GUI.BeginScrollView(listVisibleRect, scrollPosListPatchs, listContentRect); //float boxY = 0; //for (int i = 0; i < listPatchs.Count; 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; // PatchOptim patch = listPatchs[i]; // string patchinfo = string.Format("{0,15} [{1:000}] {2}", patch.Drum?"Drum":"Instrument", patch.Patch, patch.Name); // //content = new GUIContent() { text = patchinfo, tooltip = MidiPlayerGlobal.CurrentMidiSet.MidiFiles[i] }; // EditorGUI.LabelField(new Rect(boxX, boxY + 9, 200, itemHeight), patchinfo); // //boxX += 280 + espace; // //patch.Selected = GUI.Toggle(new Rect(boxX, boxY + 9, 80, buttonHeight), patch.Selected, "Selected"); // boxY += itemHeight; //} //GUI.EndScrollView(); //ypos += heightAvailable + heightLine; } // // Show stat // //EditorGUI.LabelField(new Rect(localstartX + xpostitlebox, ypos, 100, heightLine), "Patch count :"); //EditorGUI.LabelField(new Rect(localstartX + xpostitlebox + 110, ypos, 100, heightLine), MidiPlayerGlobal.ImSFCurrent.PatchCount.ToString()); //ypos += heightLine; //string strSize = ""; //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"; //EditorGUI.LabelField(new Rect(localstartX + xpostitlebox, ypos, 100, heightLine), "Wave count :"); //EditorGUI.LabelField(new Rect(localstartX + xpostitlebox + 110, ypos, 100, heightLine), MidiPlayerGlobal.ImSFCurrent.WaveCount.ToString()); //ypos += heightLine; //EditorGUI.LabelField(new Rect(localstartX + xpostitlebox, ypos, 100, heightLine), "Wave size :"); //EditorGUI.LabelField(new Rect(localstartX + xpostitlebox + 110, ypos, 100, heightLine), strSize); //ypos += heightLine; } else { content = new GUIContent() { text = "No SoundFont selected", tooltip = tooltip }; EditorGUI.LabelField(new Rect(localstartX + xpostitlebox, localstartY + ypostitlebox, 300, itemHeight), content, styleBold); } } catch (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="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); } }
void OnGUI() { try { if (window == null) { Init(); } if (LogInfo == null) { LogInfo = new BuilderInfo(); } float startx = 5; float starty = 7; GUI.Box(new Rect(0, 0, window.position.width, window.position.height), "", styleWindow); GUIContent content = new GUIContent() { text = "Setup SoundFont - Version " + ToolsEditor.version, tooltip = "" }; EditorGUI.LabelField(new Rect(startx, starty, 500, itemHeight), content, styleBold); //if (GUI.Button(new Rect(startx + 300, starty, 200, buttonHeight), "Look at the Pro version")) // Application.OpenURL(ToolsEditor.UnitySite); content = new GUIContent() { text = "Doc & Contact", tooltip = "Get some help" }; // Set position of the button Rect rect = new Rect(window.position.size.x - buttonLargeWidth - 5, starty, buttonLargeWidth, buttonHeight); if (GUI.Button(rect, content)) { PopupWindow.Show(rect, new AboutMPTK()); } starty += buttonHeight + espace; widthRight = window.position.size.x - widthLeft - 2 * espace - startx; //widthRight = window.position.size.x / 2f - espace; //widthLeft = window.position.size.x / 2f - espace; heightLeftBottom = window.position.size.y - heightLeftTop - 3 * espace - starty; heightRightBottom = window.position.size.y - heightRightTop - 3 * espace - starty; // Display list of soundfont already loaded ShowListSoundFonts(startx, starty, widthLeft, heightLeftTop); ShowListBanks(startx + widthLeft + espace, starty, widthRight, heightRightTop); ShowExtractOptim(startx + widthLeft + espace, starty + heightRightTop + espace, widthRight, heightRightBottom + espace); ShowLogOptim(startx, starty + espace + heightLeftTop, widthLeft, heightLeftBottom + espace); } catch (ExitGUIException) { } catch (Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }