tur/params
warp-value
(warp-value [spec value])
Map a user-space value to OSC range using the spec's warp type.
| spec | A ParamSpec map containing at least :warp. | |
| value | Input value in user space. |
Warped value suitable for sending to scsynth. (warp-value PARAM_FREQ 440.0) ; => 440.0 (exp warp applies octave formula)
unwarp-value
(unwarp-value [spec value])
Map an OSC value back to user space using the spec's warp type.
| spec | A ParamSpec map containing at least :warp. | |
| value | Value received from scsynth in OSC space. |
Value in user space (inverse warp of warp-value). (unwarp-value PARAM_FREQ (warp-value PARAM_FREQ 440.0)) ; => 440.0
clamp-value
(clamp-value [spec value])
Clamp a value to the min/max range specified in a ParamSpec.
| spec | A ParamSpec map with :min and :max fields. | |
| value | Value to clamp. |
The value clamped to [spec.min, spec.max]. (clamp-value PARAM_AMP 1.5) ; => 1.0
param->osc
(param->osc [spec value])
Clamp and warp a user-space value ready for scsynth.
| spec | A ParamSpec map. | |
| value | User-space value. |
OSC-ready float (clamped first, then warped). (param->osc PARAM_AMP 0.8) ; => 0.8
osc->param
(osc->param [spec value])
Unwarp and clamp an OSC value back to user space.
| spec | A ParamSpec map. | |
| value | OSC value from scsynth. |
User-space float clamped to the spec's original range. (osc->param PARAM_AMP 0.8) ; => 0.8
param-spec
(param-spec [name default & [min 0.0 max 1.0 unit "" warp :linear])
Create a parameter specification with common defaults.
| name | Parameter name string (must match the SynthDef control name). | |
| default | Default value. | |
| min | Minimum value (default: 0.0). | |
| max | Maximum value (default: 1.0). | |
| unit | Unit label string, e.g. "Hz", "dB", "sec" (default: ""). | |
| warp | Warp type keyword: :linear, :exp, :log, :db, :db2 (default: :linear). |
A ParamSpec map. (param-spec "freq" 440.0 20.0 20000.0 "Hz" :exp)
synthdef-spec
(synthdef-spec [synthdef_name param-specs])
Assemble a SynthDef specification from a list of ParamSpecs.
| synthdef_name | SynthDef name (currently unused; reserved for future metadata). | |
| param-specs | Vector of ParamSpec maps describing each control. |
SynthDefSpec (currently just the param-specs vector). (synthdef-spec "mySynth" [PARAM_FREQ PARAM_AMP])
find-param
(find-param [spec param_name])
Find a ParamSpec by name within a SynthDefSpec.
| spec | SynthDefSpec (vector of ParamSpec maps). | |
| param_name | Parameter name to search for. |
The matching ParamSpec map, or nil if not found. (find-param SIN_SYNTH_SPEC "freq")
find-param-index
(find-param-index [spec param_name])
Get the zero-based index of a parameter by name.
| spec | SynthDefSpec (vector of ParamSpec maps). | |
| param_name | Parameter name to search for. |
Integer index of the parameter, or nil if not found. (find-param-index SIN_SYNTH_SPEC "amp") ; => 1
SynthController
(defstruct SynthController [])
synth-controller-new
(synth-controller-new [session synthdef-name synthdef-spec & [params {}])
Create a synth and wrap it in a typed controller.
| session | Parent ScscmSession. | |
| synthdef-name | Name of the SynthDef to instantiate. | |
| synthdef-spec | SynthDefSpec listing this SynthDef's parameters. | |
| params | Optional initial values as a name -> value map. |
A SynthController map. Panics if the synth cannot be created.
(synth-controller-new sess "mySynth" SIN_SYNTH_SPEC {"freq" 880.0})
synth-controller-free
(synth-controller-free [ctrl])
Free the synth node owned by a controller.
| ctrl | A SynthController map. |
ctrl-set
(ctrl-set [ctrl param_name value])
Set a named parameter on a synth controller (with warping).
| ctrl | A SynthController map. | |
| param_name | Name of the parameter to set. | |
| value | User-space value (will be clamped and warped before sending). |
true if the parameter was found and set, false otherwise. (ctrl-set ctrl "freq" 880.0)
ctrl-set-multi
(ctrl-set-multi [ctrl param-map])
Set multiple named parameters on a controller.
| ctrl | A SynthController map. | |
| param-map | Map of parameter name -> user-space value. |
Number of parameters successfully set.
(ctrl-set-multi ctrl {"freq" 880.0 "amp" 0.6}) ; => 2
ctrl-get
(ctrl-get [ctrl param_name])
Get the current value for a named parameter (returns spec default).
| ctrl | A SynthController map. | |
| param_name | Parameter name to look up. |
Default value from the ParamSpec, or nil if the parameter is not found. (ctrl-get ctrl "freq") ; => 440.0 (spec default)
midi->hz
(midi->hz [note])
Convert a MIDI note number to frequency in Hz.
| note | MIDI note number (69 = A4 = 440 Hz). |
Frequency in Hz as a float. (midi->hz 69) ; => 440.0
vel->amp
(vel->amp [vel])
Convert a MIDI velocity to linear amplitude.
| vel | MIDI velocity (0-127). |
Amplitude in [0.0, 1.0]. (vel->amp 64) ; => ~0.504
db->amp
(db->amp [db])
Convert a decibel level to linear amplitude.
| db | Level in decibels. |
Linear amplitude as a float. (db->amp -6.0) ; => ~0.501
amp->db
(amp->db [amp])
Convert linear amplitude to decibels.
| amp | Linear amplitude (0.0 or below returns -90.0). |
Level in decibels. (amp->db 0.5) ; => ~-6.02