Ejemplo n.º 1
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.º 2
0
        /// <summary>
        /// Call by the first MidiPlayer awake
        /// </summary>
        //public static void Init()
        //{
        //    Instance.StartCoroutine(Instance.InitThread());
        //}

        /// <summary>
        /// Call by the first MidiPlayer awake
        /// </summary>
        private IEnumerator InitThread()
        {
            if (!Initialized)
            {
                //Debug.Log("MidiPlayerGlobal InitThread");
                SoundFontLoaded = false;
                Initialized     = true;
                ImSFCurrent     = null;

                try
                {
                    AudioListener = Component.FindObjectOfType <AudioListener>();
                    if (AudioListener == null)
                    {
                        Debug.LogWarning("No audio listener found. Add one and only one AudioListener component to your hierarchy.");
                        //return;
                    }
                }
                catch (System.Exception ex)
                {
                    MidiPlayerGlobal.ErrorDetail(ex);
                }

                try
                {
                    AudioListener[] listeners = Component.FindObjectsOfType <AudioListener>();
                    if (listeners != null && listeners.Length > 1)
                    {
                        Debug.LogWarning("More than one audio listener found. Some unexpected behaviors could happen.");
                    }
                }
                catch (System.Exception ex)
                {
                    MidiPlayerGlobal.ErrorDetail(ex);
                }

                try
                {
                    LoadMidiSetFromRsc();
                    DicAudioClip.Init();
                }
                catch (System.Exception ex)
                {
                    MidiPlayerGlobal.ErrorDetail(ex);
                }

                if (CurrentMidiSet == null)
                {
                    Debug.LogWarning("No Midi defined, go to menu 'Tools/MPTK - Midi File Setup' or alt-m");
                    yield return(0);
                }
                else if (CurrentMidiSet.ActiveSounFontInfo == null)
                {
                    Debug.LogWarning("No Active SoundFont found. Define SoundFont from the menu 'Tools/MPTK - SoundFont Setup' or alt-f");
                    yield return(0);
                }

                LoadCurrentSF();
                //Debug.Log("");

                if (ImSFCurrent != null)
                {
                    SoundFontLoaded = true;
                }
            }
        }