~nasser/8fl

8af6c788a46dd18f5c27210cd19c74001ea0a341 — Ramsey Nasser 2 months ago 47a58dd
First pass at midi cc control api
1 files changed, 58 insertions(+), 1 deletions(-)

M core.fnl
M core.fnl => core.fnl +58 -1
@@ 80,6 80,48 @@
           (coroutine.yield
            (string.format "%s%02X" note instrument-number))))))))

(tset _G :_CC_VALUES {})

;; TODO cache
(fn maybe-install-device [name]
    (when (= nil (. _G._CC_VALUES name))
      (each [i device (ipairs (renoise.Midi.available_input_devices))]
            (when (contains device name)
              (let [m {}]
                   (tset _G._CC_VALUES name m)
                   (tset _G._CC_VALUES device m)
                   (renoise.Midi.create_input_device
                    device
                    (fn [[s cc value]]
                        (when (= s 176)
                          (status (.. "MIDI CC " device " " cc " " value))
                          (tset m cc value)))))))))


(fn cc [device cc]
    (maybe-install-device device)
    (if cc
        (or (. _G._CC_VALUES device cc) 0)
        #(or (. _G._CC_VALUES device $) 0)))

(fn cc% [device cc]
    (maybe-install-device device)
    (if cc
        (let [v (. _G._CC_VALUES device cc)] (if v (/ v 127) 0))
        #(let [v (. _G._CC_VALUES device $)] (if v (/ v 127) 0))))

(fn cc%1- [device cc]
    (maybe-install-device device)
    (if cc
        (let [v (. _G._CC_VALUES device cc)] (- 1 (if v (/ v 127) 0)))
        #(let [v (. _G._CC_VALUES device $)] (- 1 (if v (/ v 127) 0)))))

(fn cc? [device cc]
    (maybe-install-device device)
    (if cc
        (let [v (. _G._CC_VALUES device cc)] (if v (> v 0) false))
        #(let [v (. _G._CC_VALUES device $)] (if v (> v 0) false))))

(fn or-default [s d]
  (match (# s)
    0 d


@@ 216,9 258,24 @@
            (lua :break))))
    columns*))

;; rle
(fn & [...]
    (let [in (seq.iter [...])]
         (coroutine.wrap
          #(while true
            (var count (in))
            (if (= nil count)
                (lua :break)
                (let [value (in)]
                     (while (> count 0)
                       (coroutine.yield value)
                       (set count (- count 1)))))))))

{ : get-note-value : get-note-name : scale : or-default : str-sub-or-default
  : sub-or-default : splice : expand : splice-line : splice-lines : note
  : instrument : volume : pan : delay : fx : fxn : fxa : rest? : off? : balance
  : track-lookup : instrument-lookup : note?
  : desugar-instrument
  : samples }
\ No newline at end of file
  : samples
  : cc : cc% : cc%1- : cc?
  : & }
\ No newline at end of file