Search in sources :

Example 1 with MusicElement

use of com.xenoage.zong.core.music.MusicElement 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 MusicElement

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

the class VoicesBeatOffsetter method computeVoicesBeats.

/**
 * Returns a sorted list of all beats, where
 * chords or rests begin, from the given list of voice spacings.
 * There are no duplicate beats. The ending beats of the voices are not added.
 */
SortedList<Fraction> computeVoicesBeats(List<VoiceSpacing> voiceSpacings) {
    SortedList<Fraction> beats = Companion.sortedListNoDuplicates();
    Fraction beat;
    for (VoiceSpacing voiceSpacing : voiceSpacings) {
        beat = Fraction.Companion.get_0();
        for (ElementSpacing spacingElement : voiceSpacing.elements) {
            MusicElement element = spacingElement.getElement();
            if (element instanceof VoiceElement) {
                // add beat
                beats.add(beat);
                // find the next beat
                beat = beat.add(((VoiceElement) element).getDuration());
            }
        }
    // do not add beat here, because the ending beat of an incomplete measure
    // is not interesting for computing beat offsets.
    }
    return beats;
}
Also used : ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) MusicElement(com.xenoage.zong.core.music.MusicElement) VoiceElement(com.xenoage.zong.core.music.VoiceElement) Fraction(com.xenoage.utils.math.Fraction) VoiceSpacing(com.xenoage.zong.musiclayout.spacing.VoiceSpacing)

Example 3 with MusicElement

use of com.xenoage.zong.core.music.MusicElement 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 MusicElement

use of com.xenoage.zong.core.music.MusicElement 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 MusicElement

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

the class MeasureStamper method stampLeading.

/**
 * Stamps the {@link MeasureElement}s of the leading spacing.
 * @param leadingXMm  the horizontal position on the staff in mm, where
 *                    the leading spacing of the measure starts.
 */
public List<Stamping> stampLeading(MeasureSpacing measure, float leadingXMm, StamperContext context) {
    LeadingSpacing leading = measure.leading;
    if (leading == null)
        return emptyList;
    List<Stamping> ret = alist(leading.elements.size());
    for (ElementSpacing element : leading.elements) {
        MusicElement me = element.getElement();
        if (me != null) {
            float xMm = leadingXMm + element.xIs * measure.interlineSpace;
            Notation notation = context.getNotation(me);
            if (notation == null)
                throw new RuntimeException("No notation for element " + me + " at " + MP.getMP(me));
            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) LeadingSpacing(com.xenoage.zong.musiclayout.spacing.LeadingSpacing) 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)

Aggregations

MusicElement (com.xenoage.zong.core.music.MusicElement)5 ElementSpacing (com.xenoage.zong.musiclayout.spacing.ElementSpacing)4 Stamping (com.xenoage.zong.musiclayout.stampings.Stamping)4 Notation (com.xenoage.zong.musiclayout.notation.Notation)3 ClefNotation (com.xenoage.zong.musiclayout.notation.ClefNotation)2 TimeNotation (com.xenoage.zong.musiclayout.notation.TimeNotation)2 TraditionalKeyNotation (com.xenoage.zong.musiclayout.notation.TraditionalKeyNotation)2 Fraction (com.xenoage.utils.math.Fraction)1 Point2f (com.xenoage.utils.math.geom.Point2f)1 VoiceElement (com.xenoage.zong.core.music.VoiceElement)1 Chord (com.xenoage.zong.core.music.chord.Chord)1 MPElement (com.xenoage.zong.core.position.MPElement)1 ScoreFrame (com.xenoage.zong.layout.frames.ScoreFrame)1 ScoreFrameLayout (com.xenoage.zong.musiclayout.ScoreFrameLayout)1 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)1 BeamSpacing (com.xenoage.zong.musiclayout.spacing.BeamSpacing)1 LeadingSpacing (com.xenoage.zong.musiclayout.spacing.LeadingSpacing)1 RestSpacing (com.xenoage.zong.musiclayout.spacing.RestSpacing)1 VoiceSpacing (com.xenoage.zong.musiclayout.spacing.VoiceSpacing)1