Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
  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
Exemplo n.º 4
0
  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
Exemplo n.º 5
0
    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()
Exemplo n.º 6
0
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()
Exemplo n.º 8
0
        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()
Exemplo n.º 9
0

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()
    
    "Transposes all notes by 1 octave"
    
    def _transp(self, ch, note):
        if ch != 9: # not the drums!
            note += 12
            if note > 127:
                note = 127
        return note


    def note_on(self, channel=0, note=0x40, velocity=0x40):
        note = self._transp(channel, note)
        MidiOutFile.note_on(self, channel, note, velocity)
        
        
    def note_off(self, channel=0, note=0x40, velocity=0x40):
        note = self._transp(channel, note)
        MidiOutFile.note_off(self, channel, note, velocity)


out_file = 'midiout/transposed.mid'
midi_out = Transposer(out_file)

#in_file = 'midiout/minimal_type0.mid'
#in_file = 'test/midifiles/Lola.mid'
in_file = 'test/midifiles/tennessee_waltz.mid'
midi_in = MidiInFile(midi_out, in_file)
midi_in.read()

Exemplo n.º 11
0
"""
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()
Exemplo n.º 12
0
                lineText += segment.text

        print 'Timestamp:' + str(timeStamp) + 'pitch: ' + str(
            goalPitch - 60) + ' LineText: ' + lineText
        sleep(0.1)
        '''

    for segment in song.songSegments:
        print "\tType: " , segment.type , "\tTimeStamp: " , segment.timeStamp , "\tDuration: " , segment.duration , 			"\tPitch: " , segment.pitch , "\ttext: " , segment.text, "\tFrequenz: ", 440 * (2 ** ((segment.pitch-12-69) / 12))

        print "\n\n"

        '''


if __name__ == '__main__':

    # get data
    #test_file = 'test/midifiles/alleMeineEntchen.mid'
    test_file = 'test/midifiles/Bruder Jakob.mid'
    f = open(test_file, 'rb')

    # do parsing
    from MidiInFile import MidiInFile
    x = MidiToText()
    midiIn = MidiInFile(x, f)
    midiIn.read()
    f.close()
    func1(x.song)
    x.song.write_to_txt('test.txt')