Search the Community
Showing results for tags 'lisp'.
-
;;;; function (-> don't know if this is already existing in opusmodus) (defun expand-intervals/integers (seq &key (type 'add) (value 1)) (cond ((equal type 'add) (loop for i in seq when (> i 0) collect (+ i value) when (< i 0) collect (- i value) when (= i 0) collect i)) ((equal type 'multiply) (loop for i in seq collect (* i value))) ((equal type 'expt) (loop for i in seq when (>= i 0) collect (expt i value) else collect (* (expt i value) -1))) ((equal type 'fibonacci) (loop for i in seq when (>= i 0) collect (+ i (fibonacci i)) else collect (- i (fibonacci (abs i))))))) ;;; examples (expand-intervals/integers '(0 -1 1 -2 2 -3 3) :type 'add :value 2) (expand-intervals/integers '(0 -1 1 -2 2 -3 3) :type 'multiply :value 2) (expand-intervals/integers '(0 -1 1 -2 2 -3 3) :type 'expt :value 2) (expand-intervals/integers '(0 -1 1 -2 2 -3 3 -4 4 -5 5) :type 'fibonacci)
-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;PERMUTE-SYMMETRCIAL -> seq of any lengths;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; SUB (defun divide-seq-length (seq) (if (evenp (length seq)) (/ (length seq) 2) (/ (1- (length seq)) 2))) ;;; MAIN (defun permute-symmetrical (row &key (chance 0.5)) (let ((1st (loop repeat (divide-seq-length row) for cnt = 0 then (incf cnt) collect (nth cnt row))) (2nd (loop repeat (divide-seq-length row) for cnt = (- (length row) 1) then (decf cnt) collect (nth cnt row)))) (loop for i in 1st for j in 2nd when (prob? chance) collect j into 1st-bag and collect i into 2nd-bag else collect i into 1st-bag and collect j into 2nd-bag when (= (length 1st-bag) (divide-seq-length row)) do (return (if (evenp (length row)) (append 1st-bag (reverse 2nd-bag)) (append 1st-bag (list (nth (length 1st) row)) (reverse 2nd-bag))))))) ;;; EXAMPLE (pitch-list-plot (permute-symmetrical '(a4 bb4 ab4 b4 g4 c5 fs4 cs4 f4 d4 e4 eb4) ;zimmermann-row :chance 0.3))
-
;;;;perhaps you could/would extend the "rnd-sample-seq" function by: ;;;;(also with OMN-format) ... regards andré ;;;;SUBFUNCTIONS (defun pick-sample-from-center (list span) (let ((center (if (evenp (length list)) (/ (length list) 2) (/ (1+ (length list)) 2))) (span (if (> span (length list)) (length list) (append span)))) (loop repeat span with startpoint = (if (evenp span) (- center (/ span 2)) (- center (/ (1+ span) 2))) for i = startpoint then (incf startpoint) collect (nth i list)))) ;;;;MAINFUNCTION ;;;;sampling-machine (defun sampling-seq-machine (&key seq (type 'rnd) (sample-lengths 'rnd)) (let ((span (if (equal sample-lengths 'rnd) (1+ (random (length seq))) (rnd-pick sample-lengths)))) (cond ((equal type 'rnd) (rnd-sample-seq span seq)) ((equal type 'from-center) (loop repeat span with center = (center-position-in-list (omn :length seq)) with startpoint = (if (evenp span) (- center (/ span 2)) (- center (/ (1+ span) 2))) for i = startpoint then (incf startpoint) append (position-filter i seq))) ((equal type 'from-start) (loop repeat span for i = 0 then (incf i) append (position-filter i seq))) ;;; don't ((equal type 'from-end) (loop repeat span for i = (- (length (omn :length seq)) span) then (incf i) append (position-filter i seq)))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (sampling-seq-machine :seq '(1 2 3 4 5 6 7 8 9) :type 'from-end :sample-lengths '(3 5 7)) (sampling-seq-machine :seq '(t bb3 pppp a3 ppp g3 pp eb3 p gs2 mp cs2 mf fs1 mp d1 p c1 pp) :type 'rnd :sample-lengths '(3 5 7)) (sampling-seq-machine :seq '(t bb3 pppp a3 ppp g3 pp eb3 p gs2 mp cs2 mf fs1 mp d1 p c1 pp) :type 'from-start :sample-lengths '(3 5 7)) (sampling-seq-machine :seq '(t bb3 pppp a3 ppp g3 pp eb3 p gs2 mp cs2 mf fs1 mp d1 p c1 pp) :type 'from-center :sample-lengths '(3 5 7)) (sampling-seq-machine :seq '(t bb3 pppp a3 ppp g3 pp eb3 p gs2 mp cs2 mf fs1 mp d1 p c1 pp) :type 'from-end :sample-lengths '(3 5 7)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
have fun or delete it... chord-rotation by karel goeyvaerts (his early works), also used/modfied by stockhausen & co, etc... regards a. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;some OLD code -> changed for OMN ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; goeyvaerts-rotation -> from "komposition 1";;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; SUBS (defun weighted-random (list) (loop for item in list with rand-num = (random (loop for x in list sum (second x))) for add = (second item) then (+ add (second item)) when (< rand-num add) return (first item))) ;;; (defun weighted-t/nil (on-weight) (let ((off-weight (- 1 on-weight))) (weighted-random (list (list 't on-weight) (list 'nil off-weight))))) ;;; (defun single-pitch-transpose (pitch interval &key (midi-output 'nil)) (if (numberp pitch) (if (equal midi-output 'nil) (midi-to-pitch (+ interval pitch)) (+ interval pitch)) (if (equal midi-output 'nil) (midi-to-pitch (+ interval (pitch-to-midi pitch))) (+ interval (pitch-to-midi pitch))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;MAIN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun goeyvaerts-rotation (&key pitches static-pitches generations goeyvaerts-transpose-interval (direction 'up) low-border high-border correction-interval) (let ((pitches (filter-remove (pitch-to-midi static-pitches) (pitch-to-midi pitches)))) (midi-to-pitch (append (list (append pitches (pitch-to-midi static-pitches))) (cond ((equal direction 'up) (loop repeat generations collect (append (setf pitches (append (loop for i in pitches when (> i (- (pitch-to-midi high-border) goeyvaerts-transpose-interval)) collect (- i (- (abs correction-interval) 12)) else collect (+ i goeyvaerts-transpose-interval)))) (pitch-to-midi static-pitches)))) ((equal direction 'down) (loop repeat generations collect (append (setf pitches (append (loop for i in pitches when (< i (+ (pitch-to-midi low-border) goeyvaerts-transpose-interval)) collect (+ i correction-interval 12) else collect (- i goeyvaerts-transpose-interval)))) (pitch-to-midi static-pitches))))))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (chordize (goeyvaerts-rotation :pitches '(cs2 a2 gs3 d4 bb4 a5 eb6) :static-pitches '(d4) :direction 'down :generations 3 :goeyvaerts-transpose-interval 12 :low-border 'c2 :high-border 'c5 :correction-interval 24)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;put in in a specific interval-to-chord-function ;;;;;;;;;;;;; ;;;;;:type rnd-octaves or goeyvaerts ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun interval-to-chord+ (&key interval-seq startpitch (generations 1) (no-duplicates 'nil) (type 'rnd-octaves) (transpose-intervals '(-12 12)) (transpose-chance 0.5) (arpeggiando 'nil) (goeyvaerts-direction 'up) (goeyvaerts-static-pitches '(c4)) (goeyvaerts-transpose-interval 12) (goeyvaerts-low-border 'c2) (goeyvaerts-high-border 'c5) (goeyvaerts-correction-interval 24) (sorted-asc 't)) (let ((pitches (interval-to-pitch interval-seq :start startpitch))) (setf pitches (if (equal no-duplicates 't) (remove-duplicates pitches) (append pitches))) (setf pitches ;;type with rnd-octaves (cond ((equal type 'rnd-octaves) (loop repeat generations collect (setf pitches (loop for i in pitches collect (single-pitch-transpose i (if (weighted-t/nil transpose-chance) (rnd-pick transpose-intervals) (append 0))))))) ;;type with goeyvaerts-transp -> (from "komposition 1") ((equal type 'goeyvaerts) (goeyvaerts-rotation :pitches pitches :static-pitches goeyvaerts-static-pitches :direction goeyvaerts-direction :generations generations :goeyvaerts-transpose-interval goeyvaerts-transpose-interval :low-border goeyvaerts-low-border :high-border goeyvaerts-high-border :correction-interval goeyvaerts-correction-interval)) (t (append pitches)))) (if (equal sorted-asc 't) (setf pitches (sort-asc pitches))) (if (equal arpeggiando 't) (append pitches) (chordize pitches)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; examples ;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; GOEYVAERTS (pitch-list-plot (flatten (interval-to-chord+ :type 'goeyvaerts :interval-seq '(5 3 3 3 5 3 3 3 5) :generations 10 :startpitch 'c4 :type 'goeyvaerts :goeyvaerts-direction 'up :goeyvaerts-low-border 'c2 :goeyvaerts-high-border 'c5 :goeyvaerts-correction-interval 48 :arpeggiando t :sorted-asc 't))) ;;; RND-OCTAVES (pitch-list-plot (flatten (interval-to-chord+ :type 'rnd-octaves :interval-seq '(5 3 3 3 5 3 3 3 5) :startpitch 'c4 :type 'rnd-octaves :no-duplicates 't :transpose-intervals '(-12 12) :transpose-chance 0.5 :arpeggiando t :sorted-asc 't)))
-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ASHBY-OPERATOR: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; i coded somethings special, that i have seen in a book ;;; of HEINZ VON FOERSTER (my favorite writer/philosopher..) ;;; https://en.wikipedia.org/wiki/Heinz_von_Foerster ;;; => i didn't found this ASHBY-algo (he is writing about it) ;;; anywhere else, but for me it was interesting to code it. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; every list of integers (from 0 to ?) will end with "0" ;;; perhaps you could map it with whatever you want ....... ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun ashby-operator-1 (liste) (append (list liste) (loop with slot-pos with slot-val with slot-product ;; choose two positions in the list do (setq slot-pos (loop repeat 2 collect (random (length liste)))) ;; picks the values from the positions do (setq slot-val (list (nth (first slot-pos) liste) (nth (second slot-pos) liste)) ;; gen the product of the two values slot-product (* (first slot-val) (second slot-val))) ;; replace the value of the first pos with the (first (explode slot-product)) ;; or when it's < 10 with 0 do (setq liste (loop for i in liste for cnt = 0 then (incf cnt) when (= cnt (first slot-pos)) collect (if (> slot-product 9) (first (explode slot-product)) (append 0)) else collect i)) ;; replace the value of the second pos with the (second (explode slot-product)) ;; or or when it's < 10 with the slot-product collect (setq liste (loop for i in liste for cnt = 0 then (incf cnt) when (= cnt (second slot-pos)) collect (if (> slot-product 9) (second (explode slot-product)) (append slot-product)) else collect i)) into bag ;; collects all into bag ;; when LISTE only '(0 0 0 0 0 ...) return all generations when (= (sum liste) 0) do (return bag)))) ;;;examples (ashby-operator-1 '(0 1 2 3 4 5 6 7 8 9)) (list-plot (flatten (ashby-operator-1 '(0 1 2 3 4 5 6 7 8 9 11))) :point-radius 0.1 :style :fill :line-width 1) (integer-to-pitch (ashby-operator-1 '(0 1 2 3 4 5 6 7 8 9 10 11))) (chordize-list (integer-to-pitch (remove-duplicates (ashby-operator-1 '(0 1 2 3 5 8 13)))))
-
bad code but nice results... :-) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; rnd-symm-expand => generates rnd-symm transpositions ;;;; in different sequences (intervals, OMN-form,rhythms... ;;;; :chance => 0.0 - 1.0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun rnd-symm-expand (seq &key (possible-intervals '(12 -12)) (chance 1)) (let ((row) (firstpart) (rev-secondpart) (out)) (setq row (if (pitchp (first seq)) (pitch-to-midi seq) (append seq))) (setq firstpart (loop repeat (if (evenp (length row)) (/ (length row) 2) (/ (1- (length row)) 2)) for cnt = 0 then (incf cnt) collect (nth cnt row))) (setq rev-secondpart (loop repeat (if (evenp (length row) ) (/ (length row) 2) (/ (1- (length row)) 2)) for cnt = (- (length row) 1) then (decf cnt) collect (nth cnt row))) (loop for i in firstpart for j in rev-secondpart with int = 0 do (if (prob? chance) (setq int (rnd-pick possible-intervals)) (setq int 0)) collect (+ i int) into bag1 collect (+ j (* -1 int)) into bag2 when (= (length bag2) (if (evenp (length row)) (/ (length row) 2) (/ (1- (length row)) 2))) do (if (evenp (length row)) (setq out (append bag1 (reverse bag2))) (setq out (append bag1 (list (nth (length firstpart) row)) (reverse bag2))))) (if (pitchp (first seq)) (midi-to-pitch out) (append out)))) ;;;examples (rnd-symm-expand '(0 0 0 0 0 0 0 0 0 0) :possible-intervals '(4 12 7) :chance 0.5) (rnd-symm-expand '(1/4 1/4 1/4 1/4 1/4) :possible-intervals '(-1/32 1/32) :chance 0.5) (rnd-symm-expand '(c1 c2 c3 c4 c5 c6) :possible-intervals '(1 -1) :chance 0.5)
-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; modify time-signatures like '(1 4 3) to (3 4 1), ;;; helps me after (split-tuplet-lengths) to clean up ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; with the :exclude and :threshold ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun modify-time-signature-repetitions (time-signature-seq &key (exclude '((0 0))) (threshold '10/4) (numerator-threshold 20)) (loop for i in time-signature-seq when (and (> (third i) 1) (< (/ (first i) (second i)) threshold) (< (* (first i) (third i)) numerator-threshold) (not (if (listp (first exclude)) (loop for x in exclude when (equal (butlast i) x) collect t) (equal (butlast i) exclude)))) collect (list (* (first i) (third i)) (second i) 1) else collect i)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq bars '((5 4 4) (1 4 2) (3 4 2) (1 8 5) (1 32 8))) (modify-time-signature-repetitions bars) (modify-time-signature-repetitions bars :exclude '(1 4)) (modify-time-signature-repetitions bars :exclude '((1 4) (1 8))) (modify-time-signature-repetitions bars :exclude '((1 32)) :threshold '4/4) (modify-time-signature-repetitions bars :numerator-threshold 7) ;; because i don't want 200/4 - bars :-) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; a little function to compensate special-rhy-changes ;;; to 1/4-note structure... (or all :compensating-to -values) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; best format-solution was 1/32 => '(1 32) etc... otherwise ;;; i get in trouble with 1/8 = 4/32 - what is mathematicclay ;;; correct - but bringing BUGS to the output ;;; if anybody could transform things '(2/32) to '(2 32) or ;;; '(3/12) to '(3 12) would be nice, i coudn't code it. this ;;; things are necessary because the function makes decicions ;;; bewtween the denominators, so there sould be constant!!!! ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun length-compensate2 (liste &key (compensating-to '(1 4))) (butlast (loop for event in (loop for i in (append liste (list (list (* -1 (first compensating-to)) (/ 1 (second compensating-to))))) collect (list (first i) (/ 1 (second i)))) with nenner with modulo with event_stack with add_duration = 0 with corr_event when (or (null event_stack) (= (second event_stack) (second event))) do (setq add_duration (+ add_duration (abs (first event))) event_stack event corr_event nil) else do (progn (setq nenner (/ (/ 1 (second event_stack)) (second compensating-to)) modulo (mod add_duration nenner)) (if (/= modulo 0) (setq corr_event (* (* -1 (- nenner modulo)) (second event_stack)))) (setq add_duration (abs (first event)))) when (not (equal corr_event 'nil)) collect corr_event and do (setq corr_event nil) collect (* (first event) (second event)) do (setq event_stack event)))) ;example-1 (length-compensate2 (loop repeat 5 collect (rnd-pick '((1 16) (-1 16) (2 32) (5 7) (13 9) (4 20) (6 20) (3 20) (5 16))))) ;exampl-2 (length-compensate2 (loop repeat 5 collect (rnd-pick '((1 16) (-1 16) (2 32) (5 7) (13 9) (4 20) (6 20) (3 20) (5 16)))) :compensating-to '(1 8))
-
hi all i need a little lisp-help... i want to split things like this perhaps 'an3 into '(a n 3) is there a way? thanx andré
-
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))
-
;;little function to make a transition by FIBONACCI-seq ;;i have seen this idea in "slippery chicken" (by michael edwards), ;;so here is a - "not so smart" but working - basic-function. (defun transition-with-fibonacci (number-of-values value-a value-b) (let ((fib-length) (fib-seq) (all-seq)) (setq fib-length (loop for cnt = 1 then (incf cnt) collect (sum (fibonacci 2 cnt)) into bag when (> (car (last bag)) number-of-values) do (return (1- (length bag)))) fib-seq (fibonacci 2 fib-length) all-seq (append (reverse fib-seq) (loop repeat (- number-of-values (sum fib-seq)) collect 1))) (loop for i in all-seq append (loop repeat i for cnt = 0 then (incf cnt) when (= cnt 0) collect value-b else collect value-a)))) ;;example-1 => only the process (transition-with-fibonacci 70 1 2) ;;example-2 => with context = sequence with 1 or 2 (before/after transition) (list-plot (append (gen-repeat 10 1) (transition-with-fibonacci 32 1 2) (gen-repeat 10 2)) :zero-based t :point-radius 2 :join-points t)
-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;another little markov-game => markov with "global-tendency" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;a "neutral table with 4 values" (setq transitions '((1 (1 1) (2 1) (3 1) (4 1)) (2 (1 1) (2 1) (3 1) (4 1)) (3 (1 1) (2 1) (3 1) (4 1)) (3 (1 1) (2 1) (3 1) (4 1)) (4 (1 1) (2 1) (3 1) (4 1)))) ;;;subfunctions (defun filter-first-last (n sequence) (car (filter-last n sequence))) (defun substitute-transition-weight (transition-list value new-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)) new-weight) else collect (nth cnt j))))) ;;;mainfuction (defun markov-with-tendency (transitions size generations value) (loop repeat generations with list = (gen-markov-from-transitions transitions :size size :start 1) with weight = 1 with weight-add = 0 do (setq transitions (substitute-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-add)))) ;;;some simulations => evaluate!!! (list-plot (markov-with-tendency transitions 10 20 1) :point-radius 0 :style :fill) (list-plot (list (markov-with-tendency transitions 10 20 1) (markov-with-tendency transitions 10 20 2) (markov-with-tendency transitions 10 20 4)) :point-radius 0 :style :fill) (list-plot ;;non-neutral-table (markov-with-tendency '((1 (1 1) (2 4)) (2 (1 1) (4 1)) (3 (1 4) (3 5) (4 3)) (3 (1 1) (2 4) (3 2)) (4 (1 1) (3 2) (4 3))) 10 20 1) :point-radius 0 :style :fill)
-
if you want to pick a sample from approx.center (depends on odd/even) of a list... (defun pick-sample-from-center (list span) (let ((center (if (evenp (length list)) (/ (length list) 2) (/ (1+ (length list)) 2))) (span (if (> span (length list)) (length list) (append span)))) (loop repeat span with startpoint = (if (evenp span) (- center (/ span 2)) (- center (/ (1+ span) 2))) for i = startpoint then (incf startpoint) collect (nth i list)))) ;;;EXAMPLES: (pick-sample-from-center '(1 2 3 4 5 4 3 2 1) 7) => (2 3 4 5 4 3 2) (pick-sample-from-center '(1 2 3 4 5 4 3 2 1) 3) => (4 5 4) (pick-sample-from-center '(1 2 3 4 5 4 3 2 1) 6) => (3 4 5 4 3 2) (pick-sample-from-center '(1 2 3 4 5 4 3 2 1) 20) ; (if (> span length) => input-list as output => (1 2 3 4 5 4 3 2 1)
-
i'm working on a program including "markov"... so i coded this small FUNCTION to SUBSTITUTE markov-rules-values (because in my "project" i'm generating a feedback on the markov-rules (after a pattern-match)). i know it could be coded a lot smarter but it works. have fun! andré ;;;;FUNCTION (defun substitute-transition-value (transition-list value-old value-new) (loop for j in transition-list collect (loop for i in j when (numberp i) append (substitute value-new value-old (list i)) when (listp i) collect (append (substitute value-new value-old (list (first i))) (list (second i)))))) ;;;;;EXAMPLE (setq transitions '((1 (2 1) (3 3) (5 2) (8 1)) (2 (1 2) (5 3)) (3 (1 2) (8 1) (2 3)) (5 (3 2) (2 1) (1 3)) (8 (1 2) (2 2) (3 1)))) (substitute-transition-value transitions 1 -1) => ((-1 (2 1) (3 3) (5 2) (8 1)) (2 (-1 2) (5 3)) (3 (-1 2) (8 1) (2 3)) (5 (3 2) (2 1) (-1 3)) (8 (-1 2) (2 2) (3 1)))
-
hi all, i coded a little markov-program who changes the LEVEL-size if necessary to generate the number of values you want exactly. it would be nice if someone could check/test the IDEA, and if it's correct and makes sense :-) the markov starts on LEVEL 3 and tries to generate a number of output-levels with its TRANSITION-rules (level-3-rules), if it's possible (=generating the size) everything's fine. but if it's not possible, then the programm changes on LEVEL-2-rules ... if this is also not possible (to generate the size) then it changes to LEVEL 1... here is the code... ;;;FUNCTION (defun gen-multiple-markov (sequence &key size) (let ((transitions-level-1 (gen-markov-transitions sequence :level 1)) ;; gen transition-table level-1 (transitions-level-2 (gen-markov-transitions sequence :level 2)) ;; gen transition-table level-2 (seq (gen-markov-from-transitions (gen-markov-transitions sequence :level 3) :size size))) ;; gen markov-seq on level-3 (if (< (length seq) size) ;; test if seq is too short (/= (length seq) size) (progn ;; if too short -> combine the last seq with a new one (level 2) (setq seq (append seq (gen-markov-from-transitions transitions-level-2 :size (- size (length seq)) :start (last seq)))) (if (< (length seq) size) ;; same test as above (append (append seq (gen-markov-from-transitions transitions-level-1 :size (- size (length seq)) :start (last seq)))) (append seq))) (append seq)))) ;;;TEST (gen-multiple-markov '(1 2 3 2 1 2 3 2 1 2 2 2 2 1 1 1 1 2 2 3 2 1 1 2) :size 36) best wishes and THANX andré
-
here is a little function, to use or optimize... greetings andré ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; a little lisp-function that's switches by a "hysteresis" from one value to the other ;;;;;;;;;;;;;;;;;;;;;;; ;;;; could be used for any-value ;;;; :start-weight -> tendency at the beginning ;;;; :sensitivity -> change-step of tendency when switch/match ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; subfunctions (defun weighted-random (list) (loop for item in list with rand-num = (random (loop for x in list sum (second x))) for add = (second item) then (+ add (second item)) when (< rand-num add) return (first item))) (defun weighted-t/nil (on-weight) (let ((off-weight (- 1 on-weight))) (weighted-random (list (list 't on-weight) (list 'nil off-weight))))) (weighted-t/nil 0.5) ;;;; mainfunction (defun binary-hysteresis-1.0 (&key number-of-values (values '(0 1)) (start-weight 0.1) (sensitivity 0.02)) (loop repeat number-of-values with weight = start-weight with cnt = 0 when (equal (weighted-t/nil weight) 'nil) collect (first values) else collect (second values) and do (incf cnt) when (= cnt 3) do (setq weight (+ weight sensitivity) cnt 0))) ;;;; example with 0/1 (length-list-plot (binary-hysteresis-1.0 :number-of-values 200 :values '(0 1) :start-weight 0.1 :sensitivity 0.07)) ;;;; example with two pitches (make-omn :pitch (binary-hysteresis-1.0 :number-of-values 200 :values '(c4 c5) :start-weight 0.05 :sensitivity 0.1) :length (gen-repeat 200 '(1/32)))
-
;;;;small function -> create symmetrical lists (palindrom) with markov (for generating half-seq) (setf transition '((1 (4 1) (5 1) (-6 2)) (2 (5 2) (4 1)) (3 (4 1)) (4 (5 1) (2 1)) (5 (1 3) (-6 2) (4 1)) (-6 (4 1) (3 2)) (7 (1 1) (-6 1)))) ;;;FUNCTION (defun gen-sym-markov (&key seq-length transition-matrix) (let ((vals 0)) ;falls seq-length = liste, werden positive werte gezählt und neu ;seq-length (= angepasst, formatunabhängig) (if (listp seq-length) (setq seq-length (car (last (loop for i in seq-length with cnt = 0 when (> i 0) collect (incf cnt)))))) ;entscheindung grad/ungrad (if (evenp seq-length) (progn (setq vals (gen-markov-from-transitions transition-matrix :size (/ seq-length 2) :start (rnd-pick (flatten (filter-first 1 transition-matrix))))) (append vals (reverse vals))) (progn (setq vals (gen-markov-from-transitions transition-matrix :size (/ (- seq-length 1) 2) :start (rnd-pick (flatten (filter-first 1 transition-matrix))))) (append vals (list (rnd-pick (flatten (filter-first 1 transition-matrix)))) (reverse vals)))))) ;;;;EXAMPLE (gen-sym-markov :seq-length 8 :transition-matrix transition)
-
little lisp-problem/question with &optionel / &key... here are two test-programs to explore keyword and optional paramters this test-program works (defun test1 (liste add &key (add-on/off)) (loop for i in liste when (equal add-on/off 'on) collect (+ i add) else collect i)) (test1 '(1 2 3 4 5) 100 :add-on/off 'on) this version with &optional don't work... why? (defun test2 (liste add &optional (x 10) &key (add-on/off)) (loop for i in liste when (equal add-on/off 'on) collect (+ i add x) else collect i)) (test2 '(1 2 3 4 5) 100 :add-on/off 'on) > Error: While compiling test2 : > Bad lambda list : (liste add &key add-on/off &optional (x 10)), in process Listener-1(7). thanx for help andré
-
Hello! Just letting you know -- I ran into this error while trying out the (gen-mandelbrot) function: (setf man-int (gen-mandelbrot 6 6 6)) (setf man-lis (integer-to-pitch (array-to-list man-int))) (gen-divide 6 (substitute-map '(1/4 1/8 -1/8 1/8 1/16 1/16) (1 2 3 4 5 6) (flatten (array-to-list man-int)))) >Error: Car of (1 2 3 4 5 6) is not a function name or lambda-expression. I figured out that (1 2 3 4 5 6) needs to be '(1 2 3 4 5 6) Really enjoying learning opusmodus! Elliot
-
Following from this question, I want to use several different Lisp packages through quicklisp, but I can't get the installation to work correctly. After doing some digging, I found out that the path to quicklisp is not defined correctly. This is the content of the ql:*quicklisp-home* global: > ql:*quicklisp-home* #P"/Users/opusmodus/quicklisp/" I realised that changing this manually doesn't fix the issue, and because of this I can't install or use quicklisp correctly. Note that I do not have a user by the name opusmodus and creating that directory with my user's permission does not fix it. I managed to do something by using SBCL as my own user to load and install quicklisp, and then in opusmodus use the following: (load #p"/Users/ajf-/quicklisp/setup.lisp") But it's actually a workaround and it's not very reliable (also gives an error sometimes). Can you please point me in the right direction? Thank you very much
-
Hi, is there a shortcut for indentation of complete lisp code blocks in Opusmodus ? Achim