;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; helper:mmplayp_f_with_offset
;
; helper used by :steps playpattern function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define helper:mmplayp_f_with_offset
(lambda (beat dur midiout . args)
(let ((pclas '(0 1 2 3 4 5 6 7 8 9 10 11))
(offset 0)
(poffset 0)
(inst '())
(data '())
(vols '())
(durs '())
(channel 0)
(datal 0)
(cycle 0)
(step 0))
;; channel
(set! channel (car args))
(set! args (cdr args))
;; first always cycle-var
(set! cycle (car args))
(if (not (number? cycle))
(println "Error: cycle value must be a number"))
(set! args (cdr args))
;; now offset/poffset or notes
(if (list? (car args))
(set! data (car args)) ;; pitch list
(begin
(set! offset (car args)) ;; offset
(set! args (cdr args))
(if (list? (car args))
(set! data (car args)) ;; pitch list
(begin
(set! poffset (car args)) ;; poffset
(set! args (cdr args))
(set! data (car args)))))) ;; pitch list
(set! inst midiout) ;; instrument (hardwired)
(set! args (cdr args))
(set! datal (length data))
(set! vols (car args))
(set! args (cdr args))
; allow dur to be inferred if empty
(if (> (length args) 0)
(begin
(if *debug* (log-info 'found-dur (car args)))
(set! durs (car args))
(set! args (cdr args)))
(begin
(if *debug* (log-info 'inferring-dur (* (/ cycle datal) 0.9)))
(set! durs (* (/ cycle datal) 0.9)))
)
; (set! channel (car args)) ;; 2022-10-09 removed
; (set! args (cdr args))
(set! step (/ cycle datal))
(let ((local_beat (modulo beat cycle))
(mod_diff 0)
(volume vols)
(phase 0.0)
(duration durs)
(pitch 0))
(dotimes (i (* 2 datal))
(set! mod_diff (- (* i step) local_beat))
(set! pitch (list-ref data (modulo i datal)))
(if (symbol? pitch) (set! pitch (eval pitch)))
(if (list? durs)
(if (and (symbol? (car durs))
(defined? (car durs))
(or (closure? (eval (car durs)))
(procedure? (eval (car durs)))
(macro? (eval (car durs)))))
(set! duration durs)
(if (= (length durs) datal)
(set! duration (list-ref durs (modulo i datal)))
(set! duration step))))
(if (list? vols)
(if (and (symbol? (car vols))
(defined? (car vols))
(or (closure? (eval (car vols)))
(procedure? (eval (car vols)))
(macro? (eval (car vols)))))
(set! volume vols)
(if (= (length vols) datal)
(set! volume (list-ref vols (modulo i datal)))
(set! volume 80))))
(if (list? pitch)
(begin
(if (and (>= mod_diff 0)
(< mod_diff dur)
(not (null? pitch)))
(helper:mplayp_play_list_v2 beat dur pclas inst volume duration channel pitch mod_diff step offset poffset args)))
(begin
(set! phase (+ mod_diff offset))
(if (and (>= mod_diff 0)
(< mod_diff dur)
(> pitch 0))
(eval `(mplay ,phase ;(+ mod_diff offset)
,inst
,(pc:quantize (+ pitch poffset) pclas)
,volume
,duration
; ,channel
;; NOTE ch is 0based in xtm, but user sends it as 1-based
,(- channel 1)
,@args))
(begin #f)))))))))