Search in sources :

Example 6 with Voice

use of com.xenoage.zong.core.music.Voice in project Zong by Xenoage.

the class SingleVoiceSpacer method compute.

public VoiceSpacing compute(Context context, Notations notations) {
    Voice voice = context.score.getVoice(context.mp);
    float is = context.score.getInterlineSpace(context.mp);
    Fraction measureBeats = context.score.getMeasureBeats(context.mp.measure);
    int staffLinesCount = context.score.getStaff(context.mp).getLinesCount();
    return compute(voice, is, measureBeats, staffLinesCount, notations, context.settings);
}
Also used : Fraction(com.xenoage.utils.math.Fraction) Voice(com.xenoage.zong.core.music.Voice)

Example 7 with Voice

use of com.xenoage.zong.core.music.Voice in project Zong by Xenoage.

the class Utils method checkGraceChords.

public static void checkGraceChords(Staff staff, Chord[] expectedChords, boolean skipRests) {
    int iChord = 0;
    for (int iM = 0; iM < staff.getMeasures().size(); iM++) {
        Voice voice = staff.getMeasure(iM).getVoice(0);
        for (VoiceElement e : voice.getElements()) {
            if (e instanceof Rest && skipRests)
                continue;
            // check duration, type and notes
            Chord chord = (Chord) e;
            Chord expectedChord = expectedChords[iChord];
            assertEquals("chord " + iChord, expectedChord.getDuration(), chord.getDuration());
            assertEquals("chord " + iChord, expectedChord.getGrace(), chord.getGrace());
            assertEquals("chord " + iChord, expectedChord.getNotes(), chord.getNotes());
            iChord++;
        }
    }
    assertEquals("not all chords found", expectedChords.length, iChord);
}
Also used : Rest(com.xenoage.zong.core.music.rest.Rest) VoiceElement(com.xenoage.zong.core.music.VoiceElement) Voice(com.xenoage.zong.core.music.Voice) Chord(com.xenoage.zong.core.music.chord.Chord) SlurWaypoint(com.xenoage.zong.core.music.slur.SlurWaypoint)

Example 8 with Voice

use of com.xenoage.zong.core.music.Voice in project Zong by Xenoage.

the class VoiceElementWriteTest method testTimeAware.

/**
 * Obey the time signature. Fail is written element is too long.
 */
@Test
public void testTimeAware() {
    Score score = ScoreFactory.create1Staff4Measures();
    score.getHeader().getColumnHeaders().get(1).setTime(new TimeSignature(TimeType.Companion.getTime_3_4()));
    // create options
    VoiceElementWrite.Options options = new VoiceElementWrite.Options();
    options.checkTimeSignature = true;
    // measure 0: senza misura: write 100 1/4 chords
    Voice voice = score.getVoice(MP.atVoice(0, 0, 0));
    for (int i : range(100)) new VoiceElementWrite(voice, atElement(0, 0, 0, i), new Rest(Companion.fr(1, 4)), options).execute();
    // measure 2: must work for 3/4, then fail
    for (int i : range(3)) new VoiceElementWrite(voice, atElement(0, 2, 0, i), new Rest(Companion.fr(1, 4)), options).execute();
    try {
        new VoiceElementWrite(voice, atElement(0, 2, 0, 3), new Rest(Companion.fr(1, 4)), options).execute();
        fail();
    } catch (MeasureFullException ex) {
    }
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) MeasureFullException(com.xenoage.zong.utils.exceptions.MeasureFullException) Voice(com.xenoage.zong.core.music.Voice) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) Test(org.junit.Test)

Example 9 with Voice

use of com.xenoage.zong.core.music.Voice in project Zong by Xenoage.

the class VoiceElementWriteTest method createTestScoreEighths.

/**
 * Creates a score with a single staff, a single measure,
 * two voices with each 8 quarter notes which are beamed.
 */
