tur/synth

stdlib/synth.tur
defn

pat->param

(pat->param [p session node-id param-index])

send a pattern value to a synth control at the current beat time.

pNumPattern to evaluate
sessionscscm session
node-idsynth node ID
param-indexcontrol parameter index
defn

pats->params

(pats->params [session node-id param-patterns])

send multiple pattern values to synth controls.

sessionscscm session
node-idsynth node ID
param-patternslist of [param-index pattern] tuples
defn

pats->named-params

(pats->named-params [session node-id param-map param-name->index])

send pattern values to named synth controls.

sessionscscm session
node-idsynth node ID
param-mapmap of param-name -> [control-index pattern]
param-name->indexfunction mapping param names to control indices
defstruct

PatternPlayer

(defstruct PatternPlayer [])

a player that triggers and controls synths from a pattern.

defn

player-new

(player-new [session def-name pattern bpm])

create a new (stopped) pattern player.

sessionscscm session
def-nameSynthDef name
patternPattern<map<cstr,float>> producing parameter maps
bpmtempo in beats per minute

PatternPlayer (not yet started).

defn

player-start

(player-start [player])

start a pattern player.

playerPatternPlayer to start

Updated PatternPlayer with running=true.

defn

player-stop

(player-stop [player])

stop a pattern player and free all its synth nodes.

playerPatternPlayer to stop

Updated PatternPlayer with running=false.

defn

player-update

(player-update [player new-pattern])

swap the pattern in a running player.

playerPatternPlayer to update
new-patternreplacement pattern

Updated PatternPlayer.

defn

player-swap

(player-swap [player new-param-map])

atomically swap parameter-map pattern in a player.

playerPatternPlayer to update
new-param-mapnew parameter map pattern

Updated PatternPlayer.

defn

pattern-synth

(pattern-synth [session def-name param-patterns & [bpm time/DEFAULT_BPM])

create a synth driven by pattern parameters at time 0.

sessionscscm session
def-nameSynthDef name
param-patternslist of [control-index pattern] tuples
bpmtempo (default: time/DEFAULT_BPM)

Node ID of created synth, or nil on failure.

defn

pattern-synth-player

(pattern-synth-player [session def-name param-patterns bpm duration])

create a player that continuously updates synth parameters.

sessionscscm session
def-nameSynthDef name
param-patternslist of [control-index pattern] tuples
bpmtempo
durationduration in beats

PatternPlayer (already started).

defn

note->freq

(note->freq [note])

convert a MIDI note number to frequency in Hz.

noteMIDI note number (0-127; 69 = A4 = 440 Hz)
Frequency in Hz.

  (note->freq 69)  ; => 440.0
defn

vel->amp

(vel->amp [vel])

convert a MIDI velocity to a linear amplitude value.

velMIDI velocity (0-127)
Amplitude in [0, 1].

  (vel->amp 127)  ; => 1.0
defn

note-pattern

(note-pattern [pitch & [vel (pattern/const 100) gate (pattern/const true)])

produce a synth parameter map from pitch, velocity, and gate patterns.

pitchIntPattern of MIDI note numbers
velNumPattern for velocity (default: const 100)
gateBoolPattern for gate (default: const true)
Pattern<map> with :freq, :amp, and :gate keys.

  ((note-pattern (cycle 60 62 64)) 0.0)
defn

note-pattern-dur

(note-pattern-dur [pitch vel dur & [gate (pattern/const true)])

note pattern including note duration.

pitchIntPattern
velNumPattern
durNumPattern for duration in beats
gateBoolPattern (default: const true)

Pattern<map> with :freq, :amp, :gate, and :dur keys.

defn

chord-pattern

(chord-pattern [& note-patterns])

stack multiple note patterns to play chords.

note-patternsone or more Pattern<map> to play simultaneously

Pattern<vec<map>> with one map per note.

defn

arp-pattern

(arp-pattern [chord & [speed 4 direction :up])

arpeggiate a chord pattern.

chordPattern<vec<int>> producing MIDI note lists
speednotes per beat (default: 4 = 16th notes)
direction:up, :down, :up-down, or :random (default: :up)
IntPattern cycling through chord tones.

  ((arp-pattern my-chord 4 :up) 0.0)
defn

drum-pattern

(drum-pattern [& hits])

build a drum pattern from a list of (time, name, velocity) hits.

hitslist of [time-in-cycle drum-name velocity] tuples

Pattern<map> with :note and :vel keys for the active hit, or {} for silence.

defn

drum-name->note

(drum-name->note [name])

map a drum abbreviation to a GM MIDI note number.

namedrum name string (e.g., "bd", "sd", "hh")

MIDI note number.

defn

kick

(kick [& times])

kick drum pattern triggered at specific beat positions.

timesbeat positions within the cycle to trigger the kick
Pattern<map> with {:note 36 :vel 127} on hits, {} otherwise.

  ((kick 0 1 2 3) 0.0)
defn

snare

(snare [& times])

snare drum pattern triggered at specific beat positions.

timesbeat positions to trigger the snare
Pattern<map> with {:note 38 :vel 100} on hits, {} otherwise.

  ((snare 1 3) 1.0)
defn

hat

(hat [& times])

hi-hat pattern triggered at specific beat positions.

timesbeat positions to trigger the hi-hat
Pattern<map> with {:note 42 :vel 80} on hits, {} otherwise.

  ((hat 0 0.5 1 1.5 2 2.5 3 3.5) 0.0)
defn

pattern->osc

(pattern->osc [pattern session node-id time])

send a parameter map pattern to a synth node via OSC.

patternPattern<map<cstr,float>>
sessionscscm session
node-idsynth node ID
timecurrent time in beats
defn

trigger-pattern

(trigger-pattern [session def-name pattern bpm])

create a player that spawns a new synth on each pattern event.

sessionscscm session
def-nameSynthDef name
patternPattern<map> producing parameters for each new note
bpmtempo

PatternPlayer (already started).

defn

freq-pattern

(freq-pattern [base-freq & [modulation (pattern/const 0)])

frequency pattern with optional additive modulation.

base-freqbase frequency in Hz
modulationadditive NumPattern (default: const 0)

NumPattern for synth frequency.

defn

amp-pattern

(amp-pattern [base-amp & [envelope (pattern/const 1)])

amplitude pattern with optional envelope modulation.

base-ampbase amplitude (0-1)
envelopemultiplicative NumPattern (default: const 1)

NumPattern for synth amplitude.

defn

pan-pattern

(pan-pattern [base-pan & [modulation (pattern/const 0)])

stereo pan pattern with optional modulation, clamped to [-1, 1].

base-panbase pan position (-1 = left, 0 = center, 1 = right)
modulationadditive NumPattern (default: const 0)

NumPattern clamped to [-1, 1].

defn

synth-params

(synth-params [freq-pattern amp-pattern pan-pattern])

combine freq, amp, and pan patterns into a parameter map pattern.

freq-patternNumPattern for frequency
amp-patternNumPattern for amplitude
pan-patternNumPattern for pan

Pattern<map> with :freq, :amp, and :pan keys.

defn

synth-pattern-player

(synth-pattern-player [session def-name param-patterns bpm])

create a player driven by a named parameter map.

sessionscscm session
def-nameSynthDef name
param-patternsmap of param-name -> pattern
bpmtempo

PatternPlayer (already started).