/** * 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); } } }
/** * Brick (Special launcher constructor) Creates a specific launcher from a single chord * * @param c : a ChordBlock * @param name : indentifies the type of launcher (a String) * @param m : the new brick's mode */ public Brick(ChordBlock c, String name, String m) { super(name + " " + LAUNCHER_KEYWORD); key = c.getKey(); type = LAUNCHER_KEYWORD; ArrayList<Block> singleton = new ArrayList<Block>(); singleton.add(c); subBlocks = singleton; duration = c.getDuration(); mode = m; endValue = c.getSectionEnd(); }
/** * Brick (Launcher constructor) Creates a Launcher from a single chord * * @param c : a ChordBlock * @param m : the new brick's mode */ public Brick(ChordBlock c, String m) { super(LAUNCHER_KEYWORD); key = (c.getKey() + PostProcessor.DOM_ADJUST) % PostProcessor.OCTAVE; type = LAUNCHER_KEYWORD; ArrayList<Block> singleton = new ArrayList<Block>(); singleton.add(c); subBlocks = singleton; duration = c.getDuration(); mode = m; endValue = c.getSectionEnd(); }
/** * 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(); }