MP3 Player or Noise Maker: Part 1

Brandon Beck: gte196n

Before even starting this assignment, I spent 2 or 3 hours deciding on what methods I would need to make this program short and easy.

I first thought about what attributes I would need in SoundFileGroup.  The first two obvious things were the directory to search in, and the matches that were found in that directory.  After using the Squeak book as a resource, I decided that I would need to have separate code to get each on the file extensions to play; one for each of them.  Initially I decided to throw them into the SoundFileGroup as methods, but then at a second glance I decided to have the code to play the files in a different class because it would allow for better abstraction and easier access to code.  That way, if I later wanted to support a different sound file type, it would be easy to change.  Also, if I were to write another class that wanted to be able to play music (for example an alarm clock that plays a song when it reaches "zero").

Now I had two classes.  I started with the most specific stuff.  Since I had already determined that I would need a different method to play each one of the file extensions: aiff, mp3, midi, and wav, I would need 4 methods in my Players class (the class used to play music files).  Thus I had a class Players with four methods in it: playAIFF, playMP3, playMIDI, and playWAV.  I didn't start coding yet; I still wanted to get the rest of my design down, so I went onto designing SoundFileGroup.

With SoundFIleGroup, I had already determined that I would need a dirName, and a set of matches found given the search criteria.  After more thought, I determined that I would need another variable to hold the songs playing (player).  By just looking at the requirements, I knew that I would need at least five methods in this class: playAndWait, startPlaying, stopPlaying, fileArray, and printString.  As I thought about printString, I started looking at other classes in squeak because everything has a printString.  As I browsed around the squeak browser, I noticed that printString called printOn, and printOn was coded for each class.  After seeing this, I decided that I would not need to code printString, but rather a printOn method.

Since I wanted to print both that it was a soundfilegroup, and the matches that were found, printOn would have two purposes.  Therefore, I decided to break each printing job up and make two new methods: printElementsOn: using: and printNameOn.  printNameOn printed out that it was a SoundFileGroup while printElementsOn: using: printed out the songs that were matched.  Now I turned to fileArray.  I figured fileArray was already simple enough and would not need to call another method.  playAndWait is where I would need to make use of the Players class and my player instance variable.  For this, I can just traverse my matches, and check for the appropriate extension and call the correct play mehtod in my Players class.  I want to code the play methods to play the entire song, so I should not have to check anything here.  For the startPlaying, I think I should just be able to make a new process with Background priority and call my playAndWait method.  And for stopPlaying, just stop the process.  This means I need another instance variable (process).

After I finished with this, I thought about how I was going to code match: from:  I spent most of this time searching the squeak browser.  I found fullNamesOfAllFilesInSubtree and includesSubString.  So, think I can get all the file names of a subtree and do a do loop on my collection of search specs while doing another do loop within that one on the file names.  Then I can call includes SubString.  In the design part, the match: from: method took the longest to decide what to do.  One reason for this is because it will probably be the largest (in length of code) and I spent most of the time searching and getting familiar with FileDirectory and String.

 

After that....I took a good two day break and started the coding!!!  With this desing, which I thought was good and well thought out; I figured I could use this design for the remainder of the assignments without much change.  Also it only took about 2 hours of actual coding to get it to work!  Which is why it is important to design first and code second!!!