aboutsummaryrefslogtreecommitdiff
path: root/site/udo/twist/automation.udo
diff options
context:
space:
mode:
authorRichard <q@1bpm.net>2025-04-13 18:48:02 +0100
committerRichard <q@1bpm.net>2025-04-13 18:48:02 +0100
commit9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22 (patch)
tree291bd79ce340e67affa755a8a6b4f6a83cce93ea /site/udo/twist/automation.udo
downloadapps.csound.1bpm.net-9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22.tar.gz
apps.csound.1bpm.net-9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22.tar.bz2
apps.csound.1bpm.net-9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22.zip
initial
Diffstat (limited to 'site/udo/twist/automation.udo')
-rwxr-xr-xsite/udo/twist/automation.udo241
1 files changed, 241 insertions, 0 deletions
diff --git a/site/udo/twist/automation.udo b/site/udo/twist/automation.udo
new file mode 100755
index 0000000..39585fb
--- /dev/null
+++ b/site/udo/twist/automation.udo
@@ -0,0 +1,241 @@
+#ifndef TWST_AUTOMATION
+#define TWST_AUTOMATION ##
+/*
+ Twist waveform editor and transformer
+ Automation and modulation
+
+ This file is part of the SONICS UDO collection by Richard Knight 2024
+ License: GPL-2.0-or-later
+ http://1bpm.net
+*/
+
+
+opcode twst_xa_rms, 0, S
+ Schannel xin
+ kscale chnget strcat(Schannel, "xrmsscale")
+ kporttime chnget strcat(Schannel, "porttime")
+
+ aL, aR, ileft, iright _twst_getcrossinput "xrms"
+ if (ileft == 1 && iright == 1) then
+ kvalue rms (aL + aR) / 2
+ elseif (ileft == 1) then
+ kvalue rms aL
+ else
+ kvalue rms aR
+ endif
+
+ kvalue *= kscale
+ if (kporttime > 0) then
+ kresultvalue portk kvalue, kporttime
+ else
+ kresultvalue = kvalue
+ endif
+ chnset kresultvalue, Schannel
+endop
+
+opcode twst_xa_pitchamdf, 0, S
+ Schannel xin
+ kscale chnget strcat(Schannel, "xpitchscale")
+ ipitchmin chnget strcat(Schannel, "xpitchmin")
+ ipitchmax chnget strcat(Schannel, "xpitchmax")
+ kporttime chnget strcat(Schannel, "porttime")
+ aL, aR, ileft, iright _twst_getcrossinput "xpitch"
+
+ if (ileft == 1 && iright == 1) then
+ kcps, krms pitchamdf (aL + aR) / 2, ipitchmin, ipitchmax
+ elseif (ileft == 1) then
+ kcps, krms pitchamdf aL, ipitchmin, ipitchmax
+ else
+ kcps, krms pitchamdf aR, ipitchmin, ipitchmax
+ endif
+
+ kvalue = ((ipitchmin + max:k(0, kcps)) / (ipitchmax - ipitchmin)) * kscale
+ if (kporttime > 0) then
+ kresultvalue portk kvalue, kporttime
+ else
+ kresultvalue = kvalue
+ endif
+ chnset kresultvalue, Schannel
+endop
+
+opcode twst_xa_pitch1, 0, S
+ Schannel xin
+ kscale chnget strcat(Schannel, "xpitchscale")
+ ihopsize chnget strcat(Schannel, "xpitchhopsize")
+ kporttime chnget strcat(Schannel, "porttime")
+
+ ipitchmin = 20
+ ipitchmax = sr / 2
+ ihopsize = pow(2, ihopsize)
+
+ aL, aR, ileft, iright _twst_getcrossinput "xpitch"
+ if (ileft == 1 && iright == 1) then
+ kcps, kamp ptrack (aL + aR) / 2, ihopsize
+ elseif (ileft == 1) then
+ kcps, kamp ptrack aL, ihopsize
+ else
+ kcps, kamp ptrack aR, ihopsize
+ endif
+
+ kvalue = ((ipitchmin + max:k(0, kcps)) / (ipitchmax - ipitchmin)) * kscale
+ if (kporttime > 0) then
+ kresultvalue portk kvalue, kporttime
+ else
+ kresultvalue = kvalue
+ endif
+ chnset kresultvalue, Schannel
+endop
+
+opcode twst_xa_pitch2, 0, S
+ Schannel xin
+ kscale chnget strcat(Schannel, "xpitchscale")
+ iperiod chnget strcat(Schannel, "xpitchperiod")
+ ipitchmin = octcps(chnget:i(strcat(Schannel, "xpitchmin")))
+ ipitchmax = octcps(chnget:i(strcat(Schannel, "xpitchmax")))
+ iampthresh chnget strcat(Schannel, "xpitchampthresh")
+ kporttime chnget strcat(Schannel, "porttime")
+
+ aL, aR, ileft, iright _twst_getcrossinput "xpitch"
+ if (ileft == 1 && iright == 1) then
+ koct, kamp pitch (aL + aR) / 2, iperiod, ipitchmin, ipitchmax, iampthresh
+ elseif (ileft == 1) then
+ koct, kamp pitch aL, iperiod, ipitchmin, ipitchmax, iampthresh
+ else
+ koct, kamp pitch aR, iperiod, ipitchmin, ipitchmax, iampthresh
+ endif
+
+ kcps cpsoct koct
+ kvalue = ((ipitchmin + max:k(0, kcps)) / (ipitchmax - ipitchmin)) * kscale
+ if (kporttime > 0) then
+ kresultvalue portk kvalue, kporttime
+ else
+ kresultvalue = kvalue
+ endif
+ chnset kresultvalue, Schannel
+endop
+
+opcode twst_xa_centroid, 0, S
+ Schannel xin
+ kscale chnget strcat(Schannel, "xcentroidscale")
+ ifftsize chnget strcat(Schannel, "xcentroidfftsize")
+ kperiod chnget strcat(Schannel, "xcentroidperiod")
+ kporttime chnget strcat(Schannel, "porttime")
+ ipitchmin = 20
+ ipitchmax = sr / 2
+ ktrig metro 1 / kperiod
+
+ aL, aR, ileft, iright _twst_getcrossinput "xcentroid"
+ if (ileft == 1 && iright == 1) then
+ kcent centroid (aL + aR) / 2, ktrig, ifftsize
+ elseif (ileft == 1) then
+ kcent centroid aL, ktrig, ifftsize
+ else
+ kcent centroid aL, ktrig, ifftsize
+ endif
+
+ kvalue = ((ipitchmin + max:k(0, kcent)) / (ipitchmax - ipitchmin)) * kscale
+ if (kporttime > 0) then
+ kresultvalue portk kvalue, kporttime
+ else
+ kresultvalue = kvalue
+ endif
+ chnset kresultvalue, Schannel
+endop
+
+opcode twst_mod_jitter, 0, S
+ Schannel xin
+ kbase chnget strcat(Schannel, "base")
+ kamp chnget strcat(Schannel, "amp")
+ kfreqmin chnget strcat(Schannel, "freqmin")
+ kfreqmax chnget strcat(Schannel, "freqmax")
+ imin chnget strcat(Schannel, "min")
+ imax chnget strcat(Schannel, "max")
+ kval jitter kamp, kfreqmin, kfreqmax
+ kval = kbase + (kval * (imax - imin))
+ kval = min:k(max:k(kval, imin), imax)
+ chnset kval, Schannel
+endop
+
+opcode twst_mod_jitter2, 0, S
+ Schannel xin
+ kbase chnget strcat(Schannel, "base")
+ ktotalamp chnget strcat(Schannel, "totalamp")
+ kamp1 chnget strcat(Schannel, "amp1")
+ kfreq1 chnget strcat(Schannel, "freq1")
+ kamp2 chnget strcat(Schannel, "amp2")
+ kfreq2 chnget strcat(Schannel, "freq2")
+ kamp3 chnget strcat(Schannel, "amp3")
+ kfreq3 chnget strcat(Schannel, "freq3")
+ imin chnget strcat(Schannel, "min")
+ imax chnget strcat(Schannel, "max")
+ kval jitter2 ktotalamp, kamp1, kfreq1, kamp2, kfreq2, kamp3, kfreq3, 1
+ kval = kbase + (kval * (imax - imin))
+ kval = min:k(max:k(kval, imin), imax)
+ chnset kval, Schannel
+endop
+
+opcode twst_mod_lfo, 0, S
+ Schannel xin
+ krate chnget strcat(Schannel, "rate")
+ kbase chnget strcat(Schannel, "base")
+ kgain chnget strcat(Schannel, "gain")
+ imin chnget strcat(Schannel, "min")
+ imax chnget strcat(Schannel, "max")
+ kfn twst_tf_getwaveformk chnget:k(strcat(Schannel, "wave"))
+ kval = kbase + (oscilikt:k(kgain, krate, kfn) * (imax - imin))
+ kval = min:k(max:k(kval, imin), imax)
+ chnset kval, Schannel
+endop
+
+opcode twst_mod_line, 0, S
+ Schannel xin
+ ilatency twst_getlatencyseconds
+ ifirst chnget strcat(Schannel, "first")
+ ilast chnget strcat(Schannel, "last")
+ if (ilatency > 0) then
+ ksig linseg ifirst, ilatency, ifirst, p3, ilast
+ else
+ ksig linseg ifirst, p3, ilast
+ endif
+
+ chnset ksig, Schannel
+endop
+
+opcode twst_mod_random, 0, S
+ Schannel xin
+ krate chnget strcat(Schannel, "rate")
+ kmin chnget strcat(Schannel, "min")
+ kmax chnget strcat(Schannel, "max")
+ kporttime chnget strcat(Schannel, "porttime")
+
+ imin chnget strcat(Schannel, "min")
+ imax chnget strcat(Schannel, "max")
+ initval random imin, imax
+
+ kval init initval
+ ktrig metro krate
+ if (ktrig == 1) then
+ kval = random:k(kmin, kmax)
+ endif
+ kportval portk kval, kporttime
+ chnset kportval, Schannel
+endop
+
+
+instr twst_automationprepare
+ icbid = p4
+ itemnum = pcount()
+ index = 5
+ Sinstr = "instr twst_automaterun\n"
+ while (index < itemnum + 1) do
+
+ Sinstr = strcat(strcat(Sinstr, strget(p(index))), "\n")
+ index += 1
+ od
+ Sinstr = strcat(Sinstr, "a_ init 0\nout a_\nendin\n")
+ ires compilestr Sinstr
+ io_sendstring("callback", sprintf("{\"cbid\":%d,\"status\":%d}", icbid, (ires == 0) ? 1 : 0))
+endin
+
+
+#end \ No newline at end of file