aboutsummaryrefslogtreecommitdiff
path: root/site/udo/interop.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/interop.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/interop.udo')
-rwxr-xr-xsite/udo/interop.udo178
1 files changed, 178 insertions, 0 deletions
diff --git a/site/udo/interop.udo b/site/udo/interop.udo
new file mode 100755
index 0000000..84a3f00
--- /dev/null
+++ b/site/udo/interop.udo
@@ -0,0 +1,178 @@
+#ifndef UDO_INTEROP
+#define UDO_INTEROP ##
+/*
+ SONICS container interoperation
+
+ This file is part of the SONICS UDO collection by Richard Knight 2021
+ License: GPL-2.0-or-later
+ http://1bpm.net
+*/
+
+
+
+/*
+ Send string to channel at i-time
+
+ io_sendstring Schannel, Svalue
+
+ Schannel channel name
+ Svalue string to send
+*/
+#ifdef LOCALINTEROPINSTR
+opcode io_sendstring, 0, SS
+ Schannel, Svalue xin
+ schedule("$LOCALINTEROPINSTR", 0, 1, Schannel, Svalue)
+endop
+#else
+opcode io_sendstring, 0, SS
+ Schannel, Svalue xin
+ if (timeinstk() == -1) then
+ outvalue Schannel, Svalue
+ endif
+endop
+#end
+
+/*
+ Send value to channel at i-time
+
+ io_send Schannel, ivalue
+
+ Schannel channel name
+ ivalue value to send
+*/
+opcode io_send, 0, Si
+ Schannel, ivalue xin
+ outvalue Schannel, ivalue
+endop
+
+
+/*
+ Send value to channel at k-rate, if changed
+
+ io_send Schannel, kvalue
+
+ Schannel channel name
+ kvalue value to send
+*/
+opcode io_send, 0, Sk
+ Schannel, kvalue xin
+ if (changed:k(kvalue) == 1) then
+ outvalue Schannel, kvalue
+ endif
+endop
+
+
+instr io_callback
+ icbid = p4
+ if (qnan(p5) == 1) then
+ Sextra = sprintf(",%s", strget(p5))
+ else
+ Sextra = ""
+ endif
+ io_sendstring("callback", sprintf("{\"cbid\": %d%s}", icbid, Sextra))
+ turnoff
+endin
+
+
+instr io_compile_channel
+ icbid = p4
+ Schannel = p5
+ prints sprintf("including from channel %s \n\n", Schannel)
+ Sdata chnget Schannel
+ ires = compilestr(Sdata)
+ Sres = (ires == -1) ? "false" : "true"
+ io_sendstring("callback", sprintf("{\"cbid\": %d, \"success\": \"%s\"}", icbid, Sres))
+ turnoff
+endin
+
+/*
+ Stop instrument if playing; schedule instrument indefinitely if not playing
+ at k-rate with optional trigger (trigger resets after one iteration)
+
+ toggle_instrumentk instrnum [, ktrigger = 1]
+ toggle_instrumentk Sinstrument [, ktrigger = 1]
+
+ instrnum instrument number
+ Sinstrument instrument name to toggle
+ ktrigger perform action when 1
+*/
+opcode toggle_instrumentk, 0, iP
+ instrnum, ktrigger xin
+ if (ktrigger == 1) then
+ if (active:k(instrnum) > 0) then
+ turnoff2 instrnum, 0, 1
+ else
+ schedulek instrnum, 0, -1
+ endif
+ ktrigger = 0
+ endif
+endop
+
+; override for named instrument
+opcode toggle_instrumentk, 0, SP
+ Sinstrument, ktrigger xin
+ toggle_instrumentk(nstrnum(Sinstrument), ktrigger)
+endop
+
+
+/*
+ Stop instrument if playing; schedule instrument indefinitely if not playing, at init time
+
+ toggle_instrument instrnum
+ toggle_instrument Sinstrument
+
+ instrnum instrument number
+ Sinstrument instrument name to toggle
+*/
+opcode toggle_instrument, 0, i
+ instrnum xin
+ if (active:i(instrnum) > 0) then
+ turnoff2 instrnum, 0, 1
+ else
+ schedule instrnum, 0, -1
+ endif
+endop
+
+; override for named instrument
+opcode toggle_instrument, 0, S
+ Sinstrument xin
+ toggle_instrument(nstrnum(Sinstrument))
+endop
+
+
+
+/*
+ Stop instrument if playing; schedule instrument indefinitely if not playing, at init time
+ For host invocation.
+
+ p4 instrument number or name
+*/
+instr toggle_instrument
+ if (qnan(p4) == 1) then
+ Sinstrument = p4
+ toggle_instrument(Sinstrument)
+ else
+ instrnum = p4
+ toggle_instrument(instrnum)
+ endif
+ turnoff
+endin
+
+instr turnonoff_instrument
+ if (qnan(p4) == 1) then
+ Sinstrument = strget(p4)
+ instrnum = nstrnum(Sinstrument)
+ else
+ instrnum = p4
+ endif
+ istate = p5
+ iruntime = (p6 == 0) ? 36000 : p6
+ if (istate == 1) then
+ schedule instrnum, 0, iruntime
+ else
+ turnoff2 instrnum, 0, 1
+ endif
+endin
+
+
+#end