资源描述:
《python编写的midi制作软件》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、用Python编写的Mid音频制作软件源代码如下:#Midi.py:#ThisfilecanbeusedtosimplyturnMidiTxtfiletoMidfile.#Author:loupen#Date:2010-7-20#Ifyouwanttouseit,youmustwritetheMidiTxtfilebysomerules.#Readthedocumenttolearnmore.fromstructimport*#ThreeglobalvariablesTrackBegin=[]TrackEnd=[]ToneFore=1#writeth
2、eMidiHeaderdefMidiHeader(buffer):buffer.write(pack('ccccBBBB','M','T','h','d',0,0,0,6))defmsg(buffer,tracks,deltatime):ifdeltatime>0xff:buffer.write(pack('BBBBBB',0,1,0,tracks,deltatime>>8,deltatime&0xff))else:buffer.write(pack('BBBBBB',0,1,0,tracks,0,deltatime))returnbuffer.te
3、ll()-3#writetheheaderandtailoftracksdefTrackHeader(buffer,list):buffer.write(pack('cccc','M','T','r','k'))list.append(buffer.tell())buffer.write(pack('i',0))defTrackTail(buffer,list):buffer.write(pack('BBBB',0,0xff,0x2f,0))list.append(buffer.tell())#Setthepulse,instrumentandcon
4、trollerdefSetSpeed(buffer,time):time=60.0/int(time)time=int(time*(10**6))buffer.write(pack('BBBBBBB',0,0xff,0x51,3,time>>16,(time&0xff00)>>8,time&0xff))return1#Thewords,FenZiandFenMu,arefromChinese.~O~defSetPulse(buffer,FenZi,FenMu):QQ:750825502E-mail:loupen@yeah.netFenZi=int(F
5、enZi)FenMu=int(FenMu)ifFenMu==2:FenMu=1elifFenMu==4:FenMu=2elifFenMu==8:FenMu=3else:return0buffer.write(pack('BBBBBBBB',0,0xff,0x58,4,int(FenZi),int(FenMu),0x18,0x08))return1defSetTone(buffer):buffer.write(pack('BBBBBB',0,0xff,0x59,2,0,0))return1defSetNumOrder(buffer,time):buff
6、er.write(pack('BBBB',time>>24,(time&0xff0000)>>16,(time&0xff00)>>8,time&0xff))defSetTrackNum(buffer,ad,n):buffer.seek(ad)buffer.write(pack('B',n+1))defSetInstrument(buffer,trackNum,ITNum):trackNum=int(trackNum)trackNum+=0xc0buffer.write(pack('BBB',0,trackNum,ITNum))defSetContro
7、ller(buffer,trackNum,CtrNum):trackNum=int(trackNum)trackNum+=0xb0buffer.write(pack('BBBB',0,trackNum,11,CtrNum))buffer.write(pack('BBB',0,0xa,0x40))defSetVolume(buffer,trackNum,S):trackNum=int(trackNum)trackNum+=0xb0ifS=='H':buffer.write(pack('BBBB',0,trackNum,7,0x7f))buffer.wr
8、ite(pack('BBB',0,0xa,0x40))ifS=='L':buffer.write(pack(