Search in sources :

Example 1 with Dynamic

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

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

the class TimeMapperTest method getScore.

/**
 * Creates the following score (each space is a quarter note)
 *
 * measures:
 * repetitions: voltas/signs:            1───┐2───┐   d.c. senza rep
 *              barlines:     |    |:   |   :|    |1   ||
 * part 0: staff 0: voice 0:  |1   |1   |2 2 |1   |1   ||
 *                  voice 1:  |    |442 |42 4|1 d |1   ||   //d = direction
 *         staff 1: voice 0:  |2 44|1   |    |1   |1   ||
 * part 1: staff 2: voice 0:  |1   |1   |2 2 |    |2 2 ||
 *
 * play ranges:               0---------------
 *                                 1----     2---------
 *                            3---------     4---------
 */
private Score getScore() {
    val score = new Score();
    new PartAdd(score, new Part("p0", null, 2, null), 0, null).execute();
    new PartAdd(score, new Part("p1", null, 1, null), 1, null).execute();
    new MeasureAdd(score, 5).execute();
    // time, barlines, voltas and signs
    score.getColumnHeader(0).setTime(new TimeSignature(TimeType.Companion.getTime_4_4()));
    score.getColumnHeader(1).setStartBarline(Companion.barlineForwardRepeat(Regular));
    score.getColumnHeader(2).setVolta(new Volta(1, range(1, 1), "1", true));
    score.getColumnHeader(2).setEndBarline(Companion.barlineBackwardRepeat(Regular, 1));
    score.getColumnHeader(3).setVolta(new Volta(1, range(2, 2), "2", true));
    score.getColumnHeader(4).setNavigationOrigin(new DaCapo(false));
    // staff 0, voice 0
    val cursor = new Cursor(score, mp0, true);
    cursor.write(e(1));
    cursor.write(e(1));
    cursor.write(e(2));
    cursor.write(e(2));
    cursor.write(e(1));
    cursor.write(e(1));
    // staff 0, voice 1
    cursor.setMp(atElement(0, 1, 1, 0));
    cursor.write(e(4));
    cursor.write(e(4));
    cursor.write(e(2));
    cursor.write(e(4));
    cursor.write(e(2));
    cursor.write(e(4));
    cursor.write(e(1));
    cursor.write(e(1));
    new MeasureElementWrite(new Dynamic(DynamicValue.f), score.getMeasure(atMeasure(0, 3)), Companion.get_1$2()).execute();
    // staff 1, voice 0
    cursor.setMp(atElement(1, 0, 0, 0));
    cursor.write(e(2));
    cursor.write(e(4));
    cursor.write(e(4));
    cursor.write(e(1));
    cursor.setMp(atElement(1, 2, 0, 0));
    cursor.write(e(1));
    cursor.write(e(1));
    // staff 2, voice 0
    cursor.setMp(atElement(2, 0, 0, 0));
    cursor.write(e(1));
    cursor.write(e(1));
    cursor.write(e(2));
    cursor.write(e(2));
    cursor.setMp(atElement(2, 4, 0, 0));
    cursor.write(e(2));
    cursor.write(e(2));
    return score;
}
Also used : lombok.val(lombok.val) Score(com.xenoage.zong.core.Score) MeasureAdd(com.xenoage.zong.commands.core.music.MeasureAdd) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) Part(com.xenoage.zong.core.music.Part) PartAdd(com.xenoage.zong.commands.core.music.PartAdd) DaCapo(com.xenoage.zong.core.music.direction.DaCapo) Cursor(com.xenoage.zong.io.selection.Cursor) MeasureElementWrite(com.xenoage.zong.commands.core.music.MeasureElementWrite) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) Volta(com.xenoage.zong.core.music.volta.Volta)

Example 3 with Dynamic

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

the class MidiVelocityConverterTry method createTestScore.

