示例#1
0
 /**
  * Creates a score with a single staff, two measures, and a number of clefs, keys and chords. The
  * score, the list of clefs and the list of keys is returned.
  */
 private Tuple3<Score, List<Clef>, List<Key>> createTestScoreClefsKeys() {
   // create two measures:
   // clef-g, key-Gmaj, C#1/4, clef-f, Db1/4, clef-g, key-Fmaj, Cnat1/4 |
   // C#1/4, key-Cmaj, clef-f, C2/4.
   Score score = ScoreFactory.create1Staff();
   new MeasureAdd(score, 1).execute();
   List<Clef> clefs = new ArrayList<Clef>();
   List<Key> keys = new ArrayList<Key>();
   Clef c;
   Key k;
   // measure 0
   Measure measure = score.getMeasure(atMeasure(0, 0));
   new Clef(ClefType.clefTreble);
   clefs.add(c = new Clef(ClefType.clefTreble));
   new MeasureElementWrite(c, measure, fr(0, 4)).execute();
   keys.add(k = new TraditionalKey(1, Mode.Major));
   new MeasureElementWrite(k, measure, fr(0, 4)).execute();
   new VoiceElementWrite(
           measure.getVoice(0), atElement(0, 0, 0, 0), chord(pi(0, 1, 4), fr(1, 4)), null)
       .execute();
   clefs.add(c = new Clef(ClefType.clefBass));
   new MeasureElementWrite(c, measure, fr(1, 4)).execute();
   new VoiceElementWrite(
           measure.getVoice(0), atElement(0, 0, 0, 1), chord(pi(1, -1, 4), fr(1, 4)), null)
       .execute();
   clefs.add(c = new Clef(ClefType.clefTreble));
   new MeasureElementWrite(c, measure, fr(2, 4)).execute();
   keys.add(k = new TraditionalKey(-1, Mode.Major));
   new MeasureElementWrite(k, measure, fr(2, 4)).execute();
   new VoiceElementWrite(
           measure.getVoice(0), atElement(0, 0, 0, 2), chord(pi(0, 0, 4), fr(1, 4)), null)
       .execute();
   // measure 1
   measure = score.getMeasure(atMeasure(0, 1));
   new VoiceElementWrite(
           measure.getVoice(0), atElement(0, 1, 0, 0), chord(pi(0, 1, 4), fr(1, 4)), null)
       .execute();
   keys.add(k = new TraditionalKey(0, Mode.Major));
   new MeasureElementWrite(k, measure, fr(1, 4)).execute();
   clefs.add(c = new Clef(ClefType.clefBass));
   new MeasureElementWrite(c, measure, fr(1, 4)).execute();
   new VoiceElementWrite(
           measure.getVoice(0), atElement(0, 1, 0, 1), chord(pi(0, 0, 4), fr(2, 4)), null)
       .execute();
   return t3(score, clefs, keys);
 }
示例#2
0
 @Test
 public void test() {
   Pitch[] expectedPitches = getExpectedPitches();
   int iPitch = 0;
   Staff staff = getFirstStaff();
   for (int iM = 0; iM < staff.getMeasures().size(); iM++) {
     Measure measure = staff.getMeasures().get(iM);
     Voice voice = measure.getVoice(0);
     for (VoiceElement e : voice.getElements()) {
       if (e instanceof Chord) {
         // check note and pitch
         Chord chord = (Chord) e;
         assertEquals(expectedPitches[iPitch++], chord.getNotes().get(0).getPitch());
       }
     }
   }
   // TODO - ignore this test, since MusicXML input file has a bug (only a single measure),
   // so currently only the first measure is tested
   // assertEquals("not all notes found", expectedPitches.length, iPitch);
 }