use of com.xenoage.zong.core.music.Voice in project Zong by Xenoage.
the class Test03b method test.
@Test
public void test() {
Measure measure = getScore().getMeasure(mp0);
// two voices
assertEquals(2, measure.getVoices().size());
// check first voice
Voice voice = measure.getVoice(0);
assertEquals(2, voice.getElements().size());
assertEquals(Companion.pi(0, 0, 4), ((Chord) voice.getElement(0)).getNotes().get(0).getPitch());
assertEquals(Companion.fr(1, 4), voice.getElement(0).getDuration());
assertEquals(Companion.pi(0, 0, 4), ((Chord) voice.getElement(1)).getNotes().get(0).getPitch());
assertEquals(Companion.fr(1, 4), voice.getElement(1).getDuration());
// check second voice
// in Zong!, there is no "empty" space in voices. Instead, an invisible rest is used
voice = measure.getVoice(1);
assertTrue(voice.getElement(0) instanceof Rest);
assertTrue(((Rest) voice.getElement(0)).isHidden());
assertEquals(Companion.fr(1, 4), voice.getElement(0).getDuration());
assertEquals(Companion.pi(5, 0, 3), ((Chord) voice.getElement(1)).getNotes().get(0).getPitch());
assertEquals(Companion.fr(1, 4), voice.getElement(1).getDuration());
assertEquals(Companion.pi(5, 0, 3), ((Chord) voice.getElement(2)).getNotes().get(0).getPitch());
assertEquals(Companion.fr(1, 4), voice.getElement(2).getDuration());
}
use of com.xenoage.zong.core.music.Voice in project Zong by Xenoage.
the class Test42a method test.
@Test
public void test() {
Staff staff = getFirstStaff();
// test chords
for (int iMeasure : range(2)) {
for (int iVoice : range(2)) {
MP mpVoice = atVoice(0, iMeasure, iVoice);
Voice expectedVoice = expectedStaff.getVoice(mpVoice);
Voice voice = staff.getVoice(mpVoice);
assertEqualsVoice(expectedVoice, voice, mpVoice);
}
}
// test slurs
assertSlurBetween(getVoiceChords(staff.getVoice(atVoice(0, 1, 0))), 1, 2, SlurType.Slur);
assertSlurBetween(getVoiceChords(staff.getVoice(atVoice(0, 1, 1))), 1, 2, SlurType.Slur);
}
use of com.xenoage.zong.core.music.Voice in project Zong by Xenoage.
the class ScoreReader method readToScore.
public void readToScore(Score score, ErrorHandling errorHandling) {
Context context = new Context(score, new ReaderSettings(errorHandling));
// create the measures of the parts
It<MxlPart> mxlParts = it(doc.getParts());
for (MxlPart mxlPart : mxlParts) {
// create measures
execute(new MeasureAddUpTo(score, mxlPart.getMeasures().size()));
// initialize each measure with a C clef
Part part = score.getStavesList().getParts().get(mxlParts.getIndex());
StavesRange stavesRange = score.getStavesList().getPartStaffIndices(part);
for (int staff : stavesRange.getRange()) {
execute(new MeasureElementWrite(new Clef(ClefType.Companion.getClefTreble()), score.getMeasure(MP.atMeasure(staff, 0)), Companion.get_0()));
}
}
// write a 4/4 measure and C key signature in the first measure
execute(new ColumnElementWrite(new TimeSignature(TimeType.Companion.getTime_4_4()), score.getColumnHeader(0), Companion.get_0(), null));
execute(new ColumnElementWrite(new TraditionalKey(0), score.getColumnHeader(0), Companion.get_0(), null));
// read the parts
mxlParts = it(doc.getParts());
for (MxlPart mxlPart : mxlParts) {
// clear part-dependent context values
context.beginNewPart(mxlParts.getIndex());
// read the measures
It<MxlMeasure> mxlMeasures = it(mxlPart.getMeasures());
for (MxlMeasure mxlMeasure : mxlMeasures) {
try {
MeasureReader.readToContext(mxlMeasure, mxlMeasures.getIndex(), context);
} catch (MusicReaderException ex) {
throw new RuntimeException("Error at " + ex.getContext().toString(), ex);
} catch (Exception ex) {
throw new RuntimeException("Error (roughly) around " + context.toString(), ex);
}
}
}
// remove unclosed elements
context.removeUnclosedWedges();
// go through the whole score, and fill empty measures (that means, measures where
// voice 0 has no single VoiceElement) with rests
Fraction measureDuration = Companion.fr(1, 4);
for (int iStaff = 0; iStaff < score.getStavesCount(); iStaff++) {
Staff staff = score.getStaff(atStaff(iStaff));
for (int iMeasure : range(staff.getMeasures())) {
Measure measure = staff.getMeasure(iMeasure);
TimeSignature newTime = score.getHeader().getColumnHeader(iMeasure).getTime();
if (newTime != null) {
// time signature has changed
measureDuration = newTime.getType().getMeasureBeats();
}
if (measureDuration == null) {
// senza misura
// use whole rest
measureDuration = Companion.fr(4, 4);
}
Voice voice0 = measure.getVoice(0);
if (voice0.isEmpty()) {
// TODO: "whole rests" or split. currently, also 3/4 rests are possible
MP mp = atElement(iStaff, iMeasure, 0, 0);
new VoiceElementWrite(score.getVoice(mp), mp, new Rest(measureDuration), null).execute();
}
}
}
}
use of com.xenoage.zong.core.music.Voice 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.core.music.Voice 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;
}
Aggregations