Example #1
0
def midiwrite(filename, piano_roll, r=(21, 109), dt=0.2, patch=0):
  midi = MidiOutFile(filename)
  midi.header(division=100)
  midi.start_of_track()
  midi.patch_change(channel=0, patch=patch)
  t = 0
  samples = [i.nonzero()[0] + r[0] for i in piano_roll]

  for i in xrange(len(samples)):
    for f in samples[i]:
      if i==0 or f not in samples[i-1]:
        midi.update_time(t)
        midi.note_on(channel=0, note=f, velocity=90)
        t = 0

    t += int(dt*200)

    for f in samples[i]:
      if i==len(samples)-1 or f not in samples[i+1]:
        midi.update_time(t)
        midi.note_off(channel=0, note=f, velocity=0)
        t = 0

  midi.update_time(0)
  midi.end_of_track()
  midi.eof()
Example #2
0
        if channel == 0:
            print channel, note, velocity, self.abs_time(), self.currTime
            self.notes[note] = self.currTime * 1.0

    def note_off(self, channel=0, note=0, velocity=0):
        if channel == 0:
            print "Off with note ", note, " with duration ", self.currTime - self.notes[
                note]
            self.notes[note] = 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)
Example #3
0
 def createFile(self, filename):
     self.file = MidiOutFile(filename)
     self.file.header()
     self.file.start_of_track()