use of com.xenoage.zong.core.music.time.TimeSignature 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();
}
use of com.xenoage.zong.core.music.time.TimeSignature in project Zong by Xenoage.
the class StrategyTest method getScore.
@Override
public Score getScore() {
// collect test material
List<Example> examples = getAllExamples();
// text style
FormattedTextStyle style = Companion.getDefaultStyle().withFont(new FontInfo("Arial", 6f, FontStyle.normal));
// one chord in each measure
Score score = ScoreFactory.create1Staff();
Cursor cursor = new Cursor(score, mp0, true);
cursor.write(new TimeSignature(TimeType.Companion.getTime_3_4()));
for (int i : range(examples)) {
Example example = examples.get(i);
cursor.setMp(atElement(0, i, 0, 0));
// write key
int fifths = ((TraditionalKey) example.getContext().getKey()).getFifths();
cursor.write((ColumnElement) new TraditionalKey(fifths));
// write example name (each 2nd example one line down for better reading)
String text = (i % 2 == 1 ? "\n" : "") + example.getName();
cursor.write((MeasureElement) new Words(styleText(text, style)));
// write chord with all accidentals from context (or a rest)
Map<Pitch, Integer> accs = example.getContext().getAccidentals();
if (accs.size() > 0) {
Pitch[] pitches = new Pitch[accs.size()];
int accIndex = 0;
for (Pitch acc : accs.keySet()) {
pitches[accIndex] = Companion.pi(acc.getStep(), accs.get(acc), acc.getOctave());
accIndex++;
}
Chord accsChords = ChordFactory.chord(pitches, Companion.get_1$4());
cursor.write(accsChords);
} else {
cursor.write(new Rest(Companion.get_1$4()));
}
// write a rest
cursor.write(new Rest(Companion.get_1$4()));
// write the tested chord
Chord testedChord = ChordFactory.chord(example.getPitches().toArray(new Pitch[0]), Companion.get_1$4());
cursor.write(testedChord);
}
return score;
}
use of com.xenoage.zong.core.music.time.TimeSignature in project Zong by Xenoage.
the class ColumnElementIteratorTest method createTestScore.
/**
* Test score with 4 measures. The measures 1 and 3 have each
* a time signature, a middle barline at 1/4 and an end barline.
*/
public static Score createTestScore() {
Score score = new Score();
Cursor cursor = new Cursor(score, MP.mp0, true);
for (int measure : new int[] { 1, 3 }) {
cursor.setMp(mp(unknown, measure, 0, Companion.get_0(), 0));
cursor.write(new TimeSignature(Companion.getTime_4_4()));
cursor.setMp(mp(unknown, measure, unknown, Companion.fr(1, 4), 0));
cursor.write(Companion.barlineRegular());
ColumnHeader column = score.getColumnHeader(measure);
column.setEndBarline(Companion.barline(LightLight));
}
return score;
}
use of com.xenoage.zong.core.music.time.TimeSignature in project Zong by Xenoage.
the class Base46e method getExpectedStaff.
static Staff getExpectedStaff() {
Score score = ScoreFactory.create1Staff();
Cursor cursor = new Cursor(score, mp0, true);
cursor.write(new TimeSignature(TimeType.Companion.getTimeCommon()));
// measure 0, voice 0
cursor.write(chord(Companion.pi('C', 0, 5), Companion.fr(1, 4)));
// measure 1, voice 0
cursor.setMp(atElement(0, 1, 0, 0));
cursor.write(chord(Companion.pi('C', 0, 5), Companion.fr(1, 4)));
cursor.write(chord(Companion.pi('A', 0, 4), Companion.fr(1, 4)));
cursor.write(chord(Companion.pi('F', 0, 4), Companion.fr(1, 4)));
cursor.write(chord(Companion.pi('C', 0, 5), Companion.fr(1, 4)));
// measure 1, voice 1
cursor.setMp(atElement(0, 1, 1, 0));
cursor.write(new Rest(Companion.fr(1, 4)));
cursor.write(chord(Companion.pi('C', 0, 4), Companion.fr(1, 4)));
return score.getStaff(0);
}
use of com.xenoage.zong.core.music.time.TimeSignature 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();
}
}
}
}
Aggregations