public static Score createTestScore() {
    Score ret = new Score();
    Instrument instr = Instrument.Companion.getDefaultInstrument();
    Part pianoPart = new Part("Test", "T", 1, ilist(instr));
    new PartAdd(ret, pianoPart, 0, null).execute();
    Cursor cursor = new Cursor(ret, mp0, true);
    cursor.write((ColumnElement) new TraditionalKey(-3));
    cursor.write((ColumnElement) new TimeSignature(Companion.timeType(3, 4)));
    cursor.write(new Clef(ClefType.Companion.getClefTreble()));
    Fraction f4 = Companion.fr(1, 4);
    Chord attachC;
    cursor.write(attachC = chord(f4, Pitch.Companion.pi(Pitch.Companion.getG(), 4)));
    attachC.addDirection(new Dynamic(DynamicValue.pp));
    cursor.write(attachC = chord(f4, Pitch.Companion.pi(Pitch.Companion.getA(), 4)));
    attachC.addDirection(new Dynamic(DynamicValue.ff));
    cursor.write(attachC = chord(f4, Pitch.Companion.pi(Pitch.Companion.getG(), 4)));
    attachC.addDirection(new Dynamic(DynamicValue.sfp));
    /*
		Chord chord;
		Voice voice = measure.getVoices().get(0);
		chord = voice.addNote(pi'G', 0, 4), fr(1, 4));
		chord.addDirection(new Dynamic(DynamicsType.pp));
		
		

		chord = voice.addNote(pi'A', 0, 4), fr(1, 4));
		chord.addDirection(new Dynamic(DynamicsType.ff));

		chord = voice.addNote(pi'G', 0, 4), fr(1, 4));
		chord.addDirection(new Dynamic(DynamicsType.sfp));
		*/
    cursor.setMp(mp0.withVoice(1));
    cursor.write(attachC = chord(f4, Pitch.Companion.pi(Pitch.Companion.getC(), 4)));
    attachC.addDirection(new Dynamic(DynamicValue.fff));
    /*
		voice = measure.addVoice();
		
		chord = voice.addNote(pi'C', 0, 4), fr(1, 4));
		chord.addDirection(new Dynamic(DynamicsType.fff));
		*/
    cursor.setMp(mp0.withMeasure(1));
    cursor.write(attachC = chord(f4, Pitch.Companion.pi(Pitch.Companion.getG(), 4)));
    // cursor.withScore(ScoreController.attachElement(cursor.getScore(), attachC, new Dynamic(DynamicsType.pp)));
    cursor.write(attachC = chord(f4, Pitch.Companion.pi(Pitch.Companion.getA(), 4)));
    attachC.addDirection(new Dynamic(DynamicValue.pp));
    cursor.write(attachC = chord(f4, Pitch.Companion.pi(Pitch.Companion.getG(), 4)));
    attachC.addDirection(new Dynamic(DynamicValue.pp));
    cursor.setMp(cursor.getMP().withElement(0).withVoice(1));
    cursor.write(attachC = chord(f4, Pitch.Companion.pi(Pitch.Companion.getC(), 5)));
    /*		
		measure = staff.getMeasures().get(1);

		voice = measure.getVoices().get(0);
		chord = voice.addNote(pi'G', 0, 4), fr(1, 4));
		//chord.addDirection(new Dynamic(DynamicsType.pp));

		chord = voice.addNote(pi'A', 0, 4), fr(1, 4));
		chord.addDirection(new Dynamic(DynamicsType.pp));

		chord = voice.addNote(pi'G', 0, 4), fr(1, 4));
		chord.addDirection(new Dynamic(DynamicsType.pp));

		voice = measure.addVoice();
		chord = voice.addNote(pi'C', 0, 5), fr(1, 4));
		*/
    cursor.setMp(mp0.withMeasure(2));
    cursor.write(attachC = chord(f4, Pitch.Companion.pi(Pitch.Companion.getG(), 4)));
    attachC.addDirection(new Dynamic(DynamicValue.sfz));
    cursor.write(chord(f4, Pitch.Companion.pi(Pitch.Companion.getA(), 4)));
    // cursor = cursor.withScore(ScoreController.attachElement(cursor.getScore(), attachC, new Dynamic(DynamicsType.pp)));
    cursor.write(chord(f4, Pitch.Companion.pi(Pitch.Companion.getG(), 4)));
    // cursor = cursor.withScore(ScoreController.attachElement(cursor.getScore(), attachC, new Dynamic(DynamicsType.pp)));
    cursor.setMp(mp0.withMeasure(2).withVoice(2));
    cursor.write(chord(f4, Pitch.Companion.pi(Pitch.Companion.getC(), 5)));
    /*
		measure = staff.getMeasures().get(2);

		
		voice = measure.getVoices().get(0);
		chord = voice.addNote(pi'G', 0, 4), fr(1, 4));
		chord.addDirection(new Dynamic(DynamicsType.sfz));

		chord = voice.addNote(pi'A', 0, 4), fr(1, 4));
		//chord.addDirection(new Dynamic(DynamicsType.pp));

		chord = voice.addNote(pi'G', 0, 4), fr(1, 4));
		//chord.addDirection(new Dynamic(DynamicsType.pp));
		
		voice = measure.addVoice();
		voice = measure.addVoice();
		chord = voice.addNote(pi'C',0,5), fr(1,2));

		*/
    return cursor.getScore();
}
Also used : Score(com.xenoage.zong.core.Score) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) Part(com.xenoage.zong.core.music.Part) Instrument(com.xenoage.zong.core.instrument.Instrument) PartAdd(com.xenoage.zong.commands.core.music.PartAdd) Clef(com.xenoage.zong.core.music.clef.Clef) Fraction(com.xenoage.utils.math.Fraction) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Cursor(com.xenoage.zong.io.selection.Cursor) Chord(com.xenoage.zong.core.music.chord.Chord) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature)

