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