Search in sources :

Example 1 with ScoreFrameLayout

use of com.xenoage.zong.musiclayout.ScoreFrameLayout in project Zong by Xenoage.

the class Content method onClick.

/**
 * This method is called when the mouse was clicked on the content.
 * A message with the clicked element is shown to the user.
 */
public void onClick(Point2f positionPx) {
    if (layout.getScoreFrames().size() == 0)
        return;
    // get the layout of first score frame
    ScoreFrame frame = layout.getScoreFrames().get(0);
    ScoreFrameLayout frameLayout = frame.getScoreFrameLayout();
    // convert position from screen space to page space, then from page space
    // to frame space, and them from frame space to score frame space
    Point2f positionMm = positionPx.scale(Units.pxToMm(1, mainWindow.getZoom()));
    Point2f framePositionMm = positionMm.sub(frame.getAbsolutePosition());
    Point2f scorePositionMm = frame.getScoreLayoutPosition(framePositionMm);
    // find elements under this position
    for (Stamping stamping : frameLayout.getAllStampings()) {
        if (stamping.getBoundingShape() != null && stamping.getBoundingShape().contains(scorePositionMm)) {
            MusicElement element = stamping.getMusicElement();
            if (element != null) {
                // music element found
                String message = "An element was clicked: " + element;
                if (element instanceof MPElement) {
                    // music element with a known musical position found
                    MPElement mpElement = (MPElement) element;
                    if (mpElement.getParent() != null)
                        message += " at " + mpElement.getMP();
                }
                mainWindow.showMessageDialog(message);
            }
        }
    }
}
Also used : Stamping(com.xenoage.zong.musiclayout.stampings.Stamping) ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) Point2f(com.xenoage.utils.math.geom.Point2f) MusicElement(com.xenoage.zong.core.music.MusicElement) MPElement(com.xenoage.zong.core.position.MPElement) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout)

Example 2 with ScoreFrameLayout

use of com.xenoage.zong.musiclayout.ScoreFrameLayout 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 3 with ScoreFrameLayout

use of com.xenoage.zong.musiclayout.ScoreFrameLayout in project Zong by Xenoage.

the class PlaybackLayouter method createCursorAt.

/**
 * Returns a new {@link SystemCursorStamping} at the given {@link Time},
 * representing the current playback position, or null if there is none.
 */
public SystemCursorStamping createCursorAt(Time time) {
    ScoreFrameLayout frame = scoreLayout.getScoreFrameLayout(time.getMeasure());
    if (frame != null) {
        StaffStamping topStaff = frame.getStaffStamping(0, time.getMeasure());
        StaffStamping bottomStaff = frame.getStaffStamping(scoreLayout.score.getStavesCount() - 1, time.getMeasure());
        if (topStaff != null && bottomStaff != null)
            return new SystemCursorStamping(topStaff, bottomStaff, frame.getPositionX(time));
    }
    return null;
}
Also used : SystemCursorStamping(com.xenoage.zong.musiclayout.stampings.SystemCursorStamping) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout)

Example 4 with ScoreFrameLayout

use of com.xenoage.zong.musiclayout.ScoreFrameLayout in project Zong by Xenoage.

the class ScoreLayouter method createScoreFrameLayouts.

/**
 * Creates all {@link ScoreFrameLayout}s.
 */
List<ScoreFrameLayout> createScoreFrameLayouts(FramesSpacing frames, Notations notations, Context context, Map<Beam, BeamSpacing> beamsSpacing) {
    ArrayList<ScoreFrameLayout> ret = alist();
    ArrayList<ContinuedElement> continuedElements = alist();
    for (int iFrame : range(frames.size())) {
        ScoreFrameLayout sfl = scoreFrameLayouter.computeScoreFrameLayout(frames.get(iFrame), iFrame, notations, continuedElements, context, beamsSpacing);
        ret.add(sfl);
        continuedElements = sfl.getContinuedElements();
    }
    return ret;
}
Also used : ContinuedElement(com.xenoage.zong.musiclayout.continued.ContinuedElement) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout)

Example 5 with ScoreFrameLayout

use of com.xenoage.zong.musiclayout.ScoreFrameLayout in project Zong by Xenoage.

the class ScoreLayouter method createLayoutWithExceptions.

/**
 * Computes the whole layout and returns it.
 * If something fails, an exception is thrown.
 */
public ScoreLayout createLayoutWithExceptions() {
    // notations of elements
    Notations notations = notator.computeAll(context);
    // compute optimal measure column spacings
    List<ColumnSpacing> columns = columnsSpacer.compute(notations, context);
    // break columns into systems and frames
    FramesSpacing frames = framesSpacer.compute(columns, target, context, notations);
    // system stretching (horizontal)
    fillSystemsHorizontally(frames, target);
    // frame filling (vertical)
    fillFramesVertically(frames, target, context.score);
    // compute beam spacings. these are computed only now, after the horizontal
    // and vertical spacing of the score is fixed, since the beam slants depend on the
    // exact spacings
    Map<Beam, BeamSpacing> beams = beamsSpacer.compute(context.score, notations, frames);
    // create score frame layouts from the collected information
    List<ScoreFrameLayout> scoreFrameLayouts = createScoreFrameLayouts(frames, notations, context, beams);
    // create score layout
    return new ScoreLayout(context.score, scoreFrameLayouts, context.symbols, context.settings);
}
Also used : Beam(com.xenoage.zong.core.music.beam.Beam) FramesSpacing(com.xenoage.zong.musiclayout.spacing.FramesSpacing) BeamSpacing(com.xenoage.zong.musiclayout.spacing.BeamSpacing) ColumnSpacing(com.xenoage.zong.musiclayout.spacing.ColumnSpacing) Notations(com.xenoage.zong.musiclayout.notation.Notations) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout)

Aggregations

ScoreFrameLayout (com.xenoage.zong.musiclayout.ScoreFrameLayout)10 ScoreFrame (com.xenoage.zong.layout.frames.ScoreFrame)3 Point2f (com.xenoage.utils.math.geom.Point2f)2 Score (com.xenoage.zong.core.Score)2 StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)2 Stamping (com.xenoage.zong.musiclayout.stampings.Stamping)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 Fraction (com.xenoage.utils.math.Fraction)1 Rectangle2f (com.xenoage.utils.math.geom.Rectangle2f)1 Size2f (com.xenoage.utils.math.geom.Size2f)1 ScoreHeader (com.xenoage.zong.core.header.ScoreHeader)1 Measure (com.xenoage.zong.core.music.Measure)1 MusicElement (com.xenoage.zong.core.music.MusicElement)1 Part (com.xenoage.zong.core.music.Part)1 Staff (com.xenoage.zong.core.music.Staff)1 StavesList (com.xenoage.zong.core.music.StavesList)1 Voice (com.xenoage.zong.core.music.Voice)1 VoiceElement (com.xenoage.zong.core.music.VoiceElement)1 Beam (com.xenoage.zong.core.music.beam.Beam)1