Suggestion for new Nyquist plug-in, Morse code generator

So that you can see where we’re going with this, here’s a little teaser :wink:
Can you work out what it’s doing and how? Feel free to ask questions.

;type generate

(setf data (list  0 0 0 0 2  0 2 0 1 0 0 2 
                  0 1 0 0 2 1 1 1 3
                  0 1 1 2 1 1 1 2 0 1 0 2
                  0 1 0 0 2 1 0 0 2))

(setf letter 0.12)  ; length of gap between characters
(setf word 0.3)     ; length of gap between words
(setf dot 0.06)     ; length of dot in seconds
(setf dott 0.12)    ; total length of dot including pause
(setf dash 0.18)    ; length of dash in seconds
(setf dasht 0.24)   ; total length of dash

(defun pulse (x)
  (case x
    (0  (pwlv 1 dot 1 dot 0 dott 0))
    (1  (pwlv 1 dash 1 dash 0 dasht 0))
    (2  (s-rest letter))
    (t  (s-rest word))))

(setf dur (* dasht (length data))) ; quick guess at total duration

(mult (osc (hz-to-step 700) dur)
      (seqrep (x (length data))(pulse (nth x data))))