Search in sources :

Example 1 with Wedge

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

the class WedgeStamper method stampSystem.

/**
 * Creates all wedge stampings in the given system.
 * @param openWedges  input and output parameter: voltas, which are still open from the
 *                    last system. After the method returns, it contains the voltas which
 *                    are still open after this system
 */
public List<WedgeStamping> stampSystem(SystemSpacing system, Score score, StaffStampings staffStampings, OpenWedges openWedges) {
    List<WedgeStamping> ret = alist();
    // find new wedges beginning in this staff
    for (int iStaff : range(score.getStavesCount())) {
        Staff staff = score.getStaff(iStaff);
        for (int iMeasure : system.getMeasures()) {
            Measure measure = staff.getMeasure(iMeasure);
            for (BeatE<Direction> dir : measure.getDirections()) {
                if (dir.getElement() instanceof Wedge) {
                    Wedge wedge = (Wedge) dir.getElement();
                    // if the position of the end element is known
                    if (wedge.getWedgeEnd().getMP() != null)
                        openWedges.wedges.add(new ContinuedWedge((Wedge) dir.getElement()));
                }
            }
        }
    }
    // draw wedges in the cache, and remove them if closed in this system
    for (Iterator<ContinuedWedge> itW = openWedges.wedges.iterator(); itW.hasNext(); ) {
        ContinuedWedge wedge = itW.next();
        ret.add(stamp(wedge.element, staffStampings.get(system.getSystemIndexInFrame(), wedge.element.getMP().staff)));
        if (MP.getMP(wedge.element.getWedgeEnd()).measure <= system.getEndMeasure()) {
            // wedge is closed
            itW.remove();
        }
    }
    return ret;
}
Also used : ContinuedWedge(com.xenoage.zong.musiclayout.continued.ContinuedWedge) Staff(com.xenoage.zong.core.music.Staff) Measure(com.xenoage.zong.core.music.Measure) WedgeStamping(com.xenoage.zong.musiclayout.stampings.WedgeStamping) Direction(com.xenoage.zong.core.music.direction.Direction) Wedge(com.xenoage.zong.core.music.direction.Wedge) ContinuedWedge(com.xenoage.zong.musiclayout.continued.ContinuedWedge)

Example 2 with Wedge

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

the class DynamicsFinder method getStaffDynamicStartAt.

/**
 * Returns the {@link DynamicsType} starting at the given time within the given staff (not a voice),
 * or null, if nothing starts here.
 */
@MaybeNull
private DynamicsType getStaffDynamicStartAt(int staff, Time time, DynamicValue currentDynamicValue) {
    val measure = score.getMeasure(atMeasure(staff, time.getMeasure()));
    // when there is a Wedge (possible with a Dynamic as the start volume), create
    // a gradient dynamic, when there is only a Dynamic, create a fixed dynamic
    val foundDynamic = (Dynamic) measure.getDirections().get(time.getBeat(), MusicElementType.Dynamic);
    val foundWedge = (Wedge) measure.getDirections().get(time.getBeat(), MusicElementType.Wedge);
    if (foundWedge != null) {
        // gradient
        val startDynamicValue = (foundDynamic != null ? foundDynamic.getValue() : currentDynamicValue);
        val endDynamicValue = startDynamicValue.getWedgeEndValue(foundWedge.getType());
        // can be replaced later, when end dynamic is found
        return new GradientDynamics(startDynamicValue, endDynamicValue);
    } else if (foundDynamic != null) {
        // fixed value
        return new FixedDynamics(foundDynamic.getValue());
    }
    return null;
}
Also used : lombok.val(lombok.val) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) FixedDynamics(com.xenoage.zong.io.midi.out.dynamics.type.FixedDynamics) Wedge(com.xenoage.zong.core.music.direction.Wedge) GradientDynamics(com.xenoage.zong.io.midi.out.dynamics.type.GradientDynamics) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 3 with Wedge

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

the class Base43e method getExpectedDirections.

static List<Tuple2<MP, Direction>> getExpectedDirections() {
    Wedge wedge;
    List<Tuple2<MP, Direction>> directions = alist();
    directions.add(t(atBeat(0, 0, unknown, Companion.get_0()), new Dynamic(DynamicValue.ffff)));
    directions.add(t(atBeat(0, 0, unknown, Companion.fr(3, 4)), new Dynamic(DynamicValue.p)));
    directions.add(t(atBeat(1, 0, unknown, Companion.get_0()), wedge = new Wedge(WedgeType.Crescendo)));
    directions.add(t(atBeat(1, 0, unknown, Companion.fr(2, 4)), wedge.getWedgeEnd()));
    return directions;
}
Also used : Dynamic(com.xenoage.zong.core.music.direction.Dynamic) Tuple2(com.xenoage.utils.kernel.Tuple2) Wedge(com.xenoage.zong.core.music.direction.Wedge)

Example 4 with Wedge

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

the class DynamicsFinderTest method getAdvancedScore.

/**
 * See {@link #testAdvanced()}.
 */
