#structure for the piece Temperate Music #-------------------------------------- #first some functions import random def subdivision(lista,perc): '''bepaalde percentage van waardes 1 in lista vervangen door 0''' listb=[] listc=[] listd=lista[:] listaindex=range(len(lista)) for num,nr in zip(listd,listaindex): if num==1: listb.append(nr) listc=random.sample(listb,int(round(perc*len(listb)))) for a in listc: for i,v in enumerate(listd): if a==i: listd[i]=0 return listd def listtime (lista,listdur): listc=[] for nm, nr in zip(lista,listdur): listc=[nm]*nr + listc listc.reverse() return listc def randomsum(sm,fac,min,max): '''random numbers which add up to a given number, sm = sum, fac = number of factors, min = minimum of the value of these factors, max = maximum of the value of these factors''' lista=[0]*fac while sum(lista) != sm: for i,v in enumerate(lista): lista[i]=random.randint(min,max) return lista from numpy import argsort def listmodel(lista,listmodel): '''uses the second list as a model to shape the first list''' listd=argsort(listmodel) listas=sorted(lista) listemp=[0]*len(lista) for num,ns,nr in zip(listd,listas,listemp): listemp[num]=ns return listemp def listwrite01 (list,length): '''als in list vb waarde 8 staat wordt 8 keer 1 en 1 keer 0 geschreven (bij length=9)''' if max(list)>length: print "impossible: some values in the list are bigger than the length you have given" else: listb=[] for num in list: listy=[1]*num+[0]*(length-num) random.shuffle(listy) listb=listb+listy return listb def rescale (num,minin,maxin,minout,maxout): numout=minout+((num-minin)*(maxout-minout))/(maxin-minin) return numout #------------------------------------------------------ #this is were the structure of Temperate Music starts #sea wnd tmp: 3 parameters about the weather/season #their values have to be changed every time a new version is made sea=3 wnd=3 tmp=2 eventsperpartlookup=[0,15,12,9,6,9,12,15,18,15,15] epp=eventsperpartlookup[sea] nrp=9 from __future__ import division from composition import randomsum from composition import listmodel from composition import listwrite01 from composition import subdivision from composition import rescale #nrsier - vanaf hier aantal siernoten nrswndlookup=[0,0,2,4,8,16] nrssealookup= [0,6,4,3,2,3,4,6,8,6] nrstmplookup= [0,16,8,4,8,16] basiccurvenrsier = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 1, 5, 2, 0, 0, 0, 5, 4, 3, 4, 5, 2, 1, 0, 2, 3, 4, 5, 0, 5, 6, 0, 0, 1, 2, 3, 4, 3, 2, 1, 0, 4, 6, 3, 0, 2, 6, 3, 2, 1, 6, 5, 4, 0, 0, 4, 3, 2, 1, 2, 4, 3, 0, 0, 5, 3, 2, 1, 1, 3, 2, 0, 0, 2, 4, 3, 0, 0, 0, 0, 2, 4, 1, 5, 2, 0] hw1=(nrswndlookup[wnd]+nrssealookup[sea]+nrstmplookup[tmp])/3 print "hw1 nrsier =",hw1 sm=int(round(((nrswndlookup[wnd]+nrssealookup[sea]+nrstmplookup[tmp])/3)*nrp)) mx=int(round(((nrswndlookup[wnd]+nrssealookup[sea]+nrstmplookup[tmp])/3)*1.75)) nrsiera=randomsum(sm,nrp,2,mx) nrsierend=listmodel(nrsiera,basiccurvenrsier[9*sea:9*(sea+1)]) print "nr siernoten",sea,wnd,tmp for num in nrsierend: print num #Gonoff-sieronoff: vanaf hier tabellen sierwndlookup=[0,70,40,30,40,70] siertmplookup=[0,70,40,30,40,70] basiccurvesieronoff=[0,0,0,0,0,0,0,0,0,2,0,1,1,1,0,1,1,1,0,0,1,2,4,5,6,3,1,1,2,2,2,2,2,2,2,1,0,1,2,3,4,5,3,1,0,3,5,1,0,2,3,5,6,7,6,4,1,0,0,2,5,7,8,3,2,1,2,3,4,4,2,1,0,0,5,1,6,2,5,4,0,2,0,1,1,1,0,1,1,1] tmp1=(sierwndlookup[wnd]+siertmplookup[tmp])/2 if sea == 7 or sea == 9 or sea == 1: hw2=int(round(rescale(tmp1,30,70,25,55))) elif sea == 8: hw2=int(round(rescale(tmp1,30,70,20,45))) else: hw2=tmp1 print "hw2 sieronoff =",hw2 sm=int(round((hw2/100)*(nrp*epp))) sieronoffa=randomsum(sm,nrp,0,epp) sieronoffmodel=listmodel(sieronoffa,basiccurvesieronoff[9*sea:9*(sea+1)]) print "sieronoffmodel",sieronoffmodel sieronoffend=listwrite01(sieronoffmodel,epp) gonoffend=sieronoffend[:] print "sieronoff",sea,wnd,tmp for num in sieronoffend: print num gonwndlookup=[0,0,0,20,30,50] gontmplookup=[0,75,50,25,50,75] basiccurvegonoff=[0,0,0,0,0,0,0,0,0,3,0,2,1,0,0,0,1,2,0,0,1,2,3,5,7,4,3,0,1,2,2,2,2,2,2,1,0,1,2,3,4,5,2,1,0,0,0,1,2,3,4,5,6,7,6,4,2,0,0,1,4,7,6,0,0,0,1,2,3,0,4,0,0,0,2,0,3,4,6,5,0,3,0,2,1,0,0,0,1,2] tmp1=(gonwndlookup[wnd]+gontmplookup[tmp])/2 if sea == 7 or sea == 9 or sea == 1: hw3=int(round(rescale(tmp1,12.5,62.5,17,40))) elif sea == 8: hw3=int(round(rescale(tmp1,12.5,62.5,20,33))) else: hw3=tmp1 print "hw3 gonoff=",hw3 sm=int(round((hw3*nrp)/5)) print "sm",sm gonoffa=randomsum(sm,nrp,0,20) gonoffmodel=listmodel(gonoffa,basiccurvegonoff[9*sea:9*(sea+1)]) print "gonoffmodel, maal 5 doen om percentages te bekomen", gonoffmodel listperc=[] for num in gonoffmodel: listperc.append(1-((num*5)/100)) print listperc gonofftmp=[] gonoffendend=[] for i,v in enumerate(listperc): gonofftmp=subdivision(gonoffend[epp*i:epp*(i+1)],v) gonoffendend=gonoffendend+gonofftmp print "Gonoff",sea,wnd,tmp for num in gonoffendend: print num #instr2Gonoff basiccurve2onoff=[0,0,0,0,0,0,0,0,0,0,0,1,1,1,2,1,1,1,6,4,1,0,0,3,6,1,1,0,0,0,1,2,3,4,5,6,2,4,6,2,1,0,0,3,5,0,2,3,4,2,0,4,5,0,0,0,3,4,5,6,6,2,1,3,2,1,2,3,4,4,0,0,0,3,2,0,0,1,0,2,3,0,0,1,1,1,2,1,1,1] instr2wndlookup=[0,45,35,30,25,15] instr2sealookup=[0,40,40,30,20,30,40,40,50,40] hw4=((instr2wndlookup[wnd]*0.6)+(instr2sealookup[sea]*0.4)) sm=int(round(((hw4/100)*nrp)*epp)) print "hw4 instr2onoff =",hw4 instr2onoffa=randomsum(sm,nrp,0,epp) instr2onoffmodel=listmodel(instr2onoffa,basiccurve2onoff[9*sea:9*(sea+1)]) instr2onoffend=listwrite01(instr2onoffmodel,epp) print "instr2onoff",sea,wnd,tmp for num in instr2onoffend: print num #scalesverdicht scalestmplookup=[0,9,7,5,3,1] scalessealookup=[0,3,5,6,8,7,5,4,2,3] volgordescales=[0,6,0,10,4,2,8,0,10] basiccurvescales=[0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,2,3,4,0,1,2,3,4,3,2,1,0,0,1,2,3,4,3,2,1,0,0,1,2,3,4,3,2,1,0,5,4,3,2,1,0,1,2,3,3,2,1,0,0,1,2,3,4,3,2,1,0,0,1,0,1,0,0,1,0,1,0,1,1,0,1] sm=int(round((scalestmplookup[tmp]*0.6)+(scalessealookup[sea]*0.4))) scalesa=randomsum(sm,nrp,0,1) scalesmodel=listmodel(scalesa,basiccurvescales[9*sea:9*(sea+1)]) print "scalesmodel=",scalesmodel scalesend=[] for num,nr in zip(scalesmodel,volgordescales): scalesend.append(num+nr) print "scalesverdicht",sea,wnd,tmp print scalesend #instr1Gonoff basiccurveinstr1Gonoff=[6,0,0,1,2,3,2,1,0,0,0,0,4,1,5,2,3,0,0,1,2,3,4,3,2,1,0,2,2,2,2,2,2,2,2,2,6,5,4,3,0,3,4,5,6,7,6,5,4,3,2,1,0,0,0,0,0,7,6,5,4,3,2,1,1,1,1,1,1,2,0,0,0,0,0,4,1,6,2,3,0] instr1wndlookup=[0,10,15,20,25,30] tmp1=instr1wndlookup[wnd] print "tmp1",tmp1 if sea == 7 or sea == 9 or sea == 1: hw6=int(round(rescale(tmp1,10,30,15,30))) elif sea == 8: hw6=int(round(rescale(tmp1,10,30,20,33))) else: hw6=tmp1 print "hw6 instr1Gonoff =",hw6 tmp2=int(round((100/(100-hw6))*(nrp*epp))) nepp=int(round(tmp2/nrp)) print "nepp",nepp sm=int(round(tmp2-(nrp*epp))) instr1onoffa=randomsum(sm,nrp,0,nepp) instr1onoffmodel=listmodel(instr1onoffa,basiccurveinstr1Gonoff[9*sea:9*(sea+1)]) print "instr1Gonoffmodel",instr1onoffmodel instr1onoffend=listwrite01(instr1onoffmodel,nepp) print "instr1Gonoff",sea,wnd,tmp for num in instr1onoffend: print num #presetinstr1 basiccurvepreset=[0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,3,2,1,3,5,3,3,0,0,0,3,5,5,4,3,2,1,0,1,3,2,3,2,1,0,0,0,1,3,2,3,2,1,3,0,0,0,0,3,0,1,5,4,3,0,0,1,2,0,1,2,3,1,0,0,0,4,5,0,0,4,0,1,2,3,0,0,4,0,0,0,0,3,2,1] presettmplookup=[0,30,25,20,15,10] tmp1=presettmplookup[tmp] if sea == 7 or sea == 9 or sea == 1: hw7=int(round(rescale(tmp1,10,30,15,40))) elif sea == 8: hw7=int(round(rescale(tmp1,10,30,20,50))) else: hw7=tmp1 print "hw7 preset0of1 =",hw7 sm=int(round((hw7/100)*nrp*epp)) preseta=randomsum(sm,nrp,0,epp) presetmodel=listmodel(preseta,basiccurvepreset[9*sea:9*(sea+1)]) print "preset0of1model",presetmodel presetend=listwrite01(presetmodel,epp) print "preset0of1",sea,wnd,tmp for num in presetend: print num #instr3onoff basiccurveinstr3onoff=[0,0,0,0,0,0,0,0,0,0,5,3,2,1,4,0,0,0,0,1,2,3,4,3,2,1,0,0,0,1,2,3,4,5,6,7,0,0,1,2,3,4,5,6,7,0,1,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,2,0,0,1,2,3,2,0,0,0,1] instr3tmplookup=[0,15,35,55,70,85] tmp1=instr3tmplookup[tmp] print "tmp1",tmp1 if sea == 7 or sea == 9 or sea == 1: hw5=int(round(rescale(tmp1,15,85,15,70))) elif sea == 8: hw5=int(round(rescale(tmp1,15,85,10,52))) else: hw5=tmp1 print "hw5 instr3onoff",hw5 sm=int(round((hw5/100)*nrp*epp)) instr3onoffa=randomsum(sm,nrp,0,epp) instr3onoffmodel=listmodel(instr3onoffa,basiccurveinstr3onoff[9*sea:9*(sea+1)]) print "instr3Gonoffmodel",instr3onoffmodel instr3onoffend=listwrite01(instr3onoffmodel,epp) print "instr3Gonoff",sea,wnd,tmp for num in instr3onoffend: print num #filteronoff if hw5+1>35 and hw6+1>20 and hw4+1>30: print "filter ON" #discontinu ja of nee dislookup=[0,4,3,2,1,2,3,4,5,4] tmp1=int(round((dislookup[sea]*0.45)+(wnd*0.55))) if tmp1>3: tmp2=11 tmp3=21 else: tmp2=15 tmp3=25 if hw6+1>tmp2 and hw7+1>tmp2 and hw3+1>tmp3 and hw4+1>tmp3: print "discontinu"