Beispiel #1
0
  // ~ Methods ----------------------------------------------------------------
  // ------------//
  // runPattern //
  // ------------//
  @Override
  public int runPattern() {
    int successNb = 0;

    // Constants for clef verification
    final double maxBassDotPitchDy = constants.maxBassDotPitchDy.getValue();
    final double maxBassDotDx = scale.toPixels(constants.maxBassDotDx);

    // Specific adapter definition for bass clefs
    CompoundAdapter bassAdapter = new BassAdapter(system, Grades.clefMinGrade);

    for (Glyph top : system.getGlyphs()) {
      // Look for top dot
      if ((top.getShape() != Shape.DOT_set)
          || (Math.abs(top.getPitchPosition() - -3) > maxBassDotPitchDy)) {
        continue;
      }

      int topX = top.getCentroid().x;
      StaffInfo topStaff = system.getStaffAt(top.getCentroid());

      // Look for bottom dot right underneath, and in the same staff
      for (Glyph bot : system.getGlyphs()) {
        if ((bot.getShape() != Shape.DOT_set)
            || (Math.abs(bot.getPitchPosition() - -1) > maxBassDotPitchDy)) {
          continue;
        }

        if (Math.abs(bot.getCentroid().x - topX) > maxBassDotDx) {
          continue;
        }

        if (system.getStaffAt(bot.getCentroid()) != topStaff) {
          continue;
        }

        // Here we have a couple
        logger.debug("Got bass dots #{} & #{}", top.getId(), bot.getId());

        Glyph compound = system.buildCompound(top, true, system.getGlyphs(), bassAdapter);

        if (compound != null) {
          successNb++;
        }
      }
    }

    return successNb;
  }
Beispiel #2
0
  /**
   * 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;
  }
 @Override
 public String toString() {
   return "stick#" + stick.getId();
 }