use of com.xenoage.zong.core.music.Part in project Zong by Xenoage.
the class ScoreFactory method create1Staff.
/**
* Creates a score with a single staff and 1 empty measure.
*/
public static Score create1Staff() {
Score score = new Score();
new PartAdd(score, new Part("", null, 1, null), 0, null).execute();
new MeasureAdd(score, 1).execute();
return score;
}
use of com.xenoage.zong.core.music.Part 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.Part in project Zong by Xenoage.
the class Test41b method test.
@Test
public void test() {
Score score = getScore();
StavesList stavesList = score.getStavesList();
List<Part> parts = stavesList.getParts();
assertEquals(expectedNames.length, parts.size());
for (int i : range(parts)) {
assertEquals(expectedNames[i], parts.get(i).getName());
}
}
use of com.xenoage.zong.core.music.Part 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.Part in project Zong by Xenoage.
the class StavesListReader method read.
public StavesList read() {
// list of parts
List<Part> parts = alist();
partsIDtoIndex = map();
// list of groups
List<PartsBarlineGroup> barlineGroups = alist();
List<PartsBracketGroup> bracketGroups = alist();
// open groups with number as index
Map<String, PartsBarlineGroup> openBarlineGroups = map();
Map<String, PartsBracketGroup> openBracketGroups = map();
// read score-part and part-group elements
// each score-part is a part in our application
MxlPartList mxlPartList = mxlScore.getScoreHeader().getPartList();
int currentPartIndex = 0;
for (MxlPartListContent mxlItem : mxlPartList.getContent()) {
// score-part
if (mxlItem.getPartListContentType() == PartListContentType.ScorePart) {
MxlScorePart mxlScorePart = (MxlScorePart) mxlItem;
Part part = PartReader.read(mxlScorePart, findCorrespondingPart(mxlScorePart, mxlScore));
parts.add(part);
partsIDtoIndex.put(mxlScorePart.getId(), currentPartIndex);
currentPartIndex++;
} else // part-group
if (mxlItem.getPartListContentType() == PartListContentType.PartGroup) {
PartsGroups group = readPartGroup(currentPartIndex, (MxlPartGroup) mxlItem, openBarlineGroups, openBracketGroups);
if (group != null) {
// a group was closed, add it
if (group.barlineGroup != null)
barlineGroups.add(group.barlineGroup);
if (group.bracketsGroup != null)
bracketGroups.add(group.bracketsGroup);
}
}
}
// if there are unclosed score-groups, report a problem
if (openBarlineGroups.size() > 0 || openBracketGroups.size() > 0) {
errorHandling.reportError("There are unclosed score-groups");
}
// count the number of staves and measures used by each part
HashMap<String, Integer> partsStaves = countStaves(mxlScore);
for (String partID : partsStaves.keySet()) {
Integer partIndex = partsIDtoIndex.get(partID);
if (partIndex == null)
throw new IllegalStateException("Unknown part \"" + partID + "\"");
Integer partStaves = partsStaves.get(partID);
if (partStaves == null)
throw new IllegalStateException("Unused part \"" + partID + "\"");
if (partStaves > 1)
parts.get(partIndex).setStavesCount(partStaves);
}
// creates the final StavesList for this document
stavesList = createStavesList(parts, barlineGroups, bracketGroups);
return stavesList;
}
Aggregations