import micro import guy import gal import wave from array import array import struct #import pickle def l2h(t): h_t = array('h') l_t = len(t) for i in range(l_t): h_t.append(t[i]) return h_t def f2l(fn): s = wave.open(fn,"r") t = s.readframes(s.getnframes()) l = list(struct.unpack('%dh'%(len(t)/s.getsampwidth()),t)) s.close() t = [] ll = int(len(l)/2) print("adjusting file",fn,ll) for i in range(1,ll): l[2*i-2] = l[2*i]-l[2*i-2] l[2*i-1] = l[2*i+1]-l[2*i-1] mx = abs(max(l)) mn = abs(min(l)) if mn > mx: mx = mn print("max=",mx,"-1.0-1.0nizing") del l[-2:] ll = ll-1 for i in range(ll): l[2*i] = l[2*i]/mx l[2*i+1] = l[2*i+1]/mx return [l,ll,mx] def slnc(m,l): for f in range(2*l): m.append(m[-2]) def s_g_a(s,g,t,insts,nns,strt): l = [] sco = "" instsl = len(insts) nnsl = len(nns) sm = 77 ml = s[2] gl = len(g) fltr = 35753 for f in range(s[1]): for lr in range(2): flr = 2*f+lr if s[0][flr] > 0: d = 65535-t[lr] else: d = t[lr] if d < ml: ml = d t[lr] = t[lr]+int(ml*s[0][flr]) for ag in g: ags = ag[0].sing() for lr in range(2): if ags > 0: d = (65535-t[lr])/ag[2][lr] else: d = t[lr]/ag[2][lr] t[lr] = t[lr]+int(d*ags) if ag[2][lr] > sm: w = t[lr]%gl if g[w][2][lr]+1 != g[w][2][(lr+1)%2] and ag[2][lr]-1 != ag[2][(lr+1)%2]: if g[w][1] != 1 and g[w][1] != 2 and ag[1] != 1 and ag[1] != 3: ag[2][lr] = ag[2][lr]-1 g[w][2][lr] = g[w][2][lr]+1 if ag[2][lr] == sm: if instsl != 0: sco = sco+"i"+str(insts[t[lr]%instsl]) sco = sco+" "+"%12.6f"%(strt+f/44100) sco = sco+" "+"%12.6f"%(0.1+t[(lr+1)%2]%3.21) sco = sco+" "+"%12.6f"%(321.0+t[lr]%7654.321) sco = sco+" "+str(nns[t[(lr+1)%2]%nnsl]) sco = sco+"\n" ag[1] = 1 if g[w][1] < 10: g[w][1] = g[w][1]+10 else: g[w][1] = g[w][1]-10 h = (f+t[0]+t[1])%fltr if h == 12 or h == 212 or h == 1212: w = (f+t[0])%gl print(w,"will reincarnate") g[w][0].reincarnate(f) if instsl != 0: sco = sco+"i"+str(insts[(t[0]+t[1])%instsl]) sco = sco+" "+"%12.6f"%(strt+f/44100) sco = sco+" "+"%12.6f"%(0.1+t[0]%3.21) sco = sco+" "+"%12.6f"%(321.0+t[1]%7654.321) sco = sco+" "+str(nns[(t[0]-t[1])%nnsl]) sco = sco+"\n" if g[w][1] < 10: g[w][1] = g[w][1]+10 else: g[w][1] = g[w][1]-10 if g[w][1] == 1: g[w][1] = f%4 elif h == 13 or h == 313 or h == 1313: w = t[0]%gl m = t[1]%gl print( m,"fucks",w) g[m][0].fuck(g[w][0]) if instsl != 0: sco = sco+"i"+str(insts[(t[1]-t[0])%instsl]) sco = sco+" "+"%12.6f"%(strt+f/44100) sco = sco+" "+"%12.6f"%(0.1+t[1]%3.21) sco = sco+" "+"%12.6f"%(321.0+t[0]%7654.321) sco = sco+" "+str(nns[(t[0]+t[1])%nnsl]) sco = sco+"\n" g[w][1] = (f+t[1])%4 g[m][1] = (f+t[0])%4 if f % 44100 == 0: print( f,"/",s[1]) print("[",t[0],t[1],"]") for ag in g: print(ag[2]) l.append(t[0]) l.append(t[1]) if ml < s[2]: ml = ml+1 return [l,sco] # sw = 0=muteboth 1=queenonly 2=both 3=csonly [previous,current] def q_m(q,cs,t,hmf,strt): place = [0.0,strt] sw = [2,2] p = 0 cs.livein(place) l = [] sco = "" fltr = 5335 # phat = int(0.5*q.tits[1]) phat = int(q.tits[1]) ml = phat for f in range(hmf): if p > 300000: h = (f+t[0]+t[1])%fltr if h == 11 or h == 212: q.reincarnate(f+t[0]) sw[0] = sw[1] sw[1] = (f+int(place[1])+3*t[1])%5 place[0] = place[1] place[1] = strt+f/44100 p = 0 print(sw) print(place) if sw[0] == 2 or sw[0] == 3: cs.livein(place) for c in range(3+t[0]%17): if c % 2 == 0: cs.breathe_in(210000012-(c+3)*t[0]) else: cs.breathe_out(21000012-(c+7)*t[1]) sco = sco+cs.sing() if sw[1] == 0 or sw[1] == 3: for lr in range(2): l.append(t[lr]) else: s = q.sing() ml = phat for lr in range(2): if s[lr] > 0: d = 65535-t[lr] else: d = t[lr] if d < ml: ml = d t[lr] = t[lr]+int(ml*s[lr]) l.append(t[lr]) # if ml < phat: # ml = ml+1 p = p+1 return [l,sco] #src = [f2l("cymbals01.wav"),f2l("fu.pa.wav")] src = [f2l("202105sing2kora.wav"),f2l("fu.pa.wav")] cs = micro.Sa() #hz = 27.5 * 2 ** (5.0/12.0) overtones = [[1,1],[5,4],[3,2],[13,8],[15,8]] cs.change_mind(overtones) sco = "" arb = "" #queen = gal.She() # [fartnuc, 0=free,1=fix,2=-,3=+,[L,R]] # smaller the bigger guys = [ [guy.Sa(),1,[100,100]], [guy.Ri(),2,[500,500]], [guy.Ga(),0,[300,300]], [guy.Ma(),2,[150,150]], [guy.Pa(),3,[150,150]], [guy.Da(),0,[300,300]], [guy.Ni(),3,[500,500]] ] strt = 0.0 tmp = s_g_a(src[0],guys,[32768,32768],[730,731,732,737,750,751,752,757],[36,38,40,43,45,48],strt) muzik = tmp[0] arb = arb+tmp[1] #strt = strt+src[0][1]/44100 # #tmp = q_m(queen,cs,[muzik[-2],muzik[-1]],44100*120,strt) #muzik.extend(tmp[0]) #sco = sco+tmp[1] #strt = strt+120.0 # ##slnc(muzik,44100*3) ##strt = strt+3.0 # #tmp = s_g_a(src[1],guys,[muzik[-2],muzik[-1]],[1,2,3,4,5,6,7,10,11,12,13,14,15,16],[12,16,19,21,24],strt) #muzik.extend(tmp[0]) #arb = arb+tmp[1] arb = arb+"e"+"\n" sco = sco+"e"+"\n" f = open("micro.sco","w") f.writelines(sco) f.close() f = open("arbitrary.sco","w") f.writelines(arb) f.close() for f in range(len(muzik)): muzik[f] = muzik[f]-32768 for i in range(1000): f = 2*i muzik[f] = int(muzik[f]*i/1000) muzik[f+1] = int(muzik[f+1]*i/1000) f = -2*i-2 muzik[f] = int(muzik[f]*i/1000) muzik[f+1] = int(muzik[f+1]*i/1000) thang = l2h(muzik) a_thang = wave.open("episode.wav", "w") a_thang.setnchannels(2) a_thang.setsampwidth(2) a_thang.setframerate(44100) a_thang.writeframes(thang.tostring()) a_thang.close() print("done") #for line in lines: # sco = sco + will_it_exist(line, universe) #sco = sco + "e" + "\n" # #print "dumping plutonium" #pickle.dump(nuc[0][0],open("plutonium","w"))