template.esl 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. (lambda (data)
  2. (var info (array
  3. (array "text" "Type" "Sequencer")
  4. (array "text" "ID" data.id)
  5. (array "step" "Step" (+ data.step "/" data.seq.length))))
  6. (var header (/h ".device-header" (array
  7. (/templates/module/label data.label (+ "Sequencer " data.id))
  8. (/h ".device-buttons" (array
  9. (?: /state/session/sampler (./sequencer-connect data.id) null)
  10. (/templates/module/info info))))))
  11. (var note-names (array "C" "C#" "D" "D#" "E" "F" "F#" "G" "G#" "A" "A#" "B"))
  12. (var keys (array))
  13. (var lanes (array))
  14. (var events (array))
  15. (.for-each (Object.keys data.events) add-events)
  16. (for (var i 0) (< i 12) (++ i) (add-lane i))
  17. (var bar-width "25%")
  18. (var timeline (array))
  19. (var grid (array (grid-bar 0) (grid-bar 1) (grid-bar 2) (grid-bar 3)))
  20. (for (var i 0) (< i 16) (++ i) (add-notch i))
  21. (var piano-roll (/h ".sequencer-piano" (array
  22. ;(/h ".sequencer-piano-timeline" timeline)
  23. (/h ".sequencer-piano-keys" keys)
  24. (/h ".sequencer-piano-body" (array events grid)))))
  25. (var steps (/h ".sequencer-steps" (data.seq.map (lambda (val i) (return
  26. (/h (+ ".sequencer-step" (?: (> val 0) ".active" "") (?: (=== i data.step) ".current" ""))
  27. (object "onclick" (/emit ./events/click data.id i))))))))
  28. (return (/h ".device.sequencer" (array header piano-roll)))
  29. (function add-lane (i)
  30. (var note (get note-names (% i 12)))
  31. (var color (?: (=== 2 note.length) ".black" ".white"))
  32. (keys.push (/h (+ ".sequencer-piano-key" color) note)))
  33. (function add-events (t)
  34. (var style (+
  35. "left:" (* 100 (/ t 16)) "%;"
  36. "bottom:" (* 100 (/ (get data.events t) 12)) "%"))
  37. (events.push (/h ".sequencer-piano-note" (object
  38. "style" style
  39. "onclick" (/emit ./events/piano/delete data.id t (get data.events t))))))
  40. (function add-notch (i)
  41. (timeline.push (/h ".sequencer-piano-notch" (String i))))
  42. (function grid-bar (i) (return (/h ".sequencer-piano-grid-bar"
  43. (object "style" (+ "width:" bar-width ";left:" (* i 25) "%"))
  44. (array (grid-beat i 0) (grid-beat i 1) (grid-beat i 2) (grid-beat i 3)))))
  45. (function grid-beat (i j)
  46. (var beat-lanes (array))
  47. (for (var k 0) (< k 12) (++ k) (grid-beat-lane beat-lanes (+ (* i 4) j) k))
  48. (return (/h ".sequencer-piano-grid-beat"
  49. (object "style" (+ "width:25%;left:" (* j 25) "%")) beat-lanes)))
  50. (function grid-beat-lane (beat-lanes t n)
  51. (beat-lanes.push (/h ".sequencer-piano-grid-lane"
  52. (object "onclick" (/emit ./events/piano/draw data.id t n)))))
  53. )