Jump to content

omn-component-replace


Recommended Posts

;;;function which replaces/rewrites the component in OMN-seq

(defun omn-component-replace (omn-sequence replace-component)
  (make-omn :length (if (lengthp (car replace-component))
                     (append replace-component)
                     (omn :length omn-sequence))
            :pitch (if (pitchp (car replace-component))
                     (append replace-component)
                     (omn :pitch omn-sequence))
            :velocity (if (velocityp (car replace-component))
                        (append replace-component)
                        (omn :velocity omn-sequence))
            :articulation (if (articulationp (car replace-component))
                            (append replace-component)
                            (omn :articulation omn-sequence))))

(setf seq1 '(s gs3 ppp tasto q.t cs4 pppp tasto s f4 ppp tasto))
(omn-component-replace seq1 '(5/16 7/16 3/32))

 

Link to comment
Share on other sites

The function OMN-COMPONENT-REPLACE in a real OMN world will return errors with a complex attributes (articulations):

ttrem, app, gliss etc...

 

Anyway, bellow you will find few example how to manipulate algorithmically the OMN plists:

 

(setf sequence '(q c4 pp e d4 mp e4 s f4 f> fs4 > g4 > gs4 pp))

(disassembling-omn ((pitch plist) sequence :pitch :flat nil :span :length)
  (let ((pitch (remove nil pitch)))
    (pitch-transpose -12 pitch)))

(disassembling-omn ((length plist) sequence :length :flat nil :span :length)
    '(s s s s))

(disassembling-omn ((length plist) sequence :length :flat nil :span :pitch)
    '(s s s s))

(disassembling-omn ((velocity plist) sequence :velocity :flat nil :span :length)
    '(f f p p f f))

 

And now a complete function example with DISASSEMBLING-OMN macro:

(defun length-rational-quantize (sequence &key (round 1/4) (type :extend) section exclude omn)
  (do-verbose ("length-rational-quantize")
    (labels ((length-rational-quantize-1 (length round)
               (let* ((sum (sum (abs! length)))
                      (out (- (find-length-base sum round) sum)))
                 (remove 0 (append length (list (neg! out))))))
             
             (length-rational-quantize-l (list round &key (type :extend))
               (let ((group (lists! (split-lengths list :type type))))
                 (flatten
                  (loop for i in group 
                    collect (length-rational-quantize-1 i round)))))
             
             (length-rational-quantize-ls (list round &key (type :extend))
               (let* ((len (length list))
                      (round (gen-trim* len (list! round))))
                 (loop for i in list for x in round
                   collect (length-rational-quantize-l i x :type type))))
             
             (length-rational-quantize* (list round &key (type :extend))
               (if (listsp list) (length-rational-quantize-ls list round :type type)
                 (length-rational-quantize-l list round :type type))))
      
      (disassembling-omn ((sequence plist) sequence :length :span :length)
        (let ((len (length sequence)))
          (maybe-omn-decode
           omn
           (if exclude
             (maybe-section (lambda (x) (length-rational-quantize* x round :type type))
                            sequence (num-exclude len exclude))
             (maybe-section (lambda (x) (length-rational-quantize* x round :type type))
                            sequence section))))))))

 

Note:
Please don't distribute or share any of the code from the Source Code forum section.

 

Link to comment
Share on other sites

  • 3 months later...

hi stephane

 

i think it works fine, feel free to use & optimize it ( perhaps to replace more then ONE parameter in ONE function-call?)... for me the function is very useful...

greetings

andré

(defun omn-component-replace (omn-sequence replace-component)
  (make-omn :length (if (lengthp (car replace-component))
                     (append replace-component)
                     (omn :length omn-sequence))
            :pitch (if (pitchp (car replace-component))
                     (append replace-component)
                     (omn :pitch omn-sequence))
            :velocity (if (velocityp (car replace-component))
                        (append replace-component)
                        (omn :velocity omn-sequence))
            :articulation (if (articulationp (car replace-component))
                            (append replace-component)
                            (omn :articulation omn-sequence))))

 

examples:

 


(setf seq1 '(s gs3 ppp tasto q.t cs4 pppp tasto s f4 ppp tasto))

(omn-component-replace seq1 '(5/16 7/16 3/32))
(omn-component-replace seq1 '(ponte))
(omn-component-replace seq1 '(c4 d4 e4 f4))

 

Link to comment
Share on other sites

here is a version with MULTIPLE replacements...

you have to write replacements different... a list in a list... have a look to the examples:

 

(defun omn-component-replace2 (omn-sequence replace-component)
  (car (last (loop for i in replace-component
               collect (setf omn-sequence
                             (make-omn :length (if (lengthp (car i))
                                                 (append i)
                                                 (omn :length omn-sequence))
                                       :pitch (if (pitchp (car i))
                                                (append i)
                                                (omn :pitch omn-sequence))
                                       :velocity (if (velocityp (car i))
                                                   (append i)
                                                   (omn :velocity omn-sequence))
                                       :articulation (if (articulationp (car i))
                                                       (append i)
                                                       (omn :articulation omn-sequence))))))))


(omn-component-replace2 '(S C4 PPP TASTO Q.T D4 PPPP TASTO S E4 PPP TASTO) '((p)))
(omn-component-replace2 '(S C4 PPP TASTO Q.T D4 PPPP TASTO S E4 PPP TASTO) '((p) (ponte) (e2 b2 d2)))

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

Terms of Use Privacy Policy