added gui tut
This commit is contained in:
parent
6599178e5f
commit
549cbb398a
3 changed files with 55 additions and 7 deletions
|
@ -42,10 +42,15 @@ The purpose of playing notes on different tracks is we can have different filter
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
All these examples start with `(require oregano)`.
|
||||||
|
|
||||||
### 1. Playing a note using a preset instrument
|
### 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
|
```scheme
|
||||||
|
#lang racket
|
||||||
|
(require oregano)
|
||||||
|
|
||||||
;; this plays the key
|
;; this plays the key
|
||||||
(define my-note (play-note "sin-inst" 440))
|
(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
|
### 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
|
```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))
|
(define weird-note (play-note "my-inst" 440))
|
||||||
|
|
||||||
; change frequency
|
; change frequency
|
||||||
(set-note-param my-note "freq" 808)
|
(set-note-param weird-note "freq" 808)
|
||||||
|
|
||||||
; change modulation
|
; 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.
|
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))
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
### 3. Playing a note using a custom instrument
|
### 3. Playing a note using a custom instrument
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
(require oregano)
|
(require oregano)
|
||||||
|
|
||||||
|
|
||||||
|
#|
|
||||||
(define my-note (play-note "sin-inst" 440))
|
(define my-note (play-note "sin-inst" 440))
|
||||||
(sleep 1)
|
(sleep 1)
|
||||||
;; stop playing note
|
;; stop playing note
|
||||||
|
@ -15,3 +15,15 @@
|
||||||
(note-on my-note2)
|
(note-on my-note2)
|
||||||
(sleep 1)
|
(sleep 1)
|
||||||
(note-off my-note2)
|
(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)
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
(require rsc3)
|
(require rsc3)
|
||||||
|
|
||||||
|
(provide
|
||||||
|
(all-from-out rsc3))
|
||||||
|
|
||||||
(provide (all-defined-out))
|
(provide (all-defined-out))
|
||||||
|
|
||||||
|
@ -30,7 +32,8 @@
|
||||||
(letc ([bus 0]
|
(letc ([bus 0]
|
||||||
[freq 440])
|
[freq 440])
|
||||||
;; TODO - remove slider
|
;; 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
|
(define saw-instrument
|
||||||
(letc ([bus 0]
|
(letc ([bus 0]
|
||||||
|
|
Loading…
Reference in a new issue