from math import sqrt, floor from random import random def linear(scale=None): if scale is None: return (1 - sqrt(random())) else: return int(floor(scale * (1 - sqrt(random())))) pattern_duration = 16 notes = [ 12, 1, 5, 6, 8, 10, 3 ] durations = [ 0.5, 1.0, 2.0, 4.0, 1.5, 3.0, 2.5, 3.5 ] octaves = [ 7, 8, 8, 8, 8, 9, 6 ] def create_pattern(): pat = [] total_dur = pattern_duration while (total_dur > 0): dur = durations[linear(len(durations))] if (total_dur - dur < 0): dur = total_dur total_dur = 0 else: total_dur -= dur pat.append( (octaves[linear(len(octaves))], notes[linear(len(notes))], dur) ) return pat def format_pattern(pat, start_time=0.0, time_multiplier=1): r = '' for p in pat: note = "%d.%02d" % (p[0], p[1]) r += "i 1 %.4f %.4f %s\n" % (start_time, p[2] * time_multiplier, note) start_time += p[2] * time_multiplier return r if __name__ == '__main__': # print function table definitions print "f 1 0 512 10 1" pata = create_pattern() patb = create_pattern() # print lowest frequency for i in range(4): if i == 2: print format_pattern(patb, i*pattern_duration) else: print format_pattern(pata, i*pattern_duration) # print mid frequency for i in range(8): if (i + 2) % 4 == 0: print format_pattern(patb, i*pattern_duration/2, 0.5) else: print format_pattern(pata, i*pattern_duration/2, 0.5) for i in range(16): if (i + 2) % 4 == 0: print format_pattern(patb, i*pattern_duration/4, 0.25) else: print format_pattern(pata, i*pattern_duration/4, 0.25)