Overview
Comment: | add some instruments, fix some bugs (piano is not real yet) |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
5422ffcfca2085c3b54be1d35c75c7ab |
User & Date: | lexi on 2025-03-14 17:35:14 |
Other Links: | manifest | tags |
Context
2025-03-14
| ||
19:27 | add docs Leaf check-in: a597ad7ee7 user: lexi tags: trunk | |
17:35 | add some instruments, fix some bugs (piano is not real yet) check-in: 5422ffcfca user: lexi tags: trunk | |
2025-03-12
| ||
06:46 | initial ostinata commit check-in: 908662f1b1 user: lexi tags: trunk | |
Changes
Modified ostinata/ostinata.janet from [ec4176d797] to [567adb1f1f].
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)
Modified ostinata/ostinata.orc from [fcb089814a] to [1a1b5670ed].
8 8 ; p5 freq 9 9 10 10 givol ftgen 1, 0, 10000, 25, \ 11 11 500, 60, \ 12 12 1000, 20, \ 13 13 7000, 3, \ 14 14 10000, 5 15 +gipian ftgen 2, 0, 10000, 10, \ 16 + 1, 0.5, 0.3, 0.25, 0.2, 0.167, 0.14, 0.125, .111 15 17 16 18 instr sine 17 19 tigoto skipinit 18 20 kt init 0 19 21 al init 1.0 20 22 ifreq = p5 21 23 ichime = p6 ................................................................................ 50 52 51 53 if p3 >= 0 then 52 54 aw = aw * at 53 55 endif 54 56 out aw 55 57 endin 56 58 59 + 60 +instr warbulator 61 + tigoto skipinit 62 + irange = p6 63 + ifreq = p5 64 + ivol = p4 * 40 * table(ifreq, givol) 65 + 66 + ata poscil 1.0, 100 67 + atf poscil 1.0, bpf(ata, 0,1, 1,100) 68 + atq poscil 1.0, bpf(atf, 0,ifreq, 1,ifreq*irange) 69 + skipinit: 70 + 71 + aw = atq 72 + 73 + if p3 >= 0 then 74 + at linseg 1, p3, 0 75 + aw = aw * at 76 + endif 77 + out ivol * aw 78 +endin 79 + 80 +instr bell 81 + tigoto skipinit 82 + ifreq = p5 83 + ivol = p4 * 40 * table(ifreq, givol) 84 + at poscil 1.0, ifreq*2 85 + af poscil 1.0, bpfcos(at, 0,ifreq, 1,ifreq*2.5) 86 + 87 + skipinit: 88 + aw = af 89 + if p3 >= 0 then 90 + at linseg 1, p3, 0 91 + aw = aw * at 92 + endif 93 + out ivol * aw 94 +endin