Ejemplo n.º 1
0
        /// <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);
            }
        }
Ejemplo n.º 2
0
        private static void LoadSoundFont()
        {
            if (MidiPlayerGlobal.ImSFCurrent != null)
            {
                Debug.Log("Load MidiPlayerGlobal.ImSFCurrent: " + MidiPlayerGlobal.ImSFCurrent.SoundFontName);
                Debug.Log("Load CurrentMidiSet.ActiveSounFontInfo: " + CurrentMidiSet.ActiveSounFontInfo.Name);

                MidiPlayerGlobal.SoundFontLoaded = false;
                MidiPlayerGlobal.LoadCurrentSF();
                Debug.Log("Time To Load SoundFont: " + Math.Round(MidiPlayerGlobal.MPTK_TimeToLoadSoundFont.TotalSeconds, 3).ToString() + " second");
                if (Application.isPlaying)
                {
                    Debug.Log("Time To Load Waves: " + Math.Round(MidiPlayerGlobal.MPTK_TimeToLoadWave.TotalSeconds, 3).ToString() + " second");
                }
                MidiPlayerGlobal.SoundFontLoaded = true;
            }
        }
Ejemplo n.º 3
0
        private static IEnumerator LoadSoundFontThread()
        {
            if (MidiPlayerGlobal.ImSFCurrent != null)
            {
                Debug.Log("Load MidiPlayerGlobal.ImSFCurrent: " + MidiPlayerGlobal.ImSFCurrent.SoundFontName);
                Debug.Log("Load CurrentMidiSet.ActiveSounFontInfo: " + CurrentMidiSet.ActiveSounFontInfo.Name);

                MidiPlayerGlobal.SoundFontLoaded = false;
                MidiPlayer[] midiplayers = null;
                if (Application.isPlaying)
                {
                    midiplayers = GameObject.FindObjectsOfType <MidiPlayer>();
                    if (midiplayers != null)
                    {
                        foreach (MidiPlayer mp in midiplayers)
                        {
                            //if (mp is MidiFilePlayer) ((MidiFilePlayer)mp).MPTK_Pause();
                            yield return(Instance.StartCoroutine(mp.MPTK_ClearAllSound(true)));
                        }
                    }
                    //return;
                    DicAudioClip.Init();
                }
                MidiPlayerGlobal.LoadCurrentSF();
                Debug.Log("   Time To Load SoundFont: " + Math.Round(MidiPlayerGlobal.MPTK_TimeToLoadSoundFont.TotalSeconds, 3).ToString() + " second");
                Debug.Log("   Time To Load Waves: " + Math.Round(MidiPlayerGlobal.MPTK_TimeToLoadWave.TotalSeconds, 3).ToString() + " second");
                MidiPlayerGlobal.SoundFontLoaded = true;

                if (Application.isPlaying)
                {
                    if (midiplayers != null)
                    {
                        foreach (MidiPlayer mp in midiplayers)
                        {
                            if (mp is MidiFilePlayer)
                            {
                                ((MidiFilePlayer)mp).MPTK_ReSyncTime();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 private void Awake()
 {
     MidiPlayerGlobal.LoadCurrentSF();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Update list SoundFont and Midi
        /// </summary>
        public static void CheckMidiSet()
        {
            // Activate one time to renum all the midi files in resource folder
            //RenumMidiFile();

            //
            // Check Soundfont
            //
            try
            {
                string folder = Path.Combine(Application.dataPath + "/", MidiPlayerGlobal.PathToSoundfonts);
                if (Directory.Exists(folder))
                {
                    bool     tobesaved   = false;
                    string[] fileEntries = Directory.GetFiles(folder, "*" + MidiPlayerGlobal.ExtensionSoundFileDot, SearchOption.AllDirectories);

                    // Check if sf has been removed by user in resource
                    int isf = 0;
                    while (isf < MidiPlayerGlobal.CurrentMidiSet.SoundFonts.Count)
                    {
                        bool found = false;
                        foreach (string filepath in fileEntries)
                        {
                            string filename = Path.GetFileNameWithoutExtension(filepath);
                            if (filename == MidiPlayerGlobal.CurrentMidiSet.SoundFonts[isf].Name)
                            {
                                found = true;
                            }
                        }
                        if (!found)
                        {
                            MidiPlayerGlobal.CurrentMidiSet.SoundFonts.RemoveAt(isf);
                            tobesaved = true;
                        }
                        else
                        {
                            isf++;
                        }
                    }

                    // Active sound font exists in midiset ?
                    if (MidiPlayerGlobal.CurrentMidiSet != null && MidiPlayerGlobal.ImSFCurrent != null)
                    {
                        if (MidiPlayerGlobal.CurrentMidiSet.SoundFonts != null && MidiPlayerGlobal.CurrentMidiSet.SoundFonts.Find(s => s.Name == MidiPlayerGlobal.ImSFCurrent.SoundFontName) == null)
                        {
                            // no the current SF has been remove from resource, define first SF  as active or nothing if no SF exists
                            if (MidiPlayerGlobal.CurrentMidiSet.SoundFonts.Count >= 0)
                            {
                                MidiPlayerGlobal.CurrentMidiSet.SetActiveSoundFont(0);
                                MidiPlayerGlobal.LoadCurrentSF();
                                //LoadImSF();
                            }
                            else
                            {
                                MidiPlayerGlobal.CurrentMidiSet.SetActiveSoundFont(-1);
                            }
                            tobesaved = true;
                        }
                    }
                    if (tobesaved)
                    {
                        MidiPlayerGlobal.CurrentMidiSet.Save();
                    }
                }
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }

            try
            {
                string pathMidi = Path.Combine(Application.dataPath, MidiPlayerGlobal.PathToMidiFile);
                if (!Directory.Exists(pathMidi))
                {
                    Directory.CreateDirectory(pathMidi);
                }

                RenameExtFileFromMidToBytes();

                //
                // Check Midifile : remove from DB midifile removed from resource
                //
                bool          tobesaved = false;
                List <string> midiFiles = GetMidiFilePath();
                int           im        = 0;
                while (im < MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count)
                {
                    bool found = false;
                    foreach (string filepath in midiFiles)
                    {
                        string filename = Path.GetFileNameWithoutExtension(filepath);
                        if (filename == MidiPlayerGlobal.CurrentMidiSet.MidiFiles[im])
                        {
                            found = true;
                        }
                    }
                    if (!found)
                    {
                        MidiPlayerGlobal.CurrentMidiSet.MidiFiles.RemoveAt(im);
                        tobesaved = true;
                    }
                    else
                    {
                        im++;
                    }
                }

                //
                // Check Midifile : Add to DB midifile found from resource
                //
                foreach (string pathmidifile in midiFiles)
                {
                    string filename = Path.GetFileNameWithoutExtension(pathmidifile);
                    if (MidiPlayerGlobal.CurrentMidiSet.MidiFiles.FindIndex(s => s == filename) < 0)
                    {
                        tobesaved = true;
                        MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Add(filename);
                    }
                }

                if (tobesaved)
                {
                    MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Sort();
                    MidiPlayerGlobal.CurrentMidiSet.Save();
                }
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }