| ||||||||||
c. From SongPhrase.javastatic public Phrase riff2(){ double[] phrasedata = {JMC.D4,JMC.EN,JMC.C4,JMC.EN,JMC.E4,JMC.EN,JMC.G4,JMC.EN}; Phrase myPhrase = new Phrase(); myPhrase.addNoteREMOVEDst(phrasedata); return myPhrase; } |
d. From Sound.javapublic Sound reverse(){ Sound target = new Sound(getLength()); int sampleValue; for (int srcIndex=0,trgIndex=getLength()-1; srcIndex < getLength();srcIndex++,trgIndex--) sampleValue = this.getSampleValueAt(srcIndex); target.setSampleValueAt(trgIndex,sampleValue); return target; } |
For part (a), can you explain what childSound = childSound.append(node.collect()) is doing? I can follow the rest of the code, and I understand that in the step before this, the code has just gotten the next after collecting all the children. Is this just adding the children of this node to the ones of the previous one? |
For part (b), are the two for loops interchangeable, or does the the code need to traverse the columns before traversing the rows? |
public Sound reverse.doc |
a.)From SoundBranch.javapublic Sound collect(){ Sound childSound; childSound = new Sound(1); CollectableNode node; if (children != null){ childSound = children.collect(); } if (this.getNext() != null){ node=(CollectableNode) this.getNext(); childSound=childSound.append(node.collect()); } else return childSound; } |
b.) From Picture.javapublic void mirrorHorizontalBottomToTop(){ Pixel topPixel = null; Pixel bottomPixel = null; int mirrorPoint = (int) (getHeight() / 2); for (int y=1; y < mirrorPoint; y++){ for (int x=0; x < getWidth(); x++){ topPixel = getPixel(x,(mirrorPoint - y)); bottomPixel = getPixel(x,(mirrorPoint + y)); topPixel.setColor(bottomPixel.getColor()); } } } |
c. From SongPhrase.javastatic public Phrase riff2(){ Phrase myPhrase = new Phrase(); double[] phrasedata = {JMC.D4,JMC.EN,JMC.C4,JMC.EN,JMC.E4,JMC.EN,JMC.G4,JMC.EN}; myPhrase.addNoteREMOVEDst(phrasedata); return myPhrase; } |