tutorial works till part 2
This commit is contained in:
parent
72dd6033b9
commit
7de4af814b
6 changed files with 104 additions and 40 deletions
|
@ -42,7 +42,7 @@ The purpose of playing notes on different tracks is we can have different filter
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
### 2. Playing a note using a preset instrument
|
### 1. Playing a note using a preset instrument
|
||||||
|
|
||||||
|
|
||||||
```scheme
|
```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.
|
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)
|
(note-on my-note2)
|
||||||
(sleep 1)
|
(sleep 1)
|
||||||
(note-off my-note2)
|
(note-off my-note2)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Creating an instrument
|
||||||
### 1. Creating an instrument
|
|
||||||
|
|
||||||
You can either use a preset instrument or define your own 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
|
;; create a custom instrument
|
||||||
;; can use oscilators and envelopes
|
;; can use oscilators and envelopes
|
||||||
;; "freq" is the frequency parameter
|
;; "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
|
;; add envelope to instrument
|
||||||
(define my-inst (preset-instrument "sine"
|
(define my-inst (preset-instrument "sine"
|
||||||
(envelope A S D R))
|
(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.
|
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.
|
You can add filters to a specific track.
|
||||||
|
|
||||||
|
|
28
oregano/examples/gui-example.rkt
Normal file
28
oregano/examples/gui-example.rkt
Normal 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)
|
|
@ -3,22 +3,15 @@
|
||||||
(require oregano)
|
(require oregano)
|
||||||
|
|
||||||
|
|
||||||
(define my-sin (preset-instrument "sin-inst"))
|
|
||||||
|
|
||||||
(param-slider "change frequency" 300 1000 400
|
(define my-note (play-note "sin-inst" 440))
|
||||||
(lambda (val)
|
(sleep 1)
|
||||||
(set-inst-param my-sin "freq" val)))
|
;; 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:
|
(define my-note2 (make-note "sin-inst" 880))
|
||||||
(sleep 0.5)
|
(note-on my-note2)
|
||||||
; (note-on my-sin 500 1)
|
(sleep 1)
|
||||||
|
(note-off my-note2)
|
||||||
; (note-off my-sin)
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
(require "gui.rkt")
|
(require "gui.rkt")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(define current-node-id 1000)
|
(define current-node-id 1000)
|
||||||
(define (gen-node-id)
|
(define (gen-node-id)
|
||||||
(set! current-node-id (add1 current-node-id))
|
(set! current-node-id (add1 current-node-id))
|
||||||
|
@ -44,18 +45,23 @@
|
||||||
(mouse-y kr 200 30000 1 0.1) 3 0))))
|
(mouse-y kr 200 30000 1 0.1) 3 0))))
|
||||||
|
|
||||||
;; TODO
|
;; TODO
|
||||||
(define (make-instrument graph)
|
#;(define (make-instrument name graph)
|
||||||
(let ([sd (letc ([bus 0])
|
(let ([sd (letc ([bus 0])
|
||||||
(out bus graph))]
|
(out bus ugen))]
|
||||||
[name (format "synth~a" current-node-id)])
|
;[name (format "synth~a" current-node-id)]
|
||||||
|
)
|
||||||
(with-sc3 (lambda (fd)
|
(with-sc3 (lambda (fd)
|
||||||
(send-synth fd name sd)))
|
(send-synth fd name sd)))
|
||||||
|
|
||||||
name
|
|
||||||
))
|
))
|
||||||
|
|
||||||
|
(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
|
;; example of definst macro like overtone's definst
|
||||||
#;(define-syntax-rule (define-instrument inst-name [[argname argdefault] ...] ugen)
|
#;(define-syntax-rule (define-instrument inst-name [[argname argdefault] ...] ugen)
|
||||||
|
@ -74,25 +80,41 @@
|
||||||
perset-instrument-map)
|
perset-instrument-map)
|
||||||
|
|
||||||
|
|
||||||
; === user instrument funcs ===
|
|
||||||
|
|
||||||
|
; === user note funcs ===
|
||||||
|
|
||||||
(struct note (id [freq #:mutable]))
|
(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))
|
(send-msg (s-new0 name node-id 1 1))
|
||||||
; don't make sound upon creation
|
; 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)
|
node-id)
|
||||||
|
|
||||||
(define (preset-instrument name)
|
#;(define (preset-instrument name)
|
||||||
(let ([node-id (gen-node-id)])
|
(let ([node-id (gen-node-id)])
|
||||||
(create-synth name 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)
|
(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-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)
|
(define (note-off the-note)
|
||||||
(send-msg (n-run1 (note-id the-note) 0)))
|
(send-msg (n-run1 (note-id the-note) 0)))
|
||||||
|
|
|
@ -5,6 +5,17 @@
|
||||||
"gui.rkt"
|
"gui.rkt"
|
||||||
"sample.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
|
(provide
|
||||||
(all-from-out "instrument.rkt"
|
(all-from-out "instrument.rkt"
|
||||||
"gui.rkt"
|
"gui.rkt"
|
||||||
|
|
|
@ -3,18 +3,16 @@
|
||||||
(require rsc3 rhs/rhs)
|
(require rsc3 rhs/rhs)
|
||||||
|
|
||||||
|
|
||||||
(with-sc3 reset)
|
|
||||||
|
|
||||||
(send-msg (dump-osc 1))
|
|
||||||
|
|
||||||
;; load a smple in a buffer
|
;; load a smple in a buffer
|
||||||
; (send-async-msg (b-alloc-read 42 "./Samples/Synth Hits/Synth Hit 01.wav" 0 0))
|
; (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")
|
(define fname "./Samples/Synth Hits/Synth Hit 01.wav")
|
||||||
|
|
||||||
|
#|
|
||||||
(send-async-msg (b-alloc 0 16380 2))
|
(send-async-msg (b-alloc 0 16380 2))
|
||||||
(send-async-msg (b-read 0 fname 0 -1 0 1))
|
(send-async-msg (b-read 0 fname 0 -1 0 1))
|
||||||
|
|
||||||
(audition (out 0 (disk-in 2 ar 0)))
|
(audition (out 0 (disk-in 2 ar 0)))
|
||||||
|
|
||||||
|
|
||||||
|
|#
|
||||||
|
|
Loading…
Reference in a new issue