示例#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()
示例#2
0
def midiwrite(filename, piano_roll, r=(21, 109), dt=32, patch=0):
  midi = MidiOutFile(filename)
  midi.header(division=128)
  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]
          or i%4 == 0):
        midi.update_time(t)
        midi.note_on(channel=0, note=f, velocity=90)
        t = 0
    
    t += int(dt)

    for f in samples[i]:
      if (i==len(samples)-1 
          or f not in samples[i+1]
          or i%4 == 3):
        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()
all the midi events are in the same track.
"""

out_file = '../minimal_type0.mid'
midi = MidiOutFile(out_file)

# non optional midi framework
midi.header(format=1)
midi.start_of_track() 


# musical events

import ipdb;ipdb.set_trace()
midi.update_time(10)
midi.note_on(channel=0, note=0x40)
midi.update_time(0)
midi.note_on(channel=0, note=0x41)
midi.update_time(192)
midi.note_off(channel=0, note=0x40)

midi.update_time(0)
midi.note_off(channel=0, note=0x41)
midi.update_time(0)
midi.note_off(channel=0, note=0x42)
midi.update_time(0)
midi.note_off(channel=0, note=0x43)
midi.update_time(0)
midi.note_off(channel=0, note=0x44)
midi.update_time(0)
midi.note_off(channel=0, note=0x45)
 def note_on(self, channel=0, note=0x40, velocity=0x40):
     note = self._transp(channel, note)
     MidiOutFile.note_on(self, channel, note, velocity)
示例#5
0
            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)

# 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()
示例#6
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)
 def note_on(self, channel=0, note=0x40, velocity=0x40):
     note = self._transp(channel, note)
     MidiOutFile.note_on(self, channel, note, velocity)
from MidiOutFile import MidiOutFile

"""
This is an example of the smallest possible type 0 midi file, where 
all the midi events are in the same track.
"""

out_file = 'midiout/minimal_type0.mid'
midi = MidiOutFile(out_file)

# non optional midi framework
midi.header()
midi.start_of_track() 


# musical events

midi.update_time(0)
midi.note_on(channel=0, note=0x40)

midi.update_time(192)
midi.note_off(channel=0, note=0x40)


# non optional midi framework
midi.update_time(0)
midi.end_of_track()

midi.eof()
示例#9
0
"""
This is an example of the smallest possible type 0 midi file, where 
all the midi events are in the same track.
"""

out_file = '../prueba.mid'
ntracks= 3
midi = MidiOutFile(out_file)

# non optional midi framework
midi.header(format= 1, nTracks=ntracks)


# musical events
#import ipdb;ipdb.set_trace()
for i in xrange(0,ntracks):
    midi.start_of_track(i) 
    #midi.continuous_controller(i,RESET_ALL_CONTROLLERS,0x01)
    #midi.continuous_controller(i,CHANNEL_VOLUME,0x32)
    midi.update_time(192*i)
    midi.note_on(channel=i, note=0x40)

    midi.update_time(192*(i+1))
    midi.note_off(channel=i, note=0x40)
    #midi.update_time(0)
    midi.end_of_track() 


midi.eof()
示例#10
0
 def note_on(self, channel=0, note=0x40, velocity=0x40):
     #note = self._transp(channel, note)
     note = self.reduct_note(channel, note)
     velocity = self.reduct_velocity(channel, velocity)
     MidiOutFile.note_on(self, channel, note, velocity)