Search in sources :

Example 26 with MP

use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.

the class ColumnSpacing method getElement.

/**
 * Convenience method to get the {@link ElementSpacing} of the given
 * {@link VoiceElement} {@link Notation} in this column.
 */
public ElementSpacing getElement(Notation notation) {
    MP mp = notation.getMp();
    VoiceSpacing voice = getVoice(mp.getStaff(), mp.getVoice());
    return voice.getElement((VoiceElement) notation.getElement());
}
Also used : MP(com.xenoage.zong.core.position.MP)

Example 27 with MP

use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.

the class StemDirector method compute.

/**
 * Computes the {@link StemDirection} of the given chord (and maybe connected
 * ones) and returns them. The chord must be part of a score.
 */
public Map<Chord, StemDirection> compute(Chord chord) {
    Map<Chord, StemDirection> ret = map();
    Beam beam = chord.getBeam();
    Score score = chord.getScore();
    if (beam != null) {
        // compute stem directions for all chords of the beam
        StemDirection[] beamedStems = beamedStemDirector.compute(beam, score);
        for (int iChord : range(beam.size())) ret.put(beam.getChord(iChord), beamedStems[iChord]);
    } else {
        // compute stem direction for single chord
        MP mp = MP.getMP(chord);
        StemDirection stem = singleStemDirector.compute(chord, score.getMusicContext(mp, BeforeOrAt, Before));
        ret.put(chord, stem);
    }
    // but it was bad and outdated, so we removed it.
    return ret;
}
Also used : Beam(com.xenoage.zong.core.music.beam.Beam) Score(com.xenoage.zong.core.Score) MP(com.xenoage.zong.core.position.MP) Chord(com.xenoage.zong.core.music.chord.Chord) StemDirection(com.xenoage.zong.core.music.chord.StemDirection)

Example 28 with MP

use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.

the class BeamsSpacer method compute.

public Map<Beam, BeamSpacing> compute(Score score, Notations notations, FramesSpacing frames) {
    Map<Beam, BeamSpacing> ret = map();
    BeamIterator itB = new BeamIterator(score);
    for (Beam beam : itB) {
        MP mp = itB.getMp();
        int staffLinesCount = score.getStaff(mp).getLinesCount();
        val frame = frames.getFrame(mp.measure);
        val system = frame.getSystem(mp.measure);
        val beamNotation = (BeamNotation) notations.get(beam);
        ret.put(beam, beamSpacer.compute(beamNotation, system, score));
    }
    return ret;
}
Also used : Beam(com.xenoage.zong.core.music.beam.Beam) lombok.val(lombok.val) BeamSpacing(com.xenoage.zong.musiclayout.spacing.BeamSpacing) MP(com.xenoage.zong.core.position.MP) BeamIterator(com.xenoage.zong.core.util.BeamIterator) BeamNotation(com.xenoage.zong.musiclayout.notation.BeamNotation)

Example 29 with MP

use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.

the class OneMeasureOneStaff method compute.

@Override
public StemDirection[] compute(Beam beam, Score score) {
    int staffLinesCount = getStaffLinesCount(beam.getChord(0), score);
    ChordLps[] chordsLps = new ChordLps[beam.size()];
    for (int iChord : range(chordsLps)) {
        Chord chord = beam.getChord(iChord);
        MP mp = MP.getMP(chord);
        MusicContext mc = score.getMusicContext(mp, BeforeOrAt, Before);
        chordsLps[iChord] = new ChordLps(chord, mc);
    }
    return compute(chordsLps, staffLinesCount);
}
Also used : MP(com.xenoage.zong.core.position.MP) ChordLps(com.xenoage.zong.musiclayout.notation.chord.ChordLps) Chord(com.xenoage.zong.core.music.chord.Chord) MusicContext(com.xenoage.zong.core.music.MusicContext)

Example 30 with MP

use of com.xenoage.zong.core.position.MP 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

MP (com.xenoage.zong.core.position.MP)46 Test (org.junit.Test)30 Score (com.xenoage.zong.core.Score)19 Chord (com.xenoage.zong.core.music.chord.Chord)16 Voice (com.xenoage.zong.core.music.Voice)14 Rest (com.xenoage.zong.core.music.rest.Rest)11 ChordTest (musicxmltestsuite.tests.utils.ChordTest)6 Pitch (com.xenoage.zong.core.music.Pitch)4 Measure (com.xenoage.zong.core.music.Measure)3 Direction (com.xenoage.zong.core.music.direction.Direction)3 MP.atVoice (com.xenoage.zong.core.position.MP.atVoice)3 VoiceTest.assertEqualsVoice (musicxmltestsuite.tests.utils.VoiceTest.assertEqualsVoice)3 MeasureElementWrite (com.xenoage.zong.commands.core.music.MeasureElementWrite)2 VoiceElementWrite (com.xenoage.zong.commands.core.music.VoiceElementWrite)2 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)2 Staff (com.xenoage.zong.core.music.Staff)2 Beam (com.xenoage.zong.core.music.beam.Beam)2 Tempo (com.xenoage.zong.core.music.direction.Tempo)2 Position (com.xenoage.zong.core.music.format.Position)2 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)2