def rmfunky(score, reps, dur, keys): """ Main composer chooses input spectra , creates a ring modulated output spectrum and plays them using two parts. Parameters ---------- score : Score The musical score. reps : int The number of sections to compose. dur : int The surface rhythm keys : list List of keynums for ring modulation input. """ num = choose([1, 2, 3]) # scramble the cycle of fourths pat = jumble(keys) for _ in range(reps): # input1 is 1, 2 or 3 notes from cycle of 4ths keys1 = [next(pat) for _ in range(next(num))] # input2 is same keys2 = [next(pat) for _ in range(next(num))] # ring modulate the inputs spect = rmspectrum([hertz(k) for k in keys1], [hertz(k) for k in keys2]) # convert to keynums keys3 = spect.keynums(quant=1, unique=True, minkey=21, maxkey=108) # sprout composers to play inputs and output playn = pick(3, 4, 5) score.compose(accompaniment(score, playn, dur, keys1, keys2)) score.compose(melody(score, playn, dur, keys3)) # do it again after composers finish yield (dur * playn * 2)
def jazz_drums(score, tmpo, ampl): """ Randomly selects between playing the snare, the bass drum or resting one quarter of the time. One tenth of the time it produces a very loud tone. """ elec_snare = 40 bass_drum = 35 knums = choose(['r', elec_snare, bass_drum], [.25, 1, 1]) rhys = cycle([2 / 3, 1 / 3]) amps = choose([.7, .95], [1, .1]) for _ in range(8): k = next(knums) a = next(amps) r = intempo(next(rhys), tmpo) if k != 'r': m = Note(time=score.now, duration=r, pitch=k, amplitude=a * ampl, instrument=9) score.add(m) yield r
def continuum(score, rhy, minkeys, maxkeys, seclens): """ Calls register() to create the next section's material and then waits until the section is over before creating another section. """ # random pattern of section lengths. pat = choose(seclens) # iterate all the min and max key numbers for low, high in zip(minkeys, maxkeys): # get the section's duration secdur = next(pat) # sprout the next section score.compose(register(score, rhy, secdur, low, high, .4)) # wait till end of section yield secdur
def jazz_bass(score, on, tmpo, ampl): """ The bass part plays a melodic line built out of tones from the jazz-scale's tonic seventh chord alternating with color tones outside the tonic chord. The bass plays a series of 12 triplets per measure, on each triplet only one of the two sets is possible. On all but the first triplet a rest is also possible. """ # 5 possible patterns for triplets 1-4 a = choose(['trrc', 'trrr', 'trtc', 'tctc', 'tctr'], [1.0, .25, .22, .065, .014]) # 5 possible patterns for 5-7 b = choose(['rrt', 'rrr', 'rct', 'tct', 'tcr'], [1.0, .25, .22, .038, .007]) # 5 possible patterns for 8-10 c = choose(['rrc', 'rtc', 'rrr', 'ctc', 'ctr'], [1.0, .415, .25, .11, .018]) # two possible values for 11 d = choose(['r', 't'], [1, .25]) # two possible values for 12 e = choose(['r', 'c'], [1, .25]) # the measure map meas = next(a) + next(b) + next(c) + next(d) + next(e) rhy = intempo(1 / 3, tmpo) tonics = choose([jazz_scale[i] for i in [0, 2, 4, 6, 7]]) colors = choose([jazz_scale[i] for i in [1, 3, 5, 6, 8]]) amps = cycle([.5, .4, 1.0, .9, .4, .9, .5, .4, 1.0, .9, .5, .9]) durs = cycle([2 / 3, 1 / 3, 1 / 3]) for x in meas: k = -1 if x == 't': k = next(tonics) elif x == 'c': k = next(colors) if k > -1: a = next(amps) d = next(durs) m = Note(time=score.now, duration=d, pitch=on + k, amplitude=ampl * a, instrument=1) score.add(m) yield rhy
def composer_stephen_foster(score, num, shift=0, chan=0): # A second-order markov process generates the melody. melody = pattern_stephen_foster() # randomly select rhythmic patterns characterisitic of Foster's style rhythms = choose( [[2, 2], [1, 1, 1, 1], [2, 1, 1], [1, 1, 2], [1, 2, 1], [4]], [.375, .125, .125, .125, .25, .125]) for _ in range(num): n = 0 for r in next(rhythms): k = keynum(next(melody)) + (shift * 12) r = intempo(r, 200) m = Note(time=score.now + n, duration=r, pitch=k, amplitude=.5, instrument=chan) score.add(m) n += r yield n
def spray(score, *, length=None, end=None, rhythm=.5, duration=None, pitch= 60, band=0, amplitude=.5, instrument=0): """ Generates Notes using discrete random selection. Most parameters allow lists of values to be specified, in which case elements are randomly selected from the lists every time an event is output. Parameters ---------- Parameters are the same as brush() except for these changes or additions: pitch : number | list A MIDI key number or list of key numbers to play. If a list is specified a key number is randomly selected from the list for each midi event. band : number | list A number is treated as a half-step range on either side of the current key choice from which the next key number will be chosen. If a list of intervals is specified then randomly selected intervals are added added to the current key number to determine the key number played. The list can also contain sublists of intervals, in which case each sublist is treated as a chord, i.e. the intervals in the sublist are added to the current key and performed simultaneously. """ # user must specify either length or end parameter counter = 0 if length: if end: raise TypeError("specify either leng or end, not both.") stopitr = length thisitr = (lambda: counter) else: if not end: raise TypeError("specify either length or end.") stopitr = end thisitr = (lambda: score.elapsed) # convert each param into a chooser pattern. ran = (lambda x: choose(x if type(x) is list else [x])) rhy = ran(rhythm) dur = ran(duration) key = ran(pitch) amp = ran(amplitude) chan = ran(instrument) band = choose( [i for i in range(-band, band+1)] if type(band) is int else band ) while (thisitr() < stopitr): t = score.now #print("counter=", counter, "now=", t) r = next(rhy) d = next(dur) k = next(key) a = next(amp) c = next(chan) b = next(band) if type(b) is list: k = [k+i for i in b] else: k = k + b #print("pitch=", k, end=" ") if r > 0: if not d: d = r if type(k) is list: for j in k: m = Note(time=t, duration=d, pitch=j, amplitude=a, instrument=c) score.add(m) else: m = Note(time=t, duration=d, pitch=k, amplitude=a, instrument=c) score.add(m) counter += 1 yield abs(r)
def subpat(wt): r1 = choose([ride1, 'r'], [1, wt]) r2 = choose([ride2, 'r'], [1, wt]) return choose([r1, r2], [1.5, 1])