;; jellyfish-2.sal -- left-hand/right-hand simulation ;; (c) 2008 by Roger B. Dannenberg define variable lh-heap = list(g3, ef4, f4), rh-heap = list(g4, bf4, c5, d5), lh-pat = make-heap(lh-heap, for: 1), rh-pat = make-heap(rh-heap, for: 1), lh-cnt = 0, ; how many previous lh? rh-cnt = 0, ; how many previous rh? lh-prev, rh-prev ; remember prev pitches ; choose left or right hand, ; generate non-duplicate pitch define function select-pitch() begin with lhw = 1 + lh-cnt * lh-cnt, rhw = 1 + rh-cnt * rh-cnt ; weights ; favor the hand used the least so far if rrandom() > float(lhw) / (lhw + rhw) then begin ; use left hand set lh-cnt += 1 ; increment use count ; generate left-hand pitch until itŐs ; not a duplicate loop for pitch = next(lh-pat) while pitch = lh-prev finally begin ; remember selection set lh-prev = pitch return pitch end end end else ; use right hand begin ; just like the left-hand code set rh-cnt += 1 ; increment use count loop for pitch = next(rh-pat) while pitch = rh-prev finally begin ; remember the selection set rh-prev = pitch return pitch end end end end define function j2(beatdur, notes, notedur) begin return score-gen(score-len: notes, save: quote(j1-score), dur: notedur, ioi: beatdur, vel: real-random(70, 120), pitch: select-pitch()) end exec score-play(j2(0.35, 20, 0.5))