Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. (require rsound)
  2. (require 2htdp/universe)
  3.  
  4. ;;; DATA DEFINITIONS ;;;
  5.  
  6. ; a second is a number
  7. ; representing a length of time
  8.  
  9. ; a frame is a number
  10. ; representing a length of time
  11.  
  12. ; a playerstate is a (make-playerstate boolean boolean number)
  13. (define-struct playerstate (1? 2? songpos))
  14. ; where
  15. ; 1? represents whether the first track is playing,
  16. ; 2? represents whether the second track is playing,
  17. ; and
  18. ; songpos represents the number of frames that have passed
  19. ; ex
  20. (make-playerstate #t
  21. #t
  22. 0)
  23.  
  24. ;;; GLOBAL CONSTANTS ;;;
  25. (define FR 48000)
  26. (define TRACK1 (rs-read "sounds/1a.wav"))
  27. (define TRACK2 (rs-read "sounds/1b.wav"))
  28. (define INIT (make-playerstate #t
  29. #t
  30. 0))
  31. (define STREAM (make-pstream))
  32.  
  33. ;;; HELPER FUNCTIONS ;;;
  34.  
  35. ; second -> frame
  36. ; convert seconds to frames
  37. (define (sec s)
  38. (* s FR))
  39. (check-expect (sec 5) (* 5 FR))
  40. (check-expect (sec 0) 0)
  41.  
  42. ; ps -> boolean
  43. ; decide whether the pstream should queue another sound
  44. (define (queue? ps)
  45. #true)
  46.  
  47.  
  48.  
  49. ;;; BIG BANG FUNCTIONS ;;;
  50.  
  51. ; if its time to play then assemble a sound from all of the currently playing sections
  52. ; overlay into one sound and play that or queue each sound
  53.  
  54. ; ps -> ps
  55. ; process a new playerstate
  56. (define (tock ps)
  57. (cond [(queue? ps)
  58. (cond [(playerstate-1? ps) (andqueue STREAM TRACK1 (playerstate-songpos ps)
  59. ps)]
  60. [(playerstate-2? ps) (andqueue STREAM TRACK2 (playerstate-songpos ps)
  61. ps)]
  62. [else ...] ; do nothing
  63. )]
  64. [else ...] ; do nothing
  65. ))
  66.  
  67. ; ps -> image
  68. ; render an image based on the playerstate
  69. (define (render ps)
  70. (empty-scene 200 200))
  71.  
  72. ; ps ke -> ps
  73. ; handle key input and return a new playerstate
  74. (define (key-handler ps ke)
  75. (
  76. )
  77.  
  78. (define (main x)
  79. (big-bang INIT
  80. [on-tick tock (/ 1 48000]
  81. [to-draw render]
  82. [on-key key-handler]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement