Skip to content

Instantly share code, notes, and snippets.

@jbclements
Forked from anonymous/CPE 123 11.15.13
Last active December 28, 2015 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbclements/7493671 to your computer and use it in GitHub Desktop.
Save jbclements/7493671 to your computer and use it in GitHub Desktop.
;; Nancy Truong, Mitchell Salles, Dan Stone
;; CPE 123 (3:00 P - 5:00 P)
(define (s sec) (* 44100 sec))
;; a note is (make-note midi-num frames frames)
(define-struct note (pitch time dur))
;; note -> boolean
(define (check-if-first-ten n)
(if (<= (+ (note-time n) (note-dur n)) (s 10)) true false))
; list-of-notes -> list-of-notes
;; returns alist of notes that end in the first 10 seconds
(define (first-ten lon)
(cond [(empty? lon) empty]
[else
(if (check-if-first-ten (first lon))
(cons (first lon)
(first-ten (rest lon)))
(first-ten (rest lon)))]))
(check-expect (first-ten (cons (make-note 40 0 (s 2))
(cons (make-note 50 (s 3) (s 2))
(cons (make-note 40 (s 5) (s 4))
(cons (make-note 40 (s 10) (s 2)) empty)))))
(cons (make-note 40 0 (s 2))
(cons (make-note 50 (s 3) (s 2))
(cons (make-note 40 (s 5) (s 4)) empty))))
(check-expect (first-ten (cons (make-note 40 (s 9) (s 2))
(cons (make-note 50 (s 11) (s 2))
(cons (make-note 40 (s 13) (s 4))
(cons (make-note 40 (s 3) (s 2)) empty)))))
(cons (make-note 40 (s 3) (s 2)) empty))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment