QQ: 750825502 E-mail: loupen@yeah.net
用 Python 编写的 Mid 音频制作软件
源代码如下:
#Midi.py:
#This file can be used to simply turn MidiTxt file to Mid file.
#Author:loupen
#Date:2010-7-20
#If you want to use it, you must write the MidiTxt file by some rules.
#Read the document to learn more.
from struct import *
#Three global variables
TrackBegin=[]
TrackEnd=[]
ToneFore=1
#write the MidiHeader
def MidiHeader(buffer):
buffer.write(pack('ccccBBBB','M','T','h','d',0,0,0,6))
def msg(buffer,tracks,deltatime):
if deltatime>0xff:
buffer.write(pack('BBBBBB',0,1,0,tracks,deltatime>>8,deltatime&0xff))
else:
buffer.write(pack('BBBBBB',0,1,0,tracks,0,deltatime))
return buffer.tell()-3
#write the header and tail of tracks
def TrackHeader(buffer,list):
buffer.write(pack('cccc','M','T','r','k'))
list.append(buffer.tell())
buffer.write(pack('i',0))
def TrackTail(buffer,list):
buffer.write(pack('BBBB',0,0xff,0x2f,0))
list.append(buffer.tell())
#Set the pulse , instrument and controller
def SetSpeed(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))
return 1
#The words , FenZi and FenMu , are from Chinese . ~O~
def SetPulse(buffer,FenZi,FenMu):
评论0
最新资源