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