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]); }
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); }
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; }
/// <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(); } }