Ejemplo n.º 1
0
  /**
   * printBrick Prints a String representation of a Brick with its subblocks to the error
   * printstream
   */
  public void printBrick() {
    String brickName = this.getName();
    if (!this.getVariant().isEmpty()) {
      brickName += "(" + this.getVariant() + ")";
    }
    String brickKey = BrickLibrary.keyNumToName(this.getKey());
    long brickDur = this.getDuration();
    String brickType = this.getType();
    System.out.println(
        "Printing brick " + brickName + " " + brickType + " " + brickKey + " " + brickDur);

    ArrayList<Block> subBlockList = this.getSubBlocks();
    Iterator<Block> blockIter = subBlockList.iterator();

    while (blockIter.hasNext()) {
      Block currentBlock = blockIter.next();

      if (currentBlock instanceof Brick) {
        Brick currentBrick = (Brick) currentBlock;
        String currentBrickName = currentBrick.getName();
        Long currentBrickKey = currentBrick.getKey();
        String currentBrickKeyString = BrickLibrary.keyNumToName(currentBrickKey);
        long dur = currentBrick.getDuration();
        System.out.println(
            "Printing brick " + currentBrickName + " " + currentBrickKeyString + " " + dur);
      } else if (currentBlock instanceof ChordBlock) {
        ChordBlock currentChord = (ChordBlock) currentBlock;
        String currentChordName = currentChord.getName();
        int currentDuration = currentChord.getDuration();
        System.out.println("Printing Chord" + currentChordName + " " + currentDuration);
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * setDuration Changes the duration to be as close as possible to the newly specified duration
   *
   * @param newDuration, an int duration.
   */
  @Override
  public void setDuration(int newDuration) {
    float newDurFloat = newDuration;
    float ratio = (newDurFloat / this.getDuration());

    List<Block> currentSubBlocks = this.getSubBlocks();
    Iterator<Block> subBlockIter = currentSubBlocks.iterator();
    ArrayList<Block> adjustedSubBlocks = new ArrayList<Block>();

    while (subBlockIter.hasNext()) {
      Block currentBlock = subBlockIter.next();
      if (currentBlock instanceof ChordBlock) {
        ((ChordBlock) currentBlock).changeChordDuration(ratio);
        adjustedSubBlocks.add(currentBlock);
      } else if (currentBlock instanceof Brick) {
        Brick adjustedSubBrick = (Brick) currentBlock;
        int newDur = Math.round(ratio * adjustedSubBrick.getDuration());
        adjustedSubBrick.setDuration(newDur);
        adjustedSubBlocks.add(adjustedSubBrick);
      }
    }

    this.subBlocks = adjustedSubBlocks;
    this.updateDuration();
  }