erka Posted September 21 Share Posted September 21 I was looking for a function like Scale-quantize in Logic or quantize-modules in VCV-Rack etc. I tried tonality-map and harmonic-path, but they are changing the start point of the sequence. So I wrote a function that does what I want. Maybe there is already a function like this. Maybe there is a way to do the same with tonality-map etc and I didn't get it. Please let me know. (defun rk_pitch-quantize ( sequence scale &key seed ) ;with rnd-seed "sequence can be omn-form or pitches. scale being e.g.'(g0 dorian)" (when (not (or (every 'listp sequence) (omn-formp sequence) (every 'pitchp sequence) ) ) (error "rk_pitch-quant: sequence can be omn-form or pitches.")) (let (state) (setf state *init-seed*) (setf seed (rnd-seed seed)) (do-verbose ("rk_pitch-quant ~s" seed) (let* ( (expscalemidi (pitch-to-midi (loop for i upto 8 append (pitch-transpose (* 12 i) (expand-tonality scale) :ambitus 'midi)))) (has-subl (every 'listp sequence)) (seq (if has-subl sequence (list sequence))) (pitchmidi (if (omn-formp seq) (pitch-to-midi (omn :pitch seq)) (pitch-to-midi seq))) (pitchquant (loop for s in pitchmidi collect (midi-to-pitch (loop for i in s collect (if (member i expscalemidi) i (find-closest i expscalemidi :seed seed) ))))) (out (if (omn-formp seq) (omn-replace :pitch pitchquant seq) pitchquant)) ) (init-state state) (if has-subl out (car out)) ))) ) (setf mat3 '(s c4 d4 e4 f4 g4 a4 b4 c5)) (tonality-map '( dorian :closest up :root g0) mat3) ;=>(s g0 mf a0 c1 c1 d1 e1 f1 f1) (harmonic-path '(g0 dorian) mat3) ;=>(s g4 mf a4 bb4 c4 d4 e4 f4 g5) (rk_pitch-quantize mat3 '(g0 dorian) :seed 241) ;=>(s c4 d4 e4 f4 g4 a4 c5 c5) (rk_pitch-quantize mat3 '(g0 dorian) :seed 2) ;=>(s c4 d4 e4 f4 g4 a4 bb4 c5) (loop for i in '( (c0 major) (b0 major) (d0 major) (f0 major) (g0 dorian) (fs0 major) (fs0 pentatonic)) collect (rk_pitch-quantize mat3 i )) ;=>((s c4 d4 e4 f4 g4 a4 b4 c5) (s cs4 eb4 e4 fs4 gs4 bb4 b4 cs5) (s cs4 d4 e4 fs4 g4 a4 b4 cs5) (s c4 d4 e4 f4 g4 a4 c5 c5) (s c4 d4 e4 f4 g4 a4 bb4 c5) (s cs4 eb4 f4 f4 gs4 bb4 b4 cs5) (s b3 cs4 eb4 fs4 fs4 gs4 b4 b4)) When I use :seed (seed) in find-closest I don't get the same result for the same seed. :seed in find-closest works the same without the rnd-seed lines. How is that? Quote Link to comment Share on other sites More sharing options...
opmo Posted September 21 Share Posted September 21 (find-closest i expscalemidi :seed (seed)) Quote Link to comment Share on other sites More sharing options...
erka Posted September 21 Author Share Posted September 21 As mentioned that does not work here. Gives different result on consecutive calls with the same seed. (find-closest i expscalemidi :seed (seed)) gives different result on consecutive calls with the same seed. (find-closest i expscalemidi :seed seed) gives same result on consecutive calls with the same seed. Not using the rnd-seed lines at all gives same result on consecutive calls with the same seed. Quote Link to comment Share on other sites More sharing options...
opmo Posted September 21 Share Posted September 21 Any function which is using seed needs to include the seed in your function. Quote Link to comment Share on other sites More sharing options...
erka Posted September 21 Author Share Posted September 21 Okay. But why don't I get the same result on consecutive calls with :seed (seed) but with :seed seed? Quote Link to comment Share on other sites More sharing options...
opmo Posted September 21 Share Posted September 21 Your function needs to be rewriten. Here you get the result: (tonality-map '(dorian :root c4 :map octave :seed 45) mat3) Quote Link to comment Share on other sites More sharing options...
erka Posted September 21 Author Share Posted September 21 It looks to me like different results: (tonality-map '(dorian :root c4 :map octave :seed 45) mat3) =>(s c4 mf d4 eb4 f4 g4 a4 bb4 c5) (rk_pitch-quantize mat3 '(g0 dorian) :seed 2) =>(s c4 d4 e4 f4 g4 a4 bb4 c5) I want to map mat3 to g-dorian not c-dorian When I change the :root the sequence changes it root. That is not what quantize in Logic does: (tonality-map '(dorian :root g3 :map octave :seed 45) mat3) =>(s g3 mf a3 bb3 c4 d4 e4 f4 g4) re:Your function needs to be rewritten. How? Always happy to learn. Quote Link to comment Share on other sites More sharing options...
opmo Posted September 21 Share Posted September 21 (tonality-map '(dorian :closest down :root g4 :map octave) (pitch-transpose -7 mat3)) => (s c4 mf d4 e4 f4 g4 a4 bb4 c5) Quote Link to comment Share on other sites More sharing options...
erka Posted September 22 Author Share Posted September 22 I rewrote the function. Gives now more control of up and down and doesn't need a seed. (defun rk_pitch-quantize ( sequence scale &optional (updown 'up) ) "sequence can be omn-form or pitch-symbols (incl. chords). scale being e.g.'(g0 dorian). updown being 'up or 'down." (when (not (or (equal updown 'up) (equal updown 'down) )) (error "rk_pitch-quantize: third argument must be 'up or 'down")) (labels ((f_pquant (mpitch mscale) (if (member mpitch mscale) mpitch (if (equal updown 'up) (find-above mpitch mscale :first t ) (find-below mpitch mscale :first t )))) ) (let* ( (expscalemidi (pitch-to-midi (loop for i upto 8 append (pitch-transpose (* 12 i) (expand-tonality scale) :ambitus 'midi)))) (has-subl (every 'listp sequence)) (seq (if has-subl sequence (list sequence))) (pitchmidi (if (omn-formp seq) (pitch-to-midi (omn :pitch seq)) (pitch-to-midi seq))) (pitchquant (loop for subl in pitchmidi collect (midi-to-pitch (loop for pitch in subl collect (if (listp pitch) (loop for i in pitch collect (f_pquant i expscalemidi)) (f_pquant pitch expscalemidi)))))) (out (if (omn-formp seq) (omn-replace :pitch pitchquant seq) pitchquant)) ) (if has-subl out (car out)) ) ) ) (setf mat2 '(c4 d4 e4 f4 g4 a4 b4 c5)) (rk_pitch-quantize mat2 '(g0 dorian) ) ;=>(s c4 d4 e4 f4 g4 a4 c5 c5) (rk_pitch-quantize mat2 '(g0 dorian) 'down) ;=>(s c4 d4 e4 f4 g4 a4 bb4 c5) (setf mat7 '((q e5 leg e fs5 leg gs5 q a5 ten cs6 ten) (h cs6 leg q b5 e d6 leg cs6 leg) (q a5 cs6 marc+leg gs5 cs6 leg) (h. fs5))) (loop for i in '( (c0 major) (b0 major) (d0 major) (f0 major) (g0 dorian) (fs0 major) (fs0 pentatonic)) collect (rk_pitch-quantize mat7 i )) Quote Link to comment Share on other sites More sharing options...
Stephane Boussuge Posted September 22 Share Posted September 22 Hi, i have a tendency to use tonality-map with pitch-class sets in that case, something like: (tonality-map '((0 2 4 5 7 9 10) :map 'octave) mat3) => (c4 d4 e4 f4 g4 a4 bb4 c5) S. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.