Search in sources :

Example 1 with Part

use of com.xenoage.zong.core.music.Part in project Zong by Xenoage.

the class ScoreFrameLayouter method computeScoreFrameLayout.

/**
 * Creates a {@link ScoreFrameLayout} from the given {@link FrameSpacing}.
 *
 * @param unclosedElements  unclosed elements from the last frame, like slurs
 *                          spanning over more than one frame
 */
public ScoreFrameLayout computeScoreFrameLayout(FrameSpacing frame, int frameIndex, Notations notations, List<ContinuedElement> unclosedElements, Context layouterContext, Map<Beam, BeamSpacing> beamsSpacing) {
    layouterContext.saveMp();
    Score score = layouterContext.score;
    SymbolPool symbols = layouterContext.symbols;
    StamperContext context = new StamperContext();
    context.layouter = layouterContext;
    context.notations = notations;
    ScoreHeader header = score.getHeader();
    int stavesCount = score.getStavesCount();
    StavesList stavesList = score.getStavesList();
    ArrayList<StaffStamping> staffStampsPool = alist();
    ArrayList<Stamping> otherStampsPool = alist();
    // default lyric style
    FormattedTextStyle defaultLyricStyle = new FormattedTextStyle(score.getFormat().getLyricFont());
    // caches
    OpenSlursCache openCurvedLinesCache = new OpenSlursCache();
    OpenWedges openWedges = new OpenWedges();
    OpenLyricsCache openLyricsCache = new OpenLyricsCache();
    LastLyrics lastLyrics = new LastLyrics();
    OpenTupletsCache openTupletsCache = new OpenTupletsCache();
    OpenVolta openVolta = new OpenVolta();
    // add continued elements
    for (ContinuedElement ce : unclosedElements) {
        if (ce instanceof ContinuedSlur) {
            openCurvedLinesCache.add(SlurCache.createContinued((ContinuedSlur) ce));
        } else if (ce instanceof ContinuedVolta) {
            openVolta.volta = (ContinuedVolta) ce;
        } else if (ce instanceof ContinuedWedge) {
            openWedges.wedges.add((ContinuedWedge) ce);
        }
    }
    // create staff stampings
    StaffStampings staffStampings = staffStamper.createStaffStampings(score, frame);
    staffStampings.addAllTo(staffStampsPool);
    context.staffStampings = staffStampings;
    // go through the systems
    for (int iSystem : range(frame.getSystems())) {
        context.systemIndex = iSystem;
        SystemSpacing system = frame.getSystems().get(iSystem);
        List<StaffStamping> systemStaves = staffStampings.getAllOfSystem(iSystem);
        StaffStamping systemFirstStaff = getFirst(systemStaves);
        // add the part names (first system) or part abbreviations (other systems)
        int iStaffInPart = 0;
        for (Part part : stavesList.getParts()) {
            PartNameStamper.Style style = (frameIndex == 0 && iSystem == 0 ? PartNameStamper.Style.Full : PartNameStamper.Style.Abbreviated);
            addNotNull(otherStampsPool, partNameStamper.stamp(part, iStaffInPart, systemStaves, style));
            iStaffInPart += part.getStavesCount();
        }
        // create the brackets at the beginning of the system
        for (BracketGroup bracketGroup : stavesList.getBracketGroups()) {
            StavesRange r = bracketGroup.getStaves();
            otherStampsPool.add(new BracketStamping(systemStaves.get(r.getStart()), systemStaves.get(r.getStop()), system.getMarginLeftMm() - 1.4f, bracketGroup.getStyle()));
        }
        // create the barlines and measure numbers
        otherStampsPool.addAll(barlinesStamper.stamp(system, systemStaves, score));
        // fill the staves
        for (int iStaff : range(stavesCount)) {
            layouterContext.mp = layouterContext.mp.withStaff(iStaff);
            context.staffIndex = iStaff;
            float xMm = context.getCurrentStaffStamping().positionMm.x;
            for (int iMeasure : range(system.columns)) {
                int globalMeasureIndex = system.getStartMeasure() + iMeasure;
                layouterContext.mp = layouterContext.mp.withMeasure(globalMeasureIndex);
                context.measureIndex = globalMeasureIndex;
                ColumnSpacing measureColumnSpacing = system.columns.get(iMeasure);
                MeasureSpacing measure = measureColumnSpacing.getMeasures().get(iStaff);
                // add leading spacing elements, if available
                otherStampsPool.addAll(measureStamper.stampLeading(measure, xMm, context));
                // add directions
                otherStampsPool.addAll(directionStamper.stamp(context));
                // add measure elements within this measure
                float voicesXMm = xMm + measureColumnSpacing.getLeadingWidthMm();
                otherStampsPool.addAll(measureStamper.stampMeasure(measure, voicesXMm, context));
                // add voice elements within this measure
                otherStampsPool.addAll(voiceStamper.stampVoices(measure, voicesXMm, staffStampings, context, defaultLyricStyle, beamsSpacing, openCurvedLinesCache, openLyricsCache, lastLyrics, openTupletsCache));
                xMm += measureColumnSpacing.getWidthMm();
            }
        }
        // create all voltas in this system, including open voltas from the last system
        otherStampsPool.addAll(voltaStamper.stampSystem(systemFirstStaff, openVolta, header, defaultLyricStyle));
        // create all wedges in this system
        otherStampsPool.addAll(wedgeStamper.stampSystem(system, score, staffStampings, openWedges));
    }
    // create the collected ties and slurs
    otherStampsPool.addAll(createTiesAndSlurs(openCurvedLinesCache, staffStampings, frame.getSystems().size()));
    // create the open lyric underscore lines
    for (Tuple3<StaffTextStamping, NoteheadStamping, Integer> openUnderscore : openLyricsCache.getUnderscores()) {
        // TODO: fetch style efficiently
        FormattedTextStyle style = defaultLyricStyle;
        FormattedTextElement firstElement = openUnderscore.get1().getText().getFirstParagraph().getElements().getFirst();
        if (firstElement instanceof FormattedTextString) {
            style = ((FormattedTextString) firstElement).getStyle();
        }
        otherStampsPool.addAll(lyricStamper.createUnderscoreStampings(openUnderscore.get1(), openUnderscore.get2(), style, staffStampings.getAllOfStaff(openUnderscore.get3())));
    }
    // create tuplet brackets/numbers
    for (Tuplet tuplet : openTupletsCache) {
        otherStampsPool.add(tupletStamper.createTupletStamping(tuplet, openTupletsCache, symbols));
    }
    // collect elements that have to be continued on the next frame
    ArrayList<ContinuedElement> continuedElements = alist();
    for (SlurCache clc : openCurvedLinesCache) {
        continuedElements.add(clc.getContinuedCurvedLine());
    }
    if (openVolta.volta != null)
        continuedElements.add(openVolta.volta);
    continuedElements.addAll(openWedges.wedges);
    layouterContext.restoreMp();
    return new ScoreFrameLayout(frame, staffStampsPool, otherStampsPool, continuedElements);
}
Also used : PartNameStamper(com.xenoage.zong.musiclayout.stamper.PartNameStamper) SlurCache(com.xenoage.zong.musiclayout.layouter.cache.util.SlurCache) LastLyrics(com.xenoage.zong.musiclayout.layouter.scoreframelayout.util.LastLyrics) StavesRange(com.xenoage.zong.core.music.group.StavesRange) OpenSlursCache(com.xenoage.zong.musiclayout.layouter.cache.OpenSlursCache) SymbolPool(com.xenoage.zong.symbols.SymbolPool) OpenTupletsCache(com.xenoage.zong.musiclayout.layouter.cache.OpenTupletsCache) FormattedTextString(com.xenoage.zong.core.text.FormattedTextString) BracketGroup(com.xenoage.zong.core.music.group.BracketGroup) FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle) Tuplet(com.xenoage.zong.core.music.tuplet.Tuplet) StamperContext(com.xenoage.zong.musiclayout.stamper.StamperContext) Score(com.xenoage.zong.core.Score) ScoreHeader(com.xenoage.zong.core.header.ScoreHeader) Part(com.xenoage.zong.core.music.Part) StavesList(com.xenoage.zong.core.music.StavesList) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout) OpenLyricsCache(com.xenoage.zong.musiclayout.layouter.cache.OpenLyricsCache) StaffStampings(com.xenoage.zong.musiclayout.layouter.scoreframelayout.util.StaffStampings) FormattedTextElement(com.xenoage.zong.core.text.FormattedTextElement)

Example 2 with Part

use of com.xenoage.zong.core.music.Part in project Zong by Xenoage.

the class Test72b method testTransposes.

@Test
public void testTransposes() {
    for (int iPart : range(expectedTransposes.length)) {
        Part part = score.getStavesList().getParts().get(iPart);
        PitchedInstrument instrument = (PitchedInstrument) part.getFirstInstrument();
        assertEquals("Part " + iPart, expectedTransposes[iPart], instrument.getTranspose());
    }
}
Also used : Part(com.xenoage.zong.core.music.Part) PitchedInstrument(com.xenoage.zong.core.instrument.PitchedInstrument) Test(org.junit.Test)

Example 3 with Part

use of com.xenoage.zong.core.music.Part in project Zong by Xenoage.

the class StavesListReader method createStavesList.

/**
 * Creates the (still empty) {@link StavesList} for this document.
 */
private StavesList createStavesList(List<Part> parts, List<PartsBarlineGroup> barlineGroups, List<PartsBracketGroup> bracketGroups) {
    StavesList ret = new StavesList();
    // add parts
    for (Part part : parts) {
        ret.getParts().add(part);
        for (int i = 0; i < part.getStavesCount(); i++) {
            Staff staff = Staff.Companion.staffMinimal();
            staff.setParent(ret);
            ret.getStaves().add(staff);
        }
    }
    // add groups
    for (PartsBarlineGroup barlineGroup : barlineGroups) {
        int startIndex = getFirstStaffIndex(barlineGroup.startPartIndex, parts);
        int endIndex = getLastStaffIndex(barlineGroup.stopPartIndex, parts);
        ret.addBarlineGroup(new StavesRange(startIndex, endIndex), barlineGroup.style);
    }
    for (PartsBracketGroup bracketGroup : bracketGroups) {
        int startIndex = getFirstStaffIndex(bracketGroup.startPartIndex, parts);
        int endIndex = getLastStaffIndex(bracketGroup.stopPartIndex, parts);
        ret.addBracketGroup(new StavesRange(startIndex, endIndex), bracketGroup.style);
    }
    // parts with more than one staff
    for (int i : range(parts)) {
        if (parts.get(i).getStavesCount() > 1 && !isPartInGroup(i, barlineGroups, bracketGroups)) {
            int startIndex = getFirstStaffIndex(i, parts);
            int endIndex = getLastStaffIndex(i, parts);
            ret.addBarlineGroup(new StavesRange(startIndex, endIndex), BarlineGroup.Style.Common);
            ret.addBracketGroup(new StavesRange(startIndex, endIndex), BracketGroup.Style.Brace);
        }
    }
    return ret;
}
Also used : StavesRange(com.xenoage.zong.core.music.group.StavesRange) MxlPart(com.xenoage.zong.musicxml.types.partwise.MxlPart) Part(com.xenoage.zong.core.music.Part) StavesList(com.xenoage.zong.core.music.StavesList) Staff(com.xenoage.zong.core.music.Staff)

