// ~ Methods ------------------------------------------------------------ @Override protected Rectangle getBox(Glyph stick) { Point2D top = stick.getStartPoint(VERTICAL); Rectangle box = new Rectangle( (int) Math.rint(top.getX()), (int) Math.rint(top.getY() - (nHeight / 2)), nWidth, 2 * nHeight); stick.addAttachment("tr", box); return box; }
// ~ Methods ------------------------------------------------------------ @Override protected Rectangle getBox(Glyph stick) { Point2D bottom = stick.getStopPoint(VERTICAL); Rectangle box = new Rectangle( (int) Math.rint(bottom.getX()), (int) Math.rint(bottom.getY() - (1.5 * nHeight)), nWidth, 2 * nHeight); stick.addAttachment("br", box); return box; }
// ~ Methods ------------------------------------------------------------ // Retrieve the distance with proper staff border @Override protected double getValue(GlyphContext context) { Glyph stick = context.stick; Point2D stop = stick.getStopPoint(VERTICAL); // Which staff area contains the bottom of the stick? StaffInfo staff = staffManager.getStaffAt(stop); // How far are we from the stop of the staff? double staffBottom = staff.getLastLine().yAt(stop.getX()); double dy = sheet.getScale().pixelsToFrac(Math.abs(staffBottom - stop.getY())); // Change limits according to rough & partDefining if (rough && context.isPartDefining) { setLowHigh(constants.maxStaffShiftDyLowRough, constants.maxStaffShiftDyHighRough); } else { setLowHigh(constants.maxStaffShiftDyLow, constants.maxStaffShiftDyHigh); } // Side-effect if (dy <= getLow()) { context.botStaff = context.bottomArea; } return dy; }
// ~ Methods ------------------------------------------------------------ @Override public void onEvent(UserEvent event) { try { // Ignore RELEASING if (event.movement == MouseMovement.RELEASING) { return; } if (event instanceof GlyphEvent) { BarsChecker.GlyphContext context = null; GlyphEvent glyphEvent = (GlyphEvent) event; Glyph glyph = glyphEvent.getData(); if (glyph != null) { // Make sure this is a rather vertical stick if (Math.abs(glyph.getInvertedSlope()) <= constants.maxCoTangentForCheck.getValue()) { // Apply a fresh suite context = new BarsChecker.GlyphContext(glyph); applySuite(new BarCheckSuite(), context); return; } } tellObject(null); } } catch (Exception ex) { logger.warn(getClass().getName() + " onEvent error", ex); } }
/** * Check if the stick/bar is a thick one * * @param stick the bar stick to check * @return true if thick */ private boolean isThickBar(Glyph stick) { // Max width of a thin bar line, otherwise this must be a thick bar final int maxThinWidth = scale.toPixels(constants.maxThinWidth); // Average width of the stick final int meanWidth = (int) Math.rint((double) stick.getWeight() / (double) stick.getLength(Orientation.VERTICAL)); return meanWidth > maxThinWidth; }
// ~ Methods ------------------------------------------------------------ // Retrieve the difference between stick slope and global slope @Override protected double getValue(GlyphContext context) { Glyph stick = context.stick; Point2D start = stick.getStartPoint(VERTICAL); Point2D stop = stick.getStopPoint(VERTICAL); // Beware of sign of stickSlope (it is opposite of globalSlope) double stickSlope = -(stop.getX() - start.getX()) / (stop.getY() - start.getY()); return Math.abs(stickSlope - sheet.getSkew().getSlope()); }
// ~ Methods ------------------------------------------------------------ // Retrieve the length data @Override protected double getValue(GlyphContext context) { Glyph stick = context.stick; int height = Integer.MAX_VALUE; // Check wrt every staff in the stick getRange for (int i = context.topArea; i <= context.bottomArea; i++) { StaffInfo area = staffManager.getStaff(i); height = Math.min(height, area.getHeight()); } return sheet.getScale().pixelsToFrac(height - stick.getLength(Orientation.VERTICAL)); }
// ~ Methods ------------------------------------------------------------ // Retrieve the distance with proper staff border @Override protected double getValue(GlyphContext context) { Glyph stick = context.stick; Point2D stop = stick.getStopPoint(VERTICAL); // Which staff area contains the bottom of the stick? StaffInfo staff = staffManager.getStaffAt(stop); // How far are we from the stop of the staff? double staffBottom = staff.getLastLine().yAt(stop.getX()); double dy = sheet.getScale().pixelsToFrac(Math.abs(staffBottom - stop.getY())); return dy; }
// ~ Methods ------------------------------------------------------------ // Retrieve the stick abscissa @Override protected double getValue(GlyphContext context) { Glyph stick = context.stick; double dist = Double.MAX_VALUE; // Check wrt every staff in the stick range for (int i = context.topArea; i <= context.bottomArea; i++) { StaffInfo staff = staffManager.getStaff(i); Point2D top = staff.getFirstLine().getEndPoint(LEFT); Point2D bot = staff.getLastLine().getEndPoint(LEFT); double y = (top.getY() + bot.getY()) / 2; double x = stick.getPositionAt(y, Orientation.VERTICAL); double dx = x - staff.getAbscissa(LEFT); dist = Math.min(dist, dx); } return sheet.getScale().pixelsToFrac(dist); }