aboutsummaryrefslogtreecommitdiffstats
path: root/alv-lib/glsl.moon
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2025-03-14 23:59:49 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-14 23:59:49 +0000
commitda9f62d57afc464fd04bb39e0f250b40f23d78f3 (patch)
tree49b1ed4eafe17b313aed23519692c16ef3b38919 /alv-lib/glsl.moon
parentupdate Dockerfile ref (diff)
downloadalive-macros.tar.gz
alive-macros.zip
Diffstat (limited to 'alv-lib/glsl.moon')
-rw-r--r--alv-lib/glsl.moon66
1 files changed, 66 insertions, 0 deletions
diff --git a/alv-lib/glsl.moon b/alv-lib/glsl.moon
new file mode 100644
index 0000000..3f973ae
--- /dev/null
+++ b/alv-lib/glsl.moon
@@ -0,0 +1,66 @@
+import Constant, Op, Builtin, Input, T, Struct, const, any from require 'alv.base'
+import new_message, add_item from require 'alv-lib._osc'
+import dns, udp from require 'socket'
+
+glsl_type = (type) ->
+ switch type
+ when T.num then 'float'
+ when T.str then 'sampler3D'
+ when T.bool then 'bool'
+ else
+ error "unknown primitive type"
+
+resubst = (str, fn) ->
+ str = str\gsub '##', '#'
+ str\gsub '#{(%d+)}', fn
+
+shader = Constant.meta
+ meta:
+ name: 'gate'
+ summary: "gate from note-on and note-off messages."
+ examples: { '(midi/gate [port] note [chan])' }
+
+ value: class extends Op
+ pattern = const.str + any!^0
+
+ setup: (inputs, scope) =>
+ { code, params } = pattern\match inputs
+
+ super [Input.hot param for param in *params]
+
+ uniforms = {}
+ inputs = {}
+
+ for i, input in ipairs @inputs
+ table.insert uniforms, "uniform #{glsl_type input\type!} alv_param_#{i};"
+
+ code = code.result!
+ code = resubst code, (i) -> "alv_param_#{i}"
+
+ table.insert uniforms, code
+ code = table.concat uniforms, '\n'
+
+ print code
+
+ @state or= with sock = udp!
+ \setpeername '127.0.0.1', 9000
+
+ msg = new_message "/-/shader"
+ add_item msg, T.str, code
+ @state\send msg.pack msg.content
+
+ tick: (setup) =>
+ for i, input in ipairs @inputs
+ if setup or input\dirty!
+ msg = new_message "/alv_param_#{i}"
+ print "/alv_param_#{i}", input!
+ add_item msg, input\type!, input!
+ @state\send msg.pack msg.content
+
+Constant.meta
+ meta:
+ name: 'glsl-view'
+ summary: "glsl-view integration via OSC."
+
+ value:
+ :shader