use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.
the class NotesNotatorTest method testChordC4E4G4.
/**
* Tests a C4-E4-G4, 3/4. Stem: right, up. Width: 1x half + 1x dot.
*/
@Test
public void testChordC4E4G4() {
Chord chord = chord(new Pitch[] { Companion.pi(0, 0, 4), Companion.pi(2, 0, 4), Companion.pi(4, 0, 4) }, Companion.fr(3, 4));
NotesNotation notes = testee.compute(chord, StemDirection.Up, cw, context);
assertEquals(n, notes.stemOffsetIs, Df);
assertEquals(n + dg, notes.widthIs, Df);
assertEquals(0, notes.getNote(0).xIs, Df);
assertEquals(NoteSuspension.None, notes.getNote(0).suspension);
assertEquals(0, notes.getNote(1).xIs, Df);
assertEquals(NoteSuspension.None, notes.getNote(1).suspension);
assertEquals(0, notes.getNote(2).xIs, Df);
assertEquals(NoteSuspension.None, notes.getNote(2).suspension);
}
use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.
the class NotesNotatorTest method testChordC5D5.
/**
* Tests a C5/D5, 1/4. Stem: left, down. Width: 1x quarter.
*/
@Test
public void testChordC5D5() {
Chord chord = chord(new Pitch[] { Companion.pi(0, 0, 5), Companion.pi(1, 0, 5) }, Companion.fr(1, 4));
NotesNotation notes = testee.compute(chord, StemDirection.Down, cw, context);
assertEquals(n, notes.stemOffsetIs, Df);
assertEquals(2 * n, notes.widthIs, Df);
NoteDisplacement note = notes.getNote(0);
assertEquals(5, note.lp);
assertEquals(0, note.xIs, Df);
assertEquals(NoteSuspension.Left, note.suspension);
note = notes.getNote(1);
assertEquals(6, note.lp);
assertEquals(n, note.xIs, Df);
assertEquals(NoteSuspension.None, note.suspension);
}
use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.
the class StrategyTest method getScore.
@Override
public Score getScore() {
// collect test material
List<Example> examples = getAllExamples();
// text style
FormattedTextStyle style = Companion.getDefaultStyle().withFont(new FontInfo("Arial", 6f, FontStyle.normal));
// one chord in each measure
Score score = ScoreFactory.create1Staff();
Cursor cursor = new Cursor(score, mp0, true);
cursor.write(new TimeSignature(TimeType.Companion.getTime_3_4()));
for (int i : range(examples)) {
Example example = examples.get(i);
cursor.setMp(atElement(0, i, 0, 0));
// write key
int fifths = ((TraditionalKey) example.getContext().getKey()).getFifths();
cursor.write((ColumnElement) new TraditionalKey(fifths));
// write example name (each 2nd example one line down for better reading)
String text = (i % 2 == 1 ? "\n" : "") + example.getName();
cursor.write((MeasureElement) new Words(styleText(text, style)));
// write chord with all accidentals from context (or a rest)
Map<Pitch, Integer> accs = example.getContext().getAccidentals();
if (accs.size() > 0) {
Pitch[] pitches = new Pitch[accs.size()];
int accIndex = 0;
for (Pitch acc : accs.keySet()) {
pitches[accIndex] = Companion.pi(acc.getStep(), accs.get(acc), acc.getOctave());
accIndex++;
}
Chord accsChords = ChordFactory.chord(pitches, Companion.get_1$4());
cursor.write(accsChords);
} else {
cursor.write(new Rest(Companion.get_1$4()));
}
// write a rest
cursor.write(new Rest(Companion.get_1$4()));
// write the tested chord
Chord testedChord = ChordFactory.chord(example.getPitches().toArray(new Pitch[0]), Companion.get_1$4());
cursor.write(testedChord);
}
return score;
}
use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.
the class Test24a method testBeams.
@Test
public void testBeams() {
Staff staff = getFirstStaff();
int iChord = 0;
Beam currentBeam = null;
for (int iM = 0; iM < staff.getMeasures().size(); iM++) {
Voice voice = staff.getMeasure(iM).getVoice(0);
for (VoiceElement e : voice.getElements()) {
Chord expectedChord = expectedChords[iChord];
// beams between chord 2 and 3 and between 11 and 12
if (iChord == 2 || iChord == 11) {
assertNotNull("chord " + iChord + " unbeamed", expectedChord.getBeam());
assertEquals("chord " + iChord, WaypointPosition.Start, expectedChord.getBeam().getWaypointPosition(expectedChord));
currentBeam = expectedChord.getBeam();
} else if (iChord == 3 || iChord == 12) {
assertNotNull("chord " + iChord + " unbeamed", expectedChord.getBeam());
assertEquals("wrong beam", currentBeam, expectedChord.getBeam());
assertEquals("chord " + iChord, WaypointPosition.Stop, expectedChord.getBeam().getWaypointPosition(expectedChord));
currentBeam = null;
} else {
assertNull("chord " + iChord + " beamed", expectedChord.getBeam());
}
iChord++;
}
}
assertEquals("not all chords found", expectedChords.length, iChord);
}
use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.
the class Test32a method test.
@Test
public void test() {
Score score = getScore();
for (Tuple2<MP, ?> item : expectedAnnotations) {
MP mp = item.get1();
List<?> annotations = null;
Chord chord = (Chord) score.getVoice(mp).getElementAt(mp.beat);
assertNotNull("" + mp, chord);
// in this test, the chords contain either directions or annotations
if (false == chord.getDirections().isEmpty())
annotations = chord.getDirections();
else
annotations = chord.getAnnotations();
// check correct classes
if (item.get2() instanceof Direction) {
// single direction at this beat expected
assertEquals("" + mp, 1, annotations.size());
assertEquals("" + mp, item.get2().getClass(), annotations.get(0).getClass());
} else if (item.get2() instanceof List<?>) {
// list of annotations
// we ignore the order here (MusicXML does not contain a order)
assertEquals("" + mp, set((List<?>) item.get2()), set(annotations));
} else {
// single annotation
assertEquals("" + mp, 1, annotations.size());
assertEquals("" + mp, item.get2(), annotations.get(0));
}
}
}
Aggregations