diff options
Diffstat (limited to 'alv-lib')
| -rw-r--r-- | alv-lib/link-time.moon | 61 |
1 files changed, 39 insertions, 22 deletions
diff --git a/alv-lib/link-time.moon b/alv-lib/link-time.moon index 4f54d7a..f6b169d 100644 --- a/alv-lib/link-time.moon +++ b/alv-lib/link-time.moon @@ -5,31 +5,36 @@ clock = Constant.meta meta: name: 'clock' summary: "Create a clock source." - examples: { '(clock [synced] [bpm] [fps])' } + examples: { '(clock [sync-mode] [bpm] [fps])' } description: "Creates a new `link/clock~` stream. The clock event stream is an IO that triggers other operators at a fixed frame rate. -- `synced` has to be a bool~ constant and defaults to `false`. +- `sync-mode` has to be a bool or str and defaults to `false`: + - `\"none\"` / `false`: no syncing (link disabled) + - `\"tempo\"`: tempo sync + - `\"full\"`: tempo and start/stop sync (starts stopped) - `bpm` should be a num~ stream and defaults to `120`. - `fps` has to be a num= constant and defaults to `60` if omitted." value: class extends Op setup: (inputs) => - { synced, bpm, fps } = (sig.bool + -sig.num + -sig.num)\match inputs + { synced, bpm, fps } = (-(sig.bool / sig.str) + -sig.num + -sig.num)\match inputs super - synced: Input.hot synced or Constant.bool false + mode: Input.hot synced or Constant.bool false bpm: Input.hot bpm or Constant.num 120 fps: Input.hot fps or Constant.num 60 io: Input.hot T.bang\mk_evt! @setup_out '~', T['link/clock'] - @state or= { - link: al.create 120 - state: al.create_session_state! - } - @state.time or= @state.link\clock_micros! + if not @state + @state = { + link: al.create @inputs.bpm! + state: al.create_session_state! + } + + @state.time or= @state.link\clock_micros! poll: => time = @state.link\clock_micros! @@ -37,27 +42,39 @@ frame rate. ft = 1000*1000 / @inputs.fps! if dt >= ft and not @inputs.io.result\dirty! - @state.state = al.create_session_state! - @state.link\capture_app_session_state @state.state @inputs.io.result\set true true tick: (setup) => - { :link, :time, :state } = @state + { :link, :state } = @state + + link\capture_app_session_state state - if @inputs.synced\dirty! - link\enable @inputs.synced! + time = link\clock_micros! + dirty = false if @inputs.bpm\dirty! state\set_tempo @inputs.bpm!, time - - link\commit_app_session_state state - - if setup or @inputs.io\dirty! - time = link\clock_micros! - dt = time - @state.time - @state.time = time - @out\set :time, :state, :dt + dirty = true + + if @inputs.mode\dirty! + mode = @inputs.mode! + link\enable_start_stop_sync mode == "full" + link\enable mode != "none" and mode != false + if mode != "full" + state\set_is_playing true, time + dirty = true + + if dirty + link\commit_app_session_state state + + if setup + @out\set :time, :state, dt: 0 + else if @inputs.io\dirty! + if state\is_playing! + dt = time - @state.time + @out\set :time, :state, :dt + @state.time = time every = Constant.meta meta: |
