added default instruments (sin, saw)

This commit is contained in:
Mustafa 2014-05-15 15:22:29 -07:00
parent 6de25cd357
commit 02c38b19d3
2 changed files with 63 additions and 11 deletions

View file

@ -3,23 +3,71 @@
(require rsc3 rhs/rhs) (require rsc3 rhs/rhs)
;; simplifies sending messages to server
(define (send-msg msg)
(with-sc3 (lambda (fd)
(send fd msg))))
(define current-node-id 1000)
(define (gen-node-id)
(set! current-node-id (add1 current-node-id))
current-node-id)
(define (instrument wave-func)
(letc ([bus 0]
[freq 440])
(out bus (mul 0.2 (wave-func ar freq 0)))))
(define sin-instrument (define sin-instrument
(letc ([bus 0] (letc ([bus 0]
[freq 440]) [freq 440])
(out bus (mul 0.2 (sin-osc ar freq 0))))) (out bus (mul 0.2 (sin-osc ar freq 0)))))
(define saw-instrument
(letc ([bus 0]
[freq 440])
(out bus (mul 0.2 (sin-osc ar freq 0)))))
;; setup ;; setup
(send-synth fd "sin-inst" sin-instrument) ;; show osc messages on server
(with-sc3 (lambda (fd)
(send fd (dump-osc 1))))
(with-sc3 reset)
;; send synthdefs
(with-sc3 (lambda (fd)
(send-synth fd "sin-inst" sin-instrument)))
(define (make-instrument ins) (define (make-instrument ins)
(match ins (match ins
['sin (begin ['sin (let ([node-id (gen-node-id)])
(with-sc3 (lanbda (fd) (send-msg (s-new0 "sin-inst" node-id 1 1))
(send fd ; don't make sound upon creation
(s-new "sin-inst" -1 1 1 (send-msg (n-run1 node-id 0))
node-id)]
[else (error "unknown instrument used")]))
#|
- to stop/run:
(send-msg (n-run1 1001 1))
-
|#
;; ======== test run ===========
(define my-sin (make-instrument 'sin))
]
[else (error "unknown instrument used")]))h

View file

@ -60,7 +60,7 @@
(out 0 (mul (fb-sine-c ar sample-rate 1 (mouse-x kr 1 5 1 0.1) 1.1 (mouse-y kr 0.5 1 1 0.1) 0.1 0.1) 0.2)))) (out 0 (mul (fb-sine-c ar sample-rate 1 (mouse-x kr 1 5 1 0.1) 1.1 (mouse-y kr 0.5 1 1 0.1) 0.1 0.1) 0.2))))
;; fb-sine-c.help.scm ;; fb-sine-c.help.scm
(let* ((x (mouse-x kr 0.1 1 0 0.1)) #;(let* ((x (mouse-x kr 0.1 1 0 0.1))
(f (lambda (m a) (mul-add (lf-noise2 kr x) m a)))) (f (lambda (m a) (mul-add (lf-noise2 kr x) m a))))
(audition (audition
(out 0 (mul (fb-sine-c ar (out 0 (mul (fb-sine-c ar
@ -73,8 +73,12 @@
0.1) 0.1)
0.2)))) 0.2))))
(define (simple-mouse-x start end)
(mouse-x kr start end 0 0.1))
;; like old telephone ring. uses key-state aaaa ;; like old telephone ring. uses key-state aaaa
#; (let ([freq (mouse-x kr 600 2000 1 0.1)]) ; (let ([freq (mouse-x kr 600 2000 1 0.1)])
(let ([freq (simple-mouse-x 600 1500)])
(audition (out 0 (audition (out 0
(mul (sin-osc ar (mul (sin-osc ar
(mul-add (lf-pulse ar 15 0 0.5) 200 freq) (mul-add (lf-pulse ar 15 0 0.5) 200 freq)