use of com.xenoage.zong.core.instrument.PitchedInstrument in project Zong by Xenoage.
the class ChannelMapperTest method createScore.
private Score createScore(int[] midiPrograms, int... partStavesCount) {
val score = new Score();
for (int iPart : range(partStavesCount)) {
Instrument instrument;
if (midiPrograms[iPart] == drums)
instrument = new UnpitchedInstrument("part " + iPart);
else
instrument = new PitchedInstrument("part " + iPart, midiPrograms[iPart]);
new PartAdd(score, new Part("", null, partStavesCount[iPart], alist(instrument)), iPart, null).execute();
}
return score;
}
use of com.xenoage.zong.core.instrument.PitchedInstrument in project Zong by Xenoage.
the class AttributesReader method readToContext.
/**
* Reads the given attributes element.
*/
public void readToContext(Context context) {
// divisions
Integer divisions = mxlAttributes.getDivisions();
if (divisions != null)
context.setDivisions(divisions);
// key signature
Key key = readKey(mxlAttributes.getKey());
if (key != null)
context.writeColumnElement(key);
// time signature
TimeSignature time = readTime(mxlAttributes.getTime());
if (// TODO: attribute "number" for single staves
time != null)
context.writeColumnElement(time);
// clefs
if (mxlAttributes.getClefs() != null) {
for (MxlClef mxlClef : mxlAttributes.getClefs()) {
ClefReader clefReader = new ClefReader(mxlClef);
Clef clef = clefReader.read();
int staff = clefReader.readStaff();
if (clef != null)
context.writeMeasureElement(clef, staff);
}
}
// transposition changes - TODO: clean solution for instrument changes
PitchedInstrument instrument = readTransposedInstrument(mxlAttributes.getTranspose());
if (instrument != null) {
// write to all staves of this part
for (int staff = 0; staff < context.getPartStaffIndices().getCount(); staff++) context.writeMeasureElement(new InstrumentChange(instrument), staff);
}
}
use of com.xenoage.zong.core.instrument.PitchedInstrument in project Zong by Xenoage.
the class AttributesReader method readTransposedInstrument.
private PitchedInstrument readTransposedInstrument(MxlTranspose mxlTranspose) {
if (mxlTranspose == null)
return null;
Transpose transpose = new TransposeReader(mxlTranspose).read();
PitchedInstrument instrument = new PitchedInstrument("", 0);
instrument.setTranspose(transpose);
return instrument;
}
use of com.xenoage.zong.core.instrument.PitchedInstrument in project Zong by Xenoage.
the class InstrumentsReader method readInstrument.
private Instrument readInstrument(Info info) {
Instrument instrument = null;
if (info.midiChannel != null && info.midiChannel == 10) {
// unpitched instrument
instrument = new UnpitchedInstrument(info.id);
} else {
// pitched instrument
// midi-program is 1-based in MusicXML but 0-based in MIDI
// TODO: find value that matches instrument name
int midiProgram = notNull(info.midiProgram, 1) - 1;
midiProgram = MathUtils.INSTANCE.clamp(midiProgram, 0, 127);
PitchedInstrument pitchedInstrument;
instrument = pitchedInstrument = new PitchedInstrument(info.id, midiProgram);
pitchedInstrument.setTranspose(info.transpose);
}
instrument.setName(info.name);
instrument.setAbbreviation(info.abbreviation);
if (info.volume != null)
instrument.setVolume(info.volume);
if (info.pan != null)
instrument.setPan(info.pan);
return instrument;
}
use of com.xenoage.zong.core.instrument.PitchedInstrument in project Zong by Xenoage.
the class InstrumentsReader method createInstruments.
private List<Instrument> createInstruments() {
List<Instrument> ret = alist();
for (MxlScoreInstrument mxlScoreInstr : mxlScorePart.getScoreInstruments()) {
Instrument instrument = readInstrument(getInfo(mxlScoreInstr.getId()));
ret.add(instrument);
}
// a default instrument with this transposition
if (ret.size() == 0 && partTranspose != Transpose.Companion.getNoTranspose()) {
PitchedInstrument instrument = new PitchedInstrument(mxlPart.getId(), 0);
instrument.setTranspose(partTranspose);
ret.add(instrument);
}
return ret;
}
Aggregations