Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

PreQuiz 3 - Spring 2006

Consider the below addition to the class SoundTreeTest:

public class SoundTreeExample {

  ScaleBranch scaledBranch; // Needed between methods
  
  SoundBranch root;
  public SoundBranch root(){return root;}
  
//Ignore setUp()

    public void setUp3() {
    FileChooser.setMediaPath("D:/cs1316/MediaSources/");
    Sound clap = new Sound(FileChooser.getMediaPath("clap-q.wav"));
    Sound chirp = new Sound(FileChooser.getMediaPath("chirp-2.wav"));
    Sound rest = new Sound(FileChooser.getMediaPath("rest-1.wav"));
    Sound snap = new Sound(FileChooser.getMediaPath("snap-tenth.wav"));
    Sound clink = new Sound(FileChooser.getMediaPath("clink-tenth.wav"));
    Sound clave = new Sound(FileChooser.getMediaPath("clave-twentieth.wav"));
    Sound gong = new Sound(FileChooser.getMediaPath("gongb-2.wav"));
    Sound guzdial = new Sound(FileChooser.getMediaPath("guzdial.wav"));
    Sound is = new Sound(FileChooser.getMediaPath("is.wav"));
   
    root = new SoundBranch();
    SoundNode sn;
    
    SoundBranch branch1 = new SoundBranch();
    sn = new SoundNode(guzdial.append(is).append(snap));
    branch1.addREMOVEDld(sn);
    sn = new SoundNode(clink.append(snap).append(clave));
    branch1.addREMOVEDld(sn);
    sn = new SoundNode(guzdial.append(is).append(is));
    branch1.addREMOVEDld(sn);
    root.addREMOVEDld(branch1);
    
    scaledBranch = new ScaleBranch(0.5);
    sn = new SoundNode(guzdial.append(is).append(gong));
    scaledBranch.addREMOVEDld(sn);
    root.addREMOVEDld(scaledBranch);

    ScaledBranch scaledBranch2 = new ScaleBranch(2.0);
    sn = new SoundNode(clink.append(clave).append(gong));
    scaledBranch2.addREMOVEDld(sn);
    sn = new SoundNode(rest.append(chirp).append(clap));
    scaledBranch2.addREMOVEDld(sn);
    scaledBranch.addREMOVEDld(scaledBranch2);

    SoundBranch branch2 = new SoundBranch();
    sn = new SoundNode(clap.append(clap).append(clave));
    branch2.addREMOVEDld(sn);
    sn = new SoundNode(snap.append(snap).append(clave));
    branch2.addREMOVEDld(sn);
    root.addREMOVEDld(branch2);
    
    root.playFromMeOn();
  }

//Ignore the rest.

}


We'll execute this method like this:
> SoundTreeExample ste = new SoundTreeExample();
> ste.setUp3()


  1. Draw a diagram of what the nodes (branches, nodes, everything) connected to root will look like. Be sure to show what's contained in each node, and be sure to show what the child and next references point to – and distinguish between them. (Remember that there's a difference between how we conceptually think of as "children" and how we're IMPLEMENTING "children".)

Comments? Questions? Sample answers you'd like feedback on?




So, I just realized for the first time on Monday what exactly this whole child thing means :)
When we do Branch.addREMOVEDld(someKindOfNode), there's actually 2 possible things that can happen:
1) If the branch has no child, someKindOfNode becomes the child (stored in the variable 'children')
2) If there's already a child, we don't add another one! Instead, we go into linked list mode, setting the existing child's next to point to someKindOfNode.

I had originally thought that children worked like a sort of second (and separate) linked list structure...
Instead, each Branch has only one child, and trying to add more children to that branch adds to the branch's child's next, not the branch's "children" (or the branch's next...)

I think I was initially confused because the branches have something called 'children,' which indicates plurality...

So, maybe none of that is really any news to anyone, but I found myself rather enlightened when we went over it in recitation.
And, if I've gotten it all wrong, somebody please un-enlighten me before Monday :)
~Jim
YES! Exactly what it means! NOTE! I changed the code at 4:07 pm on 3/9 I decided to make the branches a little more complicated, to draw out the children/next distinction. Mark Guzdial

Um, I a little confused.....

root
branch1
sn = guzidal is snap click snap clave guzidal is is

So root has the child "branch1" that has the child "sn" which is a soundnode that has the list of sounds listed in the order "guzidal is snap click snap clave guzidal is is"? And since branch1 is the first child it will be played first as well?


Well, since we're not shown the code for playFromMeOn, I think that we have to assume that it looks like the CollectableNode that we have by default–this.collect().play(), and not this.collectAfter().play(). And collect() gets the child, then appends the next... So, yes.
btw, I assume that your "guzidal is snap click snap clave guzidal is is" is meant to say clink... If so, then that should be right.
~Jim

Notice that these sound nodes each contain three concatenated sounds. That's not three nodes – just one node, with one big sound in it (just composed out of three sounds). Mark Guzdial


Where exactly does scaledBranch go? Is it also a branch or the Soundbranch root or seperate? Does it matter that there are two different types of branches used(soundBranch and scaledBranch)? I felt that this was just another way to branch off the root soundBranch(root will have to main branches-soundBranch and scaledBranch, and these branches will each have their own children) but I'm starting to think there is more to it than that.

Why is the ScaleBranch scaledBranch needed between methods?

So, on the quiz, would you want something like:

root–soundbranch–branch1–sn–list of sounds in order

or something totally different?



tree.ppt

Link to this Page