aboutsummaryrefslogtreecommitdiffstats
path: root/alv-lib
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2025-08-05 01:22:59 +0000
committers-ol <s+removethis@s-ol.nu>2025-08-05 01:44:22 +0000
commit1e11c0cfee0d5febfa6fc9aa96a389374af3a670 (patch)
tree411093cbb97caa3e7a56df1d1af4bcb082bea9f2 /alv-lib
parentbuiltins: add doto macro (diff)
downloadalive-1e11c0cfee0d5febfa6fc9aa96a389374af3a670.tar.gz
alive-1e11c0cfee0d5febfa6fc9aa96a389374af3a670.zip
lib/glsl-view: add freeze and step!
Diffstat (limited to 'alv-lib')
-rw-r--r--alv-lib/glsl-view.moon66
1 files changed, 58 insertions, 8 deletions
diff --git a/alv-lib/glsl-view.moon b/alv-lib/glsl-view.moon
index 8b3ec3f..74c53a2 100644
--- a/alv-lib/glsl-view.moon
+++ b/alv-lib/glsl-view.moon
@@ -1,4 +1,4 @@
-import Constant, PureOp, Op, template_subst, Input, T, Array, Struct, sig, const from require 'alv.base'
+import Constant, PureOp, Op, template_subst, Input, T, Array, Struct, sig, evt, const, any from require 'alv.base'
import Message, Bundle, Timetag, add_item from require 'alv-lib._osc'
import dns, udp from require 'socket'
@@ -28,6 +28,8 @@ GLSL_SAMPLER_TYPES =
"CUBE_MAP_ARRAY": 'samplerCubeArray'
"BUFFER": 'samplerBuffer'
+Uniform = Struct type: T.str, val: T.str
+
uniform = Constant.meta
meta:
name: 'uniform'
@@ -83,14 +85,14 @@ video_source = Constant.meta
args: args and Input.cold args
samplertype = assert GLSL_SAMPLER_TYPES[@inputs.type!]
- @setup_out '=', (Struct type: T.str, val: T.str), type: samplertype, val: @inputs.name!
+ @setup_out '=', Uniform, type: samplertype, val: @inputs.name!
tick: =>
{ :socket, :name, :type, :filename, :format, :args } = @unwrap_all!
with @inputs.socket!
filename = tryprefix @prefix, filename
- msg = Message.new{ address: "/texture/#{name}/video", types: "ss", "TEXTURE_#{type}", filename }
+ msg = Message.new{ address: "/source/#{name}/video", types: "ss", "TEXTURE_#{type}", filename }
msg\add 's', format if format
add_item msg, @inputs.args\type!, args if args
\send Message.pack msg.content
@@ -98,7 +100,7 @@ video_source = Constant.meta
-- destroy: =>
-- name = @inputs.name!
-- with @inputs.socket!
- -- \send Message.pack { address: "/texture/#{name}/destroy", types: "" }
+ -- \send Message.pack { address: "/source/#{name}/destroy", types: "" }
stream_source = Constant.meta
meta:
@@ -132,14 +134,14 @@ stream_source = Constant.meta
args: args and Input.cold args
samplertype = assert GLSL_SAMPLER_TYPES[@inputs.type!]
- @setup_out '=', (Struct type: T.str, val: T.str), type: samplertype, val: @inputs.name!
+ @setup_out '=', Uniform, type: samplertype, val: @inputs.name!
tick: =>
{ :socket, :name, :type, :filename, :format, :args } = @unwrap_all!
with @inputs.socket!
filename = tryprefix @prefix, filename
- msg = Message.new{ address: "/texture/#{name}/stream", types: "ss", "TEXTURE_#{type}", filename }
+ msg = Message.new{ address: "/source/#{name}/stream", types: "ss", "TEXTURE_#{type}", filename }
msg\add 's', format if format
add_item msg, @inputs.args\type!, args if args
\send Message.pack msg.content
@@ -165,13 +167,59 @@ tsv_source = Constant.meta
type: Input.hot type or Constant.str "2D"
samplertype = assert GLSL_SAMPLER_TYPES[@inputs.type!]
- @setup_out '=', (Struct type: T.str, val: T.str), type: samplertype, val: @inputs.name!
+ @setup_out '=', Uniform, type: samplertype, val: @inputs.name!
tick: =>
{ :socket, :name, :type } = @unwrap_all!
with @inputs.socket!
- \send Message.pack { address: "/texture/#{name}/tsv", types: "ss", "TEXTURE_#{type}", name }
+ \send Message.pack { address: "/source/#{name}/tsv", types: "ss", "TEXTURE_#{type}", name }
+
+freeze = Constant.meta
+ meta:
+ name: 'freeze'
+ summary: "freeze a texture source."
+ examples: { '(freeze [socket] source freeze?)' }
+
+ value: class extends Op
+ pattern = -sig['osc/out'] + const[Uniform] + any.bool
+ setup: (inputs, scope) =>
+ { socket, source, freeze } = pattern\match inputs
+
+ super
+ socket: Input.hot socket or scope\get '*oscout*'
+ source: Input.cold source
+ freeze: Input.hot freeze
+
+ tick: =>
+ { :socket, :source, :freeze } = @unwrap_all!
+
+ with @inputs.socket!
+ msg = Message.new{ address: "/source/#{source.val}/freeze", types: "" }
+ add_item msg, @inputs.freeze\type!, freeze
+ \send Message.pack msg.content
+
+step_ = Constant.meta
+ meta:
+ name: 'step!'
+ summary: "step a frozen texture source."
+ examples: { '(step! [socket] source [trig!])' }
+
+ value: class extends Op
+ pattern = -sig['osc/out'] + any[Uniform] + -evt.bang
+ setup: (inputs, scope) =>
+ { socket, source, trig } = pattern\match inputs
+
+ super
+ socket: Input.hot socket or scope\get '*oscout*'
+ source: Input.hot source
+ trig: trig and Input.hot trig
+
+ tick: =>
+ { :socket, :source, :trig } = @unwrap_all!
+
+ with @inputs.socket!
+ \send Message.pack { address: "/source/#{source.val}/step", types: "I" }
shader_ = Constant.meta
meta:
@@ -284,5 +332,7 @@ Constant.meta
'stream-source': stream_source
'tsv-source': tsv_source
+ :freeze, 'step!': step_
+
shader: shader_
:draw