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);
        }
 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;
      }
 }
示例#3
0
        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 TestScoreBasic()
        {
            Scale cscale = new Scale("C", Scale.ScaleTypes.Major);
            Score score  = new Score(new Rational(4, 4), cscale, new string[] { "Piano", "S", "A", "T", "B" });

            score.AddMeasures(3);
            int[]      yankee    = { 0, 0, 2, 4, 0, 4, 2 };
            Rational[] durations = { new Rational(1, 4), new Rational(1, 4),
                                     new Rational(1, 4), new Rational(1, 4),new Rational(1,  4),
                                     new Rational(1, 4), new Rational(2, 4) };

            int item = 0;

            for (int measure = 0; measure < 3; measure++)
            {
                bool ok = false;
                do
                {
                    if (item < yankee.Length)
                    {
                        ok = score.AddNote("Piano", measure, new Note(yankee[item], 0, durations[item]));
                        if (ok)
                        {
                            //Console.WriteLine("Added note {0} to measure {1}", yankee[item], measure);
                            item++;
                        }
                    }
                    else
                    {
                        break;
                    }
                } while(ok);
            }

            // There should only be 2 of 3 measures full
            // measure one contains (C, 1/4) (C, 1/4), (D, 1/4), (E, 1/4)

            Measure m0   = score.GetMeasure("Piano", 0);
            Note    m0n0 = m0.GetNote(0);
            Note    m0n1 = m0.GetNote(1);
            Note    m0n2 = m0.GetNote(2);
            Note    m0n3 = m0.GetNote(3);

            Assert.IsTrue(m0n0.GetTone() == yankee[0] && m0n0.GetDuration().CompareTo(durations[0]) == 0);
            Assert.IsTrue(m0n1.GetTone() == yankee[1] && m0n1.GetDuration().CompareTo(durations[1]) == 0);
            Assert.IsTrue(m0n2.GetTone() == yankee[2] && m0n2.GetDuration().CompareTo(durations[2]) == 0);
            Assert.IsTrue(m0n3.GetTone() == yankee[3] && m0n3.GetDuration().CompareTo(durations[3]) == 0);

            // measure two contains (C, 1/4) (E, 1/4), (D, 1/2)
            Measure m1   = score.GetMeasure("Piano", 1);
            Note    m1n0 = m1.GetNote(0);
            Note    m1n1 = m1.GetNote(1);
            Note    m1n2 = m1.GetNote(2);

            Assert.IsTrue(m1n0.GetTone() == yankee[4] && m1n0.GetDuration().CompareTo(durations[4]) == 0);
            Assert.IsTrue(m1n1.GetTone() == yankee[5] && m1n1.GetDuration().CompareTo(durations[5]) == 0);
            Assert.IsTrue(m1n2.GetTone() == yankee[6] && m1n2.GetDuration().CompareTo(durations[6]) == 0);

            // measure three is empty

            Measure m2 = score.GetMeasure("Piano", 2);

            Assert.IsTrue(m2.Length().CompareTo(new Rational(0, 1)) == 0);
        }
 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);
 }