def formMidiList(): # read Midi file and form python list. test_file = '/home/jim/research/python/LaComparsa.mid' midiList = MidiToList() # do parsing midiIn = MidiInFile(midiList, test_file) midiIn.read() return midiList
def formMidiList(): # read Midi file and form python list. test_file = "/home/jim/research/python/LaComparsa.mid" midiList = MidiToList() # do parsing midiIn = MidiInFile(midiList, test_file) midiIn.read() return midiList
def __init__(self, filename, r=(21, 109), dt=0.2): self.notes = [] self._tempo = 500000 self.beat = 0 self.time = 0.0 midi_in = MidiInFile(self, filename) midi_in.read() self.notes = [n for n in self.notes if n[2] is not None] # purge incomplete notes length = int(numpy.ceil(max(zip(*self.notes)[2]) / dt)) # create piano-roll self.piano_roll = numpy.zeros((length, r[1]-r[0])) for n in self.notes: self.piano_roll[int(numpy.ceil(n[1]/dt)) : int(numpy.ceil(n[2]/dt)), n[0]-r[0]] = 1
def midi_port(self, value): print 'midi_port:', value def tempo(self, value): print 'tempo:', value def smtp_offset(self, hour, minute, second, frame, framePart): print 'smtp_offset', hour, minute, second, frame, framePart def time_signature(self, nn, dd, cc, bb): print 'time_signature:', nn, dd, cc, bb def key_signature(self, sf, mi): print 'key_signature', sf, mi def sequencer_specific(self, data): print 'sequencer_specific', len(data) if __name__ == '__main__': # get data test_file = 'test/midifiles/minimal.mid' f = open(test_file, 'rb') # do parsing from MidiInFile import MidiInFile midiIn = MidiInFile(MidiToText(), f) midiIn.read() f.close()
def buildScore(in_file): event_handler = ScoreBuilder() midi_in = MidiInFile(event_handler, in_file) midi_in.read() return event_handler.score
""" This is an example that uses the MidiToText eventhandler. When an event is triggered on it, it prints the event to the console. It gets the events from the MidiInFile. So it prints all the events from the infile to the console. great for debugging :-s """ # get data test_file = 'test/midifiles/minimal-cubase-type0.mid' # do parsing from MidiInFile import MidiInFile from MidiToText import MidiToText # the event handler midiIn = MidiInFile(MidiToText(), test_file) midiIn.read()
try: text = text.decode(self.from_enc).encode(self.to_enc) except UnicodeDecodeError: print >> sys.stderr, "Error decoding", text pass except UnicodeEncodeError: text = text.decode(self.from_enc).encode(self.to_enc, "replace") text = text.replace("?", "_") MidiOutFile.sequence_name(self, text) def sysex_event(self, data): MidiOutFile.system_exclusive(self, data) if __name__ == "__main__": import sys, os.path, glob if len(sys.argv) != 4: print "MIDI song title renamer" print "Usage: %s midi_file from_enc to_enc" % (os.path.basename(sys.argv[0]),) print "Example: %s test.mid cp932 gbk" % (os.path.basename(sys.argv[0]),) print "The output file is midi_file.new. midi_file can have wildcard" sys.exit(0) for fname in glob.glob(unicode(sys.argv[1])): print "Processing", fname midi_out = Transposer(fname + ".new", sys.argv[2], sys.argv[3]) midi_in = MidiInFile(midi_out, fname) midi_in.read()
event_handler = NoteOnPrinter() in_file = 'test.mid' out_file = 'test.mid' midi = MidiOutFile(out_file) # non optional midi framework midi.header(division=96) midi.start_of_track() # musical events midi.tempo(60000000 / 60) midi.update_time(0) midi.note_on(channel=0, note=69) midi.update_time(96) midi.note_on(channel=0, note=73) midi.update_time(96) midi.note_off(channel=0, note=69) midi.update_time(96) midi.note_off(channel=0, note=73) # non optional midi framework midi.update_time(0) midi.end_of_track() # not optional! midi.eof() midi_in = MidiInFile(event_handler, in_file) midi_in.read()