Python Midi package 0.1

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Max M

    Python Midi package 0.1

    If anybody is interrested in Midi, but are not on the Python Midi list,
    I will just notify that I have released the first version of a high
    level midi package for Python.

    It is fully functional. It reads and writes midi files! It is *very*
    easy to write your own event handlers to make midi files do whatever you
    want them to.

    It uses the same general ideas as the Sax parser for xml.


    ############### ############### ###########
    # example #1

    """
    This prints all note_on events on midi channel 0. It's a short example
    of creating your own event handler by subclassing the MidiOutStream.
    """

    from MidiOutStream import MidiOutStream
    from MidiInFile import MidiInFile


    class NoteOnPrinter(M idiOutStream):

    "Prints all note_on events on channel 0"

    def note_on(self, channel=0, note=0x40, velocity=0x40):
    if channel == 0:
    print channel, note, velocity, self.rel_time()


    event_handler = NoteOnPrinter()

    in_file = 'midiout/minimal_type0.m id'
    midi_in = MidiInFile(even t_handler, in_file)
    midi_in.read()

    ############### ############### ###########


    ############### ############### ###########
    # example #2

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

    from MidiOutFile import MidiOutFile

    out_file = 'midiout/minimal_type0.m id'
    midi = MidiOutFile(out _file)

    # non optional midi framework
    midi.header()
    midi.start_of_t rack()

    # musical events

    midi.update_tim e(0)
    midi.note_on(ch annel=0, note=0x40)

    midi.update_tim e(192)
    midi.note_off(c hannel=0, note=0x40)

    # midi framework

    midi.update_tim e(0)
    midi.end_of_tra ck() # not optional!

    midi.eof()
    ############### ############### ###########


    It cannot read/write midi ports at this point. So no realtime stuff yet.


    Get it at:



    regards Max M

Working...