Search in sources :

Example 6 with Measure

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

the class Test01b method test.

@Test
public void test() {
    Pitch[] expectedPitches = getExpectedPitches();
    int iPitch = 0;
    Staff staff = getFirstStaff();
    for (int iM = 0; iM < staff.getMeasures().size(); iM++) {
        Measure measure = staff.getMeasures().get(iM);
        Voice voice = measure.getVoice(0);
        for (VoiceElement e : voice.getElements()) {
            if (e instanceof Chord) {
                // check note and pitch
                Chord chord = (Chord) e;
                assertEquals(expectedPitches[iPitch++], chord.getNotes().get(0).getPitch());
            }
        }
    }
// TODO - ignore this test, since MusicXML input file has a bug (only a single measure),
// so currently only the first measure is tested
// assertEquals("not all notes found", expectedPitches.length, iPitch);
}
Also used : VoiceElement(com.xenoage.zong.core.music.VoiceElement) Staff(com.xenoage.zong.core.music.Staff) Pitch(com.xenoage.zong.core.music.Pitch) Measure(com.xenoage.zong.core.music.Measure) Voice(com.xenoage.zong.core.music.Voice) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 7 with Measure

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

the class Test01a method test.

@ToDo("the editiorial sharp (sharp in parenthesis) in the last measure is not supported yet")
@Test
public void test() {
    int[] expectedLPs = getExpectedLPs();
    Staff staff = getFirstStaff();
    ScoreFrameLayout scoreFrameLayout = getScoreFrameLayout();
    int chordIndex = 0;
    for (int iM = 0; iM < staff.getMeasures().size(); iM++) {
        Measure measure = staff.getMeasures().get(iM);
        Voice voice = measure.getVoice(0);
        for (VoiceElement e : voice.getElements()) {
            if (e instanceof Chord) {
            // check LP
            // TODO
            }
        }
    }
}
Also used : VoiceElement(com.xenoage.zong.core.music.VoiceElement) Staff(com.xenoage.zong.core.music.Staff) Measure(com.xenoage.zong.core.music.Measure) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout) Voice(com.xenoage.zong.core.music.Voice) Chord(com.xenoage.zong.core.music.chord.Chord) ToDo(musicxmltestsuite.tests.utils.ToDo) Test(org.junit.Test)

Example 8 with Measure

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

the class Test03b method test.

@Test
public void test() {
    Measure measure = getScore().getMeasure(mp0);
    // two voices
    assertEquals(2, measure.getVoices().size());
    // check first voice
    Voice voice = measure.getVoice(0);
    assertEquals(2, voice.getElements().size());
    assertEquals(Companion.pi(0, 0, 4), ((Chord) voice.getElement(0)).getNotes().get(0).getPitch());
    assertEquals(Companion.fr(1, 4), voice.getElement(0).getDuration());
    assertEquals(Companion.pi(0, 0, 4), ((Chord) voice.getElement(1)).getNotes().get(0).getPitch());
    assertEquals(Companion.fr(1, 4), voice.getElement(1).getDuration());
    // check second voice
    // in Zong!, there is no "empty" space in voices. Instead, an invisible rest is used
    voice = measure.getVoice(1);
    assertTrue(voice.getElement(0) instanceof Rest);
    assertTrue(((Rest) voice.getElement(0)).isHidden());
    assertEquals(Companion.fr(1, 4), voice.getElement(0).getDuration());
    assertEquals(Companion.pi(5, 0, 3), ((Chord) voice.getElement(1)).getNotes().get(0).getPitch());
    assertEquals(Companion.fr(1, 4), voice.getElement(1).getDuration());
    assertEquals(Companion.pi(5, 0, 3), ((Chord) voice.getElement(2)).getNotes().get(0).getPitch());
    assertEquals(Companion.fr(1, 4), voice.getElement(2).getDuration());
}
Also used : Rest(com.xenoage.zong.core.music.rest.Rest) Measure(com.xenoage.zong.core.music.Measure) Voice(com.xenoage.zong.core.music.Voice) Test(org.junit.Test)

Example 9 with Measure

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

the class MeasureElementsSpacer method compute.

public List<ElementSpacing> compute(Context context, boolean existsLeadingSpacing, List<VoiceSpacing> voiceSpacings, Notations notations) {
    Measure measure = context.score.getMeasure(context.mp);
    ColumnHeader columnHeader = context.score.getHeader().getColumnHeader(context.mp.measure);
    return compute(measure.getClefs(), columnHeader.getKeys(), columnHeader.getTime(), existsLeadingSpacing, voiceSpacings, context.mp.staff, notations, context.settings);
}
Also used : ColumnHeader(com.xenoage.zong.core.header.ColumnHeader) Measure(com.xenoage.zong.core.music.Measure)

