rsc3/oregano/Tutorial.md

240 lines
4.5 KiB
Markdown
Raw Normal View History

2014-05-05 17:39:05 +00:00
## Installing
2014-05-11 21:18:34 +00:00
You need to install SuperCollider and the Dr Racket package.
### 1. Installing SuperCollider
2014-05-05 17:39:05 +00:00
Go to https://supercollider.github.io/download.html and download the latest version (3.6.6 as of the time of writing.)
Then follow these instructions per operating system.
2014-05-11 21:18:34 +00:00
#### Linux
2014-05-05 17:39:05 +00:00
2014-05-05 17:42:03 +00:00
- install jack
2014-05-11 21:18:34 +00:00
#### Windows
2014-05-05 17:39:05 +00:00
2014-05-11 21:18:34 +00:00
#### Mac OS X
2014-05-05 17:39:05 +00:00
2014-05-11 21:18:34 +00:00
### 2. Installing oregano
2014-05-05 17:42:03 +00:00
This can be installed in two different ways:
- Either through the command line: `raco pkg install rsc3`
- Or through DrRacket: TODO
2014-05-05 17:39:05 +00:00
2014-05-11 21:18:34 +00:00
## Concepts
You can play notes from instruments on specific tracks.
The purpose of playing notes on different tracks is we can have different filters on different tracks. For example, the melody track can have a low pass filter, and and the drums track could have a delay filter.
- Instrument: This is equivalent to choosing what the note sounds like. There are default instruments (saw wave, piano, etc.) and you can also define your own using samples.
2014-05-11 21:22:54 +00:00
- Note: specifies a key from an instrument, and can be played on a track
2014-05-15 20:17:15 +00:00
- Track: a place to play notes and add filters.
2014-05-11 21:22:54 +00:00
- Filters: can be added to a track. The order in which they are added matters.
2014-05-14 03:54:20 +00:00
## Examples
2014-05-11 21:22:54 +00:00
2014-05-22 18:09:24 +00:00
All these examples start with `(require oregano)`.
2014-05-22 17:39:35 +00:00
### 1. Playing a note using a preset instrument
2014-05-22 16:58:38 +00:00
2014-05-22 18:09:24 +00:00
You can either use a preset instrument or define your own instrument. There are a few preset instruments: "sin-inst", "saw-inst", "moog-inst"
2014-05-22 16:58:38 +00:00
```scheme
2014-05-22 18:09:24 +00:00
#lang racket
(require oregano)
2014-05-22 16:58:38 +00:00
;; this plays the key
(define my-note (play-note "sin-inst" 440))
(sleep 1)
;; stop playing note
(note-off my-note)
```
2014-05-29 18:35:36 +00:00
<!--
2014-05-22 16:58:38 +00:00
Or you can create a note object then play it.
2014-05-22 17:39:35 +00:00
```scheme
(define my-note2 (make-note "sin-inst" 880))
2014-05-22 16:58:38 +00:00
(note-on my-note2)
(sleep 1)
(note-off my-note2)
2014-05-22 17:39:35 +00:00
```
2014-05-29 18:35:36 +00:00
-->
2014-05-22 16:58:38 +00:00
2014-05-22 17:39:35 +00:00
### 2. Creating an instrument
2014-05-22 18:09:24 +00:00
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)
- some are:
2014-05-12 00:13:27 +00:00
2014-05-22 18:09:24 +00:00
```scheme
(saw ar freq)
(sin-osc ar freq phrase)
```
2014-05-12 00:24:29 +00:00
2014-05-21 18:49:17 +00:00
```scheme
2014-05-21 18:07:11 +00:00
;; create a custom instrument
;; can use oscilators and envelopes
;; "freq" is the frequency parameter
(make-instrument "my-inst" ([freq 500] [mod 20])
(mul (sin-osc ar mod 0)
2014-05-22 17:39:35 +00:00
(sin-osc ar freq 0)))
(define weird-note (play-note "my-inst" 440))
2014-05-22 17:39:35 +00:00
; change frequency
2014-05-22 18:09:24 +00:00
(set-note-param weird-note "freq" 808)
2014-05-22 17:39:35 +00:00
; change modulation
2014-05-22 18:09:24 +00:00
(set-note-param weird-note "mod" 40)
```
### 3 Sliders
2014-05-22 17:39:35 +00:00
2014-05-22 18:09:24 +00:00
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)
2014-05-22 17:39:35 +00:00
```
2014-05-21 18:07:11 +00:00
2014-05-22 18:09:24 +00:00
2014-05-29 18:35:36 +00:00
### 4. Add filters to a track
2014-05-12 00:24:29 +00:00
2014-05-29 18:35:36 +00:00
You can add filters to a specific track.
2014-05-12 00:24:29 +00:00
2014-05-29 18:35:36 +00:00
Add a reverb to track 0. (currently only track 0 works.)
2014-05-12 00:24:29 +00:00
2014-05-22 16:58:38 +00:00
```scheme
2014-05-29 18:35:36 +00:00
(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))
2014-05-22 16:58:38 +00:00
2014-05-29 18:35:36 +00:00
;; apply a reverb effect on track 0
(reverb 0 0.5)
(sleep 3)
(moog-filter 0 800)
2014-05-12 00:13:27 +00:00
2014-05-22 16:58:38 +00:00
```
2014-05-12 00:27:58 +00:00
2014-05-11 21:22:54 +00:00
2014-05-29 18:35:36 +00:00
### mouse/x and mouse/y
2014-05-14 03:54:20 +00:00
2014-05-29 18:35:36 +00:00
You can parameters to filters and instruments using the mouse.
2014-05-14 03:54:20 +00:00
2014-05-29 18:35:36 +00:00
(mouse/x start-value end-value)
2014-05-14 03:54:20 +00:00
2014-05-29 18:35:36 +00:00
For example, if you want to control the cutoff frequency for a filter using the left-right position of the mouse.
2014-05-14 03:54:20 +00:00
2014-05-29 18:35:36 +00:00
(low-pass-filter 0 (mouse/x kr 200 500)))
2014-05-14 03:54:20 +00:00
2014-05-29 18:35:36 +00:00
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.
2014-05-14 03:54:20 +00:00
2014-05-15 18:30:48 +00:00
2014-05-29 18:35:36 +00:00
---
### Envelopes
2014-05-15 18:30:48 +00:00
2014-05-29 18:35:36 +00:00
```scheme
Didn't implement envelopes yet.
;; add envelope to instrument
(define my-inst (preset-instrument "sine"
(envelope A S D R))
2014-05-14 03:54:20 +00:00
2014-05-29 18:35:36 +00:00
## Functions
2014-05-14 03:54:20 +00:00
2014-05-29 18:35:36 +00:00
### Oscilators
These can be used in defining instruments.
- sin, saw, tringle, square
-
2014-05-14 03:54:20 +00:00
2014-05-15 20:17:15 +00:00
### List of Filters
- hpf, lpf
- moog
- reverb
- delay
- comb
2014-05-14 03:54:20 +00:00
2014-05-15 18:30:48 +00:00
### Loading samples
2014-05-14 03:54:20 +00:00
2014-05-15 18:30:48 +00:00
* (load-sample file-name)
2014-05-14 03:54:20 +00:00
2014-05-15 18:30:48 +00:00
* (play-sample sample)
2014-05-14 03:54:20 +00:00
2014-05-15 18:30:48 +00:00
---
2014-05-14 03:54:20 +00:00
2014-05-16 21:16:49 +00:00
##
2014-05-14 03:54:20 +00:00
2014-05-16 21:16:49 +00:00
### Sliders
2014-05-14 03:54:20 +00:00
2014-05-16 00:57:13 +00:00
(add-effect track3 (low-pass-filter resonance
2014-05-16 21:16:49 +00:00
(slider "name" 200 500 300)))
How should I deal with one instrument on multiple tracks?
keep a list of instruments per track.
create a separate synth per track.
; bus = 2
; should create a new synth
(play-note my-inst 880 track2)
; bus = 3
(play-note my-inst 880 track3)
2014-05-16 00:57:13 +00:00
2014-05-14 03:54:20 +00:00
2014-05-11 21:22:54 +00:00
2014-05-12 00:13:27 +00:00