Example #1
0
        void Awake()
        {
            LeadTrack   = new Queue <IMusicalValue>();
            MelodyTrack = new Queue <IMusicalValue>();
            Generator   = MusicGenerator.GetInstance();
            Sampler     = GetComponent <SamplerController>();
            //set starting mood
            currentMood              = ScriptableObject.CreateInstance <MusicMood>().World;
            Sampler.LeadInstrument   = currentMood.LeadInstrumentSample;
            Sampler.MelodyInstrument = currentMood.MelodyInstrumentSample;
            Sampler.SetASR(currentMood.ASRSettings);
            Metronome metro = FindObjectOfType <Metronome>();

            metro.bpm = currentMood.Tempo;
            //enqueue starting tracks
            Generator.Generate();
            GetNextTracks();
            //subscribe to the metronome tick event so we can keep time!
            Metronome.Ticked += Step;
        }
Example #2
0
        /// <summary>
        /// Step each track forward one position and pass the notevalues to the sampler
        /// at that position
        /// </summary>
        public void Step()
        {
            IMusicalValue leadValue   = LeadTrack.Dequeue();
            IMusicalValue melodyValue = MelodyTrack.Dequeue();

            Sampler.Play(leadValue, melodyValue);
            if (LeadTrack.Count < 2)
            {
                //Changing mood at some point within this
                MusicGenerator MusicGen = MusicGenerator.GetInstance();
                Metronome      metro    = FindObjectOfType <Metronome>();
                MusicGen.GetMood();
                if (MusicGen.CurrentMood != currentMood)
                {
                    Debug.Log("CHANGING MOOD");
                    MusicGen.Generate();
                    currentMood = MusicGen.CurrentMood;
                    var emptyBar = MusicGen.GetBar();
                    foreach (IMusicalValue note in emptyBar)
                    {
                        LeadTrack.Enqueue(note);
                        MelodyTrack.Enqueue(note);
                    }
                    metro.bpm = currentMood.Tempo;
                    Sampler.LeadInstrument   = currentMood.LeadInstrumentSample;
                    Sampler.MelodyInstrument = currentMood.MelodyInstrumentSample;
                    Sampler.SetASR(currentMood.ASRSettings);
                }
                //else
                //{
                //    //slow down as we fade out
                //    metro.bpm /= 2;
                //}
                GetNextTracks();
            }
        }