aboutsummaryrefslogtreecommitdiff
path: root/site/udo/scss/elasticlip_arranger.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/scss/elasticlip_arranger.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/scss/elasticlip_arranger.udo')
-rwxr-xr-xsite/udo/scss/elasticlip_arranger.udo213
1 files changed, 213 insertions, 0 deletions
diff --git a/site/udo/scss/elasticlip_arranger.udo b/site/udo/scss/elasticlip_arranger.udo
new file mode 100755
index 0000000..2b0c09f
--- /dev/null
+++ b/site/udo/scss/elasticlip_arranger.udo
@@ -0,0 +1,213 @@
+#ifndef UDO_ELASTICLIPARRANGER
+#define UDO_ELASTICLIPARRANGER ##
+
+#include "scss/elasticlip.udo"
+#include "scss/mixer/base.udo"
+#include "array_3d.udo"
+#include "sequencing_scheduled.udo"
+#include "interop.udo"
+
+giecpa_fn = -1
+giecpa_scenenumber = -1
+
+/*
+ Follow actions
+ 0 repeat
+ 1 next
+ 2 previous
+ 3 random in channel
+ 4 stop
+*/
+
+instr ecpa_boot
+ ichannelnumber = (p4 == 0) ? 12 : p4
+ isendchannels = (p5 == 0) ? 2 : p5
+ imixermaxinserts = (p6 == 0) ? 6 : p6
+ giecpa_scenenumber = (p7 == 0) ? 16 : p7
+ schedule("mx_boot", 0, 1, ichannelnumber, isendchannels, imixermaxinserts)
+
+ giecpa_fn arr3d_init ichannelnumber, giecpa_scenenumber, 5
+ turnoff
+endin
+
+
+instr ecpa_addclip
+ icbid = p4
+ iclipid = p5
+ ichannel = p6
+ iscene = p7
+
+ index arr3d_index giecpa_fn, ichannel, iscene, 0
+ tabw_i iclipid, index, giecpa_fn
+
+ ; set default follow actions
+ tabw_i 0, index + 1, giecpa_fn
+ tabw_i 0.5, index + 2, giecpa_fn
+ tabw_i 0, index + 3, giecpa_fn
+ tabw_i 16, index + 4, giecpa_fn
+ io_sendstring("callback", sprintf("{\"cbid\": %d}", icbid))
+ turnoff
+endin
+
+
+instr ecpa_moveclip
+ icbid = p4
+ ichannelfrom = p5
+ iscenefrom = p6
+ ichannelto = p7
+ isceneto = p8
+
+ index_from arr3d_index giecpa_fn, ichannelfrom, iscenefrom, 0
+ index_to arr3d_index giecpa_fn, ichannelto, isceneto, 0
+
+ index = 0
+ while (index < 5) do
+ tabw_i tab_i(index_from + index, giecpa_fn), index_to + index, giecpa_fn
+ index += 1
+ od
+ io_sendstring("callback", sprintf("{\"cbid\": %d}", icbid))
+ turnoff
+endin
+
+
+instr ecpa_rmclip
+ icbid = p4
+ ichannel = p5
+ iscene = p6
+ iclipindex arr3d_index giecpa_fn, ichannel, iscene, 0
+
+ ; if playing, stop
+
+ index = 0
+ while (index < 5) do
+ tabw_i 0, iclipindex + index, giecpa_fn
+ index += 1
+ od
+ io_sendstring("callback", sprintf("{\"cbid\": %d}", icbid))
+ turnoff
+endin
+
+
+opcode _ecpa_getnext, i, iii
+ ichannel, iscene, ifollowaction xin
+ inextscene = iscene
+
+ if (ifollowaction == 0) then ; repeat
+ goto output
+
+ elseif (ifollowaction == 1 || ifollowaction == 2) then ; next or previous
+
+ isceneindex = (ifollowaction == 1) ? iscene + 1 : iscene - 1
+ while ((ifollowaction == 1 && isceneindex < giecpa_scenenumber) || (ifollowaction == 2 && isceneindex >= 0)) do
+ item arr3d_get ichannel, isceneindex, 0
+ if (item != 0) then
+ inextscene = isceneindex
+ goto output
+ endif
+ isceneindex += (ifollowaction == 1) ? 1 : -1
+ od
+
+ isceneindex = (ifollowaction == 1) ? 0 : giecpa_scenenumber - 1
+ while ((ifollowaction == 1 && isceneindex <= iscene) || (ifollowaction == 2 && isceneindex >= iscene)) do
+ item arr3d_get ichannel, isceneindex, 0
+ if (item != 0) then
+ inextscene = isceneindex
+ goto output
+ endif
+ isceneindex += (ifollowaction == 1) ? 1 : -1
+ od
+
+ elseif (ifollowaction == 3) then ; random
+ isceneindex = 0
+ insertindex = 0
+ iactivescenesnum = 0
+ iactivescenes[] init giecpa_scenenumber
+ while (isceneindex < giecpa_scenenumber) do
+ item arr3d_get ichannel, isceneindex, 0
+ if (item != 0) then
+ iactivescenesnum += 1
+ iactivescenes[insertindex] = isceneindex
+ insertindex += 1
+ endif
+ isceneindex += 1
+ od
+ inextscene = iactivescenes[round(random(0, iactivescenesnum - 1))]
+ goto output
+ endif
+
+output:
+ xout inextscene
+endop
+
+
+instr ecpa_playslot
+ icbid = p4
+ ichannel = p5
+ iscene = p6
+ p1 += (ichannel + iscene) / 1000000
+ p3 = 36000
+
+ io_sendstring("callback", sprintf("{\"cbid\": %d, \"status\": -1}", icbid))
+ iclipindex arr3d_index giecpa_fn, ichannel, iscene, 0
+
+ ifollowaction1 = tab_i(iclipindex + 1, giecpa_fn)
+ ifollowchance = tab_i(iclipindex + 2, giecpa_fn)
+ ifollowaction2 = tab_i(iclipindex + 3, giecpa_fn)
+ ilength = tab_i(iclipindex + 4, giecpa_fn)
+
+ ifollowaction = (random(0, 1) <= ifollowchance) ? ifollowaction1 : ifollowaction2
+
+ iplaybackinstr = nstrnum("ecp_playback") + (icbid / 1000000)
+
+ klaunched init 0
+ if (gkseq_bar_trig == 1 && klaunched == 0) then
+ klaunched = 1
+ schedulek(iplaybackinstr, 0, -1, icbid, tab_i(iclipindex, giecpa_fn))
+
+ ; turnoff other scene instances
+ isceneindex = 0
+ while (isceneindex < giecpa_scenenumber) do
+ if (isceneindex != iscene) then
+ turnoff2 (ichannel + iscene) / 1000000, 4, 1
+ endif
+ isceneindex += 1
+ od
+ endif
+
+ if (klaunched == 1) then
+ ktrig nextbeatxof ilength
+ if (ktrig == 1) then
+ if (ifollowaction != 4) then ; if not stop
+ inextscene _ecpa_getnext ichannel, iscene, ifollowaction
+ schedulek("ecpa_playslot", 0, 1, icbid, ichannel, inextscene)
+ endif
+ turnoff
+ endif
+ endif
+
+ kreleasing init 0
+ if (release:k() == 1 && kreleasing == 0) then
+ kreleasing = 1
+ turnoff2 iplaybackinstr, 4, 1
+ endif
+endin
+
+
+instr ecpa_playscene
+ icbid = p4
+ iscene = p5
+
+ klaunched init 0
+ if (gkseq_bar_trig == 1 && klaunched == 0) then
+ klaunched = 1
+ ibaseinstr = nstrnum("ecpa_playslot")
+ ichannel = 0
+ while (ichannel < gichannelnumber) do
+ turnoff2 (ichannel + iscene) / 1000000, 4, 1
+ ichannel += 1
+ od
+ endif
+
+endin
+
+#end