Search in sources :

Example 26 with Chord

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);
}
Also used : NotesNotation(com.xenoage.zong.musiclayout.notation.chord.NotesNotation) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 27 with Chord

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);
}
Also used : NoteDisplacement(com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement) NotesNotation(com.xenoage.zong.musiclayout.notation.chord.NotesNotation) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 28 with Chord

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;
}
Also used : FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Cursor(com.xenoage.zong.io.selection.Cursor) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) Example(material.accidentals.Example) Words(com.xenoage.zong.core.music.direction.Words) Pitch(com.xenoage.zong.core.music.Pitch) FontInfo(com.xenoage.utils.font.FontInfo) Chord(com.xenoage.zong.core.music.chord.Chord)

Example 29 with Chord

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);
}
Also used : Beam(com.xenoage.zong.core.music.beam.Beam) VoiceElement(com.xenoage.zong.core.music.VoiceElement) Staff(com.xenoage.zong.core.music.Staff) Voice(com.xenoage.zong.core.music.Voice) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 30 with Chord

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));
        }
    }
}
Also used : Score(com.xenoage.zong.core.Score) MP(com.xenoage.zong.core.position.MP) Chord(com.xenoage.zong.core.music.chord.Chord) Direction(com.xenoage.zong.core.music.direction.Direction) Test(org.junit.Test)

Aggregations

Chord (com.xenoage.zong.core.music.chord.Chord)63 Test (org.junit.Test)34 MP (com.xenoage.zong.core.position.MP)16 Pitch (com.xenoage.zong.core.music.Pitch)12 Score (com.xenoage.zong.core.Score)11 Voice (com.xenoage.zong.core.music.Voice)10 NotesNotation (com.xenoage.zong.musiclayout.notation.chord.NotesNotation)10 VoiceElement (com.xenoage.zong.core.music.VoiceElement)8 Note (com.xenoage.zong.core.music.chord.Note)6 Rest (com.xenoage.zong.core.music.rest.Rest)6 ChordTest (musicxmltestsuite.tests.utils.ChordTest)6 Fraction (com.xenoage.utils.math.Fraction)5 Staff (com.xenoage.zong.core.music.Staff)4 Beam (com.xenoage.zong.core.music.beam.Beam)4 Grace (com.xenoage.zong.core.music.chord.Grace)4 StemDirection (com.xenoage.zong.core.music.chord.StemDirection)4 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)4 SlurWaypoint (com.xenoage.zong.core.music.slur.SlurWaypoint)4 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)4 NoteDisplacement (com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement)4