Posted October 8, 20231 yr So I was saying I'm have a problem with this code. After reading documentation several times, I admit I don't understand how to do it with my code. ;;;variation rythmique Gamme majeure 4/4 (setf mat '((e f5 g5 a5 s gb5 f5 e e5 f5 g5 s e5 eb5) (e d5 e5 f5 s d5 db5 e c5 d5 e5 s c5 b4) (e bb4 c5 d5 s b4 bb4 e a4 bb4 c5 s a4 ab4) (e g4 a4 bb4 s g4 gb4 e f4 g4 a4 -e))) (loop for i in '(0 5 -2 3 8 1 6 -1 4 9 2 7) append (pitch-transpose i (loop for bar in mat collect (list (filter-repeat 1 (rnd-order (first (gen-divide 5 bar)) :type :pitch) (second (gen-divide 5 bar))))))) Compiler warnings for "/Volumes/web/Opus modus file/test rhytme.opmo" : ; In an anonymous lambda form at position 0: In the call to filter-repeat with arguments (1 (rnd-order (car (gen-divide 5 bar)) :type :pitch) (car (cdr (gen-divide 5 bar)))), ; the variable portion of the argument list ((car (cdr (gen-divide 5 bar)))) contains an odd number ; of arguments and so can't be used to initialize keyword parameters ; for the current global definition of filter-repeat > Error: OMN Parse Error: fail > While executing: omn-to-ast, in process Listener-1(7). > Type cmd-. to abort, cmd-\ for a list of available restarts. > Type :? for other options.
October 9, 20231 yr This works here. (loop for i in '(0 5 -2 3 8 1 6 -1 4 9 2 7) append (pitch-transpose i (loop for bar in mat collect (list (filter-repeat 1 (rnd-order (first (gen-divide 5 bar))) :type :pitch) (second (gen-divide 5 bar)))))) It is a problem of position of parentheses. The filter-repeat was applied on the two half bars not on the output of (rnd-order..). When you put the mouse on the opening parentheses of a list the closing parentheses will be green, too. So you can see what is enclosed in the list. I agree with Janusz that is actually easier to program and to understand later what you did when you do this in steps with variables. (one of the examples in the last thread). What some people don't like about LISP is the lot of parentheses. But the opus modus editor is very helpful to check those. My rule is to always check the beginning and end of a list, especially in nested statements. Takes a little time but solves the problem.
October 9, 20231 yr Author this is my original message: (setf mat '((e f5 g5 a5 s gb5 f5 e e5 f5 g5 s e5 eb5) (e d5 e5 f5 s d5 db5 e c5 d5 e5 s c5 b4) (e bb4 c5 d5 s b4 bb4 e a4 bb4 c5 s a4 ab4) (e g4 a4 bb4 s g4 gb4 e f4 g4 a4 -e))) ;; divide each bar in two and only rnd-order the first half (loop for i in '(0 5 -2 3 8 1 6 -1 4 9 2 7) append (pitch-transpose i (loop for bar in mat collect (list (rnd-order (first (gen-divide 5 bar)) :seed 20) (second (gen-divide 5 bar)))))) filter-repeat 1 with the last code with change :type :pitch (loop for i in '(0 5 -2 3 8 1 6 -1 4 9 2 7) append (pitch-transpose i (loop for bar in mat collect (list (filter-repeat 1 (rnd-order (first (gen-divide 5 bar))) :type :pitch) (second (gen-divide 5 bar)))))) it work but the rhythm is not good. should I do this to get on the output of (rnd-order..) (loop for i in '(0 5 -2 3 8 1 6 -1 4 9 2 7) append (pitch-transpose i (loop for bar in mat collect (list (filter-repeat 1 (rnd-order (first (gen-divide 5 bar))) :type :pitch) (filter-repeat 1 (second (gen-divide 5 bar))))))) you are talking about parentheses will be green? my version is
October 9, 20231 yr You forgot the :type :pitch for the rnd-order and only set it for the filter-repeat. So the events were rnd-ordered not only the pitch. (loop for i in '(0 5 -2 3 8 1 6 -1 4 9 2 7) append (pitch-transpose i (loop for bar in mat collect (list (filter-repeat 1 (rnd-order (first (gen-divide 5 bar)) :type :pitch) :type :pitch) (second (gen-divide 5 bar)))))) I can't remember V2. 🙂 Time to upgrade? I like to be up to date and also like to support the development. Is there a <> at the top of the post-editor in V2. Then you can click it and post code inside the appearing box.
October 9, 20231 yr Author ok thank you very much...I'm starting to understand. with seed is this correct? (loop for i in '(0 5 -2 3 8 1 6 -1 4 9 2 7) append (pitch-transpose i (loop for bar in mat collect (list (filter-repeat 1 (rnd-order (first (gen-divide 5 bar)) :seed 21) :type :pitch) (second (gen-divide 5 bar))))))
October 10, 20231 yr (loop for i in '(0 5 -2 3 8 1 6 -1 4 9 2 7) append (pitch-transpose i (loop for bar in mat collect (list (filter-repeat 1 (rnd-order (first (gen-divide 5 bar)) :type :pitch :seed 21) :type :pitch) (second (gen-divide 5 bar))))))
October 10, 20231 yr Author thank you very much Rolf. for a question of logic, I don't understand why the second type is not after (second (gen-divide 5 bar))
October 10, 20231 yr Do you want to only rnd-order the first half or both halfs of the bar? You probably only want to filter-repeat the rnd-ordered omn to prevent repeats after ordering. When the second half is not re-ordered then filter-repeat is not needed, unless you want to prevent a repeat at the beginning of the second bar. As mentioned before try to break the whole thing into single steps. Each step assigned to a variable (setf) and work the next step on this variable. This makes things easier to understand and you easily see what a function is doing to what input and what the output is and if you want that. Or try the loop with only '(0 1) and the mat with only 1 or 2 bars and it will be easier to check if the result is what you expect. That is what I usually do. Reduce the input to see if the algorithm is working at all and then try complex things.
October 10, 20231 yr Example of separating to each function. Evaluate step by step and check the result. That is how I learned functions and checked if that is what I want. (setf mat '((e f5 g5 a5 s gb5 f5 e e5 f5 g5 s e5 eb5) (e d5 e5 f5 s d5 db5 e c5 d5 e5 s c5 b4) (e bb4 c5 d5 s b4 bb4 e a4 bb4 c5 s a4 ab4) (e g4 a4 bb4 s g4 gb4 e f4 g4 a4 -e))) (setf bar1 '(e f5 g5 a5 s gb5 f5 e e5 f5 g5 s e5 eb5)) ;; or (setf bar1 (first mat)) (setf bar1_1 (first (gen-divide 5 bar1))) (setf bar1_2 (second (gen-divide 5 bar1))) ;;rnd-order only for the first half of bar (setf bar1_1ro (rnd-order bar1_1 :type :pitch :seed 21)) ;; or without seed to get diiferent results each time (setf bar1_1fr (filter-repeat 1 bar1_1ro :type :pitch)) (setf bar1_1_2 (list bar1_1fr bar1_2)) ;; if the same for second half of bar ;;(setf bar1_2ro (rnd-order bar1_2 :type :pitch :seed 21)) ;; or without seed to get diiferent results each time ;;(setf bar1_2fr (filter-repeat 1 bar1_2ro :type :pitch)) ;;(setf bar1_1_2 (list bar1_1fr bar1_2fr)) ;;together for bar1 (setf maintask (list (filter-repeat 1 (rnd-order (first (gen-divide 5 bar1)) :type :pitch :seed 21) :type :pitch) (second (gen-divide 5 bar1)))) ;; main task applied to all bars of mat (setf loopbars (loop for bar in mat collect ;;or append (list (filter-repeat 1 (rnd-order (first (gen-divide 5 bar)) :type :pitch :seed 21) :type :pitch) (second (gen-divide 5 bar))))) ;; transpose loop (setf looptrans (loop for i in '(0 5 -2 3 8 1 6 -1 4 9 2 7) append (pitch-transpose i loopbars))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; check what happens if two pitches repeat (filter-repeat 1 '(e f5 f5 a5 s gb5 g5) :type :pitch) ;;all together in a nested loop (loop for i in '(0 5 -2 3 8 1 6 -1 4 9 2 7) append (pitch-transpose i (loop for bar in mat collect (list (filter-repeat 1 (rnd-order (first (gen-divide 5 bar)) :type :pitch :seed 21) :type :pitch) (second (gen-divide 5 bar)))))) Is more to write but easier to test. When everything works fine you could nest the different steps. But evaluating the whole script gives the same result.
October 10, 20231 yr Author for me all your examples should be burned into OM documentation! it's perfectly clear, you are a great teacher. Thanks Rolf
October 11, 20231 yr dear david this could be helpful for you... some basic-syntax-tutorials have fun! andré well explainend
October 11, 20231 yr Author very informative! the second video is really hard for me...;-) thank you very much André for help.
Create an account or sign in to comment