git.s-ol.nu alive / a672e59
rename time/sequence to time/val-seq and add time/bang-seq s-ol 1 year, 3 months ago
2 changed file(s) with 78 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
5151
5252 @out or= T.bang\mk_evt!
5353
54 if trig\type! == T.bang
55 @state or= 1
56 else
57 @state = nil
58
5459 super
5560 trig: Input.hot trig
5661 n: Input.cold n
5762 k: Input.cold k
58
59 if @inputs.trig\type! == T.bang
60 @state or= 1
61 else
62 @state = nil
6363
6464 tick: =>
6565 { :trig, :n, :k } = @unwrap_all!
2525 name: 'clock'
2626 summary: "Create a clock source."
2727 examples: { '(clock)', '(clock fps)' }
28 description: "Creates a new clock event stream.
28 description: "Creates a new `time/clock!` stream.
2929
3030 The clock event stream is an IO that triggers other operators at a fixed
3131 frame rate.
3232
33 - `fps` has to be an eval-time constant and defaults to `60` if omitted."
33 - `fps` has to be a num= constant and defaults to `60` if omitted."
3434 value: class extends Op
3535 new: (...) =>
3636 super ...
5151 examples: { '(scale-time [clock] scale)' }
5252 description: "Creates a new clock event stream scaled by `scale`.
5353
54 - `clock` should be a `time/clock` event stream. This argument can be omitted
55 and the stream be passed as a dynamic definition in `*clock*` instead.
56 - `scale` should be a num-value."
54 - `clock` should be a `time/clock!` stream. This argument can be omitted
55 and the stream be passed as a dynamic definition in `*clock*` instead.
56 - `scale` should be a num~ stream."
5757 value: class extends Op
5858 new: (...) =>
5959 super ...
7777 examples: { '(lfo [clock] freq [wave])' }
7878 description: "Oscillates betwen `0` and `1` at the frequency `freq`.
7979
80 - `clock` should be a `time/clock` event stream. This argument can be omitted
81 and the stream be passed as a dynamic definition in `*clock*` instead.
82 - `freq` should be a num-value.
80 - `clock` should be a `time/clock!` stream. This argument can be omitted
81 and the stream be passed as a dynamic definition in `*clock*` instead.
82 - `freq` should be a num~ stream.
8383 - `wave` selects the wave shape from one of the following:
8484 - `'sin'` (the default)
8585 - `'saw'`
117117 examples: { '(ramp [clock] period [max])' }
118118 description: "Ramps from `0` to `max` once every `period` seconds.
119119
120 - `clock` should be a `time/clock` event stream. This argument can be omitted
121 and the stream be passed as a dynamic definition in `*clock*` instead.
122 - `period` should be a num-value.
123 - `max` should be a num-value and defaults to `period` if omitted."
120 - `clock` should be a `time/clock!` stream. This argument can be omitted
121 and the stream be passed as a dynamic definition in `*clock*` instead.
122 - `period` should be a num~ stream.
123 - `max` should be a num~ stream and defaults to `period` if omitted."
124124 value: class extends Op
125125 new: (...) =>
126126 super ...
152152 examples: { '(tick [clock] period)' }
153153 description: "Counts upwards by one every `period` seconds.
154154
155 - `clock` should be a `time/clock` event stream. This argument can be omitted
156 and the stream be passed as a dynamic definition in `*clock*` instead.
157 - `period` should be a num-value.
158 - returns a `num` value that increases by 1 every `period`."
155 - `clock` should be a `time/clock!` stream. This argument can be omitted
156 and the stream be passed as a dynamic definition in `*clock*` instead.
157 - `period` should be a num~ stream.
158 - returns a `num~` stream that increases by 1 every `period`."
159159 value: class extends Op
160160 new: (...) =>
161161 super ...
184184 examples: { '(every [clock] period [evt])' }
185185 description: "Emits `evt` as an event once every `period` seconds.
186186
187 - `clock` should be a `time/clock` event stream. This argument can be omitted
188 and the stream be passed as a dynamic definition in `*clock*` instead.
189 - `period` should be a num-value.
187 - `clock` should be a `time/clock!` stream. This argument can be omitted
188 and the stream be passed as a dynamic definition in `*clock*` instead.
189 - `period` should be a num~ stream.
190190 - `evt` can be a value of any type. It defaults to `bang`.
191191 - the return type will be an event stream with the same type as `evt`."
192192 value: class extends Op
210210 @state -= 1
211211 @out\set @inputs.evt!
212212
213 sequence = Constant.meta
214 meta:
215 name: 'sequence'
213 val_seq = Constant.meta
214 meta:
215 name: 'val-seq'
216216 summary: "Emit a sequence of values as events over time."
217 examples: { '(sequence [clock] delay0 evt1 delay1 evt2 delay2…)' }
217 examples: { '(val-seq [clock] delay0 evt1 delay1 evt2 delay2…)' }
218218 description: "
219219 Emits `evt1`, `evt2`, … as events with delays `delay0`, `delay1`, … in between.
220220
221 - `clock` should be a `time/clock` event stream. This argument can be omitted
222 and the stream be passed as a dynamic definition in `*clock*` instead.
223 - `delay0`, `delay1`, … must be num-values.
224 - `evt1`, `evt2`, … must be values of the same type.
221 - `clock` should be a `time/clock!` stream. This argument can be omitted
222 and the stream be passed as a dynamic definition in `*clock*` instead.
223 - `delay0`, `delay1`, … must be num~ streams.
224 - `evt1`, `evt2`, … must be signal streams of the same type.
225225 - the return type will be an event stream with the same type as the `evt`s."
226226 value: class extends Op
227227 new: (...) =>
262262 if current.value and (change or current.value\dirty!)
263263 @out\set current.value!
264264
265 bang_seq = Constant.meta
266 meta:
267 name: 'bang-seq'
268 summary: "Generate rhythms based on a sequence of delays"
269 examples: { '(bang-seq [clock] delay0 delay1…)' }
270 description: "
271 Emits `bang!`s with delays `delay0`, `delay1`, … in between.
272
273 - `clock` should be a `time/clock!` stream. This argument can be omitted
274 and the stream be passed as a dynamic definition in `*clock*` instead.
275 - `delay0`, `delay1`, … must be num~ streams."
276
277 value: class extends Op
278 new: (...) =>
279 super ...
280 @out = T.bang\mk_evt!
281 @state or= { i: 1, t: 0 }
282
283 pattern = -evt.clock + sig.num*0
284 setup: (inputs, scope) =>
285 { clock, steps } = pattern\match inputs
286
287 super
288 clock: Input.hot clock or scope\get '*clock*'
289 steps: [Input.cold step for step in *steps]
290
291 tick: =>
292 if tick = @inputs.clock!
293 @state.t += tick.dt
294
295 bang = false
296 while true
297 current = @inputs.steps[@state.i]!
298 if @state.t >= current
299 @state.t -= current
300 @state.i = 1 + (@state.i % #@inputs.steps)
301 bang = true
302 else
303 break
304
305 if bang
306 @out\set true
307
265308 {
266309 :clock
267310 'scale-time': scale_time
269312 :ramp
270313 :tick
271314 :every
272 :sequence
315 'val-seq': val_seq
316 'bang-seq': bang_seq
317
273318 '*clock*': with Clock 1/60
274319 .meta =
275320 name: '*clock*'