Example 4 with Part

use of com.xenoage.zong.core.music.Part in project Zong by Xenoage.

the class TimeMapperTest method getScore.

/**
 * Creates the following score (each space is a quarter note)
 *
 * measures:
 * repetitions: voltas/signs:            1───┐2───┐   d.c. senza rep
 *              barlines:     |    |:   |   :|    |1   ||
 * part 0: staff 0: voice 0:  |1   |1   |2 2 |1   |1   ||
 *                  voice 1:  |    |442 |42 4|1 d |1   ||   //d = direction
 *         staff 1: voice 0:  |2 44|1   |    |1   |1   ||
 * part 1: staff 2: voice 0:  |1   |1   |2 2 |    |2 2 ||
 *
 * play ranges:               0---------------
 *                                 1----     2---------
 *                            3---------     4---------
 */
private Score getScore() {
    val score = new Score();
    new PartAdd(score, new Part("p0", null, 2, null), 0, null).execute();
    new PartAdd(score, new Part("p1", null, 1, null), 1, null).execute();
    new MeasureAdd(score, 5).execute();
    // time, barlines, voltas and signs
    score.getColumnHeader(0).setTime(new TimeSignature(TimeType.Companion.getTime_4_4()));
    score.getColumnHeader(1).setStartBarline(Companion.barlineForwardRepeat(Regular));
    score.getColumnHeader(2).setVolta(new Volta(1, range(1, 1), "1", true));
    score.getColumnHeader(2).setEndBarline(Companion.barlineBackwardRepeat(Regular, 1));
    score.getColumnHeader(3).setVolta(new Volta(1, range(2, 2), "2", true));
    score.getColumnHeader(4).setNavigationOrigin(new DaCapo(false));
    // staff 0, voice 0
    val cursor = new Cursor(score, mp0, true);
    cursor.write(e(1));
    cursor.write(e(1));
    cursor.write(e(2));
    cursor.write(e(2));
    cursor.write(e(1));
    cursor.write(e(1));
    // staff 0, voice 1
    cursor.setMp(atElement(0, 1, 1, 0));
    cursor.write(e(4));
    cursor.write(e(4));
    cursor.write(e(2));
    cursor.write(e(4));
    cursor.write(e(2));
    cursor.write(e(4));
    cursor.write(e(1));
    cursor.write(e(1));
    new MeasureElementWrite(new Dynamic(DynamicValue.f), score.getMeasure(atMeasure(0, 3)), Companion.get_1$2()).execute();
    // staff 1, voice 0
    cursor.setMp(atElement(1, 0, 0, 0));
    cursor.write(e(2));
    cursor.write(e(4));
    cursor.write(e(4));
    cursor.write(e(1));
    cursor.setMp(atElement(1, 2, 0, 0));
    cursor.write(e(1));
    cursor.write(e(1));
    // staff 2, voice 0
    cursor.setMp(atElement(2, 0, 0, 0));
    cursor.write(e(1));
    cursor.write(e(1));
    cursor.write(e(2));
    cursor.write(e(2));
    cursor.setMp(atElement(2, 4, 0, 0));
    cursor.write(e(2));
    cursor.write(e(2));
    return score;
}
Also used : lombok.val(lombok.val) Score(com.xenoage.zong.core.Score) MeasureAdd(com.xenoage.zong.commands.core.music.MeasureAdd) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) Part(com.xenoage.zong.core.music.Part) PartAdd(com.xenoage.zong.commands.core.music.PartAdd) DaCapo(com.xenoage.zong.core.music.direction.DaCapo) Cursor(com.xenoage.zong.io.selection.Cursor) MeasureElementWrite(com.xenoage.zong.commands.core.music.MeasureElementWrite) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) Volta(com.xenoage.zong.core.music.volta.Volta)

