aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-09-04 12:14:46 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-02 14:24:49 +0000
commit6946779f88fec479239b36128924996d0495dce6 (patch)
treea2f1ee6dc6d3fe60ba0d23cc169ca03e2b71b9c2
parenthave alv-lua modules return Results, not plain tables (diff)
downloadalive-6946779f88fec479239b36128924996d0495dce6.tar.gz
alive-6946779f88fec479239b36128924996d0495dce6.zip
update lib and docs to new module convention
-rw-r--r--alv-lib/array.moon16
-rw-r--r--alv-lib/logic.moon20
-rw-r--r--alv-lib/math.moon68
-rw-r--r--alv-lib/midi.moon20
-rw-r--r--alv-lib/midi/launchctl.moon14
-rw-r--r--alv-lib/osc.moon14
-rw-r--r--alv-lib/pilot.moon14
-rw-r--r--alv-lib/random.moon16
-rw-r--r--alv-lib/rhythm.moon12
-rw-r--r--alv-lib/sc.moon12
-rw-r--r--alv-lib/string.moon10
-rw-r--r--alv-lib/struct.moon12
-rw-r--r--alv-lib/time.moon88
-rw-r--r--alv-lib/util.moon10
-rw-r--r--alv-lib/vis.moon12
-rwxr-xr-xdocs/gen/index9
-rwxr-xr-xdocs/gen/module23
-rw-r--r--docs/gen/shim.moon21
18 files changed, 237 insertions, 154 deletions
diff --git a/alv-lib/array.moon b/alv-lib/array.moon
index cb83334..6005b14 100644
--- a/alv-lib/array.moon
+++ b/alv-lib/array.moon
@@ -236,10 +236,14 @@ concat = Constant.meta
@out\set out
-{
- :get, :set
- :head, :tail, :prepend
- :insert, :remove
+Constant.meta
+ meta:
+ name: 'array'
+ summary: "Utilities for dealing with arrays."
+
+ value:
+ :get, :set
+ :head, :tail, :prepend
+ :insert, :remove
- :size, :concat
-}
+ :size, :concat
diff --git a/alv-lib/logic.moon b/alv-lib/logic.moon
index 1d853dc..763638c 100644
--- a/alv-lib/logic.moon
+++ b/alv-lib/logic.moon
@@ -123,11 +123,15 @@ bool = Constant.meta
type: T.bool
tick: => @out\set tobool @inputs[1]!
-{
- :eq, '==': eq
- 'not-eq': not_eq, '!=': not_eq
- and: and_
- or: or_
- not: not_
- :bool
-}
+Constant.meta
+ meta:
+ name: 'logic'
+ summary: "Logical operations."
+
+ value:
+ :eq, '==': eq
+ 'not-eq': not_eq, '!=': not_eq
+ and: and_
+ or: or_
+ not: not_
+ :bool
diff --git a/alv-lib/math.moon b/alv-lib/math.moon
index 8475742..a63f124 100644
--- a/alv-lib/math.moon
+++ b/alv-lib/math.moon
@@ -152,35 +152,39 @@ log = func_def 'log', 'val [base]', math.log, "Logarithm with optional base.", n
log10 = func_def 'log10', 'val', math.log10, "Logarithm with base 10."
sqrt = func_def 'sqrt', 'val', math.sqrt, "Square root function."
-{
- :add, '+': add
- :sub, '-': sub
- :mul, '*': mul
- :div, '/': div
- :pow, '^': pow
- :mod, '%': mod
-
- :even, :odd
-
- :mix
- :min, :max
-
- pi: Constant.meta
- value: math.pi
- meta: summary: 'The pi constant.'
-
- tau: Constant.meta
- value: math.pi*2
- meta: summary: 'The tau constant.'
-
- huge: Constant.meta
- value: math.huge
- meta: summary: 'Positive infinity constant.'
-
- :sin, :cos, :tan
- :asin, :acos, :atan, :atan2
- :sinh, :cosh, :tanh
-
- :floor, :ceil, :abs
- :exp, :log, :log10, :sqrt
-}
+Constant.meta
+ meta:
+ name: 'math'
+ summary: "Mathematical functions."
+
+ value:
+ :add, '+': add
+ :sub, '-': sub
+ :mul, '*': mul
+ :div, '/': div
+ :pow, '^': pow
+ :mod, '%': mod
+
+ :even, :odd
+
+ :mix
+ :min, :max
+
+ pi: Constant.meta
+ value: math.pi
+ meta: summary: 'The pi constant.'
+
+ tau: Constant.meta
+ value: math.pi*2
+ meta: summary: 'The tau constant.'
+
+ huge: Constant.meta
+ value: math.huge
+ meta: summary: 'Positive infinity constant.'
+
+ :sin, :cos, :tan
+ :asin, :acos, :atan, :atan2
+ :sinh, :cosh, :tanh
+
+ :floor, :ceil, :abs
+ :exp, :log, :log10, :sqrt
diff --git a/alv-lib/midi.moon b/alv-lib/midi.moon
index 3f9eedd..70e3985 100644
--- a/alv-lib/midi.moon
+++ b/alv-lib/midi.moon
@@ -96,11 +96,15 @@ cc = Constant.meta
bar: @state
}
-{
- :input
- :output
- :inout
- :gate
- :trig
- :cc
-}
+Constant.meta
+ meta:
+ name: 'midi'
+ summary: "MIDI integration."
+
+ value:
+ :input
+ :output
+ :inout
+ :gate
+ :trig
+ :cc
diff --git a/alv-lib/midi/launchctl.moon b/alv-lib/midi/launchctl.moon
index d231187..8a8d599 100644
--- a/alv-lib/midi/launchctl.moon
+++ b/alv-lib/midi/launchctl.moon
@@ -184,8 +184,12 @@ Send bangs for the `i`-th note-button (MIDI-notes starting from `start`).
if @state[curr_i+1]
@out\set true
-{
- 'cc-seq': cc_seq
- 'gate-seq': gate_seq
- 'trig-seq': trig_seq
-}
+Constant.meta
+ meta:
+ name: 'midi/launchctl'
+ summary: "MIDI sequencing with the LaunchControl MIDI controller"
+
+ value:
+ 'cc-seq': cc_seq
+ 'gate-seq': gate_seq
+ 'trig-seq': trig_seq
diff --git a/alv-lib/osc.moon b/alv-lib/osc.moon
index ff58c94..17433ce 100644
--- a/alv-lib/osc.moon
+++ b/alv-lib/osc.moon
@@ -80,8 +80,12 @@ of the arguments change.
msg = pack path, if 'table' == type value then unpack value else value
socket\send msg
-{
- :connect
- :send
- :sync
-}
+Constant.meta
+ meta:
+ name: 'osc'
+ summary: "OSC integration."
+
+ value:
+ :connect
+ :send
+ :sync
diff --git a/alv-lib/pilot.moon b/alv-lib/pilot.moon
index 1f14c73..fa30708 100644
--- a/alv-lib/pilot.moon
+++ b/alv-lib/pilot.moon
@@ -81,8 +81,12 @@ effect = Constant.meta
tick: =>
send @unwrap_all!
-{
- :play
- 'play!': play_
- :effect
-}
+Constant.meta
+ meta:
+ name: 'pilot'
+ summary: "Pilot integration."
+
+ value:
+ :play
+ 'play!': play_
+ :effect
diff --git a/alv-lib/random.moon b/alv-lib/random.moon
index 322855a..5cf23d0 100644
--- a/alv-lib/random.moon
+++ b/alv-lib/random.moon
@@ -79,9 +79,13 @@ vec = (n) ->
@gen! if @inputs.trig and @inputs.trig\dirty!
@out\set [apply_range @inputs.range, v for v in *@state]
-{
- :num
- vec2: vec 2
- vec3: vec 3
- vec4: vec 4
-}
+Constant.meta
+ meta:
+ name: 'random'
+ summary: "Random number generation."
+
+ value:
+ :num
+ vec2: vec 2
+ vec3: vec 3
+ vec4: vec 4
diff --git a/alv-lib/rhythm.moon b/alv-lib/rhythm.moon
index 770bd48..57be9a7 100644
--- a/alv-lib/rhythm.moon
+++ b/alv-lib/rhythm.moon
@@ -115,7 +115,11 @@ When fed a num~ or num! stream, outputs a bang if the corresponding step is on."
if @inputs.steps[i]!
@out\set true
-{
- :euclid
- :trigseq
-}
+Constant.meta
+ meta:
+ name: 'rhythm'
+ summary: "Rhythm-generation and sequencing."
+
+ value:
+ :euclid
+ :trigseq
diff --git a/alv-lib/sc.moon b/alv-lib/sc.moon
index f4aac65..110c019 100644
--- a/alv-lib/sc.moon
+++ b/alv-lib/sc.moon
@@ -77,7 +77,11 @@ Plays the synth `synth` on the `udp/socket` `socket` whenever any `evt` is live.
msg = pack '/s_new', synth, -1, 0, 1, unpack ctrls
socket\send msg
-{
- :play
- 'play!': play_
-}
+Constant.meta
+ meta:
+ name: 'sc'
+ summary: "SuperCollider integration."
+
+ value:
+ :play
+ 'play!': play_
diff --git a/alv-lib/string.moon b/alv-lib/string.moon
index 37810a4..c43dd6a 100644
--- a/alv-lib/string.moon
+++ b/alv-lib/string.moon
@@ -12,6 +12,10 @@ str = Constant.meta
type: T.str
tick: => @out\set table.concat [tostring i! for i in *@inputs]
-{
- :str, '..': str
-}
+Constant.meta
+ meta:
+ name: 'string'
+ summary: "Utilities for dealing with strings."
+
+ value:
+ :str, '..': str
diff --git a/alv-lib/struct.moon b/alv-lib/struct.moon
index 74e23f4..94bd82f 100644
--- a/alv-lib/struct.moon
+++ b/alv-lib/struct.moon
@@ -119,7 +119,11 @@ remove = Constant.meta
@out\set struct
-{
- :get, :set
- :insert, :remove
-}
+Constant.meta
+ meta:
+ name: 'struct'
+ summary: "Utilities for dealing with structs."
+
+ value:
+ :get, :set
+ :insert, :remove
diff --git a/alv-lib/time.moon b/alv-lib/time.moon
index 85145b4..f091792 100644
--- a/alv-lib/time.moon
+++ b/alv-lib/time.moon
@@ -1,26 +1,7 @@
-import Constant, EvtStream, IOStream, Error, Op, Input, T, sig, evt
- from require 'alv.base'
+import Constant, Error, Op, Input, T, sig, evt from require 'alv.base'
+import RTNode from require 'alv'
import monotime from require 'system'
-class Clock extends IOStream
- new: (@frametime) =>
- super T.clock
-
- return unless monotime
- @last = monotime!
- @dt = 0
-
- poll: =>
- time = monotime!
- @dt = time - @last
- if @dt >= @frametime
- @set { dt: @dt, :time }
- @last = time
-
-class ScaledClock extends EvtStream
- set: (val) => @value
- unwrap: => @value
-
clock = Constant.meta
meta:
name: 'clock'
@@ -35,15 +16,38 @@ frame rate.
value: class extends Op
new: (...) =>
super ...
- @out or= Clock!
+ @out or= T.clock\mk_evt!
setup: (inputs) =>
fps = (-sig.num)\match inputs
- super fps: Input.hot fps or Constant.num 60
- @out.frametime = 1 / @inputs.fps!
+ super
+ fps: Input.cold fps or Constant.num 60
+ io: Input.hot T.bang\mk_evt!
+
+ poll: =>
+ time = monotime!
+ @state or= time
+ dt = time - @state
+ ft = 1 / @inputs.fps!
+
+ if dt >= ft
+ @inputs.io.result\set true
+ true
tick: =>
- @out.frametime = 1 / @inputs.fps!
+ time = monotime!
+ dt = time - @state
+ @state = time
+
+ @out\set :time, :dt
+
+default_clock = do
+ op = clock!!
+ op\setup {}
+ op.out.meta =
+ name: '*clock*'
+ summary: 'Default clock source (60fps).'
+ RTNode :op, result: op.out
scale_time = Constant.meta
meta:
@@ -324,18 +328,22 @@ Emits `bang!`s with delays `delay0`, `delay1`, … in between.
vis: => step: @state.i\set true
-{
- :clock
- 'scale-time': scale_time
- :lfo
- :ramp
- :tick
- :every
- 'val-seq': val_seq
- 'bang-seq': bang_seq
-
- '*clock*': with Clock 1/60
- .meta =
- name: '*clock*'
- summary: 'Default clock source (60fps).'
-}
+RTNode
+ children: { default_clock }
+
+ result: Constant.meta
+ meta:
+ name: 'time'
+ summary: "Time-variant operators."
+
+ value:
+ :clock
+ 'scale-time': scale_time
+ :lfo
+ :ramp
+ :tick
+ :every
+ 'val-seq': val_seq
+ 'bang-seq': bang_seq
+
+ '*clock*': default_clock
diff --git a/alv-lib/util.moon b/alv-lib/util.moon
index 69ef389..11c2c7e 100644
--- a/alv-lib/util.moon
+++ b/alv-lib/util.moon
@@ -18,6 +18,10 @@ edge = Constant.meta
@out\set true
@state = now
-{
- :edge
-}
+Constant.meta
+ meta:
+ name: 'util'
+ summary: "Utility operators."
+
+ value:
+ :edge
diff --git a/alv-lib/vis.moon b/alv-lib/vis.moon
index f3106a2..9429ef2 100644
--- a/alv-lib/vis.moon
+++ b/alv-lib/vis.moon
@@ -77,7 +77,11 @@ Visualizes `val` as an RGB(A) color with each component in range `0 - range`.
rgb: @state
}
-{
- :bar
- :rgb
-}
+Constant.meta
+ meta:
+ name: 'vis'
+ summary: "Operators for in-editor visualisation."
+
+ value:
+ :bar
+ :rgb
diff --git a/docs/gen/index b/docs/gen/index
index 20fb3bd..1536645 100755
--- a/docs/gen/index
+++ b/docs/gen/index
@@ -2,6 +2,7 @@
require 'alv'
import render, layout, autoref, subnav from require 'docs.gen.layout'
import section, h1, h2, p, ul, li, a, code from require 'docs.gen.dom'
+import get_module from require 'docs.gen.shim'
import compile from require 'discount'
export OUT
@@ -20,9 +21,11 @@ spit = (file, str) ->
md = slurp file
for file in *arg[3,]
- if mod = file\match '/module/(.*)%.html'
- name = mod\gsub '/', '.'
- md ..= " - [`#{name}`](module/#{mod}.html)\n"
+ if name = file\match '/module/(.*)%.html'
+ modname = name\gsub '/', '.'
+ mod = get_module "alv-lib.#{modname}"
+ summary = if mod.meta then ": #{mod.meta.summary}" else ''
+ md ..= " - [`#{modname}`](module/#{name}.html)#{summary}\n"
content = compile (autoref md), 'githubtags', 'fencedcode'
sub = subnav [a for a in *arg[3,]]
diff --git a/docs/gen/module b/docs/gen/module
index 77336cf..7b94dff 100755
--- a/docs/gen/module
+++ b/docs/gen/module
@@ -1,17 +1,11 @@
#!/usr/bin/env moon
import Constant from require 'alv'
-import render, layout, subnav from require 'docs.gen.layout'
-import h2, h3, ul, li, code from require 'docs.gen.dom'
+import render, render_meta, layout, subnav from require 'docs.gen.layout'
+import h2, h3, p, ul, li, code from require 'docs.gen.dom'
+import get_module from require 'docs.gen.shim'
import opairs from require 'alv.util'
-export OUT, require
-
-require = do
- old_require = require
- blacklist = {k, true for k in *{'osc', 'socket', 'system', 'luartmidi'}}
- (mod, ...) ->
- return {} if blacklist[mod]
- old_require mod, ...
+export OUT
slurp = (file) ->
file = io.open file, 'r'
@@ -26,18 +20,19 @@ spit = (file, str) ->
{ OUT, module, name } = arg
name or= module
-const = Constant.wrap require module
-module = const\unwrap!
+module = get_module module
+raw = module!
spit OUT, layout
title: "#{name} module reference"
body: table.concat {
subnav [a for a in *arg[4,]]
h2 (code name), ' module reference'
+ p if m = module.meta then m.summary else ''
h3 'index'
- ul for key, node in opairs module.values
+ ul for key, node in opairs raw.values
li render key, node.result, nil, true
h3 'details'
- ul for key, node in opairs module.values
+ ul for key, node in opairs raw.values
li render key, node.result
}, ''
diff --git a/docs/gen/shim.moon b/docs/gen/shim.moon
new file mode 100644
index 0000000..01a96cc
--- /dev/null
+++ b/docs/gen/shim.moon
@@ -0,0 +1,21 @@
+import RTNode from require 'alv'
+
+export require
+
+require = do
+ old_require = require
+ blacklist = {k, true for k in *{'osc', 'socket', 'system', 'luartmidi'}}
+ (mod, ...) ->
+ return {} if blacklist[mod]
+ old_require mod, ...
+
+get_module = (name) ->
+ rtn_or_module = require name
+ if rtn_or_module.__class == RTNode
+ assert rtn_or_module.result
+ else
+ rtn_or_module
+
+{
+ :get_module
+}