Jump to content

replace-on-event-number


Recommended Posts

the same idea with INSERT/REPLACE

 


(defun replace-on-event-number (omn-list &key position/list (type 'replace) (output nil))
  (progn 
    (setf omn-list (loop 
                     for i in (single-events omn-list)
                     for cnt = 0 then (incf cnt)
                     with position-list = (loop for x in position/list collect (car x))
                     with list = (loop for y in position/list collect (rest y))
                     with cnt2 = 0
                     
                     
                     when (= cnt (nth cnt2 position-list))
                     collect (cond ((equal type 'replace) 
                                    (if (listp (nth cnt2 list))
                                      (flatten (nth cnt2 list))
                                      (nth cnt2 list)))
                                   ((equal type 'add)
                                    (list i (nth cnt2 list))))
                     
                     else collect i
                     
                     when (and (= cnt  (nth cnt2 position-list))
                               (< cnt (car (last position-list))))
                     do (incf cnt2)))
    (if (equal output 'flatten)
      (flatten omn-list)
      omn-list)))
    
    

;;; EXAMPLES REPLACE

(replace-on-event-number '(q g4 -q q g4 g4 g4 -q g4 g4 g4 g4)
                           :position/list '((1 (q g5d5))
                                            (5 -q))
                           :type 'replace)

=> ((q g4 mf) (q g5d5) (q g4 mf) (q g4 mf) (q g4 mf) (-q) (q g4 mf) (q g4 mf) (q g4 mf) (q g4 mf))



(replace-on-event-number '(q g4 -q q g4 g4 g4 -q g4 g4 g4 g4)
                           :position/list '((1 (q g5d5))
                                            (5 -q))
                           :type 'replace
                           :output 'flatten)

=> (q g4 mf q g5d5 q g4 mf q g4 mf q g4 mf -q q g4 mf q g4 mf q g4 mf q g4 mf)


;;; EXAMPLES ADD

(replace-on-event-number '(q g4 -q q g4 g4 g4 -q g4 g4 g4 g4)
                           :position/list '((1 -e.)
                                            (5 -w))
                           :type 'add
                           :output nil)

=> ((q g4 mf) ((-q) (-e.)) (q g4 mf) (q g4 mf) (q g4 mf) ((-q) (-w)) (q g4 mf) (q g4 mf) (q g4 mf) (q g4 mf))



(replace-on-event-number '(q g4 -q q g4 g4 g4 -q g4 g4 g4 g4)
                           :position/list '((1 (w g6 ffff))
                                            (5 -w))
                           :type 'add
                           :output 'flatten)


=> (q g4 mf -q w g6 ffff q g4 mf q g4 mf q g4 mf -q -w q g4 mf q g4 mf q g4 mf q g4 mf)

;;;;

 

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