示例#1
0
  /**
   * Deletes all Units in the specified range, adjusting the rhythm value of the preceding Unit.
   *
   * @param first the index of the first Unit in the range
   * @param last the index of the last Unit in the range
   */
  public void delUnits(int first, int last) {
    // Trace.log(2, "delUnits from " + last + " down to " + first);

    // It seems like this approach could be fairly slow

    for (int i = last; i >= first; i--) {
      delUnit(i);
    }
  }
示例#2
0
  /**
   * Sets the slot at the specified unitIndex to the specified Unit.
   *
   * @param unitIndex the index of the slot to put the Unit in
   * @param unit the Unit to set
   */
  public void newSetUnit(int unitIndex, Unit unit) {
    if (unit != null) {
      // System.out.println("\nnewSetUnit " + unitIndex + " to " + unit);
    }
    // checkConsistency("start of newSetUnit");
    if (unitIndex >= size || unitIndex < 0) {
      return; // shouldn't happen, but can?
    }

    if (unit == null) {
      delUnit(unitIndex);
      return;
    } else {
    }

    // Pre-conditioning: If unit is too long for part, truncate it first:

    int unitDuration = unit.getRhythmValue();

    int nextUnitStart = unitIndex + unitDuration;

    if (nextUnitStart >= size) {
      unit = unit.copy();
      unit.setRhythmValue(size - unitIndex);
      nextUnitStart = size;
    }

    // If this unit overlays one or more units, set them to null.
    // Let makeConsistent fix things up.

    for (int index = unitIndex; index < nextUnitStart; index++) {
      slots.set(index, null);
    }

    // If the new unit overlays part of another unit, replace the latter
    // with a rest.
    if (nextUnitStart < size && slots.get(nextUnitStart) == null) {
      int nextUnitEnd = getNextIndex(nextUnitStart);
      if (this instanceof MelodyPart) {
        slots.set(nextUnitStart, new Rest(nextUnitEnd - nextUnitStart));
      } else {
        // HB - Disabled as of 7-8-13, not sure this is needed when pasting
        //       chords back into leadsheet.
        // slots.set(nextUnitStart, new Chord(nextUnitEnd - nextUnitStart));
      }
    }

    // Place the new unit
    setSlot(unitIndex, unit, "leaving newSetUnit");

    // Re-eneable this!! checkConsistency("end of newSetUnit");
  }
示例#3
0
  /**
   * Sets the slot at the specified unitIndex to the specified Unit.
   *
   * @param unitIndex the index of the slot to put the Unit in
   * @param unit the Unit to set
   */
  public void setUnit(int unitIndex, Unit unit) {
    if (unit != null)
      // System.out.println("setUnit " + unitIndex + " to " + unit);
      if (unitIndex >= size || unitIndex < 0) {
        return; // shouldn't happen, but can.
      }

    // Trace.log(0, "setting Unit at " + unitIndex + " to " + (unit == null ? null :
    // unit.toLeadsheet()));
    // if we want to set it to empty, we are effectively deleting it
    if (unit == null) {
      delUnit(unitIndex); // Tracing this produces too much output
      return;
    }

    // Trace.log(3, "setting Unit at " + unitIndex + " to " + unit.toLeadsheet());

    // rk: I really do not follow the logic having to do with old note values.

    Unit oldUnit = slots.get(unitIndex);

    int rv = getUnitRhythmValue(unitIndex);

    // if the slot is empty, we need to find what the rhythm value should be

    if (oldUnit == null) {
      // Note: When next unit is a rest, the above may had the effect of cutting the inserted note
      // short!!
      // See compensating code below.

      int nextIndex = getNextIndex(unitIndex);

      unitCount++;
      Unit prevUnit = getPrevUnit(unitIndex);
      if (prevUnit != null) {
        // Trace.log(3, "in setUnit - A, setting rhythmValue");
        // we also need to change the rv of the previous Unit
        prevUnit.setRhythmValue(prevUnit.getRhythmValue() - rv);
      }
    } else {
      // if there was already a Unit there, we already know the rv
      rv = oldUnit.getRhythmValue();
    }

    // Trace.log(3, "in setUnit - B, setting rhythmValue");
    unit.setRhythmValue(rv);
    slots.set(unitIndex, unit);
  }