hi all! a quick request for some advice... i'd like to add a legato parameter to a synth which would basically change the frequency of the currently sounding note (not play a new note). I've done similar using ctl however i'd like to have a more data centric, parameterized solution. thanks in advance!
Wait @frankleonrose … one can define “custom” (reusable) ugens like that? If so that’s pretty cool.
First time for me, too.
This is awesome
This way works - use latch to record to prior value:
(defcgen track-value
"Generate tracking value from single parameter."
[value {:doc "Value to reach."}
duration {:default 1 :doc "Time in seconds to settle on new value."}
curve {:default :linear}]
(:kr (let [[trigger current] (local-in:kr 2)
last (latch value trigger)
trigger-pulse (trig (absdif last value))
tracker (env-gen:kr (envelope [current current value]
[0 duration] curve)
trigger)
;; Use select to handle initial condition - when last is 0,
;; value should immediately take the initial value
tracking-value (select:kr
(thresh 1 (+ 1 last))
[tracker value])]
;; Feeding tracking-value back allows restarted envelope to start
;; at current, even when it's in motion from a recent change of value.
(local-out:kr [trigger-pulse tracking-value])
tracking-value)))
(definst tone-inst [freq 440]
(let [tracking-freq (track-value freq 2 :curve :exponential)]
(pan2 (sin-osc tracking-freq))))
(def t (tone-inst))
(ctl t :freq 2000)
(ctl t :freq 300)
I’m not sure the curve parameter is working as I expect, but it does the basic job.
Also, because it uses local-in, only one tracking value per synth.can you share the synth? I wouldn't mind giving it a shot.
Perhaps you can use and envelope (`env-gen` + envelope). Or check out the demand ugens ( I don’t really know them, but my belief is that they are used for sequencing in the SC server).
Hey, thanks! Here is the one I'm using: (sy/defsynth tone "i'm just a tone" [note 60 scaled-duration 1.0 output-bus 0 gate 1 ] (let [envl (u/env-gen:ar (envel/envelope [0.1 1 1 0.001 0] [0.2 scaled-duration 20 1] [1 1 -10 1]) :action u/FREE) sig (as-> note $ (u/midicps $) (- $ (* 1 (u/sin-osc:kr 0.5) )) ;vib (+ (u/var-saw $ :width 0.9) (u/sin-osc $)) (* $ envl) ;adsr (u/free-verb $ :mix 0.4 :room 0.7) (u/lpf $ 800) ;low pass filter (u/softclip $) (* $ 0.4) )] (u/out output-bus sig)))
New Supercollider book https://mitpress.mit.edu/9780262049702/the-supercollider-book/