use of com.xenoage.zong.musiclayout.notation.ChordNotation in project Zong by Xenoage.
the class BeamNotator method compute.
@MaybeNull
public BeamNotation compute(Beam beam, Notations notations) {
// compute fragments
List<Fragments> fragments = beamFragmenter.compute(beam);
// get minimum stem length and gap
BeamRules beamRules = BeamRules.getRules(beam);
float gapIs = beamRules.getGapIs();
// collect chords
List<ChordNotation> chords = notations.getBeamChords(beam);
// create notation
BeamNotation beamNotation = new BeamNotation(beam, beam.getMP(), fragments, gapIs, chords);
return beamNotation;
}
use of com.xenoage.zong.musiclayout.notation.ChordNotation in project Zong by Xenoage.
the class VoicesBeatOffsetterTest method createVoiceSpacings.
/**
* Create {@link VoiceSpacing}s for the first measure column
* of the given {@link Score}.
*/
private LinkedList<VoiceSpacing> createVoiceSpacings(Score score) {
LinkedList<VoiceSpacing> ret = new LinkedList<>();
for (int iStaff : range(0, score.getStavesCount() - 1)) {
Measure measure = score.getMeasure(atMeasure(iStaff, 0));
for (Voice voice : measure.getVoices()) {
Fraction beat = Companion.fr(0);
ArrayList<ElementSpacing> se = alist();
float offset = 0;
for (VoiceElement e : voice.getElements()) {
// compute width
float width = 0;
if (e.getDuration().equals(Companion.get_0()))
width = width_grace;
else if (e.getDuration().equals(dur_1_8))
width = width_1_8;
else if (e.getDuration().equals(dur_1_6))
width = width_1_6;
else if (e.getDuration().equals(dur_1_4))
width = width_1_4;
else if (e.getDuration().equals(dur_3_8))
width = width_3_8;
else if (e.getDuration().equals(dur_1_2))
width = width_1_2;
else if (e.getDuration().equals(dur_1_1))
width = width_1_1;
// create spacing element with offset
se.add(new ChordSpacing(new ChordNotation((Chord) e), beat, offset));
beat = beat.add(e.getDuration());
offset += width;
}
se.add(new BorderSpacing(beat, offset));
ret.add(new VoiceSpacing(voice, score.getFormat().getInterlineSpace(), se));
}
}
return ret;
}
use of com.xenoage.zong.musiclayout.notation.ChordNotation in project Zong by Xenoage.
the class StretchMeasuresTest method createSystemWith1MeasureGrace.
/**
* Creates and returns a simple {@link SystemSpacing} with only one
* measure and three notes: two main notes and two grace notes between them.
*/
public static SystemSpacing createSystemWith1MeasureGrace(float offsetChord1, float offsetChord2, float offsetMeasureEnd, float graceDistance) {
Chord chord1 = chord(Companion.pi(0, 0, 4), Companion.fr(2, 4));
Chord chord2grace = graceChord(Companion.pi(1, 0, 4));
Chord chord3grace = graceChord(Companion.pi(2, 0, 4));
Chord chord4 = chord(Companion.pi(3, 0, 4), Companion.fr(2, 4));
Voice voice = new Voice(alist(chord1, chord2grace, chord3grace, chord4));
List<BeatOffset> beatOffsets = alist(new BeatOffset(Companion.fr(0, 4), offsetChord1), new BeatOffset(Companion.fr(2, 4), offsetChord2), new BeatOffset(Companion.fr(4, 4), offsetMeasureEnd));
float is = 1;
List<VoiceSpacing> voiceSpacings = alist(new VoiceSpacing(voice, is, alist(new ChordSpacing(new ChordNotation(chord1), beatOffsets.get(0).getBeat(), beatOffsets.get(0).getOffsetMm()), new ChordSpacing(new ChordNotation(chord2grace), beatOffsets.get(1).getBeat(), beatOffsets.get(1).getOffsetMm() - 2 * graceDistance), new ChordSpacing(new ChordNotation(chord3grace), beatOffsets.get(1).getBeat(), beatOffsets.get(1).getOffsetMm() - 1 * graceDistance), new ChordSpacing(new ChordNotation(chord4), beatOffsets.get(1).getBeat(), beatOffsets.get(1).getOffsetMm()))));
MeasureSpacing measureSpacing = new MeasureSpacing(atMeasure(0, 0), is, voiceSpacings, empty, null);
ColumnSpacing mcs = new ColumnSpacing(-1, alist(measureSpacing), beatOffsets, alist(new BeatOffset(Companion.fr(0, 4), 0), new BeatOffset(Companion.fr(4, 4), offsetMeasureEnd)));
SystemSpacing system = new SystemSpacing(alist(mcs), 0, 0, offsetMeasureEnd, null, 0);
return system;
}
use of com.xenoage.zong.musiclayout.notation.ChordNotation in project Zong by Xenoage.
the class SingleVoiceSpacerTest method testGrace1.
/**
* Computes a voice spacing with grace notes,
* where the element before the grace notes has enough empty rear space
* to take all the grace notes.
* <pre>
* Single elements: [-r1------------][g1][g2][--r4--]
* Combined: --r1----~g1~g2~~~r4---
* </pre> (~: area used by two elements)
*/
@Test
public void testGrace1() {
// create voice and notations
Voice voice = new Voice(alist((VoiceElement) r1, g1, g2, r4));
Notations notations = new Notations();
notations.add(new RestNotation(r1, new ElementWidth(2, 2, 13), null));
notations.add(new ChordNotation(g1, new ElementWidth(1, 2, 1)));
notations.add(new ChordNotation(g2, new ElementWidth(1, 2, 1)));
notations.add(new RestNotation(r4, new ElementWidth(3, 2, 3), null));
// compute spacing
VoiceSpacing vs = testee.compute(voice, 300f, Companion.fr(4, 4), 5, notations, layoutSettings);
// check spacing
ElementSpacing[] ses = vs.elements.toArray(new ElementSpacing[0]);
;
float s = layoutSettings.offsetMeasureStart;
assertEquals(5, ses.length);
assertEquals(s + 2, ses[0].xIs, DELTA_FLOAT);
assertEquals(s + 9, ses[1].xIs, DELTA_FLOAT);
assertEquals(s + 12, ses[2].xIs, DELTA_FLOAT);
assertEquals(s + 17, ses[3].xIs, DELTA_FLOAT);
assertEquals(s + 22, ses[4].xIs, DELTA_FLOAT);
// check beats
assertEquals(Companion.fr(0, 8), ses[0].beat);
assertEquals(Companion.fr(2, 8), ses[1].beat);
assertEquals(Companion.fr(2, 8), ses[2].beat);
assertEquals(Companion.fr(2, 8), ses[3].beat);
assertEquals(Companion.fr(6, 8), ses[4].beat);
}
use of com.xenoage.zong.musiclayout.notation.ChordNotation in project Zong by Xenoage.
the class SingleVoiceSpacerTest method testGrace3.
/**
* Computes a voice spacing with grace notes,
* where the element before the grace notes has not enough empty rear space
* to take even a single grace notes.
* <pre>
* Single elements: [-r1--][g1][g2][--r4--]
* Combined: --r1_~g1~g2~~~r4---
* </pre> (~: area used by two elements, _: minimal distance between elements)
*/
@Test
public void testGrace3() {
// create voice and notations
Voice voice = new Voice(alist((VoiceElement) r1, g1, g2, r4));
Notations notations = new Notations();
notations.add(new RestNotation(r1, new ElementWidth(2, 2, 3), null));
notations.add(new ChordNotation(g1, new ElementWidth(1, 2, 1)));
notations.add(new ChordNotation(g2, new ElementWidth(1, 2, 1)));
notations.add(new RestNotation(r4, new ElementWidth(3, 2, 3), null));
// compute spacing
VoiceSpacing vs = testee.compute(voice, 400f, Companion.fr(4, 4), 5, notations, layoutSettings);
// check spacing
ElementSpacing[] ses = vs.elements.toArray(new ElementSpacing[0]);
;
float s = layoutSettings.offsetMeasureStart;
float d = layoutSettings.spacings.widthDistanceMin;
assertEquals(5, ses.length);
assertEquals(s + 2, ses[0].xIs, DELTA_FLOAT);
assertEquals(s + 5 + d, ses[1].xIs, DELTA_FLOAT);
assertEquals(s + 8 + d, ses[2].xIs, DELTA_FLOAT);
assertEquals(s + 13 + d, ses[3].xIs, DELTA_FLOAT);
assertEquals(s + 18 + d, ses[4].xIs, DELTA_FLOAT);
// check beats
assertEquals(Companion.fr(0, 8), ses[0].beat);
assertEquals(Companion.fr(2, 8), ses[1].beat);
assertEquals(Companion.fr(2, 8), ses[2].beat);
assertEquals(Companion.fr(2, 8), ses[3].beat);
assertEquals(Companion.fr(6, 8), ses[4].beat);
}
Aggregations