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);
}
}
}
}
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;
}
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;
}
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;
}
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();
}
}
Aggregations