Esempio n. 1
0
 @Test
 public void getMeasureBeatsTest() {
   Score score = ScoreFactory.create1Staff4Measures();
   // first measure: no time, 1/4 used
   score.getVoice(atVoice(0, 0, 0)).addElement(new Rest(fr(1, 4)));
   // second measure: 3/4 time, 2/4 used
   score.getColumnHeader(1).setTime(new Time(TimeType.time_3_4));
   score.getVoice(atVoice(0, 1, 0)).addElement(new Rest(fr(1, 4)));
   score.getVoice(atVoice(0, 1, 0)).addElement(new Rest(fr(1, 4)));
   // third measure: still 3/4 time, 1/4 used
   score.getVoice(atVoice(0, 2, 0)).addElement(new Rest(fr(1, 4)));
   // check
   assertEquals(fr(1, 4), score.getMeasureBeats(0));
   assertEquals(fr(3, 4), score.getMeasureBeats(1));
   assertEquals(fr(3, 4), score.getMeasureBeats(2));
 }
Esempio n. 2
0
 @Test
 public void getMeasureFilledBeatsTest() {
   // create a little test score, where the first measure only
   // uses 2/4, the second 4/4, the third 0/4, the fourth 3/4.
   Score score = ScoreFactory.create1Staff4Measures();
   score.getVoice(atVoice(0, 0, 0)).addElement(new Rest(fr(1, 4)));
   score.getVoice(atVoice(0, 0, 0)).addElement(new Rest(fr(1, 4)));
   score.getVoice(atVoice(0, 1, 0)).addElement(new Rest(fr(2, 4)));
   score.getVoice(atVoice(0, 1, 0)).addElement(new Rest(fr(2, 4)));
   score.getVoice(atVoice(0, 3, 0)).addElement(new Rest(fr(3, 4)));
   // test method
   assertEquals(fr(2, 4), score.getMeasureFilledBeats(0));
   assertEquals(fr(4, 4), score.getMeasureFilledBeats(1));
   assertEquals(fr(0, 4), score.getMeasureFilledBeats(2));
   assertEquals(fr(3, 4), score.getMeasureFilledBeats(3));
 }
Esempio n. 3
0
  @Test
  public void clipToMeasureTest() {
    Score score = ScoreFactory.create1Staff4Measures();
    score.getHeader().getColumnHeader(0).setTime(new Time(TimeType.time_3_4));

    // position before measure
    MP pos = atBeat(1, 1, 0, fr(2, 4));
    MP clippedPos = score.clipToMeasure(2, pos);
    assertEquals(clippedPos.measure, 2);
    assertTrue(clippedPos.beat.equals(_0));

    // position at the beginning of the measure
    pos = atBeat(1, 2, 0, _0);
    clippedPos = score.clipToMeasure(2, pos);
    assertEquals(clippedPos.measure, 2);
    assertTrue(clippedPos.beat.equals(_0));

    // position in the measure
    pos = atBeat(1, 2, 0, fr(2, 4));
    clippedPos = score.clipToMeasure(2, pos);
    assertEquals(clippedPos.measure, 2);
    assertTrue(clippedPos.beat.equals(fr(2, 4)));

    // position at the end of the measure
    pos = atBeat(1, 2, 0, fr(3, 4));
    clippedPos = score.clipToMeasure(2, pos);
    assertEquals(clippedPos.measure, 2);
    assertTrue(clippedPos.beat.equals(fr(3, 4)));

    // position after the end of the measure
    pos = atBeat(1, 2, 0, fr(4, 4));
    clippedPos = score.clipToMeasure(2, pos);
    assertEquals(clippedPos.measure, 2);
    assertTrue(clippedPos.beat.equals(fr(3, 4)));

    // position after the measure
    pos = atBeat(1, 3, 0, fr(2, 4));
    clippedPos = score.clipToMeasure(2, pos);
    assertEquals(clippedPos.measure, 2);
    assertTrue(clippedPos.beat.equals(fr(3, 4)));
  }
Esempio n. 4
0
 @Test
 public void getGapBetweenTest() {
   Score score = ScoreFactory.create1Staff4Measures();
   VoiceElement[] e = new VoiceElement[6];
   // 4/4 measure
   score.getColumnHeader(0).setTime(new Time(TimeType.time_4_4));
   // first measure (filled only with 7/8)
   //  voice 0: 1/4, 1/4, 1/4  (1/4 is missing)
   //  voice 1: 3/4, 1/8       (1/8 is missing)
   score.getVoice(atVoice(0, 0, 0)).addElement(e[0] = new Rest(fr(1, 4)));
   score.getVoice(atVoice(0, 0, 0)).addElement(e[1] = new Rest(fr(1, 4)));
   score.getVoice(atVoice(0, 0, 0)).addElement(e[2] = new Rest(fr(1, 4)));
   new VoiceAdd(score.getMeasure(atMeasure(0, 0)), 1).execute();
   score.getVoice(atVoice(0, 0, 1)).addElement(new Rest(fr(3, 4)));
   score.getVoice(atVoice(0, 0, 1)).addElement(new Rest(fr(1, 8)));
   // second measure: 1/4, 3/4
   score.getVoice(atVoice(0, 1, 0)).addElement(e[3] = new Rest(fr(1, 4)));
   score.getVoice(atVoice(0, 1, 0)).addElement(e[4] = new Rest(fr(3, 4)));
   // third measure: 4/4
   score.getVoice(atVoice(0, 1, 0)).addElement(e[5] = new Rest(fr(4, 4)));
   // test gaps between adjacent elements
   assertEquals(_0, score.getGapBetween(e[0], e[1]));
   assertEquals(_0, score.getGapBetween(e[1], e[2]));
   assertEquals(fr(1, 8), score.getGapBetween(e[2], e[3])); // 1/8 from second voice
   assertEquals(_0, score.getGapBetween(e[3], e[4]));
   assertEquals(_0, score.getGapBetween(e[4], e[5]));
   // test some gaps between non-adjacent elements
   assertEquals(fr(1, 4), score.getGapBetween(e[0], e[2]));
   assertEquals(fr(3, 8), score.getGapBetween(e[1], e[3])); // includes 1/8 from second voice
   assertEquals(fr(3, 8), score.getGapBetween(e[2], e[4])); // includes 1/8 from second voice
   assertEquals(
       fr(5, 8).add(fr(4, 4)), score.getGapBetween(e[0], e[5])); // includes 1/8 from second voice
   assertEquals(
       fr(3, 8).add(fr(4, 4)), score.getGapBetween(e[1], e[5])); // includes 1/8 from second voice
   // test in reverse direction
   assertEquals(fr(-2, 4), score.getGapBetween(e[1], e[0]));
   assertEquals(fr(-2, 4), score.getGapBetween(e[2], e[1]));
   assertEquals(fr(-5, 8), score.getGapBetween(e[3], e[2])); // includes 1/8 from second voice
   assertEquals(fr(-23, 8), score.getGapBetween(e[5], e[0])); // includes 1/8 from second voice
   assertEquals(fr(-21, 8), score.getGapBetween(e[5], e[1])); // includes 1/8 from second voice
 }