public void TestScaleGeneration() { Scale cscale = new Scale("C", Scale.ScaleTypes.Major); int[] cintervals = { 0, 2, 4, 5, 7, 9, 11, 0 }; for (int i = 0; i < 8; i++) { Assert.AreEqual(cscale.GetTone(i), cintervals[i]); } Scale dscale = new Scale("D", Scale.ScaleTypes.Major); int[] dintervals = { 2, 4, 6, 7, 9, 11, 1, 2 }; //dscale.Output(); for (int i = 0; i < 8; i++) { //Console.WriteLine("i={0} actual={1} expected={2}", i, dscale.GetTone(i), dintervals[i]); Assert.AreEqual(dscale.GetTone(i), dintervals[i]); } }
/// <summary> /// Create a new measure from a string. /// </summary> /// <param name="ABCNotes">A string representing a measure, written in ABC notation.</param> /// <param name="scale">The scale the measure uses tones from.</param> public Measure(String ABCNotes, Scale scale) { Notes = new List <Note>(); double length = .25; ToneClass toneClass = null; Tone tone = null; Note note = null; int index = 0; while (index < ABCNotes.Length) { if (Char.IsLetter(ABCNotes[index])) { if (note != null) { Notes.Add(note); note = null; tone = null; length = .25; } toneClass = scale.GetTone(ABCNotes[index].ToString()); tone = new Tone(toneClass, Char.IsLower(ABCNotes[index]) ? 1 : 0); note = new Note(tone, length); } else if (Char.IsNumber(ABCNotes[index])) { int numberLength = 1; while (index + numberLength < ABCNotes.Length && Char.IsNumber(ABCNotes[index + numberLength])) { numberLength++; } int times = int.Parse(ABCNotes.Substring(index, numberLength)); note = new Note(tone, length * times); } index++; } Notes.Add(note); }