Posted May 22, 20241 yr I'd like to get a random sequence of a set of pitches but want to exclude certain intervals like 7 and 4 from appearing in the resulting sequence. I don't see an interval exclude property for rnd-sample. What would be a way to do this? (setf seq (rnd-sample 16 '(c4 d4 f4 fs4 g4 a4 b4 ds5) :norep t))
May 22, 20241 yr I'll bet there is some builtin function that I don't know of, but here's an option: (setf res (interval-to-pitch (remove-if (lambda (x) (or (= 4 x) (= 7 x))) (pitch-to-interval seq)))) (pitch-to-interval res) Jesper Edit: if you want exactly 16 you could do like this. (bad programming, I know 😉 ) (setf seq (rnd-sample 24 '(c4 d4 f4 fs4 g4 a4 b4 ds5) :norep t)) (setf res (subseq (interval-to-pitch (remove-if (lambda (x) (or (= 4 x) (= 7 x))) (pitch-to-interval seq))) 0 16))
May 22, 20241 yr or: (setf seq (rnd-sample 16 '(c4 d4 f4 fs4 g4 a4 b4 ds5) :norep t)) (interval-to-pitch (filter-remove '(-7 7 -4 4) (pitch-to-interval seq)) :start (car seq)) => (a4 c4 a4 g4 e5 fs5 e5 d6 e5 d6 fs5) A simple way is to work with intervals and then convert them to pitches: (setf seq (rnd-sample 16 '(-4 -3 -2 -1 1 2 3 4) :norep t)) => (-4 2 -2 2 -1 -4 4 -1 1 -2 -1 3 -2 2 -2 -3) (interval-to-pitch seq :start 'a4) => (a4 f4 g4 f4 g4 fs4 d4 fs4 f4 fs4 e4 eb4 fs4 e4 fs4 e4 cs4) This way the length of the list will not change.
Create an account or sign in to comment