6.6

Assignment 6

home work!

Programming Language BSL

Due Date Monday 10/01 at 9pm

Purpose To practice designing world programs and working with external libraries.

Expectations
  • 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.

Project Setup

Project (Part 1)

Recall that in part 0 we asked you to design a data definition for a music player. This week, you’re going to be implementing a bare-bones version of this music player that uses that data definition. To ensure that everyone uses a data definition that allows them to add all the necessary features, we have provided our preferred data definition below. You are encouraged to use your own data definition if it is equivalent to this one (i.e., if you used different names), but you can use the one below if you wish.

; (require 2htdp/universe)
; (require 2htdp/image)
; (require neu-fall18)
; 
; A FeedbackString is one of:
; - ""
; - "dislike"
; - "like"
; - "none"
; Interpretation: The feedback that the user gave to the last song played.  The string
; "none" represents that the user gave no feedback, and the string "" represents
; that no feedback has been received yet (i.e., we are playing the first song).
(define FEEDBACKSTRING-EMPTY "")
(define FEEDBACKSTRING-DISLIKE "dislike")
(define FEEDBACKSTRING-LIKE "like")
(define FEEDBACKSTRING-NONE "none")
; (define (feedbackstring-temp fs)
;   (cond
;     [(string=? fs FEEDBACKSTRING-EMPTY) ...]
;     [(string=? fs FEEDBACKSTRING-DISLIKE) ...]
;     [(string=? fs FEEDBACKSTRING-LIKE) ...]
;     [(string=? fs FEEDBACKSTRING-NONE) ...]))
 
(define-struct player [song1 song2 feedback])
 
; A MusicPlayer is a (make-player String String FeedbackString)
; Interpretation: The state of the music player
; - song1 is the bytes of the current song being played
; - song2 is the bytes of the next song to played
; - feedback is the feedback received from the user for the last song played
(define MUSICPLAYER-1 (make-player "fakesong1" "fakesong2" "like"))
; (define (musicplayer-temp mp)
;   ... (player-song1 mp) ... (player-song2 mp) ... (feedbackstring-temp (player-feedback mp)) ...)

In this part of the project, we will actually be playing songs. To open the music player, you will use the play-sound function that is provided by the neu-fall18 library you installed above; its signature and purpose are:

; play-sound : String -> FeedbackString
; Opens a simple music player and plays the MP3 that is represented by the passed-in String.
; The String should be the raw bytes of the MP3. The player does not return until the
; user clicks the Like button (returning "like"), the user clicks the Dislike button
; (returning "dislike"), or the song ends with no user clicks (returning "none").
; NOTE: This function calls big-bang and therefore cannot be tested with check-expect

Please note that play-sound is only guaranteed to correctly play MP3-encoded files (i.e., those files ending in .mp3). It may not work for copy-protected files (.aac), or other encodings (.ogg). You will not be able to test any function that calls play-sound since you cannot guarantee what the user will do while the song is playing (whether they will click the like button, the dislike button, or neither).

Exercise 1 Use the file-as-bytes function to transform a file path into a String of bytes. Define a couple of these byte strings as constants for use in your program.

If you do not have any MP3s handy, you can download some from The Free Music Archive. Once you download the files, you will need to obtain the full path to the file to pass into file-as-bytes. On Windows, this path might look like

"C:\\Users\\amislove\\Downloads\\myfancymp3.mp3"

On OS X, this path might look like

"/Users/amislove/Downloads/myfancymp3.mp3"

Alternatively, you can move the MP3 files into the directory of your .rkt file, and then simply use

"myfancymp3.mp3"

Exercise 2 Design a world program that runs a music player. In brief, this player has two features: (1) it will display the most recently-provided feedback from the user in an image, and (2) when the user presses the space bar, it will play the next song and await the feedback. The player only supports two songs, so each time the user presses the space bar, it will effectively alternate between playing the two songs.

In more detail, the player should display the feedback string from the most recently played song, as well as an instruction to "Press space to play a song". You are free to design this user interface as you wish, as long as it meets the requirements specified here.

When the user presses the spacebar, the play-sound function should be called on the current song’s byte string (song1), and the songs should be “swapped” so that the next song to play will be song2. The feedback from play-sound should replace the prior FeedbackString stored in the MusicPlayer. You may use whichever songs you like in your music player. Any other key presses should be ignored.