当前位置: 首页>>代码示例>>Python>>正文


Python MIDIFile.close方法代码示例

本文整理汇总了Python中midiutil.MidiFile.MIDIFile.close方法的典型用法代码示例。如果您正苦于以下问题:Python MIDIFile.close方法的具体用法?Python MIDIFile.close怎么用?Python MIDIFile.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在midiutil.MidiFile.MIDIFile的用法示例。


在下文中一共展示了MIDIFile.close方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testSysEx

# 需要导入模块: from midiutil.MidiFile import MIDIFile [as 别名]
# 或者: from midiutil.MidiFile.MIDIFile import close [as 别名]
 def testSysEx(self):
     MyMIDI = MIDIFile(1)
     MyMIDI.addSysEx(0, 0, 0, struct.pack(">B", 0x01))
     MyMIDI.close()
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, "SysEx")
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[0])[0], 0x00)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[1])[0], 0xF0)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[2])[0], 3)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[3])[0], 0x00)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[4])[0], 0x01)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[5])[0], 0xF7)
开发者ID:felipebetancur,项目名称:sonify-1,代码行数:13,代码来源:miditest.py

示例2: testDeinterleaveNotes

# 需要导入模块: from midiutil.MidiFile import MIDIFile [as 别名]
# 或者: from midiutil.MidiFile.MIDIFile import close [as 别名]
 def testDeinterleaveNotes(self):
     MyMIDI = MIDIFile(1)
     MyMIDI.addNote(0, 0, 100, 0, 2, 100)
     MyMIDI.addNote(0, 0, 100, 1, 2, 100)
     MyMIDI.close()
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, "NoteOn")
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].time, 0)
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].type, "NoteOff")
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].time, 128)
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[2].type, "NoteOn")
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[2].time, 0)
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[3].type, "NoteOff")
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[3].time, 256)
开发者ID:felipebetancur,项目名称:sonify-1,代码行数:15,代码来源:miditest.py

示例3: testUniversalSysEx

# 需要导入模块: from midiutil.MidiFile import MIDIFile [as 别名]
# 或者: from midiutil.MidiFile.MIDIFile import close [as 别名]
 def testUniversalSysEx(self):
     MyMIDI = MIDIFile(1)
     MyMIDI.addUniversalSysEx(0, 0, 1, 2, struct.pack(">B", 0x01))
     MyMIDI.close()
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, "UniversalSysEx")
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[0])[0], 0x00)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[1])[0], 0xF0)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[2])[0], 6)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[3])[0], 0x7E)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[4])[0], 0x7F)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[5])[0], 0x01)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[6])[0], 0x02)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[7])[0], 0x01)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[8])[0], 0xF7)
开发者ID:felipebetancur,项目名称:sonify-1,代码行数:16,代码来源:miditest.py

示例4: testTimeShift

# 需要导入模块: from midiutil.MidiFile import MIDIFile [as 别名]
# 或者: from midiutil.MidiFile.MIDIFile import close [as 别名]
    def testTimeShift(self):

        # With one track
        MyMIDI = MIDIFile(1)
        MyMIDI.addNote(0, 0, 100, 5, 1, 100)
        MyMIDI.close()
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, "NoteOn")
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].time, 0)
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].type, "NoteOff")
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].time, 128)

        # With two tracks
        MyMIDI = MIDIFile(2)
        MyMIDI.addNote(0, 0, 100, 5, 1, 100)
        MyMIDI.addNote(1, 0, 100, 6, 1, 100)
        MyMIDI.close()
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, "NoteOn")
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].time, 0)
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].type, "NoteOff")
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].time, 128)
        self.assertEquals(MyMIDI.tracks[1].MIDIEventList[0].type, "NoteOn")
        self.assertEquals(MyMIDI.tracks[1].MIDIEventList[0].time, 128)
        self.assertEquals(MyMIDI.tracks[1].MIDIEventList[1].type, "NoteOff")
        self.assertEquals(MyMIDI.tracks[1].MIDIEventList[1].time, 128)

        # Negative Time
        MyMIDI = MIDIFile(1)
        MyMIDI.addNote(0, 0, 100, -5, 1, 100)
        MyMIDI.close()
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, "NoteOn")
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].time, 0)
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].type, "NoteOff")
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].time, 128)

        # Negative time, two tracks

        MyMIDI = MIDIFile(2)
        MyMIDI.addNote(0, 0, 100, -1, 1, 100)
        MyMIDI.addNote(1, 0, 100, 0, 1, 100)
        MyMIDI.close()
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, "NoteOn")
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].time, 0)
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].type, "NoteOff")
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].time, 128)
        self.assertEquals(MyMIDI.tracks[1].MIDIEventList[0].type, "NoteOn")
        self.assertEquals(MyMIDI.tracks[1].MIDIEventList[0].time, 128)
        self.assertEquals(MyMIDI.tracks[1].MIDIEventList[1].type, "NoteOff")
        self.assertEquals(MyMIDI.tracks[1].MIDIEventList[1].time, 128)
开发者ID:felipebetancur,项目名称:sonify-1,代码行数:50,代码来源:miditest.py

示例5: testTuning

