Get Playhead position (selection) time in seconds macro Nyquist command shortcut

Yes, and no it doesn’t matter here :wink:


I recall having the same experience when I started with Nyquist, but there was less documentation available then. There’s a forum topic here where we (mostly edgar-rtf) were figuring out how to use it: Additional *float-format* options


You did well. Please don’t take my comments as criticisms, they are just tips from someone that has worked with Nyquist for a long time. Hopefully they will save you a lot of time and effort figuring out how to use Nyquist.


Do you really want minutes to be “00” when the selection is less than 60 seconds?
Maybe something like this:

;version 4
;debugflags trace

(defun format-time(sec &optional (n 3))
  ;; Return time formatted to hh:mm:ss + n decimal places.
  (unless (and (numberp sec) (numberp n))
    (error "format-time arguments must be numbers."))
  (flet ((pad (x) (if (< x 10) (format nil "0~a" x) x)))
    (let* ((hh (truncate (/ sec 3600)))
           (mm (truncate (/ sec 60)))
           (ss (- sec (* mm 60)))
           (old-format *float-format*)
           rslt)
      (setf mm (- mm (* hh 60)))
      (setf *float-format* (format nil "%.~af" n))
      (setf rslt (format nil "~a~a~a"
                         (if (> hh 0)
                             (format nil "~a:" hh)
                             "")
                         (if (> hh 0)
                             (format nil "~a:" (pad mm))
                             (if (> mm 0)
                                 (format nil "~a:" mm)
                                 ""))
                         (if (> mm 0) (pad ss) ss)))
      (setf *float-format* old-format)
      rslt)))

; get selection start in ms
(format t (format-time (get '*selection*' start) 3))

""

Some time ago I wrote a more complex version with a lot more formatting options. You may find it interesting. It’s here on my blog: https://audionyq.com/display-time-as-hhmmss/
One of the take-aways from this is that manipulating text is a pain in Nyquist :smiley: (but of course the main purpose of Nyquist is for manipulating audio rather than text).