def gesture1(q, numtimes, o, chan): for _ in range(numtimes): if (odds(o)): q.compose(motive1(q, 5, 1, chan)) else: q.compose(motive2(q, 6, 1, chan)) yield 2
def fm_improv(q, line, beat): """ Uses a contour line of carrier frequencies (specified as midi keynums) to produces fm spectra that creates both melodic and harmoinc gestures. The inputs and outputs of the fmspectrum() calls are printed during the improvisation. """ amp = .7 dur = beat for knum in line: ismel = odds(.7) rhy = pick(dur, dur / 2, dur / 4) f, r, x = hertz(knum), between(1.1, 1.9), pick(1, 2, 3) print("\ncarrier=",f,"c/m ratio=",r,"fm index=",x) spec = fmspectrum(f,r,x) keys = spec.keynums(unique=True, minkey=knum-14, maxkey=knum+14) if ismel: random.shuffle(keys) sub = rhy / len(keys) if ismel else 0 print("melody:" if ismel else "chord:", "time=", q.now, "dur=", rhy, "keys=", keys) for i, k in enumerate(keys): m = MidiNote(time=q.now + (i * sub), dur=dur, key=k, amp=amp) q.out.addevent(m) yield rhy
def gesture3(q, numtimes, o, limit, chan, hiwait, lowwait): """Like gesture2 but takes smaller amounts of time between motives.""" for i in range(numtimes): if (odds(o)): q.compose(motive1(q, 5, limit, chan)) else: q.compose(motive2(q, 6, limit, chan)) yield qtime(i, numtimes, 2, .2, .2)
def gesture2(q, numtimes, o, limit, chan): """The same as gesture1 but with transposition upto limit.""" for _ in range(numtimes): if (odds(o)): q.compose(motive1(q, 5, limit, chan)) else: q.compose(motive2(q, 6, limit, chan)) yield 2
def jazz_piano(q, on, tmpo, ampl): """ The jazz piano improvises jazz chords based on a pattern of root changes and a scale pattern that is transposed to each root. The piano randomly choose between playing triplet eighths or straight eights for a given measure. """ reps = odds(.65, 8, 12) scal = jumble(jazz_scale) rhys = cycle([2 / 3, 1 / 3] if reps == 8 else [1 / 3]) for _ in range(reps): r = intempo(next(rhys), tmpo) l = [] if odds(2 / 5) else [next(scal) for _ in range(between(1, 9))] for k in l: a = pick(.4, .5, .6, .7, .8) m = MidiNote(time=q.now, dur=r, key=on + k, amp=a, chan=0) q.out.addevent(m) yield r
def gesture4(q, numtimes, lowoctave, highoctave, limit, chan, hiwait, lowwait): """ Gesture4 is similar to gesture3 but chooses octaves and gradually prefers motive2 over motive1. """ for i in range(numtimes): if odds(qtime(i, numtimes, 1.0, 0.0, .01)): q.compose(motive1(q, between(lowoctave, highoctave), limit, chan)) else: q.compose(motive2(q, between(lowoctave, highoctave), limit, chan)) yield qtime(i, numtimes, hiwait, lowwait, .2)
def gesture4(q, numtimes, lowoctave, highoctave, limit, chan, hiwait, lowwait): global scale global chord """ Gesture4 is similar to gesture3 but chooses octaves and gradually prefers motive2 over motive1. I have added tonal harmony using CsoundAC. """ for i in range(numtimes): if odds(qtime(i, numtimes, 1.0, 0.0, .01)): q.compose(motive1(q, between(lowoctave, highoctave), limit, chan)) else: q.compose(motive2(q, between(lowoctave, highoctave), limit, chan)) yield qtime(i, numtimes, hiwait, lowwait, .2)