public Chord(ChordEnum _chord, MusicalKey _key, ChordFunction _function, List <Note> _notes) { this.chord = _chord; this.keyThisChordIsIn = _key; this.functionWithinKey = _function; this.notes = _notes; }
public Chord GetChordOfType(MusicalKey key, ChordFunction function) // returns random chord in a given key that performs given function, (functional harmony) { Chord chord; ChordEnum chordname = ChordEnum.none; if (functionalChords[key].ContainsKey(function)) // this should always pass, just to be safe { chordname = functionalChords[key][function][Random.Range((int)0, functionalChords[key][function].Count)]; // get a random chord of this function } else { Debug.LogError("Functional type not recognised"); } if (allChords.ContainsKey(chordname)) // just in case { chord = new Chord(chordname, key, function, allChords[chordname]); return(chord); } else { Debug.LogError("chord does not exist: " + chordname.ToString()); return(null); } }
private void GenerateNextProgression() { if (sequenceNumber % 3 != 0) { currentKey = (MusicalKey)Random.Range(1, (int)MusicalKey.count); // maybe switch key // currentKey = currentKey == MusicalKey.CMajor ? MusicalKey.CMinor : MusicalKey.CMajor; // maybe switch key } currentProgression = (Progression)Random.Range(1, (int)Progression.count); // get random progression switch (currentProgression) { case Progression.None: Debug.LogError("Error in progression assignment"); break; case Progression.TonicDominantTonic: chordQueue.Enqueue(chordController.GetChordOfType(currentKey, ChordFunction.tonic)); chordQueue.Enqueue(chordController.GetChordOfType(currentKey, ChordFunction.dominant)); chordQueue.Enqueue(chordController.GetChordOfType(currentKey, ChordFunction.tonic)); chordNumber += 3; break; case Progression.TonicSubdominantTonic: chordQueue.Enqueue(chordController.GetChordOfType(currentKey, ChordFunction.tonic)); chordQueue.Enqueue(chordController.GetChordOfType(currentKey, ChordFunction.subdominant)); chordQueue.Enqueue(chordController.GetChordOfType(currentKey, ChordFunction.tonic)); chordNumber += 3; break; case Progression.TonicDominantSubdominantTonic: chordQueue.Enqueue(chordController.GetChordOfType(currentKey, ChordFunction.tonic)); chordQueue.Enqueue(chordController.GetChordOfType(currentKey, ChordFunction.dominant)); chordQueue.Enqueue(chordController.GetChordOfType(currentKey, ChordFunction.subdominant)); chordQueue.Enqueue(chordController.GetChordOfType(currentKey, ChordFunction.tonic)); chordNumber += 4; break; case Progression.count: Debug.LogError("Error in progression assignment"); break; default: Debug.LogError("Error in progression assignment"); break; } sequenceNumber++; }
public static string GetRelativeNoteInKey(MusicalKey key, string note, int distance) { if (string.IsNullOrEmpty(note)) { return(note); } int octave = int.Parse(note[note.Length - 1].ToString()); string checkNote = note.Substring(0, note.Length - 1); string returnNote = checkNote; if (keys.ContainsKey(key)) { List <string> notes = keys[key]; if (notes.Contains(checkNote)) { int index = notes.IndexOf(checkNote); //remove octaves first (up or down) while (distance > 7) { octave++; distance -= 7; } while (distance < -7) { octave--; distance += 7; } //so we're within one octave now, either up or down //beyond upper limit if (index + distance > notes.Count - 1) { octave++; index = (index + distance) - notes.Count; returnNote = notes[index]; } //beyond lower limit else if (index + distance < 0) { octave--; index = (index + distance) + notes.Count; returnNote = notes[index]; } //in range else { returnNote = notes[index + distance]; } } else { Debug.LogError(string.Format("Note not in key {0} {1}", checkNote, key)); } } else { Debug.LogError("Not implemented: " + key); } return(returnNote + octave.ToString()); }
// public int difficulty = 3; // 3 is normal, 4 is hard // Start is called before the first frame update void Start() { currentProgression = (Progression)Random.Range(1, (int)Progression.count); // get random progression currentKey = MusicalKey.CMajor; }