Example 5 with Part

use of com.xenoage.zong.core.music.Part in project Zong by Xenoage.

the class InstrumentsReaderTest method testInstrumentChanges.

/**
 * Read the file "InstrumentChanges.xml".
 * It must contain 3 instruments, namely a Clarinet in B, an Alto Sax in Eb
 * and a Trombone in C. Check also the transpositons and see if the instrument
 * changes happen at the right positions.
 */
@Test
public void testInstrumentChanges() {
    Score score = MusicXmlScoreFileInputTest.loadXMLTestScore("InstrumentChanges.xml");
    Part part = score.getStavesList().getParts().get(0);
    assertEquals(3, part.getInstruments().size());
    // clarinet
    PitchedInstrument instr0 = (PitchedInstrument) part.getInstruments().get(0);
    assertEquals("Clarinet in Bb", instr0.getName());
    assertEquals(new Integer(-1), instr0.getTranspose().getDiatonic());
    assertEquals(-2, instr0.getTranspose().getChromatic());
    // altosax
    PitchedInstrument instr1 = (PitchedInstrument) part.getInstruments().get(1);
    assertEquals("Alto Saxophone", instr1.getName());
    assertEquals(new Integer(-5), instr1.getTranspose().getDiatonic());
    assertEquals(-9, instr1.getTranspose().getChromatic());
    // trombone
    PitchedInstrument instr2 = (PitchedInstrument) part.getInstruments().get(2);
    assertEquals("Trombone", instr2.getName());
    assertEquals(new Integer(0), instr2.getTranspose().getDiatonic());
    assertEquals(0, instr2.getTranspose().getChromatic());
    // instrument changes in measures 1, 2 and 3
    Measure measure = score.getMeasure(atMeasure(0, 1));
    assertEquals(instr1, getInstrumentChangeAtBeat0(measure).getInstrument());
    measure = score.getMeasure(atMeasure(0, 2));
    assertEquals(instr2, getInstrumentChangeAtBeat0(measure).getInstrument());
    measure = score.getMeasure(atMeasure(0, 3));
    assertEquals(instr0, getInstrumentChangeAtBeat0(measure).getInstrument());
}
Also used : Score(com.xenoage.zong.core.Score) Part(com.xenoage.zong.core.music.Part) PitchedInstrument(com.xenoage.zong.core.instrument.PitchedInstrument) MP.atMeasure(com.xenoage.zong.core.position.MP.atMeasure) Measure(com.xenoage.zong.core.music.Measure) MusicXmlScoreFileInputTest(com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest) Test(org.junit.Test)

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