Ejemplo n.º 1
0
 void OnEnable()
 {
     try
     {
         instance = (UtCadence)target;
     }
     catch (System.Exception ex)
     {
         MidiPlayerGlobal.ErrorDetail(ex);
     }
 }
Ejemplo n.º 2
0
        static public void UtLoad(string songname)
        {
            SaveLoad slSong;

            Debug.Log(">>> Load");
            lock (InfinityMusic.instance)
            {
                try
                {
                    slSong = SaveLoad.LoadXML(songname);
                    if (slSong != null)
                    {
                        // Cadence
                        //Debug.Log("Cadence Count:" + slSong.Cadences.Count);
                        foreach (ImCadence im in slSong.Cadences)
                        {
                            Debug.Log(" " + im.Name);
                            UtCadence ut = (UtCadence)InfinityMusic.Instantiate(InfinityMusic.instance.TemplateCadence, Vector3.zero, Quaternion.identity);
                            ut.transform.parent = InfinityMusic.instance.transform;
                            // Common
                            LoadCommon(im, ut);

                            // Specific
                            ut.MeasureCount = im.MeasureCount;
                            ut.PctSilence   = im.PctSilence;
                            ut.RatioWhole   = im.RatioWhole;
                            ut.RatioHalf    = im.RatioHalf;
                            ut.RatioQuarter = im.RatioQuarter;
                            ut.RatioEighth  = im.RatioEighth;
                            ut.RatioSixteen = im.RatioSixteen;
                            ut.Durations    = (im.Durations != null && im.Durations.Count > 0) ? new List <Cadence>(im.Durations) : null;
                        }


                        // Math Motif
                        Debug.Log("Math Motif Count:" + slSong.Motifs.Count);
                        foreach (ImMathMotif im in slSong.Motifs)
                        {
                            //Debug.Log(" " + im.Name);
                            UtMathMotif ut = (UtMathMotif)InfinityMusic.Instantiate(InfinityMusic.instance.TemplateMathMotif, Vector3.zero, Quaternion.identity);
                            ut.transform.parent = InfinityMusic.instance.transform;

                            // Common
                            LoadCommon(im, ut);

                            // Specific
                            ut.MeasureCount  = im.MeasureCount;
                            ut.OctaveMin     = im.OctaveMin;
                            ut.OctaveMax     = im.OctaveMax;
                            ut.ScaleIndex    = im.ScaleIndex;
                            ut.PatchIndex    = im.PatchIndex;
                            ut.DrumKit       = im.DrumKit;
                            ut.SelectedAlgo  = im.SelectedAlgo;
                            ut.StepInScale   = im.StepInScale;
                            ut.RotationSpeed = im.RotationSpeed;
                            ut.Accentuation  = im.Accentuation;
                            ut.Velocity      = im.Velocity;
                            ut.RepeatRate    = im.RepeatRate;
                            if (im.IdCadence >= 0)
                            {
                                UtCadence[] cadences = GameObject.FindObjectsOfType <UtCadence>();
                                foreach (UtCadence cadence in cadences)
                                {
                                    if (cadence.UtId == im.IdCadence)
                                    {
                                        ut.CurrentCadence = cadence;
                                        break;
                                    }
                                }
                            }
                            ut.Notes = (im.Notes != null && im.Notes.Count > 0) ? new List <MathMotifNote>(im.Notes) : null;
                        }

                        //Debug.Log("Chorder Count:" + slSong.Chorders.Count);
                        //foreach (ImChorder im in slSong.Chorders)
                        //{
                        //    Debug.Log(" " + im.ImName + " " + im.ImRadiusEffect);
                        //    UtChorder ut = (UtChorder)Instantiate(UtGlobal.instance.utChorder, im.Position, Quaternion.identity);

                        //    // Common
                        //    LoadCommon(im, ut);

                        //    // Specific
                        //    ut.Trigger = im.Trigger;
                        //    ut.StepCount = im.StepCount;
                        //    ut.ChordProgression = im.ChordProgression;
                        //}


                        //// Midi Motif
                        //Debug.Log("Midi Motif Count:" + slSong.Midis.Count);
                        //foreach (ImMidiMotif im in slSong.Midis)
                        //{
                        //    Debug.Log(" " + im.ImName + " " + im.ImRadiusEffect);
                        //    UtMidiMotif ut = (UtMidiMotif)Instantiate(UtGlobal.instance.utMidiMotif, im.Position, Quaternion.identity);

                        //    // Common
                        //    LoadCommon(im, ut);

                        //    // Specific
                        //    ut.MidiName = im.MidiName;
                        //    ut.Transpose = im.Transpose;
                        //    ut.StartPlay = im.StartPlay;
                        //    ut.EndPlay = im.EndPlay;
                        //    ut.DeltaTicksPerQuarterNote = im.DeltaTicksPerQuarterNote;
                        //    ut.NumberBeatsMeasure = im.NumberBeatsMeasure;
                        //    ut.NumberQuarterBeat = im.NumberQuarterBeat;
                        //    ut.SelectedMode = im.SelectedMode;
                        //    ut.StepPlay = im.StepPlay;
                        //    //ut.MidiMeasures = im.Measures;
                        //    ut.Tracks = im.Tracks;
                        //    ut.ImportTracksToMeasure();
                        //}

                        ////
                        //// Modifier
                        ////
                        //Debug.Log("Modifier Count:" + slSong.Modifiers.Count);
                        //foreach (ImModifier im in slSong.Modifiers)
                        //{
                        //    Debug.Log(">>> Create '" + im.ImName + "'");
                        //    UtModifier ut = (UtModifier)Instantiate(UtGlobal.instance.utModifier, im.Position, Quaternion.identity);
                        //    //Debug.Log("<<< Create '" + im.ImName + "'");

                        //    // Common
                        //    LoadCommon(im, ut);

                        //    // Specific
                        //    ut.MeasureCount = im.MeasureCount;
                        //    ut.SelectedMode = im.SelectedMode;

                        //    //if (im.IndexProperties < 5)
                        //    //{
                        //    //    ut.IndexApplyTo = 1;
                        //    //    ut.IndexProperties = im.IndexProperties;

                        //    //}
                        //    //else
                        //    //{
                        //    //    ut.IndexApplyTo = 0;
                        //    //    ut.IndexProperties = 0;
                        //    //}
                        //    ut.IndexApplyTo = im.IndexApplyTo;
                        //    ut.IndexProperties = im.IndexProperties;

                        //    //Debug.Log("   im.MinSelected " + im.MinSelected);
                        //    //Debug.Log("   im.MaxSelected " + im.MaxSelected);
                        //    ut.FromSelected = im.MinSelected;
                        //    ut.ToSelected = im.MaxSelected;
                        //    ut.Step = im.Step;
                        //}

                        ////
                        //// Drum
                        ////
                        //Debug.Log("Drum Count:" + slSong.Drums.Count);
                        //foreach (ImDrum im in slSong.Drums)
                        //{
                        //    Debug.Log(">>> Create '" + im.ImName + "'");
                        //    UtDrum ut = (UtDrum)Instantiate(UtGlobal.instance.utDrum, im.Position, Quaternion.identity);
                        //    //Debug.Log("<<< Create '" + im.ImName + "'");

                        //    // Common
                        //    LoadCommon(im, ut);

                        //    // Specific
                        //    ut.Tracks = im.Tracks;
                        //    ut.RandomLevel = im.RandomLevel;
                        //}

                        ////
                        //// Activator
                        ////
                        //Debug.Log("Activator Count:" + slSong.Activators.Count);
                        //foreach (ImActivator im in slSong.Activators)
                        //{
                        //    Debug.Log(">>> Create '" + im.ImName + "'");
                        //    UtActivator ut = (UtActivator)Instantiate(UtGlobal.instance.utActivator, im.Position, Quaternion.identity);
                        //    //Debug.Log("<<< Create '" + im.ImName + "'");

                        //    // Common
                        //    LoadCommon(im, ut);

                        //    // Specific
                        //    ut.MeasureCount = im.MeasureCount;
                        //    ut.MeasureStart = im.MeasureStart;
                        //    ut.ActivateBeforeStart = im.ActivateBeforeStart;
                        //    ut.ActivateAfterLoop = im.ActivateAfterLoop;
                        //    ut.LoopCount = im.LoopCount;
                        //    ut.Activates = im.Activates;
                        //}


                        InfinityMusic.instance.MeasureLength    = slSong.MeasureLength;
                        InfinityMusic.instance.QuarterPerMinute = slSong.QuarterPerMinute;
                        InfinityMusic.instance.MaxMeasure       = slSong.MaxMeasure;
                        if (InfinityMusic.instance.MaxMeasure <= 0)
                        {
                            InfinityMusic.instance.MaxMeasure = 1000;
                        }
                        InfinityMusic.instance.SongName    = slSong.SongName;
                        InfinityMusic.instance.Description = slSong.Description;
                    }
                }
                catch (System.Exception ex)
                {
                    MidiPlayerGlobal.ErrorDetail(ex);
                }
            }
            Debug.Log("<<< Load");
        }