Ejemplo n.º 1
0
        private void AnalyseMidi()
        {
            try
            {
                MPTK_TickLast         = 0;
                MPTK_TickCurrent      = 0;
                CurrentTick           = 0;
                NextPosEvent          = 0;
                LastTimeFromStartMS   = 0;
                QuarterPerMinuteValue = double.NegativeInfinity;

                SequenceTrackName   = "";
                ProgramName         = "";
                TrackInstrumentName = "";
                TextEvent           = "";
                Copyright           = "";

                // Get midi events from midifile.Events
                MidiSorted = GetEvents();
                ChangeTempo(MPTK_InitialTempo);

                // If there is no tempo event, set a default value
                if (QuarterPerMinuteValue < 0d)
                {
                    ChangeTempo(120d);
                }
                //Debug.Log("MPTK_InitialTempo:" + MPTK_InitialTempo);

                MPTK_DeltaTicksPerQuarterNote = midifile.DeltaTicksPerQuarterNote;
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Read previous Midi from the list of midi defined in MPTK (see Unity menu Midi)
 /// </summary>
 public void MPTK_Previous()
 {
     try
     {
         if (MidiPlayerGlobal.CurrentMidiSet.MidiFiles != null && MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count > 0)
         {
             int selectedMidi = 0;
             if (!string.IsNullOrEmpty(MPTK_MidiName))
             {
                 selectedMidi = MidiPlayerGlobal.CurrentMidiSet.MidiFiles.FindIndex(s => s == MPTK_MidiName);
             }
             if (selectedMidi >= 0)
             {
                 selectedMidi--;
                 if (selectedMidi < 0)
                 {
                     selectedMidi = MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count - 1;
                 }
                 MPTK_MidiName = MidiPlayerGlobal.CurrentMidiSet.MidiFiles[selectedMidi];
             }
         }
         else
         {
             Debug.LogWarning(MidiPlayerGlobal.ErrorNoMidiFile);
         }
     }
     catch (System.Exception ex)
     {
         MidiPlayerGlobal.ErrorDetail(ex);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Build list of presets found in the SoundFont
 /// </summary>
 static public void BuildBankList()
 {
     MPTK_ListBank = new List <MPTKListItem>();
     try
     {
         //Debug.Log(">>> Load Preset - b:" + ibank + " p:" + ipatch);
         if (ImSFCurrent != null && CurrentMidiSet != null)
         {
             foreach (ImBank bank in ImSFCurrent.Banks)
             {
                 if (bank != null)
                 {
                     MPTK_ListBank.Add(new MPTKListItem()
                     {
                         Index = bank.BankNumber, Label = "Bank " + bank.BankNumber
                     });
                 }
                 else
                 {
                     MPTK_ListBank.Add(null);
                 }
             }
         }
         else
         {
             Debug.Log(MidiPlayerGlobal.ErrorNoSoundFont);
         }
     }
     catch (System.Exception ex)
     {
         MidiPlayerGlobal.ErrorDetail(ex);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Load Midi from MPTK referential
        /// </summary>
        /// <param name="index"></param>
        public bool Load(int index)
        {
            bool ok = true;

            try
            {
                if (index >= 0 && index < MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count)
                {
                    string    midiname = MidiPlayerGlobal.CurrentMidiSet.MidiFiles[index];
                    TextAsset mididata = Resources.Load <TextAsset>(Path.Combine(MidiPlayerGlobal.MidiFilesDB, midiname));
                    midifile = new MidiFile(mididata.bytes, false);
                    if (midifile != null)
                    {
                        AnalyseMidi();
                    }
                    DeltaTicksPerQuarterNote = midifile.DeltaTicksPerQuarterNote;
                }
                else
                {
                    Debug.LogWarning("MidiLoad - index out of range " + index);
                    ok = false;
                }
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
                ok = false;
            }
            return(ok);
        }
Ejemplo n.º 5
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 <float> InitThread()
        {
            if (!Initialized)
            {
                //Debug.Log("MidiPlayerGlobal InitThread");
                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(MidiPlayerGlobal.ErrorNoMidiFile);
                    yield return(Timing.WaitForOneFrame);
                }
                else if (CurrentMidiSet.ActiveSounFontInfo == null)
                {
                    Debug.Log(MidiPlayerGlobal.ErrorNoSoundFont);
                    yield return(Timing.WaitForOneFrame);
                }

                BuildMidiList();
                LoadCurrentSF();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Remove AudioSource not playing
        /// </summary>
        protected IEnumerator DestroyAllAudioSource()
        {
            try
            {
                AudioSource[] audios = GetComponentsInChildren <AudioSource>();

                if (audios != null)
                {
                    //int i = 0;
                    foreach (AudioSource audio in audios)
                    {
                        try
                        {
                            //Debug.Log("Destroy " + i++ + " " + audio.name + " " + (audio.clip != null ? audio.clip.name : "no clip"));
                            // Don't delete audio source template, the only one without a clip
                            if (audio.clip != null)
                            {
                                Destroy(audio.gameObject);
                            }
                        }
                        catch (System.Exception ex)
                        {
                            MidiPlayerGlobal.ErrorDetail(ex);
                        }
                    }
                }
                audiosources = new List <AudioSource>();
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
            yield return(0);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Play one midi event with a thread so the call return immediately.
 ///! @snippet MusicView.cs Example PlayNote
 /// </summary>
 public void MPTK_PlayEvent(MPTKEvent evnt)
 {
     try
     {
         if (MidiPlayerGlobal.MPTK_SoundFontLoaded)
         {
             if (!MPTK_CorePlayer)
             {
                 Timing.RunCoroutine(TheadPlay(evnt));
             }
             else
             {
                 QueueSynthCommand.Enqueue(new SynthCommand()
                 {
                     Command = SynthCommand.enCmd.StartEvent, MidiEvent = evnt
                 });
             }
         }
         else
         {
             Debug.LogWarningFormat("SoundFont not yet loaded, Midi Event cannot be processed Code:{0} Channel:{1}", evnt.Command, evnt.Channel);
         }
     }
     catch (System.Exception ex)
     {
         MidiPlayerGlobal.ErrorDetail(ex);
     }
 }
Ejemplo n.º 8
0
        static public List <PatchOptim> PatchUsed()
        {
            List <PatchOptim> filters = new List <PatchOptim>();

            try
            {
                if (MidiPlayerGlobal.ImSFCurrent != null)
                {
                    foreach (ImBank bank in MidiPlayerGlobal.ImSFCurrent.Banks)
                    {
                        if (bank != null && (MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.DefaultBankNumber == bank.BankNumber || MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.DrumKitBankNumber == bank.BankNumber))
                        {
                            foreach (ImPreset preset in bank.Presets)
                            {
                                if (preset != null)
                                {
                                    filters.Add(new PatchOptim()
                                    {
                                        Bank = bank.BankNumber, Patch = preset.Patch, Name = preset.Name, Selected = true, Drum = (MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.DrumKitBankNumber == bank.BankNumber)
                                    });
                                }
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
            return(filters);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Load Midi from a Midi file from Unity resources. The Midi file must be present in Unity MidiDB ressource folder.
 /// </summary>
 /// <param name="midiname">Midi file name without path and extension</param>
 /// <param name="strict">if true, check strict compliance with the Midi norm</param>
 /// <returns>true if loaded</returns>
 public bool MPTK_Load(string midiname, bool strict = false)
 {
     //! @code
     // public MidiLoad MidiLoaded;
     // // .....
     // MidiLoaded = new MidiLoad();
     // MidiLoaded.MPTK_Load("Beattles - Michelle")
     // Debug.Log("Duration:" + MidiLoaded.MPTK_Duration);
     //! @endcode
     try
     {
         TextAsset mididata = Resources.Load <TextAsset>(Path.Combine(MidiPlayerGlobal.MidiFilesDB, midiname));
         if (mididata != null && mididata.bytes != null && mididata.bytes.Length > 0)
         {
             return(MPTK_Load(mididata.bytes, strict));
         }
         else
         {
             Debug.LogWarningFormat("Midi {0} not loaded from folder {1}", midiname, MidiPlayerGlobal.MidiFilesDB);
         }
     }
     catch (System.Exception ex)
     {
         MidiPlayerGlobal.ErrorDetail(ex);
     }
     return(false);
 }
Ejemplo n.º 10
0
        //! @cond NODOC
        /// Remove AudioSource not playing
        /// </summary>
        protected IEnumerator <float> ThreadDestroyAllVoice()
        {
            try
            {
                fluid_voice[] voicesList = GetComponentsInChildren <fluid_voice>();
                //Debug.LogFormat("DestroyAllVoice {0}", (voicesList != null ? voicesList.Length.ToString() : "no voice found"));

                if (voicesList != null)
                {
                    foreach (fluid_voice voice in voicesList)
                    {
                        try
                        {
                            // Debug.Log("Destroy " + voice.IdVoice + " " + (voice.Audiosource.clip != null ? voice.Audiosource.clip.name : "no clip"));
                            // Don't delete audio source template
                            if (voice.name.StartsWith("VoiceId_"))
                            {
                                Destroy(voice.gameObject);
                            }
                        }
                        catch (System.Exception ex)
                        {
                            MidiPlayerGlobal.ErrorDetail(ex);
                        }
                    }
                    Voices.Clear();
                }
                //audiosources = new List<AudioSource>();
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
            yield return(0);
        }
Ejemplo n.º 11
0
        void OnEnable()
        {
            try
            {
                instance = (MidiFileLoader)target;

                if (!Application.isPlaying)
                {
                    // Load description of available soundfont
                    if (MidiPlayerGlobal.CurrentMidiSet == null || MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo == null)
                    {
                        MidiPlayerGlobal.InitPath();
                        ToolsEditor.LoadMidiSet();
                        ToolsEditor.CheckMidiSet();
                    }
                }

                if (winSelectMidi != null)
                {
                    //Debug.Log("OnEnable winSelectMidi " + winSelectMidi.Title);
                    winSelectMidi.SelectedItem = instance.MPTK_MidiIndex;
                    winSelectMidi.Repaint();
                    winSelectMidi.Focus();
                }

                //EditorApplication.playModeStateChanged += EditorApplication_playModeStateChanged;
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }
Ejemplo n.º 12
0
        private IEnumerator <float> TheadPlay(MPTKEvent note)
        {
            if (note != null)
            {
                try
                {
                    if (!MPTK_PauseOnDistance || MidiPlayerGlobal.MPTK_DistanceToListener(this.transform) <= VoiceTemplate.Audiosource.maxDistance)
                    {
#if DEBUGPERF
                        DebugPerf("-----> Init perf:", 0);
#endif
                        PlayEvent(note);
                        //Debug.Log("where is it");
#if DEBUGPERF
                        DebugPerf("<---- ClosePerf perf:", 2);
#endif
                    }
                }
                catch (System.Exception ex)
                {
                    MidiPlayerGlobal.ErrorDetail(ex);
                }
            }
            yield return(0);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Stop playing the note. All waves associated to the note are stop by sending a noteoff.
        /// </summary>
        /// <param name="pnote"></param>
        public virtual void MPTK_StopEvent(MPTKEvent pnote)
        {
            try
            {
                if (pnote != null && pnote.Voices != null)
                {
                    //Debug.Log(pnote.Value);
                    foreach (fluid_voice note in pnote.Voices)
                    {
                        //Debug.Log(note);

                        if (note.volenv_section != fluid_voice_envelope_index.FLUID_VOICE_ENVRELEASE &&
                            note.status != fluid_voice_status.FLUID_VOICE_OFF)
                        {
                            //&& note.key == val)
                            note.fluid_voice_noteoff();
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Add infoormation about preset
 /// </summary>
 public void CreateBankDescription()
 {
     try
     {
         foreach (ImBank bank in Banks)
         {
             if (bank != null)
             {
                 bank.PatchCount  = 0;
                 bank.Description = "";
                 foreach (ImPreset preset in bank.Presets)
                 {
                     if (preset != null)
                     {
                         bank.PatchCount++;
                         bank.Description += preset.Name + " ; ";
                     }
                 }
             }
         }
     }
     catch (System.Exception ex)
     {
         MidiPlayerGlobal.ErrorDetail(ex);
     }
 }
Ejemplo n.º 15
0
        private static List <string> GetMidiFilePath()
        {
            List <string> paths = new List <string>();

            try
            {
                string folder = Application.dataPath + "/" + MidiPlayerGlobal.PathToMidiFile;
                if (Directory.Exists(folder))
                {
                    try
                    {
                        string[] fileEntries = Directory.GetFiles(folder, "*" + MidiPlayerGlobal.ExtensionMidiFile, SearchOption.AllDirectories);
                        if (fileEntries.Length > 0)
                        {
                            paths = new List <string>(fileEntries);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        Debug.LogWarning("Error GetMidiFilePath GetFiles " + ex.Message);
                    }
                }
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
            return(paths);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Load Midi from a Midi file from Unity resources. The Midi file must be present in Unity MidiDB ressource folder.
        /// </summary>
        /// <param name="midiname">midi file name without path and extension</param>
        public bool MPTK_Load(string midiname)
        {
            //! @code
            //! public MidiLoad MidiLoaded;
            //! // .....
            //! MidiLoaded = new MidiLoad();
            //! MidiLoaded.MPTK_Load("Beattles - Michelle")
            //! Debug.Log("Duration:" + MidiLoaded.MPTK_Duration);
            //! @endcode
            Init();
            bool ok = true;

            try
            {
                string pathfilename = BuildOSPath(midiname);
                midifile = new MidiFile(pathfilename, false);
                if (midifile != null)
                {
                    AnalyseMidi();
                }
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
                ok = false;
            }
            return(ok);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Load setting (edit mode)
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static MidiSet Load(string path)
        {
            MidiSet loaded = null;

            try
            {
                if (File.Exists(path))
                {
                    var serializer = new XmlSerializer(typeof(MidiSet));
                    using (var stream = new FileStream(path, FileMode.Open))
                    {
                        loaded = serializer.Deserialize(stream) as MidiSet;
                    }
                }
                else
                {
                    loaded = new MidiSet();
                }
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }

            return(loaded);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Calculate PulseLenghtMS from QuarterPerMinute value
        /// </summary>
        /// <param name="tempo"></param>
        public void ChangeTempo(double tempo)
        {
            try
            {
                QuarterPerMinuteValue = tempo;
                TickLengthMs          = (1000d / ((QuarterPerMinuteValue * midifile.DeltaTicksPerQuarterNote) / 60f)) / Speed;
                //The BPM measures how many quarter notes happen in a minute. To work out the length of each pulse we can use the following formula: Pulse Length = 60 / (BPM * PPQN)
                //16  Sixteen Double croche

                if (LogEvents)
                {
                    Debug.Log("ChangeTempo");
                    Debug.Log("     QuarterPerMinuteValue :" + QuarterPerMinuteValue);
                    Debug.Log("     Speed :" + Speed);
                    Debug.Log("     DeltaTicksPerQuarterNote :" + midifile.DeltaTicksPerQuarterNote);
                    Debug.Log("     Pulse length in ms :" + TickLengthMs);
                }

                // Update total time of midi play
                CalculateDuration();
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }
Ejemplo n.º 19
0
 private IEnumerator <float> TheadPlay(List <MPTKEvent> events)
 {
     if (events != null && events.Count > 0)
     {
         try
         {
             try
             {
                 //TBR if (!MPTK_PauseOnDistance || MidiPlayerGlobal.MPTK_DistanceToListener(this.transform) <= VoiceTemplate.Audiosource.maxDistance)
                 {
                     PlayEvents(events);
                 }
             }
             catch (System.Exception ex)
             {
                 MidiPlayerGlobal.ErrorDetail(ex);
             }
         }
         catch (System.Exception ex)
         {
             MidiPlayerGlobal.ErrorDetail(ex);
         }
     }
     yield return(0);
 }
Ejemplo n.º 20
0
        public static void Init()
        {
            // Get existing open window or if none, make a new one:
            try
            {
                window         = GetWindow <MidiFileSetupWindow>(true, "Midi File Setup");
                window.minSize = new Vector2(828, 400);

                styleBold           = new GUIStyle(EditorStyles.boldLabel);
                styleBold.fontStyle = FontStyle.Bold;

                styleRichText           = new GUIStyle(EditorStyles.label);
                styleRichText.richText  = true;
                styleRichText.alignment = TextAnchor.UpperLeft;
                heightLine = styleRichText.lineHeight * 1.2f;

                espace       = 5;
                widthLeft    = 500;// 415;
                itemHeight   = 25;
                buttonWidth  = 150;
                buttonHeight = 18;

                xpostitlebox = 2;
                ypostitlebox = 5;
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Play a list of midi events with a thread so the call return immediately.
 /// @snippet TestMidiStream.cs Example MPTK_PlayNotes
 /// </summary>
 public void MPTK_PlayEvent(List <MPTKEvent> events)
 {
     try
     {
         if (MidiPlayerGlobal.MPTK_SoundFontLoaded)
         {
             if (!MPTK_CorePlayer)
             {
                 Timing.RunCoroutine(TheadPlay(events));
             }
             else
             {
                 foreach (MPTKEvent evnt in events)
                 {
                     QueueSynthCommand.Enqueue(new SynthCommand()
                     {
                         Command = SynthCommand.enCmd.StartEvent, MidiEvent = evnt
                     });
                 }
             }
         }
     }
     catch (System.Exception ex)
     {
         MidiPlayerGlobal.ErrorDetail(ex);
     }
 }
Ejemplo n.º 22
0
        //        private void OnLostFocus()
        //        {
        //#if UNITY_2017_1_OR_NEWER
        //            // Trig an  error before v2017...
        //            if (Application.isPlaying)
        //            {
        //                window.Close();
        //            }
        //#endif
        //        }

        /// <summary>
        /// Reload data
        /// </summary>
        private void OnFocus()
        {
            // Load description of available soundfont
            try
            {
                ToolsEditor.LoadMidiSet();
                ToolsEditor.CheckMidiSet();
                if (MidiPlayerGlobal.ImSFCurrent != null)
                {
                    KeepAllPatchs     = MidiPlayerGlobal.ImSFCurrent.KeepAllPatchs;
                    KeepAllZones      = MidiPlayerGlobal.ImSFCurrent.KeepAllZones;
                    RemoveUnusedWaves = MidiPlayerGlobal.ImSFCurrent.RemoveUnusedWaves;
                }
                // cause catch if call when playing (setup open on run mode)
                if (!Application.isPlaying)
                {
                    AssetDatabase.Refresh();
                }
                // Exec after Refresh, either cause errror
                ToolsEditor.LoadImSF();
            }
            catch (Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Calculate PulseLenghtMS from QuarterPerMinute value
        /// </summary>
        /// <param name="tempo"></param>
        private void ChangeTempo(double tempo)
        {
            try
            {
                QuarterPerMinuteValue = tempo;
                PulseLengthMs         = (1000d / ((QuarterPerMinuteValue * midifile.DeltaTicksPerQuarterNote) / 60f)) / Speed;
                //The BPM measures how many quarter notes happen in a minute. To work out the length of each pulse we can use the following formula: Pulse Length = 60 / (BPM * PPQN)
                //16  Sixteen Double croche

                if (LogEvents)
                {
                    Debug.Log("ChangeTempo");
                    Debug.Log("     QuarterPerMinuteValue :" + QuarterPerMinuteValue);
                    Debug.Log("     Speed :" + Speed);
                    Debug.Log("     DeltaTicksPerQuarterNote :" + midifile.DeltaTicksPerQuarterNote);
                    Debug.Log("     Pulse length in ms :" + PulseLengthMs);
                }

                // UPdate total time of midi play
                if (MidiSorted != null && MidiSorted.Count > 0)
                {
                    Duration = TimeSpan.FromMilliseconds(MidiSorted[MidiSorted.Count - 1].Event.AbsoluteTime * PulseLengthMs);
                }
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }
Ejemplo n.º 24
0
        /// <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;
#if MPTK_PRO
                if (OptimInfo != null)
                {
                    Rect listVisibleRect = new Rect(localstartX, localstartY + espace, width - 5, height - 10);
                    Rect listContentRect = new Rect(0, 0, width - 20, OptimInfo.Count * heightLine + 5);

                    scrollPosOptim = GUI.BeginScrollView(listVisibleRect, scrollPosOptim, listContentRect);
                    GUI.color      = Color.white;
                    float labelY = -heightLine;
                    foreach (string s in OptimInfo.Infos)
                    {
                        EditorGUI.LabelField(new Rect(0, labelY += heightLine, width, heightLine), s, styleRichText);
                    }
                    GUI.EndScrollView();
                }
#endif
            }
            catch (Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Read next Midi from the list of midi defined in MPTK (see Unity menu Midi)
 /// </summary>
 public void MPTK_Next()
 {
     try
     {
         if (MidiPlayerGlobal.CurrentMidiSet.MidiFiles != null && MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count > 0)
         {
             int selectedMidi = 0;
             //Debug.Log("Next search " + MPTK_MidiName);
             if (!string.IsNullOrEmpty(MPTK_MidiName))
             {
                 selectedMidi = MidiPlayerGlobal.CurrentMidiSet.MidiFiles.FindIndex(s => s == MPTK_MidiName);
             }
             if (selectedMidi >= 0)
             {
                 selectedMidi++;
                 if (selectedMidi >= MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count)
                 {
                     selectedMidi = 0;
                 }
                 MPTK_MidiName = MidiPlayerGlobal.CurrentMidiSet.MidiFiles[selectedMidi];
                 //Debug.Log("Next found " + MPTK_MidiName);
             }
         }
         else
         {
             Debug.LogWarning(MidiPlayerGlobal.ErrorNoMidiFile);
         }
     }
     catch (System.Exception ex)
     {
         MidiPlayerGlobal.ErrorDetail(ex);
     }
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Play a list of midi events with a thread so the call return immediately.
 /// @snippet TestMidiStream.cs Example MPTK_PlayEvent
 /// </summary>
 public void MPTK_PlayEvent(List <MPTKEvent> events)
 {
     try
     {
         if (MidiPlayerGlobal.MPTK_SoundFontLoaded)
         {
             if (!MPTK_CorePlayer)
             {
                 Timing.RunCoroutine(TheadPlay(events));
             }
             else
             {
                 lock (this) //V2.83
                 {
                     foreach (MPTKEvent evnt in events)
                     {
                         QueueSynthCommand.Enqueue(new SynthCommand()
                         {
                             Command = SynthCommand.enCmd.StartEvent, MidiEvent = evnt
                         });
                     }
                 }
             }
         }
         else
         {
             Debug.LogWarningFormat("SoundFont not yet loaded, Midi Events cannot be processed");
         }
     }
     catch (System.Exception ex)
     {
         MidiPlayerGlobal.ErrorDetail(ex);
     }
 }
Ejemplo n.º 27
0
 private static void LoadWave()
 {
     try
     {
         float start = Time.realtimeSinceStartup;
         //Debug.Log(">>> Load Sample");
         //int count = 0;
         if (ImSFCurrent != null)
         {
             foreach (HiSample smpl in ImSFCurrent.HiSf.Samples)
             {
                 if (smpl.Name != null)
                 {
                     if (!DicAudioWave.Exist(smpl.Name))
                     {
                         LoadWave(smpl);
                         MPTK_CountWaveLoaded++;
                     }
                 }
             }
         }
         else
         {
             Debug.Log("SoundFont not loaded ");
         }
     }
     catch (System.Exception ex)
     {
         MidiPlayerGlobal.ErrorDetail(ex);
     }
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Play previous Midi in list
 /// </summary>
 public virtual void MPTK_Previous()
 {
     try
     {
         if (MidiPlayerGlobal.CurrentMidiSet.MidiFiles != null && MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count > 0)
         {
             int selectedMidi = 0;
             if (!string.IsNullOrEmpty(MPTK_MidiName))
             {
                 selectedMidi = MidiPlayerGlobal.CurrentMidiSet.MidiFiles.FindIndex(s => s == MPTK_MidiName);
             }
             if (selectedMidi >= 0)
             {
                 selectedMidi--;
                 if (selectedMidi < 0)
                 {
                     selectedMidi = MidiPlayerGlobal.CurrentMidiSet.MidiFiles.Count - 1;
                 }
                 MPTK_MidiName = MidiPlayerGlobal.CurrentMidiSet.MidiFiles[selectedMidi];
                 MPTK_RePlay();
             }
         }
         else
         {
             Debug.LogWarning("MidiFilePlayer - no Midi defined, go to menu 'Tools/MPTK - Midi File Setup' or alt-m");
         }
     }
     catch (System.Exception ex)
     {
         MidiPlayerGlobal.ErrorDetail(ex);
     }
 }
Ejemplo n.º 29
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);
            }
        }
 /// <summary>
 /// Add Midi files from a folder
 /// </summary>
 private static void AddMidiFromFolder()
 {
     try
     {
         string selectedFolder = EditorUtility.OpenFolderPanel("Import Midi from a folder", ToolsEditor.lastDirectoryMidi, "");
         if (!string.IsNullOrEmpty(selectedFolder))
         {
             ToolsEditor.lastDirectoryMidi = Path.GetDirectoryName(selectedFolder);
             string[] files = Directory.GetFiles(selectedFolder);
             foreach (string file in files)
             {
                 if (file.EndsWith(".mid") || file.EndsWith(".midi"))
                 {
                     InsertMidiFIle(file);
                 }
             }
         }
         AssetDatabase.Refresh();
         ToolsEditor.LoadMidiSet();
         ToolsEditor.CheckMidiSet();
         AssetDatabase.Refresh();
     }
     catch (System.Exception ex)
     {
         MidiPlayerGlobal.ErrorDetail(ex);
     }
 }