def hatp(ctx): return rhythm.pattern('xxxx', bpm=BPM)
def kickp(ctx): return rhythm.pattern('x...', bpm=BPM)
def snarep(ctx): return rhythm.pattern('..x.', bpm=BPM)
for i in range(numbars): bar = dsp.buffer() numlayers = random.randint(3, 6) beat = int(((60000 / 109) / 1000) * 44100) // 4 if i // 4 % 3 == 0: chord = chords2[i % len(chords2)] else: chord = chords[i % len(chords)] freqs = tune.chord(chord, octave=3, key='d') if i > 3: for _ in range(numlayers): pattern = rhythm.pattern(16, random.randint(2, 6), random.randint(0, 3)) onsets = rhythm.onsets(pattern, beat) for onset in onsets: if random.random() > 0.5: osc.freq = random.choice(freqs) osc.wavetable = [0] + [ random.triangular(-1, 1) for _ in range(random.randint(3, 10)) ] + [0] osc.amp = 0.5 snd = osc.play(random.randint(441, 44100)) snd = snd.env('phasor') snd = snd.pan(random.random()) * random.triangular( 0.1, 0.25) bar.dub(snd, onset)
for i in range(numbars): bar = dsp.buffer() numlayers = random.randint(3, 6) beat = int(((60000 / 131)/1000) * 44100) // 4 if i//4 % 3 == 0: chord = chords2[i%len(chords2)] else: chord = chords[i%len(chords)] freqs = tune.chord(chord, octave=3, key='d') if i > 3: for _ in range(numlayers): pattern = rhythm.pattern(16, random.randint(2,6), random.randint(0, 3)) onsets = rhythm.onsets(pattern, beat) for onset in onsets: if random.random() > 0.5: osc.freq = random.choice(freqs) osc.wavetable = [0] + [ random.triangular(-1, 1) for _ in range(random.randint(3, 10)) ] + [0] osc.amp = 0.5 snd = osc.play(random.randint(441, 44100)) snd = snd.env('phasor') snd = snd.pan(random.random()) * random.triangular(0.1, 0.25) bar.dub(snd, onset) snare_onsets = rhythm.onsets('.x.x', beat * 4) for onset in snare_onsets: s = snare.speed(random.triangular(0.9, 1.1)) * random.triangular(0.85, 1)
def test_basic_patterns(self): for pattern_args, result in test_patterns: pattern = rhythm.pattern(*pattern_args) self.assertEqual(pattern, result)