Example 10 with Measure

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

the class ScoreReader method readToScore.

public void readToScore(Score score, ErrorHandling errorHandling) {
    Context context = new Context(score, new ReaderSettings(errorHandling));
    // create the measures of the parts
    It<MxlPart> mxlParts = it(doc.getParts());
    for (MxlPart mxlPart : mxlParts) {
        // create measures
        execute(new MeasureAddUpTo(score, mxlPart.getMeasures().size()));
        // initialize each measure with a C clef
        Part part = score.getStavesList().getParts().get(mxlParts.getIndex());
        StavesRange stavesRange = score.getStavesList().getPartStaffIndices(part);
        for (int staff : stavesRange.getRange()) {
            execute(new MeasureElementWrite(new Clef(ClefType.Companion.getClefTreble()), score.getMeasure(MP.atMeasure(staff, 0)), Companion.get_0()));
        }
    }
    // write a 4/4 measure and C key signature in the first measure
    execute(new ColumnElementWrite(new TimeSignature(TimeType.Companion.getTime_4_4()), score.getColumnHeader(0), Companion.get_0(), null));
    execute(new ColumnElementWrite(new TraditionalKey(0), score.getColumnHeader(0), Companion.get_0(), null));
    // read the parts
    mxlParts = it(doc.getParts());
    for (MxlPart mxlPart : mxlParts) {
        // clear part-dependent context values
        context.beginNewPart(mxlParts.getIndex());
        // read the measures
        It<MxlMeasure> mxlMeasures = it(mxlPart.getMeasures());
        for (MxlMeasure mxlMeasure : mxlMeasures) {
            try {
                MeasureReader.readToContext(mxlMeasure, mxlMeasures.getIndex(), context);
            } catch (MusicReaderException ex) {
                throw new RuntimeException("Error at " + ex.getContext().toString(), ex);
            } catch (Exception ex) {
                throw new RuntimeException("Error (roughly) around " + context.toString(), ex);
            }
        }
    }
    // remove unclosed elements
    context.removeUnclosedWedges();
    // go through the whole score, and fill empty measures (that means, measures where
    // voice 0 has no single VoiceElement) with rests
    Fraction measureDuration = Companion.fr(1, 4);
    for (int iStaff = 0; iStaff < score.getStavesCount(); iStaff++) {
        Staff staff = score.getStaff(atStaff(iStaff));
        for (int iMeasure : range(staff.getMeasures())) {
            Measure measure = staff.getMeasure(iMeasure);
            TimeSignature newTime = score.getHeader().getColumnHeader(iMeasure).getTime();
            if (newTime != null) {
                // time signature has changed
                measureDuration = newTime.getType().getMeasureBeats();
            }
            if (measureDuration == null) {
                // senza misura
                // use whole rest
                measureDuration = Companion.fr(4, 4);
            }
            Voice voice0 = measure.getVoice(0);
            if (voice0.isEmpty()) {
                // TODO: "whole rests" or split. currently, also 3/4 rests are possible
                MP mp = atElement(iStaff, iMeasure, 0, 0);
                new VoiceElementWrite(score.getVoice(mp), mp, new Rest(measureDuration), null).execute();
            }
        }
    }
}
Also used : VoiceElementWrite(com.xenoage.zong.commands.core.music.VoiceElementWrite) MP.atStaff(com.xenoage.zong.core.position.MP.atStaff) Staff(com.xenoage.zong.core.music.Staff) ColumnElementWrite(com.xenoage.zong.commands.core.music.ColumnElementWrite) MxlPart(com.xenoage.zong.musicxml.types.partwise.MxlPart) Clef(com.xenoage.zong.core.music.clef.Clef) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) MxlMeasure(com.xenoage.zong.musicxml.types.partwise.MxlMeasure) MeasureAddUpTo(com.xenoage.zong.commands.core.music.MeasureAddUpTo) StavesRange(com.xenoage.zong.core.music.group.StavesRange) Rest(com.xenoage.zong.core.music.rest.Rest) MxlMeasure(com.xenoage.zong.musicxml.types.partwise.MxlMeasure) Measure(com.xenoage.zong.core.music.Measure) MP(com.xenoage.zong.core.position.MP) MusicReaderException(com.xenoage.zong.io.musicxml.in.util.MusicReaderException) Fraction(com.xenoage.utils.math.Fraction) MusicReaderException(com.xenoage.zong.io.musicxml.in.util.MusicReaderException) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) MxlPart(com.xenoage.zong.musicxml.types.partwise.MxlPart) Part(com.xenoage.zong.core.music.Part) MeasureElementWrite(com.xenoage.zong.commands.core.music.MeasureElementWrite) 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