Example 4 with Dynamic

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

the class Test21d method testMeasure0.

@Test
public void testMeasure0() {
    // F4, whole, with accent and fermata
    Chord chord = (Chord) score.getVoice(mp0).getElementAt(Companion.get_0());
    assertEquals(1, chord.getNotes().size());
    assertEquals(Companion.pi('F', 0, 4), chord.getNotes().get(0).getPitch());
    assertEquals(Companion.get_1(), chord.getDuration());
    assertEquals(2, chord.getAnnotations().size());
    assertEquals(articulation(ArticulationType.Accent, Placement.Below), chord.getAnnotations().get(0));
    assertEquals(fermata(Placement.Above), chord.getAnnotations().get(1));
    // words "Largo"
    List<MeasureElement> directions = score.getMeasure(mp0).getMeasureElements().getAll(Companion.get_0());
    // clef, words, dynamics
    assertEquals(3, directions.size());
    Words words = (Words) directions.get(1);
    assertEquals("Largo", words.getText().toString());
    assertEquals(Placement.Above, words.getPositioning());
    // dynamics "fp"
    Dynamic dynamics = (Dynamic) directions.get(2);
    assertEquals(DynamicValue.fp, dynamics.getValue());
    assertEquals(Placement.Below, dynamics.getPositioning());
}
Also used : MeasureElement(com.xenoage.zong.core.music.MeasureElement) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) Words(com.xenoage.zong.core.music.direction.Words) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 5 with Dynamic

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

the class Base21d method getExpectedDirections.

default List<Tuple2<MP, ? extends Direction>> getExpectedDirections() {
    List<Tuple2<MP, ? extends Direction>> expectedDirections = alist();
    Words largo = new Words(new UnformattedText("Largo"));
    largo.setPositioning(Placement.Above);
    expectedDirections.add(t(mp0, largo));
    Dynamic fp = new Dynamic(DynamicValue.fp);
    fp.setPositioning(Placement.Below);
    expectedDirections.add(t(mp0, fp));
    Dynamic p = new Dynamic(DynamicValue.p);
    fp.setPositioning(Placement.Below);
    expectedDirections.add(t(mp0.withMeasure(1), p));
    return expectedDirections;
}
Also used : Dynamic(com.xenoage.zong.core.music.direction.Dynamic) Tuple2(com.xenoage.utils.kernel.Tuple2) Words(com.xenoage.zong.core.music.direction.Words) UnformattedText(com.xenoage.zong.core.text.UnformattedText) Direction(com.xenoage.zong.core.music.direction.Direction)

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