def handlePerf(type, value, duration, maxValue, track, tick): event2 = None if type == 0: # volume event1 = midi.ControlChangeEvent(tick=tick) event1.control = 7 # Main Volume #if maxValue > 0x7F: # event1.value = (value>>8)&0xFF # event2 = midi.ControlChangeEvent(tick=0) # event2.control = 39 # Volume LSB # event2.value = value&0xFF #else: # event1.value = value event1.value = (value*0x7F)/maxValue elif type == 1: # pitch event1 = midi.PitchWheelEvent(tick=tick) event1.pitch = (value*0x7FFF)/maxValue elif type == 3: # pan event1 = midi.ControlChangeEvent(tick=tick) event1.control = 10 # Pan #if maxValue > 0x7F: # event1.value = (value>>8)&0xFF # event2 = midi.ControlChangeEvent(tick=0) # event2.control = 42 # Pan LSB # event2.value = value&0xFF #else: # event1.value = value event1.value = (value*0x7F)/maxValue else: warn("Unknown perf type %d"%type) event1 = midi.TextMetaEvent(tick=tick, data=map(ord, "Perf %d (%d)"%(type, value))) track.append(event1) if event2 is not None: track.append(event2) if duration: if type == 0: # volume event = midi.ControlChangeEvent(tick=duration) event.control = 7 # Main Volume event.value = 0x7F elif type == 1: # pitch event = midi.PitchWheelEvent(tick=duration) event.pitch = 0x2000 elif type == 3: # pan event = midi.ControlChangeEvent(tick=duration) event.control = 10 # Pan event.value = 0x40 else: event = midi.TextMetaEvent(tick=duration, data=map(ord, "Perf %d (%d)"%(type, value))) return event
def addtrack(self): absoluteticks = 0 self.notes.append([]) self.channels.append(len(self.notes) + 1) self.instruments.append(None) trackname = MIDI.TextMetaEvent(text="") trackname.absoluteticks = 0 self.texts.append([trackname]) self.numberoftracks += 1
def clear(self): self.resolution = config.EDITresolution trackname = MIDI.TextMetaEvent(text="") trackname.absoluteticks = 0 self.texts = [[trackname]] self.notes = [[]] self.instruments = [config.DEFAULTinstrument] self.channels = [1] self.tempos = [] self.timesignatures = [] self.setdefaults()
def handleBankProgram(which, selection, track, tick): if which == 7: # pitch print "Pitch", selection event = midi.ControlChangeEvent(tick=tick) event.control = 101 # RPN MSB event.value = 0 track.append(event) event = midi.ControlChangeEvent(tick=0) event.control = 100 # RPN LSB event.value = 0 track.append(event) event = midi.ControlChangeEvent(tick=0) event.control = 6 # Data entry MSB event.value = selection track.append(event) event = midi.ControlChangeEvent(tick=0) event.control = 38 # Data entry LSB event.value = 0 track.append(event) elif which == 0x20: # bank print "Bank", selection event = midi.ControlChangeEvent(tick=tick) event.control = 32 # Bank Select event.value = selection track.append(event) elif which == 0x21: # program print "Program", selection event = midi.ProgramChangeEvent(tick=tick, value=selection%128) track.append(event) else: warn("Unknown bank/program %x (%d)"%(which, selection)) event = midi.TextMetaEvent(tick=tick, data=map(ord, "Bank/Program %d (%d)"%(which, selection))) track.append(event)
if pattern is not None: delay = handleSeek(0xC5, mode, point, track, delay, voices) fin.seek(point) elif cmd == 0xC6: # back # cmdRet mode, = unpack('>B', fin.read(1)) point = stack.pop() if pattern is not None: delay = handleSeek(0xC6, mode, point, track, delay, voices) fin.seek(point) elif cmd == 0xC7: warn("Unknown C7, prob jump") mode, point = unpack('>BH', fin.read(3)) if pattern is not None: delay = handleSeek(0xC7, mode, point, track, delay, voices) if 1:#totalTime < endTime: fin.seek(point) #else: track.append(midi.TextMetaEvent(tick=delay, data=map(ord, "Jump to 0x%X"%(point)))) delay = 0 if mode == 0: print "Breaking out of loop" break elif cmd == 0xC8: # seek ex # cmdJmp mode, tmp, point = unpack('>BBH', fin.read(4)) point |= tmp<<16 if pattern is not None: delay = handleSeek(0xC8, mode, point, track, delay, voices) if 1:#totalTime < endTime: fin.seek(point) #else: track.append(midi.TextMetaEvent(tick=delay, data=map(ord, "Jump to 0x%X"%(point)))) delay = 0 if mode == 0:
def test_meta_event_with_text(self): event = midi.TextMetaEvent(text="abc") self.assertListEqual(event.data, [97, 98, 99])