helper:mmplayp_f_with_offset   scheme


Defined in:  https://github.com/lambdamusic/extempore-extensions/blob/main/init/init_playp.xtm

Implementation

;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 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)))))))))


Back to Index

Similar Entries

  • cl:first    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • cl:list-flatten    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • cl:ratio_is_perfect    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • cl:shuffle    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • cl:slice-left    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • cl:string-find    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • cl:string-find-char    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • cosrfloor    macro    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • def    macro    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • fifth    macro    /lambdamusic/extempore-extensions/blob/main/init/init_makers.xtm
  • first    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • fourth    macro    /lambdamusic/extempore-extensions/blob/main/init/init_makers.xtm
  • if!=    macro    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • if-cdr-else    macro    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • if-cdr-notnull    macro    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • if-random    macro    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • if<    macro    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • if=    macro    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • if>    macro    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • ifbeat    macro    /lambdamusic/extempore-extensions/blob/main/init/init_beats.xtm
  • ifbeat-btw    macro    /lambdamusic/extempore-extensions/blob/main/init/init_beats.xtm
  • ifbeat-gt    macro    /lambdamusic/extempore-extensions/blob/main/init/init_beats.xtm
  • ifbeat-lt    macro    /lambdamusic/extempore-extensions/blob/main/init/init_beats.xtm
  • list-flatten    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • list-split-after    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • list-split-from    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • oneof    macro    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • rectrfloor    macro    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • shuffle    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm
  • zblue-fil-balance*    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_bento.xtm
  • zblue-fil-cutoff*    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_bento.xtm
  • zblue-fil-cutoff-mod*    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_bento.xtm
  • zblue-fil-distorsion*    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_bento.xtm
  • zblue-fil-feedback*    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_bento.xtm
  • zblue-fil-resonance*    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_bento.xtm
  • zblue-fil-saturation*    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_bento.xtm
  • zred-fil-balance*    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_bento.xtm
  • zred-fil-cutoff*    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_bento.xtm
  • zred-fil-cutoff-mod*    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_bento.xtm
  • zred-fil-distorsion*    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_bento.xtm
  • zred-fil-feedback*    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_bento.xtm
  • zred-fil-resonance*    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_bento.xtm
  • zred-fil-saturation*    scheme    /lambdamusic/extempore-extensions/blob/main/init/init_bento.xtm