~nasser/8fl

2934f9e8e39ea665a219f48a10db73df1b3bb91b — Ramsey Nasser a month ago fb06d6d main
Use negative track numbers for fx columns

Allows use of iterators as track "numbers" for things like chords
2 files changed, 21 insertions(+), 13 deletions(-)

M core.fnl
M renoise.fnl
M core.fnl => core.fnl +5 -5
@@ 46,14 46,14 @@

;; TODO cache
(fn track-lookup-name [name]
  (each [i track (ipairs (. (renoise.song) :tracks))]
    (if (contains track.name name)
      (lua "return i"))))
  (let [name (if (= 1 (string.find name :-)) (string.sub name 2) name)]
    (each [i track (ipairs (. (renoise.song) :tracks))]
      (if (contains track.name name)
        (lua "return i")))))

(fn track-lookup [idx]
  (match (type idx)
    :number idx
    :table (track-lookup (. idx 1))
    :number (math.abs idx)
    :string (track-lookup-name idx)))

;; TODO cache

M renoise.fnl => renoise.fnl +16 -8
@@ 68,9 68,15 @@
        (for [column 1 visible_columns]
          (tset (: line :note_column column) :note_string :OFF))))))

(fn is-fx? [col]
  (match (type col)
    :number (< col 0)
    :string (= 1 (string.find col :-))
    _ false))

;; pattern-idx -> number
;; columns -> [ [:c-4...] ...]
;; track-idxs -> [ number ...]
;; columns -> [ iter ...]
;; track-idxs -> [ number | string ...]
;; (= (# columns) (# track-idxs))
(fn render-pattern [pattern-idx columns track-idxs]
  (let [column-idxs-note {} ;; track-idx -> column-idx


@@ 81,16 87,16 @@
    (clear-and-silence pattern)
    (tset pattern :number_of_lines len)
    (each [i column (ipairs columns)]
      (let [is-fx? (= (type (. track-idxs i)) :table)
      (let [fx? (is-fx? (. track-idxs i))
            track-idx (core.track-lookup (. track-idxs i))
            column-idxs-table (if is-fx? column-idxs-fx column-idxs-note)
            column-idxs-table (if fx? column-idxs-fx column-idxs-note)
            old-column-idx (. column-idxs-table track-idx)
            column-idx (if old-column-idx (+ 1 old-column-idx) 1)]
        (tset column-idxs-table track-idx column-idx)
        (if is-fx?
        (if fx?
          (ensure-columns-fx track-idx column-idx)
          (ensure-columns-note track-idx column-idx))
        (if is-fx?
        (if fx?
          (render-track-fx pattern-idx track-idx column-idx column)
          (render-track-notes pattern-idx track-idx column-idx column))))))



@@ 102,8 108,10 @@
    (var column nil)
    (while track
      (set column (data))
      (table.insert columns column)
      (table.insert tracks track)
      ;; track might be an iterator
      (each [t (seq.iter track)]
        (table.insert tracks t)
        (table.insert columns column))
      (set track (data)))
    (render-pattern idx columns tracks)))