diff options
| author | s-ol <s+removethis@s-ol.nu> | 2025-08-05 01:22:59 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-08-05 01:44:22 +0000 |
| commit | 1e11c0cfee0d5febfa6fc9aa96a389374af3a670 (patch) | |
| tree | 411093cbb97caa3e7a56df1d1af4bcb082bea9f2 | |
| parent | builtins: add doto macro (diff) | |
| download | alive-1e11c0cfee0d5febfa6fc9aa96a389374af3a670.tar.gz alive-1e11c0cfee0d5febfa6fc9aa96a389374af3a670.zip | |
lib/glsl-view: add freeze and step!
| -rw-r--r-- | alv-lib/glsl-view.moon | 66 | ||||
| -rw-r--r-- | alv/type.moon | 2 | ||||
| -rw-r--r-- | examples/glsl-view/stream-controls.alv | 14 |
3 files changed, 67 insertions, 15 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 diff --git a/alv/type.moon b/alv/type.moon index 2e392d8..d3af642 100644 --- a/alv/type.moon +++ b/alv/type.moon @@ -30,6 +30,8 @@ local Primitive -- -- @table T T = setmetatable {}, __index: (key) => + return key if key.__class + with type = Primitive key rawset @, key, type diff --git a/examples/glsl-view/stream-controls.alv b/examples/glsl-view/stream-controls.alv index fb37c31..5fd5a03 100644 --- a/examples/glsl-view/stream-controls.alv +++ b/examples/glsl-view/stream-controls.alv @@ -1,17 +1,17 @@ ([1]import* glsl-view link-time) ([2]import osc) -([3]def - *clock* ([8]clock false 120) +([3]def + *clock* ([4]clock false 120) *oscout* ([5]osc/connect 'localhost' 9000)) -([6]def - paused? ([12]switch ([13]every 2) true false) - cam ([16]doto ([7]stream-source 'webcam' '2D' '/dev/video0') +([6]def + paused? ([7]switch ([8]every 2) true false) + cam ([9]doto ([10]stream-source 'webcam' '2D' '/dev/video0') ([11]freeze paused?) - ([14]step! ([15]every 0.5)))) + ([12]step! ([13]every 0.5)))) -([9]draw $[10]shader" +([14]draw $[15]shader" in vec2 uv; out vec4 color; |
