コード例 #1
0
ファイル: dancer.py プロジェクト: mapleyustat/research
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
コード例 #2
0
ファイル: dancer.py プロジェクト: jlakowski/research
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
コード例 #3
0
ファイル: utils.py プロジェクト: BibuTahseen/neuralnetmusic
  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
コード例 #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
コード例 #5
0
ファイル: MidiToText.py プロジェクト: mmarx/manganese
    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()
コード例 #6
0
ファイル: readmidi.py プロジェクト: raviolinguini/sixthdev
def buildScore(in_file):
    event_handler = ScoreBuilder()
    midi_in = MidiInFile(event_handler, in_file)
    midi_in.read()
    return event_handler.score
コード例 #7
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()
コード例 #8
0
ファイル: midirecode.py プロジェクト: yindian/myutils
        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()
コード例 #9
0
ファイル: midi_test.py プロジェクト: templeblock/pymir3

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()