tutorial works till part 2

This commit is contained in:
Mustafa 2014-05-22 10:39:35 -07:00
parent 72dd6033b9
commit 7de4af814b
6 changed files with 104 additions and 40 deletions

View file

@ -42,7 +42,7 @@ The purpose of playing notes on different tracks is we can have different filter
## Examples
### 2. Playing a note using a preset instrument
### 1. Playing a note using a preset instrument
```scheme
@ -56,14 +56,16 @@ The purpose of playing notes on different tracks is we can have different filter
Or you can create a note object then play it.
(define my-note2 (note "sin-inst" 880))
```scheme
(define my-note2 (make-note "sin-inst" 880))
(note-on my-note2)
(sleep 1)
(note-off my-note2)
```
### 1. Creating an instrument
### 2. Creating an instrument
You can either use a preset instrument or define your own instrument
@ -72,14 +74,24 @@ You can either use a preset instrument or define your own instrument
;; create a custom instrument
;; can use oscilators and envelopes
;; "freq" is the frequency parameter
(define-instrument my-custom-inst (mul (sin 20) (sin "freq")))
(make-instrument "my-inst" ([freq 500] [modulaion 20])
(mul (sin-osc ar modulation 0)
(sin-osc ar freq 0)))
(set-note-param my-note "freq" 808)
```
Didn't implement envelopes yet.
;; add envelope to instrument
(define my-inst (preset-instrument "sine"
(envelope A S D R))
```
### 2. Playing a note using a custom instrument
### 3. Playing a note using a custom instrument
Now that we have an instrument, we can use it to play notes on a specific track.
@ -94,7 +106,7 @@ Now that we have an instrument, we can use it to play notes on a specific track.
```
### 3. Add filters to a track
### 4. Add filters to a track
You can add filters to a specific track.

View file

@ -0,0 +1,28 @@
#lang racket
(require oregano)
(display "in example.rkt")
(sleep 0.1)
(define my-sin (preset-instrument "sin-inst"))
(param-slider "change frequency" 300 1000 400
(lambda (val)
(set-inst-param my-sin "freq" val)))
(param-check-box "synth on" #f
(lambda (v)
(if v
(inst-on my-sin)
(inst-off my-sin))))
(show-gui)
;; example:
(sleep 0.5)
; (note-on my-sin 500 1)
; (note-off my-sin)

View file

@ -3,22 +3,15 @@
(require oregano)
(define my-sin (preset-instrument "sin-inst"))
(param-slider "change frequency" 300 1000 400
(lambda (val)
(set-inst-param my-sin "freq" val)))
(define my-note (play-note "sin-inst" 440))
(sleep 1)
;; stop playing note
(note-off my-note)
(param-check-box "synth on" #f
(lambda (v)
(if v
(inst-on my-sin)
(inst-off my-sin))))
(show-gui)
;; example:
(sleep 0.5)
; (note-on my-sin 500 1)
; (note-off my-sin)
(define my-note2 (make-note "sin-inst" 880))
(note-on my-note2)
(sleep 1)
(note-off my-note2)

View file

@ -10,6 +10,7 @@
(require "gui.rkt")
(define current-node-id 1000)
(define (gen-node-id)
(set! current-node-id (add1 current-node-id))
@ -44,18 +45,23 @@
(mouse-y kr 200 30000 1 0.1) 3 0))))
;; TODO
(define (make-instrument graph)
#;(define (make-instrument name graph)
(let ([sd (letc ([bus 0])
(out bus graph))]
[name (format "synth~a" current-node-id)])
(out bus ugen))]
;[name (format "synth~a" current-node-id)]
)
(with-sc3 (lambda (fd)
(send-synth fd name sd)))
name
(send-synth fd name sd)))
))
(define-syntax-rule (make-instrument inst-name ([argname argdefault] ...) ugen)
(let ([sd (letc ([bus 0]
[argname argdefault] ...)
(out bus ugen))]
;[name (format "synth~a" current-node-id)]
)
(with-sc3 (lambda (fd)
(send-synth fd inst-name sd)))))
;; example of definst macro like overtone's definst
#;(define-syntax-rule (define-instrument inst-name [[argname argdefault] ...] ugen)
@ -74,25 +80,41 @@
perset-instrument-map)
; === user instrument funcs ===
; === user note funcs ===
(struct note (id [freq #:mutable]))
(define (create-synth name node-id)
(define (create-synth name play-on-start)
(define node-id (gen-node-id))
(send-msg (s-new0 name node-id 1 1))
; don't make sound upon creation
(send-msg (n-run1 node-id 0))
(if play-on-start
empty
(send-msg (n-run1 node-id 0)))
node-id)
(define (preset-instrument name)
#;(define (preset-instrument name)
(let ([node-id (gen-node-id)])
(create-synth name node-id)))
(define (make-note/option inst-name freq play-on-start)
(define node-id (create-synth inst-name play-on-start))
(note node-id freq))
(define (play-note inst-name freq)
(make-note/option inst-name freq #t))
(define (make-note inst-name freq)
(make-note/option inst-name freq #f))
(define (note-on the-note)
;(send-msg (n-set1 (note-id the-note) "freq" (note-freq the-note)))
;(send-msg (n-set1 inst "bus" track)) ; TODO
(send-msg (n-run1 (note-id the-note) 1)))
(send-msg (n-run1 (note-id the-note) 1))
(send-msg (n-set1 (note-id the-note) "freq" (note-freq the-note))))
(define (note-off the-note)
(send-msg (n-run1 (note-id the-note) 0)))

View file

@ -5,6 +5,17 @@
"gui.rkt"
"sample.rkt")
;; setup
(require rsc3)
;; TODO - run scsynth
;; show osc messages on server
(send-msg (dump-osc 1))
(with-sc3 reset)
(sleep 0.1)
(provide
(all-from-out "instrument.rkt"
"gui.rkt"

View file

@ -3,18 +3,16 @@
(require rsc3 rhs/rhs)
(with-sc3 reset)
(send-msg (dump-osc 1))
;; load a smple in a buffer
; (send-async-msg (b-alloc-read 42 "./Samples/Synth Hits/Synth Hit 01.wav" 0 0))
(define fname "./Samples/Synth Hits/Synth Hit 01.wav")
#|
(send-async-msg (b-alloc 0 16380 2))
(send-async-msg (b-read 0 fname 0 -1 0 1))
(audition (out 0 (disk-in 2 ar 0)))
|#