use of com.xenoage.zong.core.instrument.Instrument in project Zong by Xenoage.
the class MidiChordPlayerTry method main.
public static void main(String... args) throws Exception {
SynthManager.init(false);
MidiChordPlayer player = new MidiChordPlayer();
Instrument instrument = Instrument.Companion.getDefaultInstrument();
Pitch pitch = Companion.pi(2, 0, 4);
player.playNote(pitch, instrument);
sleep();
Chord chord = chord(new Pitch[] { Companion.pi(2, 0, 4), Companion.pi(4, 0, 4) }, Companion.fr(1));
player.playChord(chord, instrument);
sleep();
player.playChord(chord, instrument, (byte) 127);
sleep();
SynthManager.close();
}
use of com.xenoage.zong.core.instrument.Instrument 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.instrument.Instrument 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.Instrument in project Zong by Xenoage.
the class Context method writeInstrumentChange.
/**
* Changes the current instrument.
*/
public void writeInstrumentChange(String instrumentID) {
// find instrument
Part part = getScore().getStavesList().getPartByStaffIndex(mp.getStaff());
Instrument newInstrument = null;
for (Instrument instr : it(part.getInstruments())) {
if (instr.getId().equals(instrumentID)) {
newInstrument = instr;
break;
}
}
if (newInstrument == null) {
// error: instrument is unknown to this part
reportError("Unknown instrument: \"" + instrumentID + "\"");
}
// apply instrument change
new MeasureElementWrite(new InstrumentChange(newInstrument), score.getMeasure(this.mp), mp.getBeat()).execute();
}
use of com.xenoage.zong.core.instrument.Instrument 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;
}
Aggregations