# 需要导入模块: from midiutil.MidiFile import MIDIFile [as 别名]
# 或者: from midiutil.MidiFile.MIDIFile import close [as 别名]
 def testTuning(self):
     MyMIDI = MIDIFile(1)
     MyMIDI.changeNoteTuning(0, [(1, 440), (2, 880)])
     MyMIDI.close()
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, "UniversalSysEx")
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[0])[0], 0x00)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[1])[0], 0xF0)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[2])[0], 15)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[3])[0], 0x7E)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[4])[0], 0x7F)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[5])[0], 0x08)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[6])[0], 0x02)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[7])[0], 0x00)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[8])[0], 0x2)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[9])[0], 0x1)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[10])[0], 69)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[11])[0], 0)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[12])[0], 0)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[13])[0], 0x2)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[14])[0], 81)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[15])[0], 0)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[16])[0], 0)
     self.assertEquals(struct.unpack(">B", MyMIDI.tracks[0].MIDIdata[17])[0], 0xF7)
开发者ID:felipebetancur,项目名称:sonify-1,代码行数:25,代码来源:miditest.py

示例6: MidiManager

# 需要导入模块: from midiutil.MidiFile import MIDIFile [as 别名]
# 或者: from midiutil.MidiFile.MIDIFile import close [as 别名]
class MidiManager(object):
    MidiPortName = "MIDIphon"

    def __init__(self, midiPhonConfig):
        super(MidiManager, self).__init__()

        self.midiPhonConfig = midiPhonConfig
        self.midiChannels = {}
        self.oldPlayers = {}
        self.availableChannels = range(1, self.midiPhonConfig.NumMidiChannels + 1)
        self.mout = rtmidi.RtMidiOut()
        # self.min = rtmidi.RtMidiIn()
        # self.min.openVirtualPort(MidiManager.MidiPortName)
        # self.mout.openVirtualPort(MidiManager.MidiPortName)
        self.midiPort = -1
        for i in xrange(0, self.mout.getPortCount()):
            name = self.mout.getPortName(i)
            print ("Port {0} is named {1}".format(i, name))
            if name == ("IAC Driver " + MidiManager.MidiPortName):
                self.midiPort = i
                break

        if self.midiPort == -1:
            raise Exception("You need to have a virtual midi port named 'MIDIphon'")

        self.mout.openPort(self.midiPort)
        self.startedPlaying = False
        self.initialTime = time.clock()
        # for i in range(0, self.mout.getPortCount()):
        #     if self.mout.getPortName(i) == MidiManager.MidiPortName:
        #         self.midiPort = i
        #         break

        # if self.midiPort == -1:
        #     raise Exception('Epic failure of finding midi channel I just opened.')

        self.twilio_client = TwilioRestClient(
            account=self.midiPhonConfig.TwilioAppSid, token=self.midiPhonConfig.TwilioApiToken
        )

    def releaseMidi(self):
        self.mout.closePort()

    def uploadMidiFile(self, filename):
        print "Uploading midi file"
        ftp = ftplib.FTP("midiphon.bartnett.com", "midiphon_uploader", "grantophone")
        mf = open(filename)
        ftp.storbinary("STOR midiphon.bartnett.com/" + filename, mf)
        mf.close()
        print "Done storing midi file"

        if self.midiPhonConfig.BitlyApiToken:
            link = self.getBitlyLink("http://midiphon.bartnett.com/" + str(filename))
            print "GOT LINK: " + link
            self.sendBitlyLink(link)
            print "SMS Sent!"
        else:
            print "Not Bit.ly api token specified, not sending out the link to midi file."

    def getBitlyLink(self, url):
        print "Opening bitly connection"
        connect = Connection("midiphon", self.midiPhonConfig.BitlyApiToken)
        print "Shortening URL"
        short = connect.shorten(url)
        print "Done shortening URL"
        return short["url"]

    def sendBitlyLink(self, link):
        for p in self.oldPlayers:
            self.twilio_client.sms.messages.create(
                to=p, from_="13866434928", body=("Listen to your performance at " + link)
            )

        self.oldPlayers.clear()
        self.startedPlaying = False

    def setNumMidiChannels(numChannels):
        if not self.startedPlaying:
            if numChannels <= 16:
                self.availableChannels = range(1, numChannels + 1)
            else:
                print "Error: limit is 16 channels"
                return False
        else:
            print "Error, can't change number of midi channels in the middle of a session."

    def addPlayer(self, phone):
        if not self.startedPlaying:
            self.startedPlaying = True
            self.midiFile = MIDIFile(self.midiPhonConfig.NumMidiChannels)
            for i in range(0, self.midiPhonConfig.NumMidiChannels):
                self.midiFile.addTrackName(i, 0, str(i))
                self.midiFile.addTempo(i, 0, 60)

        if self.midiChannels.has_key(phone):
            return True

        channelCount = len(self.availableChannels)
        if channelCount > 0:
            self.midiChannels[phone] = PhoneMusician(
#.........这里部分代码省略.........
开发者ID:michaelbartnett,项目名称:mididial,代码行数:103,代码来源:mididial_midi.py


注:本文中的midiutil.MidiFile.MIDIFile.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。