From 7de4af814b40898f92cd9de6dacf4b062ff095c1 Mon Sep 17 00:00:00 2001 From: Mustafa Date: Thu, 22 May 2014 10:39:35 -0700 Subject: [PATCH] tutorial works till part 2 --- oregano/Tutorial.md | 26 +++++++++---- oregano/examples/gui-example.rkt | 28 ++++++++++++++ oregano/examples/instrument-example.rkt | 23 ++++-------- oregano/instrument.rkt | 50 ++++++++++++++++++------- oregano/main.rkt | 11 ++++++ oregano/sample.rkt | 6 +-- 6 files changed, 104 insertions(+), 40 deletions(-) create mode 100644 oregano/examples/gui-example.rkt diff --git a/oregano/Tutorial.md b/oregano/Tutorial.md index 707cf65..2300697 100644 --- a/oregano/Tutorial.md +++ b/oregano/Tutorial.md @@ -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. diff --git a/oregano/examples/gui-example.rkt b/oregano/examples/gui-example.rkt new file mode 100644 index 0000000..219a78e --- /dev/null +++ b/oregano/examples/gui-example.rkt @@ -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) \ No newline at end of file diff --git a/oregano/examples/instrument-example.rkt b/oregano/examples/instrument-example.rkt index 830d1f5..b7c3f9b 100644 --- a/oregano/examples/instrument-example.rkt +++ b/oregano/examples/instrument-example.rkt @@ -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) \ No newline at end of file +(define my-note2 (make-note "sin-inst" 880)) +(note-on my-note2) +(sleep 1) +(note-off my-note2) diff --git a/oregano/instrument.rkt b/oregano/instrument.rkt index b130583..a6a3b9e 100644 --- a/oregano/instrument.rkt +++ b/oregano/instrument.rkt @@ -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))) diff --git a/oregano/main.rkt b/oregano/main.rkt index 0652319..c371ff8 100644 --- a/oregano/main.rkt +++ b/oregano/main.rkt @@ -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" diff --git a/oregano/sample.rkt b/oregano/sample.rkt index e25c660..222569b 100644 --- a/oregano/sample.rkt +++ b/oregano/sample.rkt @@ -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))) +|#