Search in sources :

Example 6 with Dynamic

use of com.xenoage.zong.core.music.direction.Dynamic 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 7 with Dynamic

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

the class DynamicsFinder method getWedgeEndAt.

/**
 * Checks, if there is a {@link WedgeEnd} at the given time within the given staff (not a voice).
 * If yes, the given open wedge is closed and returned.
 */
@MaybeNull
private GradientDynamics getWedgeEndAt(int staff, Time time, GradientDynamics openWedge) {
    val measure = score.getMeasure(atMeasure(staff, time.getMeasure()));
    val foundDynamic = (Dynamic) measure.getDirections().get(time.getBeat(), MusicElementType.Dynamic);
    val foundWedgeEnd = (WedgeEnd) measure.getDirections().get(time.getBeat(), MusicElementType.WedgeEnd);
    if (foundWedgeEnd != null) {
        val endDynamicValue = (foundDynamic != null ? foundDynamic.getValue() : openWedge.end);
        return new GradientDynamics(openWedge.start, endDynamicValue);
    }
    return null;
}
Also used : lombok.val(lombok.val) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) WedgeEnd(com.xenoage.zong.core.music.direction.WedgeEnd) GradientDynamics(com.xenoage.zong.io.midi.out.dynamics.type.GradientDynamics) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 8 with Dynamic

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

the class CursorTest method write_MeasureElement_Test.

@Test
public void write_MeasureElement_Test() {
    Score score = ScoreFactory.create1Staff();
    Cursor cursor = new Cursor(score, mpe0, true);
    cursor.write(new Rest(Companion.fr(1, 4)));
    cursor.write(new Rest(Companion.fr(1, 4)));
    cursor.write(new Rest(Companion.fr(1, 4)));
    // write clef at 1/4
    Clef clef1 = new Clef(ClefType.Companion.getClefBass());
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write(clef1);
    BeatEList<Clef> clefs = score.getMeasure(atMeasure(0, 0)).getClefs();
    assertEquals(1, clefs.size());
    assertEquals(Companion.beatE(clef1, Companion.fr(1, 4)), clefs.getFirst());
    // write clef at 2/4
    Clef clef2 = new Clef(ClefType.Companion.getClefTreble());
    cursor.setMp(atElement(0, 0, 0, 2));
    cursor.write(clef2);
    clefs = score.getMeasure(atMeasure(0, 0)).getClefs();
    assertEquals(2, clefs.size());
    assertEquals(Companion.beatE(clef1, Companion.fr(1, 4)), clefs.getFirst());
    assertEquals(Companion.beatE(clef2, Companion.fr(2, 4)), clefs.getElements().get(1));
    // overwrite clef at 1/4
    Clef clef3 = new Clef(ClefType.Companion.getClefTreble());
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write(clef3);
    clefs = score.getMeasure(atMeasure(0, 0)).getClefs();
    assertEquals(2, clefs.size());
    assertEquals(Companion.beatE(clef3, Companion.fr(1, 4)), clefs.getFirst());
    assertEquals(Companion.beatE(clef2, Companion.fr(2, 4)), clefs.getElements().get(1));
    // write key at 1/4
    Key key = new TraditionalKey(5, Mode.Major);
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write((MeasureElement) key);
    // clefs must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
    // write direction at 1/4
    Direction direction1 = new Dynamic(DynamicValue.ff);
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write((MeasureElement) direction1);
    // clefs must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
    // key must still be there
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getDirections().size());
    // write another direction at 1/4, which does not replace the first one
    Direction direction2 = new Coda();
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write((MeasureElement) direction2);
    // clefs must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
    // key must still be there
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
    // now two directions
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getDirections().size());
    // write instrument change at 1/4
    InstrumentChange instrChange = new InstrumentChange(Instrument.Companion.getDefaultInstrument());
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write(instrChange);
    // clefs must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
    // key must still be there
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
    // directions must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getDirections().size());
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getInstrumentChanges().size());
    // check all added elements
    BeatEList<MeasureElement> all = score.getMeasure(atMeasure(0, 0)).getMeasureElements();
    assertEquals(6, all.size());
    assertEquals(clef3, all.getElements().get(0).getElement());
    assertEquals(key, all.getElements().get(1).getElement());
    assertEquals(direction1, all.getElements().get(2).getElement());
    assertEquals(direction2, all.getElements().get(3).getElement());
    assertEquals(instrChange, all.getElements().get(4).getElement());
    assertEquals(clef2, all.getElements().get(5).getElement());
}
Also used : InstrumentChange(com.xenoage.zong.core.music.InstrumentChange) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) Coda(com.xenoage.zong.core.music.direction.Coda) Clef(com.xenoage.zong.core.music.clef.Clef) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Direction(com.xenoage.zong.core.music.direction.Direction) MeasureElement(com.xenoage.zong.core.music.MeasureElement) Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Key(com.xenoage.zong.core.music.key.Key) Test(org.junit.Test)

Example 9 with Dynamic

use of com.xenoage.zong.core.music.direction.Dynamic 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 10 with Dynamic

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

the class DynamicsReader method read.

public static Dynamic read(MxlDynamics mxlDynamics, StaffDetails staffDetails) {
    DynamicValue type = mxlDynamics.getElement();
    Positioning positioning = new PositioningReader(staffDetails).readFromAny(mxlDynamics);
    Dynamic dynamics = new Dynamic(type);
    dynamics.setPositioning(positioning);
    return dynamics;
}
Also used : Positioning(com.xenoage.zong.core.music.format.Positioning) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) DynamicValue(com.xenoage.zong.core.music.direction.DynamicValue)

Aggregations

Dynamic (com.xenoage.zong.core.music.direction.Dynamic)13 Score (com.xenoage.zong.core.Score)5 Chord (com.xenoage.zong.core.music.chord.Chord)4 lombok.val (lombok.val)4 Test (org.junit.Test)4 PartAdd (com.xenoage.zong.commands.core.music.PartAdd)3 Part (com.xenoage.zong.core.music.Part)3 Direction (com.xenoage.zong.core.music.direction.Direction)3 Wedge (com.xenoage.zong.core.music.direction.Wedge)3 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)3 Cursor (com.xenoage.zong.io.selection.Cursor)3 MaybeNull (com.xenoage.utils.annotations.MaybeNull)2 Tuple2 (com.xenoage.utils.kernel.Tuple2)2 MeasureAdd (com.xenoage.zong.commands.core.music.MeasureAdd)2 MeasureElementWrite (com.xenoage.zong.commands.core.music.MeasureElementWrite)2 MeasureElement (com.xenoage.zong.core.music.MeasureElement)2 Clef (com.xenoage.zong.core.music.clef.Clef)2 WedgeEnd (com.xenoage.zong.core.music.direction.WedgeEnd)2 Words (com.xenoage.zong.core.music.direction.Words)2 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)2