Search in sources :

Example 1 with Instrument

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();
}
Also used : Instrument(com.xenoage.zong.core.instrument.Instrument) Pitch(com.xenoage.zong.core.music.Pitch) Chord(com.xenoage.zong.core.music.chord.Chord)

Example 2 with Instrument

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();
}
Also used : Score(com.xenoage.zong.core.Score) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) Part(com.xenoage.zong.core.music.Part) Instrument(com.xenoage.zong.core.instrument.Instrument) PartAdd(com.xenoage.zong.commands.core.music.PartAdd) Clef(com.xenoage.zong.core.music.clef.Clef) Fraction(com.xenoage.utils.math.Fraction) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Cursor(com.xenoage.zong.io.selection.Cursor) Chord(com.xenoage.zong.core.music.chord.Chord) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature)

Example 3 with Instrument

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;
}
Also used : lombok.val(lombok.val) UnpitchedInstrument(com.xenoage.zong.core.instrument.UnpitchedInstrument) Score(com.xenoage.zong.core.Score) PitchedInstrument(com.xenoage.zong.core.instrument.PitchedInstrument) Part(com.xenoage.zong.core.music.Part) UnpitchedInstrument(com.xenoage.zong.core.instrument.UnpitchedInstrument) PitchedInstrument(com.xenoage.zong.core.instrument.PitchedInstrument) Instrument(com.xenoage.zong.core.instrument.Instrument) PartAdd(com.xenoage.zong.commands.core.music.PartAdd)

Example 4 with Instrument

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();
}
Also used : Instrument(com.xenoage.zong.core.instrument.Instrument) MeasureElementWrite(com.xenoage.zong.commands.core.music.MeasureElementWrite)

Example 5 with Instrument

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;
}
Also used : UnpitchedInstrument(com.xenoage.zong.core.instrument.UnpitchedInstrument) PitchedInstrument(com.xenoage.zong.core.instrument.PitchedInstrument) UnpitchedInstrument(com.xenoage.zong.core.instrument.UnpitchedInstrument) MxlMidiInstrument(com.xenoage.zong.musicxml.types.MxlMidiInstrument) PitchedInstrument(com.xenoage.zong.core.instrument.PitchedInstrument) Instrument(com.xenoage.zong.core.instrument.Instrument) MxlScoreInstrument(com.xenoage.zong.musicxml.types.MxlScoreInstrument)

Aggregations

Instrument (com.xenoage.zong.core.instrument.Instrument)6 PitchedInstrument (com.xenoage.zong.core.instrument.PitchedInstrument)3 UnpitchedInstrument (com.xenoage.zong.core.instrument.UnpitchedInstrument)3 PartAdd (com.xenoage.zong.commands.core.music.PartAdd)2 Score (com.xenoage.zong.core.Score)2 Part (com.xenoage.zong.core.music.Part)2 Chord (com.xenoage.zong.core.music.chord.Chord)2 MxlMidiInstrument (com.xenoage.zong.musicxml.types.MxlMidiInstrument)2 MxlScoreInstrument (com.xenoage.zong.musicxml.types.MxlScoreInstrument)2 Fraction (com.xenoage.utils.math.Fraction)1 MeasureElementWrite (com.xenoage.zong.commands.core.music.MeasureElementWrite)1 Pitch (com.xenoage.zong.core.music.Pitch)1 Clef (com.xenoage.zong.core.music.clef.Clef)1 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)1 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)1 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)1 Cursor (com.xenoage.zong.io.selection.Cursor)1 lombok.val (lombok.val)1