/**
   * Return the next downbeat (beat 1) after the given point
   *
   * @param r
   * @return
   */
  public Rational nextDownBeat(Rational r) {
    Rational meterEstablishedAt = _data.floorKey(r);
    TimeSignature ts = _data.get(meterEstablishedAt);
    Rational result = meterEstablishedAt;
    Rational inc = Rational.get(ts.TOP);
    while (result.compareTo(r) <= 0) {
      result = result.plus(inc);
    }

    // Look ahead - if a new Time Signature overrode our
    // old time signature before it completed a measure
    // we need to compensate for that.
    Rational higher = _data.higherKey(r);

    if (higher != null && result.compareTo(higher) > 0) result = higher;

    return result;
  }