public bool HasChord( List <Scale> scales, List <Scale> chords, BasedChord chord) { //chordnote+transform is in this scale's space bool contained = true; //Debug.Log( this.Print(scales) + "\n" + chord.Print(chords) ); for (int i = 0; i < chords[chord.chordindex].notes.Count; i++) { //for each note in the chord if (chords[chord.chordindex].notes[i]) { if (!HasNote(scales, i + chord.pitchclass)) { //Debug.Log("disagree at note " + i.ToString()); contained = false; break; } } } return(contained); }
public Progression(string description, List <Scale> chordlist) { //Dm7-G7,Cmaj7 string[] bars = description.Split('|'); List <string> chords_str = new List <string>(); foreach (string bar in bars) { if (bar.IndexOf(',') >= 0) { string[] subbar = bar.Split(','); chords_str.Add(subbar[0]); chords_str.Add(subbar[1]); } else { chords_str.Add(bar); chords_str.Add(bar); } } chords = new List <BasedChord>(); foreach (string chord_desc in chords_str) { string trimmed = chord_desc.Trim(); if (trimmed != "") { chords.Add(BasedChord.Parse(trimmed, chordlist)); } } while (chords.Count < progressionlength) { List <BasedChord> chordcopy = new List <BasedChord>(chords); chords.AddRange(chordcopy); } }
public static BasedChord Parse(string desc, List <Scale> chordlist) { BasedChord result = null; if (chorddatabase.TryGetValue(desc, out result)) { return(result); } result = new BasedChord(); string suffix = ""; bool found = false; for (int i = 0; i < Note.Names.Length; i++) { string notename = Note.Names[i]; if (desc[0] == notename[0] && (notename.Length == 1 || (desc.Length > 1 && desc[1] == notename[1]))) { found = true; if (desc == notename) { suffix = "major"; } else { suffix = desc.Substring(notename.Length); } result.pitchclass = i; break; } } if (!found) { Debug.Log("ERROR ERROR BASEDCHORD NOT RIGHT - desc = " + desc); return(null); } bool foundchord = false; for (int i = 0; i < chordlist.Count; i++) { Scale chord = chordlist[i]; if (suffix == chord.name) { result.chordindex = i; foundchord = true; break; } } if (!foundchord) { Debug.Log("ERROR ERROR BASEDCHORD NOT RIGHT - desc = " + desc + " | " + suffix); return(null); } chorddatabase.Add(desc, result); return(result); }