#ifndef UDO_INTEROP #define UDO_INTEROP ## /* SONICS container interoperation, web interface This file is part of the SONICS UDO collection by Richard Knight 2021, 2024 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 */ opcode io_sendstring, 0, SS Schannel, Svalue xin prints sprintf("%s %s\n", Schannel, Svalue) endop /* 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 prints sprintf("%s %f\n", 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 ktrigval init 0 if (changed:k(kvalue) == 1) then printf "%s %f\n", ktrigval, Schannel, kvalue ktrigval += 1 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