Skip to content

Instantly share code, notes, and snippets.

@jbclements
Forked from ekajjake/notefilter.rkt
Created November 15, 2013 18:51
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/7489591 to your computer and use it in GitHub Desktop.
Save jbclements/7489591 to your computer and use it in GitHub Desktop.
(require rsound)
;a note is
;(make-note number number number)
(define-struct note (pitch time duration))
;a list-of-notes is one of:
;-empty, or
;-(cons note list-nof-notes)
;list-of-notes -> list-of-notes
;takes in a list of notes and produces a list of notes containing only those that end in the first 10 seconds
(define (note-filter lon)
(cond[(empty? lon) empty]
[else (if (> (* 10 44100) (+ (note-duration (first lon)) (note-time (first lon))))
(cons (first lon) (note-filter (rest lon)))
(note-filter (rest lon)))]))
(check-expect (note-filter (cons (make-note 100 10000 44100)(cons (make-note 100 10000 (* 11 44100)) (cons (make-note 100 441001 44100) empty))))
(cons (make-note 100 10000 44100) empty))
(check-expect (note-filter (cons (make-note 100 10000 44100)(cons (make-note 100 10000 (* 9 44100)) (cons (make-note 100 441001 44100) empty))))
(cons (make-note 100 10000 44100) (cons (make-note 100 10000 (* 9 44100)) empty)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment