Skip to content

Instantly share code, notes, and snippets.

@jbclements
Created October 12, 2013 00:21
Show Gist options
  • Select an option

  • Save jbclements/6944055 to your computer and use it in GitHub Desktop.

Select an option

Save jbclements/6944055 to your computer and use it in GitHub Desktop.
code from class, 2013-10-11. Requires today's version of rsound at least, to include piano sounds.
(require rsound)
(require rsound/piano-tones)
(require 2htdp/universe)
(require 2htdp/image)
;(play (piano-tone 62))
(define (both a b) b)
;; a world is zero
;; a note-num is a number
;; a triad-choice is one of
;; - 0, indicating the "root",
;; - 1, indicating the "third",
;; - 2, rep. the "fifth", or
;; - 3, rep. the "octave"
;; nth-triad-note : returns the nth triad note
;; note-num triad-choice -> note-num
(define (nth-triad-note center choice)
(cond [(= choice 0) center]
[(= choice 1) (+ center 4)]
[(= choice 2) (+ center 7)]
[(= choice 3) (+ center 12)]))
(check-expect (nth-triad-note 23 0) 23)
(check-expect (nth-triad-note 23 1) 27)
(check-expect (nth-triad-note 23 2) 30)
(check-expect (nth-triad-note 23 3) 35)
(check-expect (nth-triad-note 25 3) 37)
;; note-num key -> note-num
;; toggle the world between 60 and 67
(define (key-handler w k)
(cond [(= w 60) 67]
[(= w 67) 60]))
(check-expect (key-handler 60 "p") 67)
(check-expect (key-handler 67 "p") 60)
;; world -> world
;; plays a note
(define (play-note w)
(both (play (piano-tone
(nth-triad-note w (random 4))))
w))
#;(check-expect (play-note 28) 28)
(define (bogus-draw dc)
(empty-scene 100 100))
(big-bang 60
[to-draw bogus-draw]
[on-tick play-note 1/4]
[on-key key-handler])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment