use of com.xenoage.zong.core.music.Measure in project Zong by Xenoage.
the class ColumnSpacer method compute.
/**
* Computes a {@link ColumnSpacing} from a measure column.
* @param context the current context, with the current {@link MP} and precomputed
* element {@link Notation}s
* @param createLeading true, if a leading spacing has to be created, otherwise false
* @param notations the precomputed notations of the measure and voice elements
*/
public ColumnSpacing compute(Context context, boolean createLeading, Notations notations) {
context.saveMp();
int measureIndex = context.mp.measure;
Column column = context.score.getColumn(measureIndex);
ColumnHeader columnHeader = context.score.getHeader().getColumnHeader(measureIndex);
// compute the optimal spacings for each voice separately
List<List<VoiceSpacing>> voiceSpacingsByStaff = alist();
for (int iStaff : range(column)) {
List<VoiceSpacing> vss = alist();
Measure measure = column.get(iStaff);
for (Voice voice : measure.getVoices()) {
context.mp = MP.atVoice(iStaff, measureIndex, measure.getVoices().indexOf(voice));
VoiceSpacing vs = singleVoiceSpacer.compute(context, notations);
vss.add(vs);
}
voiceSpacingsByStaff.add(vss);
}
// compute the measure elements (like inner clefs) and accordingly updated voice spacings
ArrayList<List<ElementSpacing>> optimalMeasureElementsSpacingsByStaff = alist();
for (int iStaff : range(column)) {
context.mp = MP.atMeasure(iStaff, measureIndex);
List<ElementSpacing> measureSpacing = measureElementsSpacer.compute(context, createLeading, voiceSpacingsByStaff.get(iStaff), notations);
optimalMeasureElementsSpacingsByStaff.add(measureSpacing);
}
// compute the common beat offsets of this measure column
Fraction measureBeats = context.score.getMeasureBeats(measureIndex);
VoiceSpacingsByStaff voiceSpacings = new VoiceSpacingsByStaff(voiceSpacingsByStaff);
List<BeatOffset> beatOffsets = voicesBeatOffsetter.compute(voiceSpacings.getAll(), measureBeats, context.settings.offsetBeatsMinimal);
// recompute beat offsets with respect to barlines
BarlinesBeatOffsetter.Result offsets = barlinesBeatOffsetter.compute(beatOffsets, columnHeader, context.score.getMaxIS());
beatOffsets = offsets.voiceElementOffsets;
List<BeatOffset> barlineOffsets = offsets.barlineOffsets;
// compute the spacings for the whole column, so that equal beats are aligned
ArrayList<List<ElementSpacing>> alignedMeasureElementsSpacingsByStaff = alist();
for (int iStaff : range(column)) {
Measure measure = column.get(iStaff);
// voice spacings
for (int iVoice : range(measure.getVoices())) alignedVoicesSpacer.compute(voiceSpacings.get(iStaff, iVoice), beatOffsets);
// measure elements, based on the aligned voice spacings
context.mp = atMeasure(iStaff, measureIndex);
alignedMeasureElementsSpacingsByStaff.add(measureElementsSpacer.compute(context, createLeading, voiceSpacings.getStaff(iStaff), notations));
}
// compute spacings for each staff
List<MeasureSpacing> measureSpacings = alist(column.size());
for (int iStaff : range(column)) {
// create leading spacing, if needed
LeadingSpacing leadingSpacing = null;
if (createLeading) {
context.mp = atBeat(iStaff, measureIndex, 0, Fraction.Companion.get_0());
leadingSpacing = leadingSpacer.compute(context, notations);
}
// create measure spacing
float interlineSpace = context.score.getInterlineSpace(iStaff);
measureSpacings.add(new MeasureSpacing(atMeasure(iStaff, measureIndex), interlineSpace, voiceSpacings.getStaff(iStaff), alignedMeasureElementsSpacingsByStaff.get(iStaff), leadingSpacing));
}
context.restoreMp();
return new ColumnSpacing(measureIndex, measureSpacings, beatOffsets, barlineOffsets);
}
use of com.xenoage.zong.core.music.Measure in project Zong by Xenoage.
the class ScoreTest method testMeasureElements.
private static <T> void testMeasureElements(List<Tuple2<MP, T>> expectedElements, Score score, BiFunction<Measure, Fraction, T> getElementAtBeat) {
for (Tuple2<MP, T> expectedElement : expectedElements) {
MP mp = expectedElement.get1();
Measure measure = score.getMeasure(mp);
T element = getElementAtBeat.apply(measure, mp.beat);
assertNotNull("" + mp, element);
assertEquals("" + mp, expectedElement.get2(), element);
}
}
use of com.xenoage.zong.core.music.Measure 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;
}
use of com.xenoage.zong.core.music.Measure in project Zong by Xenoage.
the class InstrumentsReaderTest method testInstrumentChanges.
/**
* Read the file "InstrumentChanges.xml".
* It must contain 3 instruments, namely a Clarinet in B, an Alto Sax in Eb
* and a Trombone in C. Check also the transpositons and see if the instrument
* changes happen at the right positions.
*/
@Test
public void testInstrumentChanges() {
Score score = MusicXmlScoreFileInputTest.loadXMLTestScore("InstrumentChanges.xml");
Part part = score.getStavesList().getParts().get(0);
assertEquals(3, part.getInstruments().size());
// clarinet
PitchedInstrument instr0 = (PitchedInstrument) part.getInstruments().get(0);
assertEquals("Clarinet in Bb", instr0.getName());
assertEquals(new Integer(-1), instr0.getTranspose().getDiatonic());
assertEquals(-2, instr0.getTranspose().getChromatic());
// altosax
PitchedInstrument instr1 = (PitchedInstrument) part.getInstruments().get(1);
assertEquals("Alto Saxophone", instr1.getName());
assertEquals(new Integer(-5), instr1.getTranspose().getDiatonic());
assertEquals(-9, instr1.getTranspose().getChromatic());
// trombone
PitchedInstrument instr2 = (PitchedInstrument) part.getInstruments().get(2);
assertEquals("Trombone", instr2.getName());
assertEquals(new Integer(0), instr2.getTranspose().getDiatonic());
assertEquals(0, instr2.getTranspose().getChromatic());
// instrument changes in measures 1, 2 and 3
Measure measure = score.getMeasure(atMeasure(0, 1));
assertEquals(instr1, getInstrumentChangeAtBeat0(measure).getInstrument());
measure = score.getMeasure(atMeasure(0, 2));
assertEquals(instr2, getInstrumentChangeAtBeat0(measure).getInstrument());
measure = score.getMeasure(atMeasure(0, 3));
assertEquals(instr0, getInstrumentChangeAtBeat0(measure).getInstrument());
}
use of com.xenoage.zong.core.music.Measure in project Zong by Xenoage.
the class Test01a method test.
@ToDo("the editiorial sharp (sharp in parenthesis) in the last measure is not supported yet")
@Test
public void test() {
Pitch[] expectedPitches = getExpectedPitches();
Staff staff = getFirstStaff();
assertEquals(26, staff.getMeasures().size());
int iPitch = 0;
for (int iM = 0; iM < staff.getMeasures().size(); iM++) {
Measure measure = staff.getMeasures().get(iM);
Voice voice = measure.getVoice(0);
for (VoiceElement e : voice.getElements()) {
if (e instanceof Chord) {
// check note and pitch
Chord chord = (Chord) e;
assertEquals(expectedPitches[iPitch++], chord.getNotes().get(0).getPitch());
}
}
}
assertEquals("not all notes found", expectedPitches.length, iPitch);
}
Aggregations