Assignment 16
Due Date Thursday 11/15 at 9pm
Purpose To practice iterative refinement and list-processing.
You should submit a single .rkt file containing your responses to all exercises via the Handin Server. We accept NO email submissions.
You are only allowed to use the language specified at the top of this page: failure to do so will result in a 0.
All steps of the design recipe are required except for data examples and templates. However, doing them would be helpful. :)
Project (Part 4)
Recall that in part 3 we asked you to update your music player to display a history of the songs you have listened to. This application is similar to Pandora: you can’t control what song you listen to next, but you can see what you have listened to in the past. However, a more interesting program is one which allows you to choose the song you want to listen to next.
In this part of the project we will develop a program where, upon registering with the server, the server sends the client a message containing the metadata of all songs on the server, as well as their IDs. Note that this does not include the byte-string of the song, and that a well-designed client will need to function properly in between the time it starts and recieves this message from the server. It should be obvious to the user it is waiting for the metadata, even if this state only lasts a brief amount of time.
From there, the user can use the arrow keys (up/down) to tab through the songs available and then use enter (KeyEvent "\r") to send a request to the server to get the SongMsg for that song. Once the song’s information has been downloaded, the user can press " " to play the song as before.
Of course, if we want to request specific songs from the server we will have to update the way we communicate with the server.
; A ClientMsg is a Nat ; representing a request for a SongMsg with a specific ID# ; A ServerMsg is one of: ; - ErrorMsg ; - SongMsg ; - MetadataMsg ; A MetadataMsg is a (list "METADATA" [List-of IDMetaPair]) ; where the list contains all of the metadata and ids of the songs available on the server ; A IDMetaPair is a (list Nat Metadata) ; - where the nat is the id of the song ; - and the metadata contains all of the metadata of the song
Keep in mind, as you do this homework, your big-bang handlers, writing to a file, and reading from a file are all distinct, independent operations. It is recommended you ensure your entire big-bang program works, including updating play counts as songs are played, before working on writing to a file, before working on reading from a file and using that to initialize your world state.
Exercise 1 Update your data definition for a MusicPlayer to account for the changes to your program. What new information do you have to keep track of?
Exercise 2 Revise the display of your client so that instead of showing just a history of songs played, it shows all of the songs available on the server. Be sure to show the playcount (possibly 0) next to each song. This playcount should function much as it did in the past assignment, in that it saves the number of plays across multiple runs of the client. Now, though, you don’t have to have ever listened to a song to display its info and playcount. When tabbing through the songs, there should be some clear visual indication of which song pressing enter would request.
Note that this can only be done once the client has recieved all metadata from the server: be sure to have a proper display indicating that the client is waiting on metadata from the server in this case.
Visual display of the feedback from the song last played as well as info of the song being available to play should work as before.
Exercise 3 Update your world program to allow a user to move through the list of songs available using the up and down arrow keys and press "enter" to request the full song message from the server. Once the SongMsg has been recieved from the server, pressing the spacebar will play the song as before.
Also, be sure to handle up/down arrow keys at the beginning and end of the list of songs; pressing up/down at the top/bottom of your display should loop which song is currently selected back to the bottom/top of the list.
Note that this can only be done once the client has recieved all metadata from the server: be sure to properly handle key events before this happens.