Search in sources :

Example 6 with Part

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;
}
Also used : MeasureAdd(com.xenoage.zong.commands.core.music.MeasureAdd) Part(com.xenoage.zong.core.music.Part) PartAdd(com.xenoage.zong.commands.core.music.PartAdd)

Example 7 with Part

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();
}
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 8 with Part

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());
    }
}
Also used : Score(com.xenoage.zong.core.Score) Part(com.xenoage.zong.core.music.Part) StavesList(com.xenoage.zong.core.music.StavesList) Test(org.junit.Test)

Example 9 with Part

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();
            }
        }
    }
}
Also used : VoiceElementWrite(com.xenoage.zong.commands.core.music.VoiceElementWrite) MP.atStaff(com.xenoage.zong.core.position.MP.atStaff) Staff(com.xenoage.zong.core.music.Staff) ColumnElementWrite(com.xenoage.zong.commands.core.music.ColumnElementWrite) MxlPart(com.xenoage.zong.musicxml.types.partwise.MxlPart) Clef(com.xenoage.zong.core.music.clef.Clef) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) MxlMeasure(com.xenoage.zong.musicxml.types.partwise.MxlMeasure) MeasureAddUpTo(com.xenoage.zong.commands.core.music.MeasureAddUpTo) StavesRange(com.xenoage.zong.core.music.group.StavesRange) Rest(com.xenoage.zong.core.music.rest.Rest) MxlMeasure(com.xenoage.zong.musicxml.types.partwise.MxlMeasure) Measure(com.xenoage.zong.core.music.Measure) MP(com.xenoage.zong.core.position.MP) MusicReaderException(com.xenoage.zong.io.musicxml.in.util.MusicReaderException) Fraction(com.xenoage.utils.math.Fraction) MusicReaderException(com.xenoage.zong.io.musicxml.in.util.MusicReaderException) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) MxlPart(com.xenoage.zong.musicxml.types.partwise.MxlPart) Part(com.xenoage.zong.core.music.Part) MeasureElementWrite(com.xenoage.zong.commands.core.music.MeasureElementWrite) Voice(com.xenoage.zong.core.music.Voice)

Example 10 with Part

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;
}
Also used : MxlPartListContent(com.xenoage.zong.musicxml.types.choice.MxlPartListContent) MxlPart(com.xenoage.zong.musicxml.types.partwise.MxlPart) Part(com.xenoage.zong.core.music.Part)

Aggregations

Part (com.xenoage.zong.core.music.Part)19 Score (com.xenoage.zong.core.Score)8 PitchedInstrument (com.xenoage.zong.core.instrument.PitchedInstrument)6 Test (org.junit.Test)6 PartAdd (com.xenoage.zong.commands.core.music.PartAdd)5 StavesList (com.xenoage.zong.core.music.StavesList)4 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)4 MeasureAdd (com.xenoage.zong.commands.core.music.MeasureAdd)3 MeasureElementWrite (com.xenoage.zong.commands.core.music.MeasureElementWrite)3 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)3 StavesRange (com.xenoage.zong.core.music.group.StavesRange)3 Cursor (com.xenoage.zong.io.selection.Cursor)3 MxlPart (com.xenoage.zong.musicxml.types.partwise.MxlPart)3 lombok.val (lombok.val)3 Fraction (com.xenoage.utils.math.Fraction)2 ColumnElementWrite (com.xenoage.zong.commands.core.music.ColumnElementWrite)2 Instrument (com.xenoage.zong.core.instrument.Instrument)2 Measure (com.xenoage.zong.core.music.Measure)2 Staff (com.xenoage.zong.core.music.Staff)2 Clef (com.xenoage.zong.core.music.clef.Clef)2