private Score getAdvancedScore() {
    Score score = new Score();
    Wedge w;
    new PartAdd(score, new Part("", null, 2, null), 0, null).execute();
    new MeasureAdd(score, 5).execute();
    // time signature and repeats
    new ColumnElementWrite(new TimeSignature(TimeType.Companion.getTime_4_4()), score.getColumnHeader(0), null, null).execute();
    new ColumnElementWrite(Companion.barlineForwardRepeat(Regular), score.getColumnHeader(1), null, MeasureSide.Left).execute();
    new ColumnElementWrite(Companion.barlineBackwardRepeat(Regular, 1), score.getColumnHeader(2), null, MeasureSide.Right).execute();
    // staff 0
    new MeasureElementWrite(new Dynamic(mp), score.getMeasure(atMeasure(0, 0)), Companion.get_0()).execute();
    new MeasureElementWrite(new Dynamic(pp), score.getMeasure(atMeasure(0, 2)), Companion.get_0()).execute();
    new MeasureElementWrite(new Dynamic(f), score.getMeasure(atMeasure(0, 3)), Companion.get_1$2()).execute();
    new MeasureElementWrite(w = new Wedge(Crescendo), score.getMeasure(atMeasure(0, 3)), Companion.get_3$4()).execute();
    new MeasureElementWrite(new WedgeEnd(w), score.getMeasure(atMeasure(0, 4)), Companion.get_1$4()).execute();
    new MeasureElementWrite(new Dynamic(pp), score.getMeasure(atMeasure(0, 4)), Companion.get_1$2()).execute();
    // voice 0
    val cursor = new Cursor(score, mp0, true);
    cursor.write(new Rest(Companion.get_1()));
    cursor.write(new Rest(Companion.get_1()));
    cursor.write(new Rest(Companion.get_1()));
    cursor.write(new Rest(Companion.get_1()));
    // voice 1
    cursor.setMp(atElement(0, 0, 1, 0));
    cursor.write(new Rest(Companion.get_1$2()));
    val chord = chord(Companion.pi(0, 4), Companion.get_1$2());
    chord.addDirection(new Dynamic(mf));
    cursor.write(chord);
    cursor.write(new Rest(Companion.get_1()));
    cursor.write(new Rest(Companion.get_1()));
    cursor.setMp(atElement(0, 4, 1, 0));
    cursor.write(new Rest(Companion.get_1()));
    // staff 1
    new MeasureElementWrite(new Dynamic(ff), score.getMeasure(atMeasure(1, 0)), Companion.get_0()).execute();
    new MeasureElementWrite(w = new Wedge(Diminuendo), score.getMeasure(atMeasure(1, 0)), Companion.get_0()).execute();
    new MeasureElementWrite(new WedgeEnd(w), score.getMeasure(atMeasure(1, 2)), Companion.get_0()).execute();
    new MeasureElementWrite(new Dynamic(mp), score.getMeasure(atMeasure(1, 2)), Companion.get_0()).execute();
    new MeasureElementWrite(new Dynamic(p), score.getMeasure(atMeasure(1, 3)), Companion.get_0()).execute();
    return score;
}
Also used : lombok.val(lombok.val) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) ColumnElementWrite(com.xenoage.zong.commands.core.music.ColumnElementWrite) Cursor(com.xenoage.zong.io.selection.Cursor) Wedge(com.xenoage.zong.core.music.direction.Wedge) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) Score(com.xenoage.zong.core.Score) MeasureAdd(com.xenoage.zong.commands.core.music.MeasureAdd) Rest(com.xenoage.zong.core.music.rest.Rest) Part(com.xenoage.zong.core.music.Part) PartAdd(com.xenoage.zong.commands.core.music.PartAdd) MeasureElementWrite(com.xenoage.zong.commands.core.music.MeasureElementWrite) WedgeEnd(com.xenoage.zong.core.music.direction.WedgeEnd)

Example 5 with Wedge

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

the class Context method openWedge.

/**
 * Sets the beginning of a wedge with the given number.
 * When there is still an open wedge with this number, it
 * is removed from the score.
 */
public void openWedge(int number, Wedge wedge) {
    if (false == checkNumber1to6(number))
        return;
    // remove existing open wedge
    Wedge openWedge = openElements.getOpenWedges().get(number - 1);
    if (openWedge != null)
        removeUnclosedWedge(openWedge);
    // add new wedge
    List<Wedge> openWedges = openElements.getOpenWedges();
    openWedges.set(number - 1, wedge);
}
Also used : Wedge(com.xenoage.zong.core.music.direction.Wedge)

Aggregations

Wedge (com.xenoage.zong.core.music.direction.Wedge)6 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)3 lombok.val (lombok.val)2 MaybeNull (com.xenoage.utils.annotations.MaybeNull)1 Tuple2 (com.xenoage.utils.kernel.Tuple2)1 ColumnElementWrite (com.xenoage.zong.commands.core.music.ColumnElementWrite)1 MeasureAdd (com.xenoage.zong.commands.core.music.MeasureAdd)1 MeasureElementWrite (com.xenoage.zong.commands.core.music.MeasureElementWrite)1 PartAdd (com.xenoage.zong.commands.core.music.PartAdd)1 Score (com.xenoage.zong.core.Score)1 Measure (com.xenoage.zong.core.music.Measure)1 Part (com.xenoage.zong.core.music.Part)1 Staff (com.xenoage.zong.core.music.Staff)1 Direction (com.xenoage.zong.core.music.direction.Direction)1 WedgeEnd (com.xenoage.zong.core.music.direction.WedgeEnd)1 Rest (com.xenoage.zong.core.music.rest.Rest)1 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)1 FixedDynamics (com.xenoage.zong.io.midi.out.dynamics.type.FixedDynamics)1 GradientDynamics (com.xenoage.zong.io.midi.out.dynamics.type.GradientDynamics)1 Cursor (com.xenoage.zong.io.selection.Cursor)1