diff --git a/oregano/Tutorial.md b/oregano/Tutorial.md index eff6ad8..a09de33 100644 --- a/oregano/Tutorial.md +++ b/oregano/Tutorial.md @@ -42,10 +42,15 @@ The purpose of playing notes on different tracks is we can have different filter ## Examples +All these examples start with `(require oregano)`. + ### 1. Playing a note using a preset instrument +You can either use a preset instrument or define your own instrument. There are a few preset instruments: "sin-inst", "saw-inst", "moog-inst" ```scheme +#lang racket +(require oregano) ;; this plays the key (define my-note (play-note "sin-inst" 440)) @@ -66,8 +71,17 @@ Or you can create a note object then play it. ``` ### 2. Creating an instrument + A custom instrument is composed of three parts: +- it's name. This is a string and is used when playing notes +- Instrjument arguments and default values. You could change these paramers when a note is playing, in real time. +- the signal. This can use SuperCollider ugens. (TODO link) -You can either use a preset instrument or define your own instrument +- some are: + +```scheme +(saw ar freq) +(sin-osc ar freq phrase) +``` ```scheme @@ -81,20 +95,39 @@ You can either use a preset instrument or define your own instrument (define weird-note (play-note "my-inst" 440)) ; change frequency -(set-note-param my-note "freq" 808) +(set-note-param weird-note "freq" 808) ; change modulation -(set-note-param my-note "mod" 40) - +(set-note-param weird-note "mod" 40) ``` +### 3 Sliders + + +You can easily create a slider for a specific note parameter. You have to provide the title, start value, end value, default value, and a callback function. + +For example, previous note, `weird-note`: + +```scheme +(param-slider "change modulation" 1 100 40 + (lambda (val) + (set-note-param weird-note "mod" val))) + +;; show the slider +(show-gui) +``` + + +### Envelopes +```scheme Didn't implement envelopes yet. ;; add envelope to instrument (define my-inst (preset-instrument "sine" (envelope A S D R)) -``` + + ### 3. Playing a note using a custom instrument diff --git a/oregano/examples/instrument-example.rkt b/oregano/examples/instrument-example.rkt index b7c3f9b..39f8f84 100644 --- a/oregano/examples/instrument-example.rkt +++ b/oregano/examples/instrument-example.rkt @@ -3,7 +3,7 @@ (require oregano) - +#| (define my-note (play-note "sin-inst" 440)) (sleep 1) ;; stop playing note @@ -15,3 +15,15 @@ (note-on my-note2) (sleep 1) (note-off my-note2) +|# + +(make-instrument "my-inst" ([freq 500] [mod 20]) + (mul (sin-osc ar mod 0) + (sin-osc ar freq 0))) +(define weird-note (play-note "my-inst" 440)) + +(param-slider "change frequency" 1 100 40 + (lambda (val) + (set-note-param weird-note "mod" val))) + +(show-gui) \ No newline at end of file diff --git a/oregano/instrument.rkt b/oregano/instrument.rkt index a6a3b9e..338d82d 100644 --- a/oregano/instrument.rkt +++ b/oregano/instrument.rkt @@ -3,6 +3,8 @@ (require rsc3) +(provide + (all-from-out rsc3)) (provide (all-defined-out)) @@ -30,7 +32,8 @@ (letc ([bus 0] [freq 440]) ;; TODO - remove slider - (out bus (mul (signal-slider "amplitude" 100 800 200) (sin-osc ar freq 0))))) + ;(out bus (mul (signal-slider "amplitude" 100 800 200) (sin-osc ar freq 0))))) + (out bus (mul 0.2 (sin-osc ar freq 0))))) (define saw-instrument (letc ([bus 0]