private Score createTestScoreEighths() {
    Score score = ScoreFactory.create1Staff();
    new VoiceAdd(score.getMeasure(atMeasure(0, 0)), 1).execute();
    for (int iVoice : range(2)) {
        Voice voice = score.getVoice(atVoice(0, 0, iVoice));
        List<Chord> beamChords = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            Chord chord = new Chord(new Note(Companion.pi(0, 0, 4)), Companion.fr(1, 8));
            // add elements by hand, since the corresonding command is tested itself in this class
            chord.setParent(voice);
            voice.getElements().add(chord);
            beamChords.add(chord);
        }
        // create beam
        Companion.beamFromChords(beamChords);
    }
    // ensure that assert method works correctly. if not, fail now
    assertTestScoreEighthsOriginalState(score);
    return score;
}
Also used : Score(com.xenoage.zong.core.Score) Note(com.xenoage.zong.core.music.chord.Note) ArrayList(java.util.ArrayList) Voice(com.xenoage.zong.core.music.Voice) Chord(com.xenoage.zong.core.music.chord.Chord)

Example 10 with Voice

use of com.xenoage.zong.core.music.Voice in project Zong by Xenoage.

the class VoiceElementWriteTest method testOverwrite2.

/**
 * Write<pre>
 *         xxxxxxxx
 * into  aabbccddeeffgghh
 *  =>   aaxxxxxxxxffgghh</pre>
 */
@Test
public void testOverwrite2() {
    Score score = createTestScoreEighths();
    // in voice 1, write a half rest at 1/8
    MP mp = atElement(0, 0, 1, 1);
    Voice voice = score.getVoice(mp);
    VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, new Rest(Companion.fr(1, 2)), null);
    cmd.execute();
    // now, there must be the durations 1/8, 1/2, 1/8, 1/8, 1/8 in voice 1
    assertEquals(5, voice.getElements().size());
    assertEquals(Companion.fr(1, 8), getDur(voice, 0));
    assertEquals(Companion.fr(1, 2), getDur(voice, 1));
    assertEquals(Companion.fr(1, 8), getDur(voice, 2));
    assertEquals(Companion.fr(1, 8), getDur(voice, 3));
    assertEquals(Companion.fr(1, 8), getDur(voice, 4));
    // test undo
    cmd.undo();
    assertTestScoreEighthsOriginalState(score);
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) MP(com.xenoage.zong.core.position.MP) Voice(com.xenoage.zong.core.music.Voice) Test(org.junit.Test)

Aggregations

Voice (com.xenoage.zong.core.music.Voice)39 Test (org.junit.Test)25 Rest (com.xenoage.zong.core.music.rest.Rest)16 Score (com.xenoage.zong.core.Score)15 MP (com.xenoage.zong.core.position.MP)14 VoiceElement (com.xenoage.zong.core.music.VoiceElement)12 Chord (com.xenoage.zong.core.music.chord.Chord)10 Measure (com.xenoage.zong.core.music.Measure)8 VoiceSpacing (com.xenoage.zong.musiclayout.spacing.VoiceSpacing)7 Staff (com.xenoage.zong.core.music.Staff)6 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)6 ElementSpacing (com.xenoage.zong.musiclayout.spacing.ElementSpacing)5 Fraction (com.xenoage.utils.math.Fraction)4 VoiceTest (com.xenoage.zong.core.music.VoiceTest)4 Notations (com.xenoage.zong.musiclayout.notation.Notations)4 RestNotation (com.xenoage.zong.musiclayout.notation.RestNotation)4 LayoutSettingsTest (com.xenoage.zong.musiclayout.settings.LayoutSettingsTest)4 ElementWidth (com.xenoage.zong.musiclayout.spacing.ElementWidth)4 MP.atVoice (com.xenoage.zong.core.position.MP.atVoice)3 BeatOffset (com.xenoage.zong.musiclayout.spacing.BeatOffset)3