The ChucK Operator =>
Lesson 5b The => operator connects Unit Generators in series — the output of the left-hand UGen becomes the input of the right-hand UGen. It is a playful homage to ChucK, the audio programming language.
"Connect an ElecGuitar physical model into a GreyHole reverb"
synth := ElecGuitar new => GreyHole new.
dsp := synth asDsp.
dsp init.
dsp start.
"Open the UI — press ElecGuitarTrigger to pluck the string"
dsp displayUI.
"Adjust reverb parameters (room size, damping, etc.) with the knobs"
dsp stop.
How => works
The behaviour of => depends on the receiver UGen (the right-hand side). Each UGen class defines how it accepts an input signal:
| Pattern | Meaning |
|---|---|
osc => env | Oscillator multiplied by envelope (amplitude shaping) |
osc => filter | Oscillator fed into filter input |
synth => reverb | Synth signal fed into reverb input |
pulse => impulsify | Pulse wave converted to impulse train |
a => b => c equals (a => b) => c. Signal flows exactly left to right as written — natural and readable.
A richer example
"Two pulse generators — pulse1 period modulated by an LFO"
pulse1 := Pulsen new period: (LFOTriPos new freq: 0.2; offset: 0.05; amount: 4).
pulse2 := Pulsen new period: 0.35.
"Two physical model instruments, each triggered by one pulse"
djembe := Djembe new trigger: pulse1.
marimba := Marimba new
trigger: pulse2;
freq: (LFORandomPos new offset: 20; amount: 600; freq: (1 / 0.35)).
"Mix them, chuck into reverb, create stereo DSP"
dsp := (djembe + marimba => GreyHole new) stereo asDsp.
dsp init.
dsp start.
dsp stop.
Playing Notes
Lesson 13 Use playNote:prefix:dur: to send MIDI note numbers to a DSP instrument in a Pharo block. The method converts MIDI numbers to frequencies and handles note-on / note-off automatically.
Setup: labelling with symbols
For playNote:prefix:dur: to work, the instrument's freq and trigger parameters must be named consistently. Pass a Symbol (starting with #) to set the FAUST parameter label:
"Use symbols to set parameter labels — required for playNote:prefix:dur:"
synth := ElecGuitar new
freq: #ElecGuitarFreq;
trigger: #ElecGuitarTrigger.
dsp := synth asDsp.
dsp init.
dsp start.
A melodic pattern
"Play 128 random MIDI notes between 28 and 76, every 125 ms"
pattern := [
dsp playNote: (Random new nextIntegerBetween: 28 and: 76)
prefix: 'ElecGuitar'
dur: 0.11.
(Delay forMilliseconds: 125) wait
].
[128 timesRepeat: pattern] fork.
dsp stop.
"Play a MIDI note number on a DSP instrument.
midiNote — integer MIDI note (0–127; middle C = 60)
prefix — the parameter label prefix (string, e.g. 'ElecGuitar')
dur — note duration in seconds (float)
The method converts MIDI to Hz and triggers the note-on / note-off cycle."
dsp playNote: 60 prefix: 'ElecGuitar' dur: 0.25.
[ ... ] fork to run them on a background Pharo process, keeping the Playground responsive. Multiple forked blocks can run simultaneously for polyrhythmic patterns.
TpSampler Basics
Lesson 14 TpSampler is a multisampler from the TurboPhausto package. It loads a folder of .wav or .aiff files and plays them on demand — by UI, by trigger, or algorithmically.
Load and play from UI
"Create a TpSampler pointing at a folder of samples"
sp := TpSampler new pathToFolder: '/Users/you/Documents/TurboSamples/conga'.
dsp := sp stereo asDsp.
dsp init.
dsp start.
"Open UI — use tpSamplerTrigger button and tpSamplerIndex to select samples"
dsp displayUI.
Algorithmic triggering
"Play random samples at random intervals"
[128 timesRepeat: [
dsp trig: 'tpSamplerTrigger'.
dsp setValue: (Random new nextIntegerBetween: 1 and: 9)
parameter: 'tpSamplerIndex'.
(Random new nextIntegerBetween: 80 and: 310) milliSeconds wait
]] fork.
Melodic playback with the same sample
"Select a sample and play it at different pitches via MIDI note numbers"
dsp setValue: 8 parameter: 'tpSamplerIndex'.
[128 timesRepeat: [
dsp playNote: (Random new nextIntegerBetween: 35 and: 78)
prefix: 'tpSampler'
dur: 0.1.
110 milliSeconds wait
]] fork.
dsp stop.
dsp destroy.
| Message | Description |
|---|---|
| pathToFolder: aString | Set folder of .wav/.aiff samples |
| dsp trig: 'tpSamplerTrigger' | Fire the trigger (play current sample) |
| dsp setValue: n parameter: 'tpSamplerIndex' | Select sample by index (1-based) |
| dsp playNote: midi prefix: 'tpSampler' dur: s | Play sample pitched to MIDI note |
.wav or .aiff files inside the folder — no subfolders, no other file types. tpSamplerIndex selects files by sorted filename order.