Search in sources :

Example 6 with PitchedInstrument

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;
}
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 7 with PitchedInstrument

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);
    }
}
Also used : InstrumentChange(com.xenoage.zong.core.music.InstrumentChange) PitchedInstrument(com.xenoage.zong.core.instrument.PitchedInstrument) Clef(com.xenoage.zong.core.music.clef.Clef) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Key(com.xenoage.zong.core.music.key.Key) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature)

Example 8 with PitchedInstrument

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;
}
Also used : PitchedInstrument(com.xenoage.zong.core.instrument.PitchedInstrument) Transpose(com.xenoage.zong.core.instrument.Transpose)

Example 9 with PitchedInstrument

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;
}
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)

Example 10 with PitchedInstrument

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;
}
Also used : MxlScoreInstrument(com.xenoage.zong.musicxml.types.MxlScoreInstrument) 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

PitchedInstrument (com.xenoage.zong.core.instrument.PitchedInstrument)12 Part (com.xenoage.zong.core.music.Part)6 Test (org.junit.Test)4 Instrument (com.xenoage.zong.core.instrument.Instrument)3 UnpitchedInstrument (com.xenoage.zong.core.instrument.UnpitchedInstrument)3 lombok.val (lombok.val)3 Score (com.xenoage.zong.core.Score)2 InstrumentChange (com.xenoage.zong.core.music.InstrumentChange)2 MxlMidiInstrument (com.xenoage.zong.musicxml.types.MxlMidiInstrument)2 MxlScoreInstrument (com.xenoage.zong.musicxml.types.MxlScoreInstrument)2 PartAdd (com.xenoage.zong.commands.core.music.PartAdd)1 Transpose (com.xenoage.zong.core.instrument.Transpose)1 Measure (com.xenoage.zong.core.music.Measure)1 Pitch (com.xenoage.zong.core.music.Pitch)1 Clef (com.xenoage.zong.core.music.clef.Clef)1 Key (com.xenoage.zong.core.music.key.Key)1 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)1 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)1 MP.atMeasure (com.xenoage.zong.core.position.MP.atMeasure)1 DynamicsInterpretation (com.xenoage.zong.io.midi.out.dynamics.DynamicsInterpretation)1