@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)); }
@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)); }
/** * 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); }
@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))); }
@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 }
/** * Creates a score with a single staff, two measures with each two voices, with key changes and * chords with accidentals. */ private Score createTestScoreAccidentals() { // create two measures with two voices: // measure 0 | measure 1 // beat: 0 1 | 0 1 // key: Gmaj | *Fmaj Cmaj // voice 0: C4 | F#4 Bb4 Bb4 // voice 1: Fnat4 | Bb4 F#4 F#4 // (*) is a private key (not in measure column) Score score = ScoreFactory.create1Staff(); new MeasureAdd(score, 1).execute(); new VoiceAdd(score.getMeasure(atMeasure(0, 0)), 1).execute(); new VoiceAdd(score.getMeasure(atMeasure(0, 1)), 1).execute(); // keys new ColumnElementWrite( new TraditionalKey(1, Mode.Major), score.getColumnHeader(0), fr(0, 4), null) .execute(); new MeasureElementWrite( new TraditionalKey(-1, Mode.Major), score.getMeasure(atMeasure(0, 1)), fr(0, 4)) .execute(); new ColumnElementWrite( new TraditionalKey(0, Mode.Major), score.getColumnHeader(1), fr(1, 4), null) .execute(); // measure 0, voice 0 Voice voice = score.getVoice(MP.atVoice(0, 0, 0)); voice.addElement(chord(pi(0, 0, 4), fr(2, 4))); // measure 1, voice 0 voice = score.getVoice(MP.atVoice(0, 1, 0)); voice.addElement(chord(pi(3, 1, 4), fr(1, 4))); voice.addElement(chord(pi(6, -1, 4), fr(1, 8))); voice.addElement(chord(pi(6, -1, 4), fr(1, 8))); // measure 0, voice 1 voice = score.getVoice(MP.atVoice(0, 0, 1)); voice.addElement(chord(pi(3, 0, 4), fr(2, 4))); // measure 1, voice 1 voice = score.getVoice(MP.atVoice(0, 1, 1)); voice.addElement(chord(pi(6, -1, 4), fr(1, 4))); voice.addElement(chord(pi(3, 1, 4), fr(1, 8))); voice.addElement(chord(pi(3, 1, 4), fr(1, 8))); return score; }