Jump to content

gen-markov-from-transitions-with-tendency


Recommended Posts

a concrete example (but musical-nonsense)... of a TRANSITION produced by a special markov-program

 

1) functions/subfuctions

;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun add-transition-weight (transition-list value add-weight)
  (loop 
    for j in transition-list
    collect (append (list (first j))
                    (loop repeat (1- (length j))
                      for cnt = 1 then (incf cnt)
                      when (equal (first (nth cnt j)) value)
                      collect (list (first (nth cnt j)) (+ add-weight (second (nth cnt j))))
                      else collect (nth cnt j)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun count-repetitions (value-list)

  (let ((seq (append value-list (list 'nil))))
    (loop repeat (1- (length seq))
      
      with count = 1
      
      for cnt1 = 0 then (incf cnt1)
      for cnt2 = 1 then (incf cnt2)

      when (equal (nth cnt1 seq) (nth cnt2 seq)) do (incf count)
      when (not (equal (nth cnt1 seq) (nth cnt2 seq))) collect count and do (setq count 1))))


;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun eliminate-repetitions (liste)

  (let ((liste (append liste (list 'nil))))
    (loop repeat (1- (length liste))
      with cnt = 0
      when  (not (equal (nth cnt liste) (nth (+ 1 cnt) liste)))
      collect (nth cnt liste)      
      do (incf cnt))))

(eliminate-repetitions '(1 1 2 3 4 4 4 1 1 2))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun gen-markov-from-transitions-with-tendency (transitions size generations value &key (add-weight 1) (start (first (first transitions))))
  (loop repeat generations
    with list = (gen-markov-from-transitions transitions :size size :start start )
    with weight = add-weight
    with weight-growth = 0
    
    do (setq transitions (add-transition-weight transitions value weight))
    append (setq list (gen-markov-from-transitions transitions :size size :start (filter-first-last 1 list)))
    do (incf weight (incf weight-growth))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

 

2) example and possible implementation => create a TRANSITION to value 3 (=> to pitch eb4)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;evaluate a few times, to check it;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(list-plot ;;non-neutral-table
 (setq integers (gen-markov-from-transitions-with-tendency 
                          '((1 (1 1) (2 4) (3 1))
                            (2 (1 1) (4 1) (3 3))
                            (3 (1 4) (3 5) (4 3))
                            (4 (1 1) (3 2) (4 3))) 10 20 3  :add-weight 3))
  :point-radius 0 :style :fill)

#|
;;another example with different mapping
(list-plot ;;non-neutral-table
 (setq integers (gen-markov-from-transitions-with-tendency 
                          '((1 (1 1) (2 4) (3 1))
                            (2 (1 1) (4 1) (3 3) (6 1))
                            (3 (1 4) (3 5) (4 3) (6 1) (5 1))
                            (4 (1 1) (3 2) (4 3) (5 2) (6 1))
                            (5 (1 1) (3 1) (4 1))
                            (6 (2 3) (1 2) (3 1) (5 1))) 10 20 3  :add-weight 3))
  :point-radius 0 :style :fill)

(setq integers (replace-map '((5 -5) (1 0) (2 6) (3 14) (4 20) (6 25)) integers))
|#


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;gen an example-score;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
(def-score example
           (:key-signature 'chromatic
                           :time-signature '(4 8)
                           :tempo '(e 176)
                           :layout (bracket-group 
                                    (piano-grand-layout 'piano)))
  (piano 
   :omn  (make-omn :pitch (eliminate-repetitions (integer-to-pitch integers))
                   :length (gen-length (count-repetitions integers) 1/32))
   
   :sound 'gm-piano))

 

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