Search in sources :

Example 1 with SystemSpacing

use of com.xenoage.zong.musiclayout.spacing.SystemSpacing in project Zong by Xenoage.

the class StretchMeasuresTest method createSystemWith1Measure.

/**
 * Creates and returns a simple {@link SystemSpacing} with only one
 * measure with a clef and two notes, using the given parameters.
 * @param leadingWidth  width of the leading spacing in mm
 * @param offsetBeat0   offset of beat 1/4 in mm
 * @param offsetBeat1   offset of beat 3/4 in mm
 * @param offsetBeat2   width of the voice spacing in mm
 */
public static SystemSpacing createSystemWith1Measure(float leadingWidth, float offsetBeat0, float offsetBeat1, float offsetBeat2) {
    Chord chord1 = chord(Companion.pi(0, 0, 4), Companion.fr(2, 4));
    Chord chord2 = chord(Companion.pi(1, 0, 4), Companion.fr(2, 4));
    Voice voice = new Voice(alist(chord1, chord2));
    List<BeatOffset> beatOffsets = alist(new BeatOffset(Companion.fr(1, 4), offsetBeat0), new BeatOffset(Companion.fr(3, 4), offsetBeat1), new BeatOffset(Companion.fr(5, 4), offsetBeat2));
    float is = 1;
    List<VoiceSpacing> voiceSpacings = alist(new VoiceSpacing(voice, is, alist(new ChordSpacing(new ChordNotation(chord1), beatOffsets.get(0).getBeat(), beatOffsets.get(0).getOffsetMm()), new ChordSpacing(new ChordNotation(chord2), beatOffsets.get(1).getBeat(), beatOffsets.get(1).getOffsetMm()))));
    MeasureSpacing measureSpacing = new MeasureSpacing(atMeasure(0, 0), is, voiceSpacings, empty, LeadingSpacingMock.createGClefSpacing(leadingWidth));
    List<MeasureSpacing> measureSpacings = alist(measureSpacing);
    ColumnSpacing mcs = new ColumnSpacing(-1, measureSpacings, beatOffsets, alist(new BeatOffset(Companion.fr(0, 4), 0), new BeatOffset(Companion.fr(6, 4), offsetBeat2)));
    SystemSpacing system = new SystemSpacing(ilist(mcs), 0, 0, leadingWidth + offsetBeat2, null, 0);
    return system;
}
Also used : ChordNotation(com.xenoage.zong.musiclayout.notation.ChordNotation) ColumnSpacing(com.xenoage.zong.musiclayout.spacing.ColumnSpacing) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing) ChordSpacing(com.xenoage.zong.musiclayout.spacing.ChordSpacing) MeasureSpacing(com.xenoage.zong.musiclayout.spacing.MeasureSpacing) BeatOffset(com.xenoage.zong.musiclayout.spacing.BeatOffset) VoiceSpacing(com.xenoage.zong.musiclayout.spacing.VoiceSpacing) ChordFactory.graceChord(com.xenoage.zong.core.music.chord.ChordFactory.graceChord) Chord(com.xenoage.zong.core.music.chord.Chord) Voice(com.xenoage.zong.core.music.Voice)

Example 2 with SystemSpacing

use of com.xenoage.zong.musiclayout.spacing.SystemSpacing in project Zong by Xenoage.

the class StretchMeasuresTest method computeSystemArrangementTestGrace.

/**
 * Checking if the elements are stretched correctly in a simple system
 * where there are grace notes. The space between grace notes and their following
 * full chord may not be stretched.
 */
@Test
public void computeSystemArrangementTestGrace() {
    // create an easy system for testing
    float offsetChord1 = 3;
    float offsetChord2 = 12;
    float offsetMeasureEnd = 16;
    float graceDistance = 2;
    SystemSpacing system = createSystemWith1MeasureGrace(offsetChord1, offsetChord2, offsetMeasureEnd, graceDistance);
    // stretch the system
    float newWidth = 28;
    testee.compute(system, newWidth);
    // compare the result
    ColumnSpacing newCol = system.columns.get(0);
    float stretch = (newWidth - +newCol.getLeadingWidthMm()) / offsetMeasureEnd;
    // beat offsets
    assertEquals(offsetChord1 * stretch, newCol.getBeatOffsets().get(0).getOffsetMm(), df);
    assertEquals(offsetChord2 * stretch, newCol.getBeatOffsets().get(1).getOffsetMm(), df);
    // element spacings
    VoiceSpacing newVoice = newCol.measures.get(0).voices.get(0);
    assertEquals(offsetChord1 * stretch, newVoice.elements.get(0).xIs, df);
    assertEquals(offsetChord2 * stretch - 2 * graceDistance, newVoice.elements.get(1).xIs, df);
    assertEquals(offsetChord2 * stretch - 1 * graceDistance, newVoice.elements.get(2).xIs, df);
    assertEquals(offsetChord2 * stretch, newVoice.elements.get(3).xIs, df);
}
Also used : ColumnSpacing(com.xenoage.zong.musiclayout.spacing.ColumnSpacing) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing) VoiceSpacing(com.xenoage.zong.musiclayout.spacing.VoiceSpacing) Test(org.junit.Test)

Example 3 with SystemSpacing

