Differences From
Artifact [ec4176d797]:
143 143 :cfg {:base 800 :span 600 :chime 1}
144 144 :setup freq-spread-notes
145 145 :note (fn sine:note [me env n]
146 146 (def freq (get-in me [:notes (n :index)]))
147 147 [(* (me :ampl) (n :vel)) freq (get-in me [:cfg :chime])]))
148 148 :string (struct/with-proto <instr>
149 149 :name "string"
150 - :cfg {:base 500 # shortest frequency
151 - :span 300 # range of frequencies
150 + :cfg {:base 200 # shortest frequency
151 + :span 600 # range of frequencies
152 152 :decay 0}
153 153 :setup freq-spread-notes
154 - :note (fn drum:note [me env n]
154 + :note (fn string:note [me env n]
155 155 (def freq (get-in me [:notes (n :index)]))
156 156 (def c (me :cfg))
157 157 [(* (me :ampl) (n :vel)) freq (- 1 (* .1 (c :decay)))]))
158 + :piano (struct/with-proto <instr>
159 + :name "piano"
160 + :cfg {:base 400 # shortest frequency
161 + :span 600} # range of frequencies
162 + :setup freq-spread-notes
163 + :note (fn piano:note [me env n]
164 + (def freq (get-in me [:notes (n :index)]))
165 + [(* (me :ampl) (n :vel)) freq]))
166 + :warbulator (struct/with-proto <instr>
167 + :name "warbulator"
168 + :cfg {:base 400 # shortest frequency
169 + :span 600 # range of frequencies
170 + :range 3}
171 + :setup freq-spread-notes
172 + :note (fn warbulator:note [me env n]
173 + (def freq (get-in me [:notes (n :index)]))
174 + (def c (me :cfg))
175 + [(* (me :ampl) (n :vel)) freq (c :range) (c :range)]))
158 176 })
159 177
160 178
161 179 (defn timecode→string [t]
162 180 (def μs (% t 1))
163 181 (def s (math/floor (% t 60)))
164 182 (def m (math/floor (% (/ t 60) 60)))
................................................................................
239 257 (def ins (:instr-for-chan env chan))
240 258 (defn note-key? [k]
241 259 (not (nil? (get-in ins [:note-map :key->index k]))))
242 260 (defn draw-stat-line [timecode]
243 261 (def sustain @[])
244 262 (defn clr [& r] (:color (env :tty) ;r))
245 263 # (defn vbar [& r] (:vbar (env :tty) ;r))
246 - (each n (get-in ins [:note-map :keys])
247 - (when-let [k (get held n nil)]
248 - (def k (string/format "%c" n))
249 - (array/push sustain k)))
264 + (def key-color-lut
265 + [[0.8 0.0 0.2]
266 + [0.2 0.5 1.0]
267 + [0.3 1.0 0.2]
268 + ])
269 + (let [nm (ins :note-map)]
270 + (defn key->fac [k]
271 + (def ki (get-in nm [:key->index (k 0)]))
272 + (/ ki (nm :n)))
273 + (each n (nm :keys)
274 + (when-let [k (held (n 0))]
275 + (array/push sustain
276 + (clr (alg/vlut (key->fac n) key-color-lut) [0 0 0] n)))))
250 277 (:msg env "\r\e[2K%s\r"
251 278 (string
252 279 (if rec "\e[91m⏺"
253 280 "\e[94m⏹") "\e[m"
254 281 (clr [.9 .95 1] [0.1 0.2 0.4]
255 282 (string " " (timecode→string timecode) " "))
256 283 (:vol-bar env (/ loud 11))
257 284 # (vbar (/ loud 11)
258 285 # [.5 1 .25]
259 286 # [1.0 1.0 0.25]
260 287 # [.8 0 0])
261 288 " " (chan :instr) "\e[96m@" (env :chan) "\e[m"
262 - " \e[1m" (if rec "record" "play") "\e[m"
289 + " \e[1m" (if rec "record" "play") "\e[m "
263 290 (string/join sustain))))
264 291
265 292 (def timewarp (get-in chan [:cfg :timewarp] 1.0))
266 293
267 294 (defn advance-clock [res]
268 295 (protect (forever
269 296 (def cur-time (ticks))
................................................................................
282 309 (defn stop-clock []
283 310 (when clock-fiber
284 311 (ev/cancel clock-fiber nil)
285 312 (set clock-fiber nil))
286 313 (when player-fiber
287 314 (ev/cancel player-fiber nil)
288 315 (set player-fiber nil)))
316 + (defn maybe-restart-clock []
317 + (def restart? (not= nil clock-fiber))
318 + (stop-clock)
319 + (when restart? (start-clock)))
289 320
290 321 (defn ins-cmd [method & args]
291 322 ((ins method) ins env ;args))
292 323 (defn stop-all-notes []
293 324 (eachp [k v] held
294 325 (:send env ;(ins-cmd :stop v 0))))
295 326 (defn cleanup []
................................................................................
342 373 (commit-unless-shift))
343 374 {:how :press :key :shift-l} (+= loud 1)
344 375 {:how :release :key :shift-l} (-= loud 1)
345 376 {:how :press :key :shift-r} (-= loud .5)
346 377 {:how :release :key :shift-r} (+= loud .5)
347 378 {:how :press :key :tab}
348 379 (do (put env :time start-time)
349 - (stop-clock) (start-clock))
380 + (maybe-restart-clock))
350 381 ({:how :press :key n}
351 382 (<= 0x31 n 0x39))
352 383 (set loud (- n 0x30))
353 384 ({:how :press :key k}
354 385 (note-key? k)
355 386 (nil? (held k)))
356 387 (do (def note {:id cur-id :vel loud
................................................................................
379 410 (:set-mode env :cmd)
380 411 _ (:msg env "event packet: %P\r\n"
381 412 (struct/proto-flatten event))
382 413
383 414 ))))
384 415
385 416 (defn mk-channel []
386 - @{:instr :sine
417 + @{:instr :string
387 418 :ampl 1
388 419 :cfg @{}
389 420 :mute false})
390 421
391 422 (defn present-file [env text]
392 423 (def lines (string/split "\n" text))
393 424 (defn c [& r] (:color (env :tty) ;r))
................................................................................
570 601 (return give-up))
571 602 (<= (+ n histidx) lastidx)
572 603 (set histidx (max 0 (+ n histidx)))
573 604 :else (return give-up))
574 605 (set cmd-line (buffer (history histidx)))))
575 606 (when (or (= (event :how) :press)
576 607 (= (event :how) :repeat))
608 + (defn execute []
609 + (:msg env "\r\n")
610 + (set histidx nil)
611 + (do-cmd cmd-line env)
612 + (array/push history (string cmd-line))
613 + (buffer/clear cmd-line))
614 + (defn complete [])
577 615 (match event
578 616 {:key :bksp} (buffer/popn cmd-line 1)
579 - {:key :tab} (do)
617 + {:key :tab} (complete)
580 618 {:key :up} (go-history -1)
581 619 {:key :dn} (go-history 1)
582 - {:key :enter} (do
583 - (:msg env "\r\n")
584 - (set histidx nil)
585 - (do-cmd cmd-line env)
586 - (array/push history (string cmd-line))
587 - (buffer/clear cmd-line))
620 + {:key :enter} (execute)
621 + {:key :kp-enter} (execute)
588 622 {:text t} (buffer/push cmd-line t)
589 623 )))))
590 624
591 625 (defn task-cmd [env]
592 626 "command input handling"
593 627 (def {:tty tty} env)
594 628 (var mode nil)