Search in sources :

Example 1 with Notations

use of com.xenoage.zong.musiclayout.notation.Notations in project Zong by Xenoage.

the class MeasureElementsSpacerTest method notations.

private Notations notations(Rest[] rests, Clef clef) {
    Notations ret = new Notations();
    ret.add(new ClefNotation(clef, new ElementWidth(clefWidth), 0, 1));
    return ret;
}
Also used : ElementWidth(com.xenoage.zong.musiclayout.spacing.ElementWidth) Notations(com.xenoage.zong.musiclayout.notation.Notations) ClefNotation(com.xenoage.zong.musiclayout.notation.ClefNotation)

Example 2 with Notations

use of com.xenoage.zong.musiclayout.notation.Notations in project Zong by Xenoage.

the class SingleVoiceSpacerTest method testGrace2.

/**
 * Computes a voice spacing with grace notes,
 * where the element before the grace notes has enough empty rear space
 * to take at least one of the grace notes.
 * <pre>
 * Single elements: [-r1------][g1][g2][--r4--]
 * Combined:        --r1_~g1~g2~~~r4---
 * </pre> (~: area used by two elements, _: minimal distance between elements)
 */
@Test
public void testGrace2() {
    // create voice and notations
    Voice voice = new Voice(alist((VoiceElement) r1, g1, g2, r4));
    Notations notations = new Notations();
    notations.add(new RestNotation(r1, new ElementWidth(2, 2, 7), null));
    notations.add(new ChordNotation(g1, new ElementWidth(1, 2, 1)));
    notations.add(new ChordNotation(g2, new ElementWidth(1, 2, 1)));
    notations.add(new RestNotation(r4, new ElementWidth(3, 2, 3), null));
    // compute spacing
    VoiceSpacing vs = testee.compute(voice, 400f, Companion.fr(4, 4), 5, notations, layoutSettings);
    // check spacing
    ElementSpacing[] ses = vs.elements.toArray(new ElementSpacing[0]);
    ;
    float s = layoutSettings.offsetMeasureStart;
    float d = layoutSettings.spacings.widthDistanceMin;
    assertEquals(5, ses.length);
    assertEquals(s + 2, ses[0].xIs, DELTA_FLOAT);
    assertEquals(s + 5 + d, ses[1].xIs, DELTA_FLOAT);
    assertEquals(s + 8 + d, ses[2].xIs, DELTA_FLOAT);
    assertEquals(s + 13 + d, ses[3].xIs, DELTA_FLOAT);
    assertEquals(s + 18 + d, ses[4].xIs, DELTA_FLOAT);
    // check beats
    assertEquals(Companion.fr(0, 8), ses[0].beat);
    assertEquals(Companion.fr(2, 8), ses[1].beat);
    assertEquals(Companion.fr(2, 8), ses[2].beat);
    assertEquals(Companion.fr(2, 8), ses[3].beat);
    assertEquals(Companion.fr(6, 8), ses[4].beat);
}
Also used : ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) ElementWidth(com.xenoage.zong.musiclayout.spacing.ElementWidth) ChordNotation(com.xenoage.zong.musiclayout.notation.ChordNotation) VoiceElement(com.xenoage.zong.core.music.VoiceElement) RestNotation(com.xenoage.zong.musiclayout.notation.RestNotation) Notations(com.xenoage.zong.musiclayout.notation.Notations) VoiceSpacing(com.xenoage.zong.musiclayout.spacing.VoiceSpacing) Voice(com.xenoage.zong.core.music.Voice) Test(org.junit.Test) VoiceTest(com.xenoage.zong.core.music.VoiceTest) LayoutSettingsTest(com.xenoage.zong.musiclayout.settings.LayoutSettingsTest)

Example 3 with Notations

use of com.xenoage.zong.musiclayout.notation.Notations in project Zong by Xenoage.

the class SingleVoiceSpacerTest method testSimple.

/**
 * Computes a simple voice spacing.
 * <pre>
 * Single elements: [-r1---][-r2-][-r3--][----r4--]
 * Combined:        --r1--~~r2_~-r3_~~---r4---
 * </pre> (~: area used by two elements, _: minimal distance between elements)
 */
@Test
public void testSimple() {
    // create voice and notations
    Voice voice = new Voice(alist((VoiceElement) r1, r2, r3, r4));
    Notations notations = new Notations();
    notations.add(new RestNotation(r1, new ElementWidth(2, 2, 4), null));
    notations.add(new RestNotation(r2, new ElementWidth(2, 2, 2), null));
    notations.add(new RestNotation(r3, new ElementWidth(2, 2, 3), null));
    notations.add(new RestNotation(r4, new ElementWidth(5, 2, 3), null));
    // compute spacing
    VoiceSpacing vs = testee.compute(voice, 200f, Companion.fr(4, 4), 5, notations, layoutSettings);
    // check spacing
    ElementSpacing[] ses = vs.elements.toArray(new ElementSpacing[0]);
    float s = layoutSettings.offsetMeasureStart;
    float d = layoutSettings.spacings.widthDistanceMin;
    assertEquals(5, ses.length);
    assertEquals(s + 2, ses[0].xIs, DELTA_FLOAT);
    assertEquals(s + 8, ses[1].xIs, DELTA_FLOAT);
    assertEquals(s + 12 + d, ses[2].xIs, DELTA_FLOAT);
    assertEquals(s + 19 + 2 * d, ses[3].xIs, DELTA_FLOAT);
    assertEquals(s + 24 + 2 * d, ses[4].xIs, DELTA_FLOAT);
    // check beats
    assertEquals(Companion.fr(0, 8), ses[0].beat);
    assertEquals(Companion.fr(2, 8), ses[1].beat);
    assertEquals(Companion.fr(3, 8), ses[2].beat);
    assertEquals(Companion.fr(4, 8), ses[3].beat);
    assertEquals(Companion.fr(8, 8), ses[4].beat);
}
Also used : ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) ElementWidth(com.xenoage.zong.musiclayout.spacing.ElementWidth) VoiceElement(com.xenoage.zong.core.music.VoiceElement) RestNotation(com.xenoage.zong.musiclayout.notation.RestNotation) Notations(com.xenoage.zong.musiclayout.notation.Notations) VoiceSpacing(com.xenoage.zong.musiclayout.spacing.VoiceSpacing) Voice(com.xenoage.zong.core.music.Voice) Test(org.junit.Test) VoiceTest(com.xenoage.zong.core.music.VoiceTest) LayoutSettingsTest(com.xenoage.zong.musiclayout.settings.LayoutSettingsTest)

Example 4 with Notations

use of com.xenoage.zong.musiclayout.notation.Notations in project Zong by Xenoage.

the class ScoreLayouter method createLayoutWithExceptions.

/**
 * Computes the whole layout and returns it.
 * If something fails, an exception is thrown.
 */
public ScoreLayout createLayoutWithExceptions() {
    // notations of elements
    Notations notations = notator.computeAll(context);
    // compute optimal measure column spacings
    List<ColumnSpacing> columns = columnsSpacer.compute(notations, context);
    // break columns into systems and frames
    FramesSpacing frames = framesSpacer.compute(columns, target, context, notations);
    // system stretching (horizontal)
    fillSystemsHorizontally(frames, target);
    // frame filling (vertical)
    fillFramesVertically(frames, target, context.score);
    // compute beam spacings. these are computed only now, after the horizontal
    // and vertical spacing of the score is fixed, since the beam slants depend on the
    // exact spacings
    Map<Beam, BeamSpacing> beams = beamsSpacer.compute(context.score, notations, frames);
    // create score frame layouts from the collected information
    List<ScoreFrameLayout> scoreFrameLayouts = createScoreFrameLayouts(frames, notations, context, beams);
    // create score layout
    return new ScoreLayout(context.score, scoreFrameLayouts, context.symbols, context.settings);
}
Also used : Beam(com.xenoage.zong.core.music.beam.Beam) FramesSpacing(com.xenoage.zong.musiclayout.spacing.FramesSpacing) BeamSpacing(com.xenoage.zong.musiclayout.spacing.BeamSpacing) ColumnSpacing(com.xenoage.zong.musiclayout.spacing.ColumnSpacing) Notations(com.xenoage.zong.musiclayout.notation.Notations) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout)

Example 5 with Notations

use of com.xenoage.zong.musiclayout.notation.Notations in project Zong by Xenoage.

the class Notator method computeAll.

/**
 * Computes the {@link Notation}s of all elements and returns them.
 */
public Notations computeAll(Context context) {
    context.saveMp();
    Score score = context.score;
    Notations notations = new Notations();
    // iterate over all column elements, measure elements and voice elements
    ColumnElementIterator itC = new ColumnElementIterator(score);
    for (ColumnElement e : itC) {
        // column elements: one notation for each staff
        for (int iStaff : range(context.score.getStavesCount())) {
            context.mp = itC.getMp().withStaff(iStaff);
            notations.add(compute(e, context, notations), iStaff);
        }
    }
    MeasureElementIterator itM = new MeasureElementIterator(score);
    for (MeasureElement e : itM) {
        context.mp = itM.getMp();
        notations.add(compute(e, context, notations));
    }
    VoiceElementIterator itV = new VoiceElementIterator(score);
    for (VoiceElement e : itV) {
        context.mp = itV.getMp();
        notations.add(compute(e, context, notations));
    }
    BeamIterator itB = new BeamIterator(score);
    for (Beam e : itB) {
        context.mp = itB.getMp();
        notations.add(compute(e, context, notations));
    }
    context.restoreMp();
    return notations;
}
Also used : Beam(com.xenoage.zong.core.music.beam.Beam) Score(com.xenoage.zong.core.Score) VoiceElementIterator(com.xenoage.zong.core.util.VoiceElementIterator) Notations(com.xenoage.zong.musiclayout.notation.Notations) BeamIterator(com.xenoage.zong.core.util.BeamIterator) ColumnElementIterator(com.xenoage.zong.core.util.ColumnElementIterator) MeasureElementIterator(com.xenoage.zong.core.util.MeasureElementIterator)

Aggregations

Notations (com.xenoage.zong.musiclayout.notation.Notations)7 ElementWidth (com.xenoage.zong.musiclayout.spacing.ElementWidth)5 Voice (com.xenoage.zong.core.music.Voice)4 VoiceElement (com.xenoage.zong.core.music.VoiceElement)4 VoiceTest (com.xenoage.zong.core.music.VoiceTest)4 RestNotation (com.xenoage.zong.musiclayout.notation.RestNotation)4 LayoutSettingsTest (com.xenoage.zong.musiclayout.settings.LayoutSettingsTest)4 ElementSpacing (com.xenoage.zong.musiclayout.spacing.ElementSpacing)4 VoiceSpacing (com.xenoage.zong.musiclayout.spacing.VoiceSpacing)4 Test (org.junit.Test)4 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)3 Beam (com.xenoage.zong.core.music.beam.Beam)2 Score (com.xenoage.zong.core.Score)1 BeamIterator (com.xenoage.zong.core.util.BeamIterator)1 ColumnElementIterator (com.xenoage.zong.core.util.ColumnElementIterator)1 MeasureElementIterator (com.xenoage.zong.core.util.MeasureElementIterator)1 VoiceElementIterator (com.xenoage.zong.core.util.VoiceElementIterator)1 ScoreFrameLayout (com.xenoage.zong.musiclayout.ScoreFrameLayout)1 ScoreLayout (com.xenoage.zong.musiclayout.ScoreLayout)1 ClefNotation (com.xenoage.zong.musiclayout.notation.ClefNotation)1