moved functions around and added tests to main.rkt

This commit is contained in:
Mustafa 2014-03-14 13:27:31 -07:00
parent baee16e3f4
commit 5440535a7a

View file

@ -1557,6 +1557,17 @@
clear-sched
(g-new1 1 0 0))))))
;; port -> string -> ugen -> ()
(define send-synth
(lambda (fd n u)
(async fd (d-recv (encode-graphdef (synthdef n u))))))
;; port -> ugen -> ()
(define play
(lambda (fd u)
(send-synth fd "anonymous" u)
(send fd (s-new0 "anonymous" -1 1 1))))
;; (socket -> a) -> a
(define with-udp-sc3
(lambda (f)
@ -1576,6 +1587,18 @@
;; (socket -> a) -> a
(define with-sc3 with-udp-sc3)
;; ((socket -> a) -> a) -> (ugen -> ())
(define audition-using
(lambda (f)
(lambda (u)
(f
(lambda (fd)
(play fd u))))))
;; ugen -> ()
(define audition (audition-using with-udp-sc3))
;; [string]
(define status-fields
(list "# UGens "
@ -1880,28 +1903,6 @@
(lambda (n f)
(mix (mce-fill n f))))
;; port -> string -> ugen -> ()
(define send-synth
(lambda (fd n u)
(async fd (d-recv (encode-graphdef (synthdef n u))))))
;; port -> ugen -> ()
(define play
(lambda (fd u)
(send-synth fd "anonymous" u)
(send fd (s-new0 "anonymous" -1 1 1))))
;; ((socket -> a) -> a) -> (ugen -> ())
(define audition-using
(lambda (f)
(lambda (u)
(f
(lambda (fd)
(play fd u))))))
;; ugen -> ()
(define audition (audition-using with-udp-sc3))
;; float
(define dinf
9.0e8)
@ -1973,4 +1974,46 @@
;; Local Variables:
;; truncate-lines:t
;; End:
;; End:
(module+ test
(require rackunit)
;; name, ugen expr -> bytes (synthdef)
;; similar to send-synth in rsc3
(define (ugens->synthdef name ugens)
(encode-graphdef (synthdef name ugens)))
;; these should not break
(check-equal? (ugens->synthdef "sine" (mul (sin-osc ar 440 0) 0.1))
(bytes-append
#"SCgf\0\0\0\0\0\1\4sine\0\3C\334\0\0\0\0\0\0=\314\314\315"
#"\0\0\0\0\0\2\6SinOsc\2\0\2\0\1\0\0\377\377\0\0\377\377\0\1\2"
#"\fBinaryOpUGen\2\0\2\0\1\0\2\0\0\0\0\377\377\0\2\2"))
(check-equal? (ugens->synthdef "sine0" (out 0 (mul (sin-osc ar 440 0) 0.1)))
(bytes-append
#"SCgf\0\0\0\0\0\1\5sine0\0\3\0\0\0\0C\334\0\0=\314\314\315"
#"\0\0\0\0\0\3\6SinOsc\2\0\2\0\1\0\0\377\377\0\1\377\377\0\0\2"
#"\fBinaryOpUGen\2\0\2\0\1\0\2\0\0\0\0\377\377\0\2\2\3Out\2\0\2"
#"\0\0\0\0\377\377\0\0\0\1\0\0"))
(check-equal? (ugens->synthdef "ring" (out 0 (mul (ring4 (f-sin-osc ar 800 0)
(f-sin-osc ar (x-line kr 200 500 5 do-nothing) 0))
0.125)))
(bytes-append
#"SCgf\0\0\0\0\0\1\4ring\0\6\0\0\0\0DH\0\0CH\0\0C\372\0\0@\240\0\0>"
#"\0\0\0\0\0\0\0\0\6\5XLine\1\0\4\0\1\0\0\377\377\0\2\377\377\0\3"
#"\377\377\0\4\377\377\0\0\1\aFSinOsc\2\0\2\0\1\0\0\0\0\0\0\377\377"
#"\0\0\2\aFSinOsc\2\0\2\0\1\0\0\377\377\0\1\377\377\0\0\2\fBinaryOpUGen"
#"\2\0\2\0\1\0!\0\2\0\0\0\1\0\0\2\fBinaryOpUGen\2\0\2\0\1\0\2\0\3\0\0\377\377"
#"\0\5\2\3Out\2\0\2\0\0\0\0\377\377\0\0\0\4\0\0"))
)