Search in sources :

Example 1 with Stamping

use of com.xenoage.zong.musiclayout.stampings.Stamping 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 Stamping

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

the class ScoreFrameLayout method getStampingAt.

/**
 * Returns the {@link Stamping} under the given position
 * in score layout coordinates (mm relative to the
 * upper left corner) or null, if there is none.
 */
public Stamping getStampingAt(Point2f point) {
    Stamping ret = null;
    int highestLevel = -1;
    for (Stamping s : getMusicalStampings()) {
        if (s.getLevel().ordinal() > highestLevel && s.getBoundingShape().contains(point)) {
            highestLevel = s.getLevel().ordinal();
            ret = s;
        }
    }
    return ret;
}
Also used : StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) TextStamping(com.xenoage.zong.musiclayout.stampings.TextStamping) Stamping(com.xenoage.zong.musiclayout.stampings.Stamping)

Example 3 with Stamping

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

the class MeasureStamper method stampMeasure.

/**
 * Stamps all {@link MeasureElement}s of the given measure (but not the leading elements).
 * @param measureXMm  the horizontal position on the staff in mm, where the measure
 *                    starts (after leading spacing).
 */
public List<Stamping> stampMeasure(MeasureSpacing measure, float measureXMm, StamperContext context) {
    List<Stamping> ret = alist();
    for (ElementSpacing element : measure.elements) {
        MusicElement me = element.getElement();
        if (me != null) {
            Notation notation = context.getNotation(me);
            float xMm = measureXMm + element.xIs * measure.interlineSpace;
            ret.add(stamp(notation, xMm, context));
        }
    }
    return ret;
}
Also used : ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) Stamping(com.xenoage.zong.musiclayout.stampings.Stamping) MusicElement(com.xenoage.zong.core.music.MusicElement) Notation(com.xenoage.zong.musiclayout.notation.Notation) ClefNotation(com.xenoage.zong.musiclayout.notation.ClefNotation) TimeNotation(com.xenoage.zong.musiclayout.notation.TimeNotation) TraditionalKeyNotation(com.xenoage.zong.musiclayout.notation.TraditionalKeyNotation)

Example 4 with Stamping

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

the class VoiceStamper method stampVoice.

public List<Stamping> stampVoice(VoiceSpacing voice, float voiceXMm, StaffStampings staffStampings, boolean stampLeadingRests, StamperContext context, // TODO:
FormattedTextStyle defaultLyricStyle, Map<Beam, BeamSpacing> beams, OpenSlursCache openCurvedLinesCache, OpenLyricsCache openLyricsCache, LastLyrics lastLyrics, OpenTupletsCache openTupletsCache) {
    List<Stamping> ret = alist();
    // create the voice elements
    boolean onlyRestsSoFar = true;
    for (ElementSpacing spacingElement : voice.elements) {
        MusicElement element = spacingElement.getElement();
        if (element != null) /* TODO && (stampRests || !(element instanceof Rest)) */
        {
            Notation notation = context.getNotation(element);
            float xMm = voiceXMm + spacingElement.xIs * voice.interlineSpace;
            if (element instanceof Chord) {
                // chord
                onlyRestsSoFar = false;
                Chord chord = (Chord) element;
                BeamSpacing beam = beams.get(chord.getBeam());
                ret.addAll(chordStamper.stampAll((ChordNotation) spacingElement.getNotation(), xMm, beam, staffStampings, context, defaultLyricStyle, openCurvedLinesCache, openLyricsCache, lastLyrics, openTupletsCache));
            } else if (spacingElement instanceof RestSpacing) {
                // rest
                if (false == onlyRestsSoFar || stampLeadingRests) {
                    // not a leading rest, or a leading rest which should be stamped
                    ret.add(elementStamper.createRestStamping((RestSpacing) spacingElement, xMm, context));
                }
            } else {
                throw new IllegalArgumentException("Notation not supported: " + notation);
            }
        }
    }
    return ret;
}
Also used : ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) Stamping(com.xenoage.zong.musiclayout.stampings.Stamping) BeamSpacing(com.xenoage.zong.musiclayout.spacing.BeamSpacing) ChordNotation(com.xenoage.zong.musiclayout.notation.ChordNotation) MusicElement(com.xenoage.zong.core.music.MusicElement) RestSpacing(com.xenoage.zong.musiclayout.spacing.RestSpacing) Notation(com.xenoage.zong.musiclayout.notation.Notation) ChordNotation(com.xenoage.zong.musiclayout.notation.ChordNotation) Chord(com.xenoage.zong.core.music.chord.Chord)

Example 5 with Stamping

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

the class ScoreFrameRenderer method paintTransformed.

@Override
protected void paintTransformed(Frame frame, Canvas canvas, RendererArgs args) {
    Rectangle2f rect = getLocalRect(frame);
    // draw musical elements
    ScoreFrame scoreFrame = (ScoreFrame) frame;
    ScoreFrameLayout scoreLayout = scoreFrame.getScoreFrameLayout();
    if (scoreLayout != null) {
        // the coordinates of the layout elements are relative to the upper left
        // corner, so we have to translate them
        canvas.transformSave();
        canvas.transformTranslate(rect.x1(), rect.y1());
        // get musical stampings, and in interactive mode, also
        // stampings like for playback and selection
        Iterable<Stamping> stampings = (canvas.getDecoration() == CanvasDecoration.Interactive ? scoreLayout.getAllStampings() : scoreLayout.getMusicalStampings());
        // render them
        for (Stamping s : stampings) {
            StampingRenderer.drawAny(s, canvas, args);
        }
        // restore old transformation
        canvas.transformRestore();
    }
}
Also used : Stamping(com.xenoage.zong.musiclayout.stampings.Stamping) ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) Rectangle2f(com.xenoage.utils.math.geom.Rectangle2f) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout)

Aggregations

Stamping (com.xenoage.zong.musiclayout.stampings.Stamping)10 MusicElement (com.xenoage.zong.core.music.MusicElement)4 Notation (com.xenoage.zong.musiclayout.notation.Notation)3 ElementSpacing (com.xenoage.zong.musiclayout.spacing.ElementSpacing)3 StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)3 Point2f (com.xenoage.utils.math.geom.Point2f)2 Rectangle2f (com.xenoage.utils.math.geom.Rectangle2f)2 ScoreFrame (com.xenoage.zong.layout.frames.ScoreFrame)2 ScoreFrameLayout (com.xenoage.zong.musiclayout.ScoreFrameLayout)2 ClefNotation (com.xenoage.zong.musiclayout.notation.ClefNotation)2 TimeNotation (com.xenoage.zong.musiclayout.notation.TimeNotation)2 TraditionalKeyNotation (com.xenoage.zong.musiclayout.notation.TraditionalKeyNotation)2 StaffTextStamping (com.xenoage.zong.musiclayout.stampings.StaffTextStamping)2 MeasureNumbering (com.xenoage.zong.core.format.MeasureNumbering)1 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)1 Barline (com.xenoage.zong.core.music.barline.Barline)1 Chord (com.xenoage.zong.core.music.chord.Chord)1 BarlineGroup (com.xenoage.zong.core.music.group.BarlineGroup)1 MPElement (com.xenoage.zong.core.position.MPElement)1 FormattedText (com.xenoage.zong.core.text.FormattedText)1