Skip to content
View in the app

A better way to browse. Learn more.

Learn more

change randomly lengths to rests

Featured Replies

Is there a function with which I can change randomly a defined number of lengths in a list to rests?

Thanks, Achim

 

(setf alist '(1/4 1/4 1/8 1/8 1/4 1/4))
(setf n 3)
(length-invert '(1/4 1/4 1/8 1/8 1/4 1/4) :section (rnd-sample n (gen-integer 0 (1- (length alist))) :norep t))

 

  • Author

Something like this:

 

(defparameter durations '(15/16 15/32 1/32 1/32 1/32 61/32 1/32 1/2 1/32 5/32 1/32 13/16 17/32 3/2 9/16 7/16))

(defun length-to-rnd-rest (numb dur-lst)
  (let* ((llst (- (length dur-lst) 1))
         (minnumb (min numb llst))
         (posns (sort-asc (rnd-unique minnumb (gen-integer 0 llst)))))
    (loop for i in dur-lst
          for j from 0
          collect (if (member j posns)
                      (* -1 i) i ))))

(length-to-rnd-rest 5 durations)

 

I get only 4 rests in this example:

(defparameter durations '(15/16 15/32 1/32 1/32 1/32 61/32 1/32 1/2 1/32 5/32 1/32 13/16 17/32 3/2 9/16 7/16))

(length-invert durations :section (rnd-sample 5 (gen-integer 0 (1- (length durations))) :norep t :seed 4))

;; => (15/16 15/32 1/32 1/32 1/32 61/32 1/32 1/2 -5/32 -13/16 1/32 -9/16 17/32 3/2 -1/32 7/16)

 

test/evaluate it again... my output is

 

=> (-15/16 15/32 1/32 1/32 1/32 61/32 1/32 1/2 1/32 -5/32 -1/32 13/16 -17/32 3/2 9/16 -7/16)

 

 

so it's correct

  • Author

Sometimes its correct, sometimes not ...

Did you tried it with my seed? What was your result?

The seed is not part of the function therefore it will return different output each time.

Check the rnd-seed doc for how to apply seed function into your functions.

Here it is:

 

(defun length-to-rnd-rest (n sequence &key seed)
  (let (state)
    (setf state *init-seed*)
    (setf seed (rnd-seed seed))
    (do-verbose ("length-to-rnd-rest :seed ~s" seed)
      (let* ((len (length sequence))
             (sel (rnd-order
                   (append (gen-repeat n t) (gen-repeat (- len n) nil))
                   :seed (seed)))
             (result (loop for i in sel
                           for j in sequence
                           collect (if (null i) j (* j -1)))))
        (init-state state)
        result))))

 

(setf lengths '(15/16 15/32 1/32 1/32 1/32 61/32 1/32 1/2 1/32 5/32 1/32 13/16 17/32 3/2 9/16 7/16))

(length-to-rnd-rest 5 lengths)
=> (15/16 15/32 1/32 -1/32 1/32 61/32 1/32 -1/2 -1/32 -5/32 1/32 -13/16 17/32 3/2 9/16 7/16)

(length-to-rnd-rest 5 lengths :seed 5)
=> (15/16 -15/32 1/32 1/32 1/32 61/32 1/32 -1/2 1/32 -5/32 1/32 13/16 -17/32 -3/2 9/16 7/16)

 

I could make something more useful with steps, omitting existing rests and of course working with length symbols and events (omn).

Create an account or sign in to comment

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.