// ~ Methods ------------------------------------------------------------ // Retrieve the distance with proper staff border @Override protected double getValue(GlyphContext context) { Glyph stick = context.stick; Point2D start = stick.getStartPoint(VERTICAL); // Which staff area contains the top of the stick? StaffInfo staff = staffManager.getStaffAt(start); // How far are we from the start of the staff? double staffTop = staff.getFirstLine().yAt(start.getX()); double dy = sheet.getScale().pixelsToFrac(Math.abs(staffTop - start.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.topStaff = context.topArea; } return dy; }
/** * Check that each staff begins with a clef. * * @return the number of clefs rebuilt */ @Override public int runPattern() { int successNb = 0; int staffId = 0; for (StaffInfo staff : system.getStaves()) { staffId++; // Define the inner box to intersect clef glyph(s) int left = (int) Math.rint(staff.getAbscissa(HorizontalSide.LEFT)); Rectangle inner = new Rectangle( left + (2 * xOffset) + (clefWidth / 2), staff.getFirstLine().yAt(left) + (staff.getHeight() / 2), 0, 0); inner.grow((clefWidth / 2) - xOffset, (staff.getHeight() / 2) - yOffset); // Remember the box, for visual debug staff.addAttachment(" ci", inner); // We must find a clef out of these glyphs Collection<Glyph> glyphs = system.lookupIntersectedGlyphs(inner); logger.debug("{}{}", staffId, Glyphs.toString(" int", glyphs)); // We assume than there can't be any alien among them, so we should // rebuild the larger glyph which the alien had wrongly segmented Set<Glyph> impacted = new HashSet<>(); for (Glyph glyph : glyphs) { if (glyph.getShape() == Shape.STEM) { logger.debug("Clef: Removed stem#{}", glyph.getId()); impacted.addAll(glyph.getConnectedNeighbors()); impacted.add(glyph); } } if (!impacted.isEmpty()) { // Rebuild the larger glyph Glyph larger = system.buildCompound(impacted); if (larger != null) { logger.debug("Rebuilt stem-segmented {}", larger.idString()); } // Recompute the set of intersected glyphs glyphs = system.lookupIntersectedGlyphs(inner); } if (checkClef(glyphs, staff)) { successNb++; } } return successNb; }
// ~ Methods ------------------------------------------------------------ // Retrieve the distance with proper staff line @Override protected double getValue(GlyphContext context) { Glyph stick = context.stick; Point2D start = stick.getStartPoint(VERTICAL); // Which staff area contains the top of the stick? StaffInfo staff = staffManager.getStaffAt(start); // How far are we from the start of the staff? double staffTop = staff.getFirstLine().yAt(start.getX()); double dy = sheet.getScale().pixelsToFrac(Math.abs(staffTop - start.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); }