use of com.xenoage.zong.musiclayout.spacing.BeatOffset in project Zong by Xenoage.
the class AlignedVoicesSpacer method computeSharedBeats.
/**
* Returns the shared beats of the given {@link ElementSpacing}s and {@link BeatOffset}s.
* If there are no beats used by both lists, an empty list is returned.
*/
public List<BeatOffset> computeSharedBeats(List<ElementSpacing> spacingElements, List<BeatOffset> beatOffsets) {
ArrayList<BeatOffset> ret = alist(Math.min(spacingElements.size(), beatOffsets.size()));
int iElement = 0, iBeat = 0;
Fraction lastAddedBeat = Companion.fr(-1);
while (iElement < spacingElements.size() && iBeat < beatOffsets.size()) {
Fraction elementBeat = spacingElements.get(iElement).beat;
BeatOffset beatOffset = beatOffsets.get(iBeat);
if (elementBeat.equals(beatOffset.beat)) {
if (beatOffset.beat.equals(lastAddedBeat)) {
// when this beat was already added, replace it. the
// rightmost offset is the offset we need.
ret.set(ret.size() - 1, beatOffset);
} else {
ret.add(beatOffset);
}
lastAddedBeat = beatOffset.beat;
iElement++;
} else if (elementBeat.compareTo(beatOffset.beat) > 0) {
iBeat++;
} else {
iElement++;
}
}
return ret;
}
use of com.xenoage.zong.musiclayout.spacing.BeatOffset in project Zong by Xenoage.
the class BarlinesBeatOffsetterTest method computeBeatOffsetsTest.
@Test
public void computeBeatOffsetsTest() {
// notes: | 1/4 1/4 || 1/4 | 1/4 |
// barlines: |: :||: | :|
// original distance between notes
float d = 2;
// interline space
float is = 1.5f;
// create original offsets
List<BeatOffset> baseOffsets = alist(new BeatOffset(Companion.fr(0, 4), 0 * d), new BeatOffset(Companion.fr(1, 4), 1 * d), new BeatOffset(Companion.fr(2, 4), 2 * d), new BeatOffset(Companion.fr(3, 4), 3 * d), new BeatOffset(Companion.fr(4, 4), 4 * d));
// create barlines
ColumnHeader ch = new ColumnHeader(null, 0);
ch.setStartBarline(Companion.barlineForwardRepeat(HeavyLight));
ch.setMiddleBarline(Companion.barlineMiddleBothRepeat(LightLight, 1), Companion.fr(2, 4));
ch.setMiddleBarline(Companion.barlineRegular(), Companion.fr(3, 4));
ch.setEndBarline(Companion.barlineBackwardRepeat(LightHeavy, 1));
// compute new offsets and check results
BarlinesBeatOffsetter.Result result = testee.compute(baseOffsets, ch, is);
float dRep = BarlinesBeatOffsetter.repeatSpace * is;
float dMid = BarlinesBeatOffsetter.midBarlineSpace * is;
// note offsets
List<BeatOffset> vo = result.voiceElementOffsets;
assertEquals(5, vo.size());
assertEquals(new BeatOffset(Companion.fr(0, 4), 0 * d + 1 * dRep), vo.get(0));
assertEquals(new BeatOffset(Companion.fr(1, 4), 1 * d + 1 * dRep), vo.get(1));
assertEquals(new BeatOffset(Companion.fr(2, 4), 2 * d + 3 * dRep + 1 * dMid), vo.get(2));
assertEquals(new BeatOffset(Companion.fr(3, 4), 3 * d + 3 * dRep + 2 * dMid), vo.get(3));
assertEquals(new BeatOffset(Companion.fr(4, 4), 4 * d + 3 * dRep + 2 * dMid), vo.get(4));
// barline offsets
List<BeatOffset> bo = result.barlineOffsets;
assertEquals(4, bo.size());
assertEquals(new BeatOffset(Companion.fr(0, 4), 0 * d + 0 * dRep), bo.get(0));
assertEquals(new BeatOffset(Companion.fr(2, 4), 2 * d + 2 * dRep), bo.get(1));
assertEquals(new BeatOffset(Companion.fr(3, 4), 3 * d + 3 * dRep + 1 * dMid), bo.get(2));
assertEquals(new BeatOffset(Companion.fr(4, 4), 4 * d + 4 * dRep + 2 * dMid), bo.get(3));
}
use of com.xenoage.zong.musiclayout.spacing.BeatOffset 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.spacing.BeatOffset in project Zong by Xenoage.
the class AlignedVoicesSpacerTest method computeTest3.
@Test
public void computeTest3() {
float is = 4;
// voice spacing:
// beats: 0.2
// offsets: | |
// | ⌎- 2
// ⌎--- 0
VoiceSpacing voiceSpacing = new VoiceSpacing(Companion.voice(), is, alist(spacing(beat(0), 0f), spacing(beat(2), 2f)));
// given beat offsets:
// beats: 0.2
// offsets: | |
// | ⌎- 6
// ⌎--- 2
List<BeatOffset> beatOffsets = alist(new BeatOffset(beat(0), 2f), new BeatOffset(beat(2), 6f));
// shared beats: 0, 2.
//
// resulting spacing:
// beats: 0.2
// offsets: | |
// | ⌎- 6
// ⌎--- 2
testee.compute(voiceSpacing, beatOffsets);
List<ElementSpacing> finalSpacing = voiceSpacing.elements;
assertEquals(2, finalSpacing.size());
assertEquals(beat(0), finalSpacing.get(0).beat);
assertEquals(2f / is, finalSpacing.get(0).xIs, df);
assertEquals(beat(2), finalSpacing.get(1).beat);
assertEquals(6f / is, finalSpacing.get(1).xIs, df);
}
use of com.xenoage.zong.musiclayout.spacing.BeatOffset in project Zong by Xenoage.
the class AlignedVoicesSpacerTest method computeTest2.
@Test
public void computeTest2() {
float is = 3;
// voice spacing:
// beats: 0.2
// offsets: | |
// | ⌎- 2
// ⌎--- 0
VoiceSpacing voiceSpacing = new VoiceSpacing(Companion.voice(), is, alist(spacing(beat(0), 0f), spacing(beat(2), 2f)));
// given beat offsets:
// beats: 0.2
// offsets: | |
// | ⌎- 2
// ⌎--- 0
List<BeatOffset> beatOffsets = alist(new BeatOffset(beat(0), 0f), new BeatOffset(beat(2), 2f));
// shared beats: 0, 2.
//
// resulting spacing:
// beats: 0.2
// offsets: | |
// | ⌎- 2
// ⌎--- 0
testee.compute(voiceSpacing, beatOffsets);
List<ElementSpacing> finalSpacing = voiceSpacing.elements;
assertEquals(2, finalSpacing.size());
assertEquals(beat(0), finalSpacing.get(0).beat);
assertEquals(0f / is, finalSpacing.get(0).xIs, df);
assertEquals(beat(2), finalSpacing.get(1).beat);
assertEquals(2f / is, finalSpacing.get(1).xIs, df);
}
Aggregations