You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.2 KiB

#!/usr/bin/env python3
import random
def genKicks():
"""
the idea:
generate kick drum patterns by weight
so it's most likely to play on 1-2-3-4
output: a series of 1's and 0's (struct)
and also a gain pattern
100 = always always always play an event on this 16th note
0 = NEVER play an event on this 16th note
50 = play an event on this step half the time
etc
arguments: bars = how many total bars to generate (1-4)
variation = the arrangement of the bars
"""
bars = 4
patternList = []
stepWeights = [100,
10,
15,
20,
######
85,
15,
25,
10,
######
85,
10,
10,
10,
######
80,
10,
10,
10]
fullKickPattern = ""
pat = ""
for bar in range(bars):
kickPattern = "["
currentStep = 0
# which bar are we generating?
if (bar == 0):
seq = "a"
elif (bar == 1):
seq = "b"
elif (bar == 2):
seq = "c"
elif (bar == 3):
seq = "d"
for i in stepWeights:
# every 4 steps, insert a space for easier reading
if (currentStep > 3):
currentStep = 0
kickPattern = str(kickPattern)+" "
# roll the dice to generate an event, or not
if (i >= random.randint(0,100)):
# event
kickPattern = str(kickPattern)+"1"
else:
# rest
kickPattern = str(kickPattern)+"0"
currentStep = currentStep + 1
kickPattern = kickPattern + "]"
patternList.append(str(kickPattern))
#return("kick pattern: "+str(kickPattern))
fullKickPattern = fullKickPattern + " " +kickPattern
#print("fullkickpat: "+fullKickPattern)
# ok at this point we have a list that contains (bars) items,
# where each item is a generated 16 steps of 1 or 0
# now we want to generate how to play them -
# just the first? just the first and second? or ABAC?
formChoices = ["A","AB","AB","AB","ABAC","AAAB","AAAB","ABCD"]
form = random.choice(formChoices)
#print("form: "+str(form))
# there is surely a better way to do this, but I don't know what it is
# so for now, here's a hack!
if (str(form) == "A"):
pat = str(patternList[0])
elif (str(form) == "AB"):
pat = str(patternList[0])+""+str(patternList[1])
elif (str(form) == "ABAC"):
pat = str(patternList[0])+""+str(patternList[1])+str(patternList[0])+""+str(patternList[2])
elif (str(form) == "AAAB"):
pat = str(patternList[0])+""+str(patternList[0])+str(patternList[0])+""+str(patternList[1])
elif (str(form) == "ABCD"):
pat = str(patternList[0])+""+str(patternList[1])+str(patternList[2])+""+str(patternList[3])
else:
pat = str(patternList[0])
fullKickPattern = "<"+str(pat)+">/"+str(bars)
return fullKickPattern
print(genKicks())