From 0871d776c72f2391e991058fc56f060f5952c2e0 Mon Sep 17 00:00:00 2001 From: Mustafa Date: Thu, 29 May 2014 11:35:36 -0700 Subject: [PATCH] added lpf, mouse/x,y --- oregano/Tutorial.md | 76 ++++++++++++++++++++---------------- oregano/examples/filters.rkt | 21 ++++++++++ oregano/instrument.rkt | 10 ++++- oregano/main.rkt | 2 +- oregano/routing.rkt | 11 ++++-- 5 files changed, 80 insertions(+), 40 deletions(-) create mode 100644 oregano/examples/filters.rkt diff --git a/oregano/Tutorial.md b/oregano/Tutorial.md index a09de33..6358102 100644 --- a/oregano/Tutorial.md +++ b/oregano/Tutorial.md @@ -58,7 +58,7 @@ You can either use a preset instrument or define your own instrument. There are ;; stop playing note (note-off my-note) ``` - + ### 2. Creating an instrument A custom instrument is composed of three parts: @@ -120,7 +121,47 @@ For example, previous note, `weird-note`: ``` + +### 4. Add filters to a track + +You can add filters to a specific track. + +Add a reverb to track 0. (currently only track 0 works.) + +```scheme +(make-instrument "phone-inst" ([freq 500]) + (mul (sin-osc ar (mul-add (lf-pulse ar 15 0 0.5) 200 freq) 0) + (mouse-button kr 0 0.1 0.1))) + +;; click any mouse button to hear the note +(define phone-note (play-note "phone-inst" 600)) + +;; apply a reverb effect on track 0 +(reverb 0 0.5) + +(sleep 3) + +(moog-filter 0 800) + +``` + + +### mouse/x and mouse/y + +You can parameters to filters and instruments using the mouse. + + (mouse/x start-value end-value) + +For example, if you want to control the cutoff frequency for a filter using the left-right position of the mouse. + + (low-pass-filter 0 (mouse/x kr 200 500))) + +When the mouse is at the left of the screen, the frequency is 200, when the mouse is at the right, the frequency is 500. + + +--- ### Envelopes + ```scheme Didn't implement envelopes yet. ;; add envelope to instrument @@ -129,27 +170,6 @@ Didn't implement envelopes yet. -### 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. - -```scheme -;; this plays the key C#, octave 3 on track 2. -(note-on my-piano C#3 track2) - -;; to stop playing -(note-off my-piano C#3 track2) - -;; TODO - find a way to turn off a note, or make a note play for a specific time -``` - - -### 4. Add filters to a track - -You can add filters to a specific track. - - (add-effect track3 (reverb 0.5 0.9)) - ## Functions @@ -161,18 +181,6 @@ These can be used in defining instruments. - -### mouse-x and mouse-y - -You can parameters to filters and instruments using the mouse. - - (mouse-x start-value end-value) - -For example, if you want to control the cutoff frequency for a filter using the left-right position of the mouse. - - (add-effect track3 (low-pass-filter resonance - (mouse-x kr 200 500))) - -When the mouse is at the left of the screen, the frequency is 200, when the mouse is at the right, the frequency is 500. ### List of Filters diff --git a/oregano/examples/filters.rkt b/oregano/examples/filters.rkt new file mode 100644 index 0000000..b6d0ae6 --- /dev/null +++ b/oregano/examples/filters.rkt @@ -0,0 +1,21 @@ +#lang racket + +(require oregano) + +;; press 'a' +(make-instrument "my-inst" ([freq 500]) + (mul (sin-osc ar (mul-add (lf-pulse ar 15 0 0.5) 200 freq) 0) + (mouse-button kr 0 0.1 0.1))) + +(define phone-note (play-note "my-inst" 600)) + +(define track0 0) + +(sleep 1) + +(reverb track0 0.5) + +(sleep 3) + + +(moog-filter track0 800) \ No newline at end of file diff --git a/oregano/instrument.rkt b/oregano/instrument.rkt index a28d24a..601c4bb 100644 --- a/oregano/instrument.rkt +++ b/oregano/instrument.rkt @@ -132,8 +132,14 @@ (send-msg (n-set1 (note-id the-note) name val)) (void)) - - + +(define (mouse/x start end) + (mouse-x kr start end 0 0.1)) + +(define (mouse/y start end) + (mouse-y kr start end 0 0.1)) + + #| - to stop/run: diff --git a/oregano/main.rkt b/oregano/main.rkt index d90374e..83226e8 100644 --- a/oregano/main.rkt +++ b/oregano/main.rkt @@ -10,7 +10,7 @@ (require rsc3) ;; FIXME - not running -(display "Hello! from main.rkt\n") +;(display "Hello! from main.rkt\n") ;(run-super-collider) diff --git a/oregano/routing.rkt b/oregano/routing.rkt index bea7a77..a0a3718 100644 --- a/oregano/routing.rkt +++ b/oregano/routing.rkt @@ -1,6 +1,8 @@ #lang racket (require rsc3) + +(provide (all-defined-out)) #| tracks: @@ -66,13 +68,17 @@ tracks: (define (name bus) (apply-effect bus ugen))) -(define (reverb bus) +(define (reverb bus ammount) (apply-effect bus (free-verb (in 1 ar bus) 0.5 - (mouse-y kr 0 1 0 0.1) + ammount ;(mouse-y kr 0 1 0 0.1) 0.5))) +(define (low-pass-filter bus ammount) + (apply-effect bus + (lpf (in 1 ar bus) ammount))) + ; example: apply reverb on bus 0 ; (reverb 0) @@ -84,5 +90,4 @@ tracks: (apply-effect bus (comb-n (in 1 ar bus) delay-time delay-time decay-time))) -; (add-effect track0 (reverb 0.3 6)