Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (require rsound)
- (require 2htdp/universe)
- ;;; DATA DEFINITIONS ;;;
- ; a second is a number
- ; representing a length of time
- ; a frame is a number
- ; representing a length of time
- ; a playerstate is a (make-playerstate boolean boolean number)
- (define-struct playerstate (1? 2? songpos))
- ; where
- ; 1? represents whether the first track is playing,
- ; 2? represents whether the second track is playing,
- ; and
- ; songpos represents the number of frames that have passed
- ; ex
- (make-playerstate #t
- #t
- 0)
- ;;; GLOBAL CONSTANTS ;;;
- (define FR 48000)
- (define TRACK1 (rs-read "sounds/1a.wav"))
- (define TRACK2 (rs-read "sounds/1b.wav"))
- (define INIT (make-playerstate #t
- #t
- 0))
- (define STREAM (make-pstream))
- ;;; HELPER FUNCTIONS ;;;
- ; second -> frame
- ; convert seconds to frames
- (define (sec s)
- (* s FR))
- (check-expect (sec 5) (* 5 FR))
- (check-expect (sec 0) 0)
- ; ps -> boolean
- ; decide whether the pstream should queue another sound
- (define (queue? ps)
- #true)
- ;;; BIG BANG FUNCTIONS ;;;
- ; if its time to play then assemble a sound from all of the currently playing sections
- ; overlay into one sound and play that or queue each sound
- ; ps -> ps
- ; process a new playerstate
- (define (tock ps)
- (cond [(queue? ps)
- (cond [(playerstate-1? ps) (andqueue STREAM TRACK1 (playerstate-songpos ps)
- ps)]
- [(playerstate-2? ps) (andqueue STREAM TRACK2 (playerstate-songpos ps)
- ps)]
- [else ...] ; do nothing
- )]
- [else ...] ; do nothing
- ))
- ; ps -> image
- ; render an image based on the playerstate
- (define (render ps)
- (empty-scene 200 200))
- ; ps ke -> ps
- ; handle key input and return a new playerstate
- (define (key-handler ps ke)
- (
- )
- (define (main x)
- (big-bang INIT
- [on-tick tock (/ 1 48000]
- [to-draw render]
- [on-key key-handler]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement