analogue-load-preset   scheme


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/libs/core/instruments/analogue_fileio-scm.xtm

Implementation

(define analogue-load-preset
  (lambda (inst filename)
    (let* ((filein (or (open-input-file filename)
                       (open-input-file (string-append (sys:share-dir) "/" filename)))))
      (if (input-port? filein)
          (begin
            (analogue-reset inst)
            (for-each (lambda (x)
                        (define tag (symbol->string (car x)))
                        ;; we need a couple of special cases
                        (cond ((string=? tag "mod_matrix")
                               (for-each (lambda (y i)
                                           ;; (println 'set_mod_matrix 'inst (real->integer (/ i 32.0)) (modulo i 32) y)
                                           (set_mod_matrix inst (real->integer (/ i 32.0)) (modulo i 32) y))
                                         (cdr x)
                                         (range 0 (* 4 32))))
                              ((string=? (substring tag 0 3) "lfo")
                               (if (regex:match? tag "_ad_")
                                   (let* ((res (regex:matched tag "^lfo([0-9])_ad_(.*)$"))
                                          (name (string->symbol (string-append "set_lfo_ad_" (caddr res))))
                                          (num (- (string->number (cadr res)) 1))
                                          (expr `(,name inst ,num ,(cdr x))))
                                     ;; (println 'calling expr)
                                     (eval expr))
                                   (let* ((res (regex:matched tag "^lfo([0-9])_(.*)$"))
                                          (name (string->symbol (string-append "set_lfo_" (caddr res))))
                                          (num (- (string->number (cadr res)) 1))
                                          (expr `(,name inst ,num ,(cdr x))))
                                     ;; (println expr)
                                     (eval expr))))
                              (else
                               (let* ((fname (string->symbol (string-append "set_" tag)))
                                      (expr `(,fname inst ,(cdr x))))
                                 ;; (println 'calling expr)
                                 (eval expr)))))
                      (read filein))
            (close-input-port filein)
            (println 'finished 'loading filename))
          (println 'Error 'opening 'file filename)))))


Back to Index