public Note GetNote(int position) { Note noNote = new Note(0, 0, new Rational(0, 0)); // a note with 0 tone, octave, duration if (position < voice.Count) return voice[position]; else return noNote; }
public bool AddNote(Note note) { Rational currentLength = Length(); Rational newLength = currentLength.Add(note.GetDuration()); if (newLength.CompareTo(duration) > 0) return false; else { voice.Add(note); return true; } }
public void TestAdditionOfNotes() { // Create a measure in 3/4 time. Measure m = new Measure(new Rational(3, 4)); Note q = new Note(0, 0, new Rational(1, 4)); bool ok; ok = m.AddNote(q); Assert.IsTrue(ok); Assert.IsTrue( m.Length().CompareTo(new Rational(1, 4)) == 0 ); ok = m.AddNote(q); Assert.IsTrue(ok); Assert.IsTrue( m.Length().CompareTo(new Rational(2, 4)) == 0 ); ok = m.AddNote(q); Assert.IsTrue(ok); Assert.IsTrue( m.Length().CompareTo(new Rational(3, 4)) == 0 ); // This last addition should *not* be ok and should not change the length from 3/4 to anything else. ok = m.AddNote(q); Assert.IsFalse(ok); Assert.IsTrue( m.Length().CompareTo(new Rational(3, 4)) == 0 ); }
public bool AddNote(string label, int measureNumber, Note note) { // find the staff label of interest if (staff.ContainsKey(label)) { List<Measure> measures = staff[label]; if (measureNumber < measures.Count) { Measure m = measures[measureNumber]; return m.AddNote(note); } } return false; }
public void TestConstructor() { Note n = new Note(0, 0, new Rational(1, 4)); Rational r = n.GetDuration(); Assert.IsTrue(r.CompareTo(new Rational(1, 4)) == 0); }