use of com.xenoage.zong.musiclayout.spacing.SystemSpacing in project Zong by Xenoage.

the class StretchMeasuresTest method computeTest.

@Test
public void computeTest() {
    // create an easy system for testing
    float leadingWidth = 4;
    float offsetBeat1 = 3;
    float offsetBeat2 = 7;
    float offsetBeat3 = 12;
    SystemSpacing system = createSystemWith1Measure(leadingWidth, offsetBeat1, offsetBeat2, offsetBeat3);
    // stretch the system
    float newWidth = 20;
    testee.compute(system, newWidth);
    // compare the result
    // since the leading spacing (4 spaces) is not scaled, the
    // remaining 12 spaces of the voices width have to be scaled
    float stretch = (newWidth - leadingWidth) / offsetBeat3;
    ColumnSpacing newCol = system.columns.get(0);
    // beat offsets
    assertEquals(offsetBeat1 * stretch, newCol.getBeatOffsets().get(0).getOffsetMm(), df);
    assertEquals(offsetBeat2 * stretch, newCol.getBeatOffsets().get(1).getOffsetMm(), df);
    // element spacings
    VoiceSpacing newVoice = newCol.measures.get(0).voices.get(0);
    assertEquals(offsetBeat1 * stretch, newVoice.elements.get(0).xIs, df);
    assertEquals(offsetBeat2 * stretch, newVoice.elements.get(1).xIs, df);
}
Also used : ColumnSpacing(com.xenoage.zong.musiclayout.spacing.ColumnSpacing) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing) VoiceSpacing(com.xenoage.zong.musiclayout.spacing.VoiceSpacing) Test(org.junit.Test)

Example 4 with SystemSpacing

use of com.xenoage.zong.musiclayout.spacing.SystemSpacing in project Zong by Xenoage.

the class EmptySystems method createEmptySystem.

/**
 * Creates an additional system for the given {@link Score} with
 * the given width and y-offset in mm and returns it.
 */
private SystemSpacing createEmptySystem(Score score, float width, float offsetY) {
    // compute staves spacing
    StavesSpacing stavesSpacing = StavesSpacer.stavesSpacer.compute(score, 0);
    // create and returns system
    SystemLayout defaultSystemLayout = score.getFormat().getSystemLayout();
    return new SystemSpacing(CollectionUtils.<ColumnSpacing>alist(), defaultSystemLayout.getMarginLeft(), defaultSystemLayout.getMarginRight(), width, stavesSpacing, offsetY);
}
Also used : StavesSpacing(com.xenoage.zong.musiclayout.spacing.StavesSpacing) SystemLayout(com.xenoage.zong.core.format.SystemLayout) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing)

Example 5 with SystemSpacing

use of com.xenoage.zong.musiclayout.spacing.SystemSpacing in project Zong by Xenoage.

the class ScoreLayouter method fillSystemsHorizontally.

/**
 * Fills the systems horizontally according to the {@link SystemFiller}
 * of the frame.
 */
void fillSystemsHorizontally(FramesSpacing frames, Target target) {
    for (int iFrame : range(frames.size())) {
        FrameSpacing frameArr = frames.get(iFrame);
        SystemFiller hFill = target.getArea(iFrame).hFill;
        // apply strategy
        for (SystemSpacing oldSystemArr : frameArr.getSystems()) {
            float usableWidth = frameArr.getUsableSizeMm().width - oldSystemArr.getMarginLeftMm() - oldSystemArr.getMarginRightMm();
            hFill.compute(oldSystemArr, usableWidth);
        }
    }
}
Also used : SystemFiller(com.xenoage.zong.musiclayout.spacer.system.fill.SystemFiller) FrameSpacing(com.xenoage.zong.musiclayout.spacing.FrameSpacing) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing)

Aggregations

SystemSpacing (com.xenoage.zong.musiclayout.spacing.SystemSpacing)15 ColumnSpacing (com.xenoage.zong.musiclayout.spacing.ColumnSpacing)5 VoiceSpacing (com.xenoage.zong.musiclayout.spacing.VoiceSpacing)4 Size2f (com.xenoage.utils.math.geom.Size2f)3 Score (com.xenoage.zong.core.Score)3 BeatOffset (com.xenoage.zong.musiclayout.spacing.BeatOffset)3 FrameSpacing (com.xenoage.zong.musiclayout.spacing.FrameSpacing)3 StavesSpacing (com.xenoage.zong.musiclayout.spacing.StavesSpacing)3 Test (org.junit.Test)3 Point2f (com.xenoage.utils.math.geom.Point2f)2 ScoreFormat (com.xenoage.zong.core.format.ScoreFormat)2 SystemLayout (com.xenoage.zong.core.format.SystemLayout)2 ScoreHeader (com.xenoage.zong.core.header.ScoreHeader)2 Voice (com.xenoage.zong.core.music.Voice)2 Chord (com.xenoage.zong.core.music.chord.Chord)2 ChordFactory.graceChord (com.xenoage.zong.core.music.chord.ChordFactory.graceChord)2 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)2 ChordSpacing (com.xenoage.zong.musiclayout.spacing.ChordSpacing)2 MeasureSpacing (com.xenoage.zong.musiclayout.spacing.MeasureSpacing)2 JsonArray (com.google.gson.JsonArray)1