def normaliser(phr) : phr=phr+" " prov="" for i in range(len(phr)-1) : l1=phr[i] l2=phr[i+1] if l1==" " and l2==" " : l1="" prov=prov+l1 return prov def mesure(voix,ideb,inum) : ntotal=0 prov="" for i in range(len(voix)) : l1=voix[i] if l1=="|" : ntotal=ntotal+1 if ntotal>=ideb and ntotal<=ideb+inum-1 : prov=prov+l1 return prov def parametre(para) : ivoix=0 prov="" for i in range(len(para)) : k=0 l1=para[i] l2=para[i:i+2] l8=para[i:i+8] if l2=="M:" : print("Entrez une mesure comme 3/4 par exemple ou return") mesure=input() if mesure != "" : prov=prov+"M:"+mesure+"\n" k=6 l1="" elif l2=="L:" : print("Entrez une longueur comme 1/4 par exemple ou return") longueur=input() if longueur != "" : prov=prov+"L:"+longueur+"\n" k=6 l1="" elif l2=="Q:" : print("Entrez un tempo comme 1/4=120 par exemple ou return") tempo=input() if tempo != "" : prov=prov+"Q:"+tempo+"\n" k=10 l1="" elif l2=="K:" : print("Entrez un ton comme C# par exemple ou return") ton=input() if ton != "" : prov=prov+"K:"+ton+"\n" k=5 l1="" elif l8=="program " : ivoix=ivoix+1 print("Entrez un instrument pour la voix ",ivoix," comme 45 par exemple ou return") instru=input() if len(instru)==1 : instru=instru+" " elif len(instru)==1 : instru=instru+" " if instru != "" : prov=prov+"program "+instru+"\n" k=10 l1="" if i >= i+k : prov=prov+l1 return prov def repmotif(mesuremotif) : nrep=0 for i in range(len(mesuremotif)) : l1=mesuremotif[i] if l1==":" : if mesuremotif[i-1] != " " : nrep=int(mesuremotif[i-1]) if mesuremotif[i-1] != " " and mesuremotif[i-2] != " " : nrep=int(mesuremotif[i-2]+mesuremotif[i-1]) i=len(mesuremotif) return nrep def motif(mesuremotif) : motifvoix=[] for i in range(256) : motifvoix.append("*") mesuremotif=mesuremotif+" " prov="" ntrans=0 nrep=0 for i in range(len(mesuremotif)) : l1=mesuremotif[i] if l1==":" : if mesuremotif[i-1] != " " : nrep=int(mesuremotif[i-1]) if mesuremotif[i-2] != " " : nrep=int(mesuremotif[i-2:i]) if mesuremotif[i+1] != " " : ntrans=int(mesuremotif[i+1:i+3]) i=len(mesuremotif) else : prov=prov+l1 if nrep>0 : prov=prov[0:len(prov)-1] if nrep>=10 : prov=prov[0:len(prov)-2] mesuremotif=prov prov="" j=0 for i in range(len(mesuremotif)) : l1=mesuremotif[i] if l1==" " and prov != "" : motifvoix[j]=prov j=j+1 prov="" else : prov=prov+l1 jtotal=j nrep=nrep+1 itest=0 for n in range(nrep) : for j in range(jtotal) : provvoix=motifvoix[j] if provvoix[0]=="[" : provvoix=provvoix[1:len(provvoix)] itest=1 elif provvoix[0]=="." : provvoix=provvoix[1:len(provvoix)] itest=3 elif provvoix[len(provvoix)-1] == "]" : provvoix=provvoix[0:len(provvoix)-1] itest=2 if provvoix=="0" : prov=0 else : prov=int(provvoix)+n*ntrans k=j+n*jtotal if itest==1 : motifvoix[k]="["+str(prov) itest=0 elif itest==2 : motifvoix[k]=str(prov)+"]" itest=0 elif itest==3 : motifvoix[k]="."+str(prov) itest=0 else : motifvoix[k]=str(prov) #print("k motif",k,motifvoix[k]) return motifvoix def rythme(mesurerythme) : rythmevoix=[] for i in range(256) : rythmevoix.append("") mesurerythme=mesurerythme+" " prov="" j=0 for i in range(len(mesurerythme)) : l1=mesurerythme[i] if l1==" " : if prov=="1" : prov="" elif prov=="/" : prov="/2" elif prov=="//" : prov="/4" rythmevoix[j]=prov j=j+1 prov="" else : prov=prov+l1 jtotal=j return rythmevoix def nuance(mesurenuance) : nuancevoix=[] for i in range(256) : nuancevoix.append("") prov="" j=0 for i in range(len(mesurenuance)) : l1=mesurenuance[i] if l1==" " : if prov=="*" : prov="" else : prov=prov+" " nuancevoix[j]=prov j=j+1 prov="" else : prov=prov+l1 jtotal=j return nuancevoix def paravoix(voix) : itest=0 para="" paravoix="" for i in range(len(voix)) : l13=voix[i:i+13] if l13=="MIDI program " : itest=1 i=i+13 paravoix=paravoix+l13 instru=voix[i:i+4] paravoix=paravoix+instru #paravoix=paravoix+"\n" l1=voix[i] if itest==0 : paravoix=paravoix+l1 return paravoix def totalmesure(voix) : itest=0 para="" paravoix="" for i in range(len(voix)) : l1=voix[i] if itest==0 : paravoix=paravoix+l1 l12=voix[i:i+12] if l12=="MIDI program" : itest=1 i=i+12 paravoix=paravoix+l12 instru=voix[i:i+3] paravoix=paravoix+instru mesurevoix="" for i in range(len(paravoix),len(voix)) : l1=voix[i] if l1=="!" : l1="" i=i+2 if voix[i+3]=="f" or voix[i+3]=="p" : i=i+1 if l1=="|" or l1=="/" or l1=="1" or l1=="2" or l1=="3" or l1=="4" or l1=="8" or l1=="6" : l1="" mesurevoix=mesurevoix+l1 return mesurevoix def notevoix(mesurevoix) : notevoix=[] for i in range(256) : notevoix.append("") motifvoix=[] for i in range(256) : motifvoix.append("*") altvoix=[] for i in range(256) : altvoix.append("") rythmevoix=[] for i in range(256) : rythmevoix.append("") nuancevoix=[] for i in range(256) : nuancevoix.append("") print("Entrez un motif de voix ou return") mesuremotif=input() mesuremotif=normaliser(mesuremotif) nrep=repmotif(mesuremotif) print("Entrez un motif de rythme ou return") mesurerythme=input() if mesurerythme != "" : mesurerythme=normaliser(mesurerythme) if nrep>0 : prov=" "+mesurerythme for n in range(nrep) : mesurerythme=mesurerythme+prov print("motif de rythme avec répétition",mesurerythme) print("Entrez un motif de nuance ou return") mesurenuance=input() if mesurenuance != "" : mesurenuance=normaliser(mesurenuance) if nrep>0 : prov=" ".mesurenuance for n in range(nrep) : mesurenuance=mesurenuance+prov print("motif de nuance avec répétition",mesurenuance) if mesuremotif=="" : return mesurevoix j=1 itest=0 mesurevoix=mesurevoix+" " for i in range(len(mesurevoix)) : l1=mesurevoix[i] if l1=="|" : notevoix[j]=notevoix[j]+l1 if l1=="[" : itest=1 notevoix[j]=notevoix[j]+l1 if l1=="]" : itest=0 notevoix[j]=notevoix[j]+l1 if l1=="^" or l1=="=" or l1=="_" or (ord(l1)>64 and ord(l1)<72) or (ord(l1)>96 and ord(l1)<104) or l1=="z" : if l1=="^" or l1=="=" or l1=="_" : notevoix[j]=notevoix[j]+l1 else : notevoix[j]=notevoix[j]+l1 if mesurevoix[i+1]=="'" or mesurevoix[i+1]=="," : notevoix[j]=notevoix[j]+mesurevoix[i+1] if itest==0 : #print("notevoix",j,notevoix[j]) j=j+1 mesurevoix="" for j in range(256) : if notevoix[j] != "" : mesurevoix=mesurevoix+notevoix[j] #print("j notevoix",j,notevoix[j]) mesurevoix="" for j in range(256) : if motifvoix[j] != "*" : mesurevoix=mesurevoix+notevoix[j]+" " if mesuremotif != "" : j=0 prov="" for i in range(len(mesuremotif)) : l1=mesuremotif[i] if l1=="+" or l1=="-" or l1=="=" : if l1=="+" : l1="^" elif l1=="-" : l1="_" altvoix[j]=l1 l1="" if l1==" " : j=j+1 prov=prov+l1 mesuremotif=prov #print("mesurevoix sans altération",mesurevoix) motifvoix=motif(mesuremotif) if mesurerythme != "" : rythmevoix=rythme(mesurerythme) if mesurenuance != "" : nuancevoix=nuance(mesurenuance) mesurevoix="" for j in range(256) : if motifvoix[j] != "*" : #print("motifvoix",motifvoix[j]) prov=motifvoix[j] if prov=="0" : mesurevoix=nuancevoix[j]+altvoix[j]+mesurevoix+"z"+rythmevoix[j]+" " elif prov[0]=="." : prov=prov[1:len(prov)] mesurevoix=nuancevoix[j]+mesurevoix+"."+altvoix[j]+notevoix[int(prov)]+rythmevoix[j]+" " elif prov[0]=="[" : prov=prov[1:len(prov)] mesurevoix=nuancevoix[j]+mesurevoix+"["+altvoix[j]+notevoix[int(prov)]+rythmevoix[j]+" " elif prov[len(prov)-1]=="]" : prov=prov[0:len(prov)-1] provrythme=rythmevoix[j] if len(provrythme)>1 and provrythme[len(provrythme)]=="|" : provrythme=provrythme[0:len(provrythme)-1] mesurevoix=nuancevoix[j]+mesurevoix+altvoix[j]+notevoix[int(prov)]+provrythme+"]|"+" " else : mesurevoix=nuancevoix[j]+mesurevoix+altvoix[j]+notevoix[int(prov)]+"]"+rythmevoix[j]+" " else : mesurevoix=nuancevoix[j]+mesurevoix+altvoix[j]+notevoix[int(prov)]+rythmevoix[j]+" " prov="" for i in range(len(mesurevoix)) : l1=mesurevoix[i] if l1=="1" : l1="" prov=prov+l1 mesurevoix=prov print("mesurevoix",mesurevoix) return mesurevoix def trad(voix) : prov="" alt="" for i in range(len(voix)) : l1=voix[i] if l1=="C" : l1="Do "+alt alt="" elif l1=="D" : l1="Ré "+alt alt="" elif l1=="E" : l1="Mi "+alt alt="" elif l1=="F" : l1="Fa "+alt alt="" elif l1=="G" : l1="Sol "+alt alt="" elif l1=="A" : l1="La "+alt alt="" elif l1=="B" : l1="Si "+alt alt="" elif l1=="c" : l1="do "+alt alt="" elif l1=="d" : l1="ré "+alt alt="" elif l1=="e" : l1="mi "+alt alt="" elif l1=="f" : l1="fa "+alt alt="" elif l1=="g" : l1="sol "+alt alt="" elif l1=="a" : l1="la "+alt alt="" elif l1=="b" : l1="si "+alt alt="" elif l1=="_" : alt=alt+"bémol " elif l1=="^" : alt=alt+"dièse " elif l1=="=" : alt=alt+"bécarre " elif l1=="'" or l1=="," : l1=l1+" " elif l1=="[" : l1="crochet gauche " elif l1=="]" : l1="crochet droit " elif l1=="|" : l1="mesure " elif l1=="." : l1="piquée " elif l1=="1" : l1="" else : l1="" l2=voix[i:i+2] if l2=="4 " or l2=="4|" : l1="ronde " elif l2=="3" or l2=="3|" : l1="blanche pointée " elif l2=="2 " or l2=="2|" : l1="blanche " elif voix[i:i+3]=="3/2" : l1="noire pointée " i=i+2 elif voix[i:i+3]=="3/4" : l1="croche pointée " i=i+2 elif l2=="\2" or l2=="\ " : l1="croche " i=i+1 elif l2=="\\" or l2=="\4" : l1="double croche " i=i+1 prov=prov+l1 return prov def armure(ton) : armu="" if ton=="G" or ton=="G " : armu="F#" elif ton=="D" or ton=="D " : armu="F# D#" elif ton=="A" or ton=="A " : armu="F# C# G#" elif ton=="E" or ton=="E " : armu="F# C# G# D#" elif ton=="B" or ton=="B " : armu="F# C# G# D# A#" elif ton=="F" or ton=="F " : armu="B-" elif ton=="Bb" : armu="B- E-" elif ton=="Eb" : armu="B- E- A-" if ton=="Ab" : armu="B- E- A- D-" elif ton=="Db" : armu="B- E- A- D-G-" elif ton=="Cb" : armu="B- E- A- D- G- c- F-" return armu def gammetonmodetranspo(ton,mode,dt) : gammechr=[] for i in range(48) : gammechr.append("*") gammeton=[] for i in range(48) : gammeton.append("*") imotifmode=[] for i in range(48) : imotifmode.append(0) itest=0 if ton=="" : ton="C " if len(ton)==1 : ton=ton+" " if ton[1]=="#" : ton="^"+ton[0] if ton[1]=="b" : ton="_"+ton[0] ton=ton.upper() gammetonbemol="" gammechrbemol="=_C =C _D =D _E =E =F _G =G _A =A _B _c =c _d =d _e =e =f _g =g _a =a _b _c' =c' _d' =d' _e' =e' =f' _g' =g' _a' =a' _b' _c'' =c''" if ton=="F " or ton=="_B" or ton=="_E" or ton=="_A" or ton=="_D" or ton=="_G" or ton=="_C" : for i in range(len(gammechrbemol)) : l1=gammechrbemol[i] l2=gammechrbemol[i:i+2] if l2==ton : itest=1 if itest==1 : gammetonbemol=gammetonbemol+l1 gammechrdieze="C ^C D ^D E| F ^F G ^G A ^A |b |c ^c d ^d e| f ^f g ^g a ^a b| |c' ^c' d' ^d' e'| f' ^f' g' ^g' a' ^a' b' |c''" itest=0 gammetondieze="" for i in range(len(gammechrdieze)) : l1=gammechrdieze[i] l2=gammechrdieze[i:i+2] if l2==ton : itest=1 i=i+2 if itest==1 : gammetondieze=gammetondieze+l1 if gammetonbemol=="" : gammetonmode=gammetondieze+" " else : gammetonmode=gammetonbemol+" " note="" k=0 for i in range(len(gammetonmode)) : l1=gammetonmode[i] if l1==" " and l1 != "" : k=k+1 gammechr[k]=note note="" else : note=note+l1 motiftonmode="1 2 3 4 5 6 7 8 9 10 11 12 " if mode=="ton" : motiftonmode="1 3 5 7 9 11 " elif mode=="demiton" : motiftonmode="1 3 4 6 7 9 10 12 " elif mode=="pen" : motiftonmode="1 3 6 8 10 " elif mode=="maj" : motiftonmode="1 3 5 6 8 10 12 " elif mode=="min" : motiftonmode="1 3 4 6 7 9 11 " elif mode=="harm" : motiftonmode="1 3 4 6 7 9 12 " elif mode=="mel" : motiftonmode="1 3 4 6 8 10 12 " mot="" k=0 for i in range(len(motiftonmode)) : l1=motiftonmode[i] if l1==" " and mot != " " : k=k+1 imotifmode[k]=int(mot) mot="" else : mot=mot+l1 for i in range(24) : if imotifmode[i] != 0 : imotifmode[i+12]=imotifmode[i]+12 idt=int(dt) for i in range(24) : if imotifmode[i] != 0 : imotifmode[i]=imotifmode[i]+idt k=0 for i in range(48) : if imotifmode[i] != 0 : k=k+1 gammeton[k]=gammechr[imotifmode[i]] gammetranspo="" for i in range(48) : if gammeton[i] != "*" : gammetranspo=gammetranspo+gammeton[i]+" " return gammetranspo def gammetonmode(ton,mode) : gamme=gammetonmodetranspo(ton,mode,"0") return gamme