Esempio n. 1
0
        void Awake()
        {
            //Debug.Log("Awake InfinityMusic");
            HelperNoteLabel.Init();

            // Event set in Inspector
            //if (MidiPlayerGlobal.OnEventPresetLoaded != null)
            //    MidiPlayerGlobal.OnEventPresetLoaded.AddListener(() => EndLoadingSF());

            instance     = this;
            LastDateTick = DateTime.Now;
            ScaleDefinition.Init();
            HelperNoteLabel.Init();
            HelperNoteRatio.Init();
        }
Esempio 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");
        }
Esempio n. 3
0
        public void OnGUI()
        {
            try
            {
                if (customSkin != null)
                {
                    GUI.skin = customSkin;
                }
                if (myStyle == null)
                {
                    myStyle = new CustomStyle();
                }


                GUI.changed = false;
                GUI.color   = Color.white;
                //GUIStyle styleBold;
                //styleBold = new GUIStyle("Label")
                //{
                //    fontSize = 12,
                //    fontStyle = FontStyle.Bold
                //};

                float widthSelectSong = 200;
                float buttonHeight    = 30;
                float buttonWidth     = 200;
                float listHeight      = 150;
                float maxwidth        = Screen.width / 2;
                if (maxwidth < 300)
                {
                    maxwidth = 300;
                }


                if (MidiPlayerGlobal.CurrentMidiSet != null && MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo != null)
                {
                    GUILayout.BeginArea(new Rect(25, 30, maxwidth, 600));

                    GUILayout.Label("InfinityMusic - Music generated by an algo", myStyle.TitleLabel1);
                    if (GUILayout.Button(new GUIContent("Return to menu", "")))
                    {
                        GoMainMenu.Go();
                    }
                    GUILayout.Space(20);

                    GUISelectSoundFont.Display(myStyle);

                    GUILayout.Space(20);
                    GUILayout.Label(
                        string.Format("Measure {0,3:000}.{1,2:00}.{2,2:00}", InfinityMusic.instance.IndexMeasure + 1, InfinityMusic.instance.IndexQuarterMeasure + 1, InfinityMusic.instance.IndexSixteenthMeasure + 1),
                        myStyle.TitleLabel2);
                    GUILayout.Space(20);
                    GUILayout.BeginHorizontal();

                    SelectSong(widthSelectSong, listHeight);

                    GUILayout.BeginVertical();

                    if (GUILayout.Button("New", GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight)))
                    {
                        GuiMessage = null;
                        InfinityMusic.UtNewSong();
                        instance.SongName = "";
                    }

                    if (GUILayout.Button("Open", GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight)))
                    {
                        if (string.IsNullOrEmpty(SelectedSongName))
                        {
                            GuiMessage = "Select a song name";
                        }
                        else
                        {
                            GuiMessage = null;
                            string path     = Path.Combine(Application.dataPath, MidiPlayerGlobal.PathToSong);
                            string filepath = Path.Combine(path, SelectedSongName + "." + MidiPlayerGlobal.ExtensionSong);
                            if (!string.IsNullOrEmpty(filepath))
                            {
                                instance.SongName = SelectedSongName;
                                InfinityMusic.UtNewSong();
                                SaveLoad.UtLoad(filepath);
                            }
                        }
                    }

                    instance.SongName = GUILayout.TextField(instance.SongName, GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight));

                    if (GUILayout.Button("Save", GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight)))
                    {
                        if (string.IsNullOrEmpty(instance.SongName))
                        {
                            GuiMessage = "Set a name for this song";
                        }
                        else
                        {
                            GuiMessage = null;

                            string path = Path.Combine(Application.dataPath, MidiPlayerGlobal.PathToSong);
                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }

                            string filepath = Path.Combine(path, instance.SongName + "." + MidiPlayerGlobal.ExtensionSong);
                            if (!string.IsNullOrEmpty(filepath))
                            {
                                SaveLoad.UtSave(filepath);
                            }
                        }
                    }
                    GUILayout.EndVertical();

                    GUILayout.EndHorizontal();

                    GUILayout.BeginVertical();
                    if (!string.IsNullOrEmpty(GuiMessage))
                    {
                        GUI.color = Color.red;
                        GUILayout.Label(GuiMessage, myStyle.TitleLabel2);
                        GUI.color = Color.white;
                    }
                    GUILayout.Label("Go to your Hierarchy and select InfinityMusic:", myStyle.TitleLabel2);
                    GUILayout.Label("   - Add MathMotif or Cadence components by clicking on button.", myStyle.TitleLabel2);
                    GUILayout.Label("   - Select created components MathMotif or Cadence under InfinityMusic.", myStyle.TitleLabel2);
                    GUILayout.Label("   - Change parameters in inspector to change melody.", myStyle.TitleLabel2);
                    GUILayout.EndVertical();
                }
                else
                {
                    GUILayout.Label(new GUIContent("SoundFont: no soundfont selected", "Define SoundFont from the menu 'Tools/MPTK - SoundFont Setup' or alt-f"));
                }
                GUILayout.EndArea();
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }