コード例 #1
0
        public Note Adjust(int semitones)
        {
            int noteIndex   = MusicGenerator.GetNoteIndex(NoteName);
            int octaveIndex = MusicGenerator.GetOctaveIndex(Octave);
            int over        = (noteIndex + semitones) / MusicGenerator.Notes.GetLength(0);

            noteIndex   = mod(noteIndex + semitones, MusicGenerator.Notes.GetLength(0));
            octaveIndex = mod(octaveIndex + over, MusicGenerator.Notes.GetLength(1));

            return(MusicGenerator.Notes[noteIndex, octaveIndex]);
        }
コード例 #2
0
 public static MusicGenerator GetInstance()
 {
     if (_instance == null)
     {
         _instance                               = new MusicGenerator();
         _instance.CurrentLead                   = new List <IMusicalValue>();
         _instance.CurrentMelody                 = new List <IMusicalValue>();
         _instance.CurrentMelodyPatterns         = new List <List <int?> >();
         _instance.CurrentMood                   = ScriptableObject.CreateInstance <MusicMood>().World;
         _instance.GameController.MusicGenerator = _instance;
     }
     return(_instance);
 }
コード例 #3
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;
        }
コード例 #4
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();
            }
        }