Search in sources :

Example 11 with Measure

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

the class VoicesBeatOffsetterTest method createVoiceSpacings.

/**
 * Create {@link VoiceSpacing}s for the first measure column
 * of the given {@link Score}.
 */
private LinkedList<VoiceSpacing> createVoiceSpacings(Score score) {
    LinkedList<VoiceSpacing> ret = new LinkedList<>();
    for (int iStaff : range(0, score.getStavesCount() - 1)) {
        Measure measure = score.getMeasure(atMeasure(iStaff, 0));
        for (Voice voice : measure.getVoices()) {
            Fraction beat = Companion.fr(0);
            ArrayList<ElementSpacing> se = alist();
            float offset = 0;
            for (VoiceElement e : voice.getElements()) {
                // compute width
                float width = 0;
                if (e.getDuration().equals(Companion.get_0()))
                    width = width_grace;
                else if (e.getDuration().equals(dur_1_8))
                    width = width_1_8;
                else if (e.getDuration().equals(dur_1_6))
                    width = width_1_6;
                else if (e.getDuration().equals(dur_1_4))
                    width = width_1_4;
                else if (e.getDuration().equals(dur_3_8))
                    width = width_3_8;
                else if (e.getDuration().equals(dur_1_2))
                    width = width_1_2;
                else if (e.getDuration().equals(dur_1_1))
                    width = width_1_1;
                // create spacing element with offset
                se.add(new ChordSpacing(new ChordNotation((Chord) e), beat, offset));
                beat = beat.add(e.getDuration());
                offset += width;
            }
            se.add(new BorderSpacing(beat, offset));
            ret.add(new VoiceSpacing(voice, score.getFormat().getInterlineSpace(), se));
        }
    }
    return ret;
}
Also used : ChordNotation(com.xenoage.zong.musiclayout.notation.ChordNotation) Fraction(com.xenoage.utils.math.Fraction) LinkedList(java.util.LinkedList) VoiceElement(com.xenoage.zong.core.music.VoiceElement) Measure(com.xenoage.zong.core.music.Measure) Voice(com.xenoage.zong.core.music.Voice)

Example 12 with Measure

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

the class Test46e method testVoiceElements.

private void testVoiceElements() {
    for (int iMeasure : range(2)) {
        Measure expectedMeasure = expectedStaff.getMeasure(iMeasure);
        Measure measure = score.getMeasure(atMeasure(0, iMeasure));
        int expectedVoicesCount = expectedMeasure.getVoices().size();
        assertEquals(expectedVoicesCount, measure.getVoices().size());
        for (int iVoice : range(expectedVoicesCount)) {
            MP mpVoice = atVoice(0, iMeasure, iVoice);
            Voice expectedVoice = expectedStaff.getVoice(mpVoice);
            Voice voice = score.getVoice(mpVoice);
            assertEqualsVoice(expectedVoice, voice, mpVoice);
        }
    }
}
Also used : MP(com.xenoage.zong.core.position.MP) MP.atMeasure(com.xenoage.zong.core.position.MP.atMeasure) Measure(com.xenoage.zong.core.music.Measure) MP.atVoice(com.xenoage.zong.core.position.MP.atVoice) VoiceTest.assertEqualsVoice(musicxmltestsuite.tests.utils.VoiceTest.assertEqualsVoice) Voice(com.xenoage.zong.core.music.Voice)

Aggregations

Measure (com.xenoage.zong.core.music.Measure)12 Voice (com.xenoage.zong.core.music.Voice)8 Staff (com.xenoage.zong.core.music.Staff)5 Test (org.junit.Test)5 VoiceElement (com.xenoage.zong.core.music.VoiceElement)4 Fraction (com.xenoage.utils.math.Fraction)3 Chord (com.xenoage.zong.core.music.chord.Chord)3 MP (com.xenoage.zong.core.position.MP)3 MP.atMeasure (com.xenoage.zong.core.position.MP.atMeasure)3 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)2 Part (com.xenoage.zong.core.music.Part)2 Pitch (com.xenoage.zong.core.music.Pitch)2 Rest (com.xenoage.zong.core.music.rest.Rest)2 ToDo (musicxmltestsuite.tests.utils.ToDo)2 ColumnElementWrite (com.xenoage.zong.commands.core.music.ColumnElementWrite)1 MeasureAddUpTo (com.xenoage.zong.commands.core.music.MeasureAddUpTo)1 MeasureElementWrite (com.xenoage.zong.commands.core.music.MeasureElementWrite)1 VoiceElementWrite (com.xenoage.zong.commands.core.music.VoiceElementWrite)1 Score (com.xenoage.zong.core.Score)1 PitchedInstrument (com.xenoage.zong.core.instrument.PitchedInstrument)1