User:Danny van der Kleij/assignment
< User:Danny van der Kleij
Revision as of 09:49, 24 May 2011 by Danny van der Kleij (talk | contribs) (Created page with "<source lang="python"> import os, random samplelist = ['Piano_A', 'Piano_B', 'Piano_C', 'Piano_D', 'Piano_E', 'Piano_F', 'Piano_G', 'Piano_F', 'Piano_E', 'Piano_D', 'Piano_C', 'P...")
import os, random
samplelist = ['Piano_A', 'Piano_B', 'Piano_C', 'Piano_D', 'Piano_E', 'Piano_F', 'Piano_G', 'Piano_F', 'Piano_E', 'Piano_D', 'Piano_C', 'Piano_B', 'Piano_A', 'end']
#need to know, which sample comes after another sample. for example after Piano_B can come Piano_A or Piano_C.
dictionary = {}
# i is what counts through the list with numbers(0-12) r = the corresponding elements in the list, so we get
# i = 2, r = 'piano_C'
for (i, r) in enumerate(samplelist):
if i < len(samplelist) - 1:
if samplelist[i] not in dictionary:
dictionary[r] = []
dictionary[r].append(samplelist[i+1])
#now walk through the dictionary each time chosing a new element
#from the list of choices and storing that in a new list.
for j in range(0, 1):
markovlist = []
start = random.choice(dictionary['Piano_A'])
while start != 'end':
markovlist.append(start)
start = random.choice(dictionary[start])
print markovlist
for (k, s) in enumerate(markovlist):
cmd = 'mplayer %s.wav' % (markovlist[k])
os.system(cmd)