-# -*- coding: ISO-8859-1 -*-\r
-\r
-class MidiOutStream:\r
-\r
-\r
- """\r
-\r
- MidiOutstream is Basically an eventhandler. It is the most central\r
- class in the Midi library. You use it both for writing events to\r
- an output stream, and as an event handler for an input stream.\r
-\r
- This makes it extremely easy to take input from one stream and\r
- send it to another. Ie. if you want to read a Midi file, do some\r
- processing, and send it to a midiport.\r
-\r
- All time values are in absolute values from the opening of a\r
- stream. To calculate time values, please use the MidiTime and\r
- MidiDeltaTime classes.\r
-\r
- """\r
-\r
- def __init__(self):\r
- \r
- # the time is rather global, so it needs to be stored \r
- # here. Otherwise there would be no really simple way to \r
- # calculate it. The alternative would be to have each event \r
- # handler do it. That sucks even worse!\r
- self._absolute_time = 0\r
- self._relative_time = 0\r
- self._current_track = 0\r
- self._running_status = None\r
-\r
- # time handling event handlers. They should be overwritten with care\r
-\r
- def update_time(self, new_time=0, relative=1):\r
- """\r
- Updates the time, if relative is true, new_time is relative, \r
- else it's absolute.\r
- """\r
- if relative:\r
- self._relative_time = new_time\r
- self._absolute_time += new_time\r
- else:\r
- self._relative_time = new_time - self._absolute_time\r
- self._absolute_time = new_time\r
-\r
- def reset_time(self):\r
- """\r
- reset time to 0\r
- """\r
- self._relative_time = 0\r
- self._absolute_time = 0\r
- \r
- def rel_time(self):\r
- "Returns the relative time"\r
- return self._relative_time\r
-\r
- def abs_time(self):\r
- "Returns the absolute time"\r
- return self._absolute_time\r
-\r
- # running status methods\r
- \r
- def reset_run_stat(self):\r
- "Invalidates the running status"\r
- self._running_status = None\r
-\r
- def set_run_stat(self, new_status):\r
- "Set the new running status"\r
- self._running_status = new_status\r
-\r
- def get_run_stat(self):\r
- "Set the new running status"\r
- return self._running_status\r
-\r
- # track handling event handlers\r
- \r
- def set_current_track(self, new_track):\r
- "Sets the current track number"\r
- self._current_track = new_track\r
- \r
- def get_current_track(self):\r
- "Returns the current track number"\r
- return self._current_track\r
- \r
- \r
- #####################\r
- ## Midi events\r
-\r
-\r
- def channel_message(self, message_type, channel, data):\r
- """The default event handler for channel messages"""\r
- pass\r
-\r
-\r
- def note_on(self, channel=0, note=0x40, velocity=0x40):\r
-\r
- """\r
- channel: 0-15\r
- note, velocity: 0-127\r
- """\r
- pass\r
-\r
-\r
- def note_off(self, channel=0, note=0x40, velocity=0x40):\r
-\r
- """\r
- channel: 0-15\r
- note, velocity: 0-127\r
- """\r
- pass\r
-\r
-\r
- def aftertouch(self, channel=0, note=0x40, velocity=0x40):\r
-\r
- """\r
- channel: 0-15\r
- note, velocity: 0-127\r
- """\r
- pass\r
-\r
-\r
- def continuous_controller(self, channel, controller, value):\r
-\r
- """\r
- channel: 0-15\r
- controller, value: 0-127\r
- """\r
- pass\r
-\r
-\r
- def patch_change(self, channel, patch):\r
-\r
- """\r
- channel: 0-15\r
- patch: 0-127\r
- """\r
- pass\r
-\r
-\r
- def channel_pressure(self, channel, pressure):\r
-\r
- """\r
- channel: 0-15\r
- pressure: 0-127\r
- """\r
- pass\r
-\r
-\r
- def pitch_bend(self, channel, value):\r
-\r
- """\r
- channel: 0-15\r
- value: 0-16383\r
-\r
- """\r
- pass\r
-\r
-\r
-\r
-\r
- #####################\r
- ## System Exclusive\r
-\r
- def system_exclusive(self, data):\r
-\r
- """\r
- data: list of values in range(128)\r
- """\r
- pass\r
-\r
-\r
- #####################\r
- ## Common events\r
-\r
- def song_position_pointer(self, value):\r
-\r
- """\r
- value: 0-16383\r
- """\r
- pass\r
-\r
-\r
- def song_select(self, songNumber):\r
-\r
- """\r
- songNumber: 0-127\r
- """\r
- pass\r
-\r
-\r
- def tuning_request(self):\r
-\r
- """\r
- No values passed\r
- """\r
- pass\r
-\r
- \r
- def midi_time_code(self, msg_type, values):\r
- """\r
- msg_type: 0-7\r
- values: 0-15\r
- """\r
- pass\r
-\r
-\r
- #########################\r
- # header does not really belong here. But anyhoo!!!\r
- \r
- def header(self, format=0, nTracks=1, division=96):\r
-\r
- """\r
- format: type of midi file in [1,2]\r
- nTracks: number of tracks\r
- division: timing division\r
- """\r
- pass\r
-\r
-\r
- def eof(self):\r
-\r
- """\r
- End of file. No more events to be processed.\r
- """\r
- pass\r
-\r
-\r
- #####################\r
- ## meta events\r
-\r
-\r
- def meta_event(self, meta_type, data):\r
- \r
- """\r
- Handles any undefined meta events\r
- """\r
- pass\r
-\r
-\r
- def start_of_track(self, n_track=0):\r
-\r
- """\r
- n_track: number of track\r
- """\r
- pass\r
-\r
-\r
- def end_of_track(self):\r
-\r
- """\r
- n_track: number of track\r
- """\r
- pass\r
-\r
-\r
- def sequence_number(self, value):\r
-\r
- """\r
- value: 0-16383\r
- """\r
- pass\r
-\r
-\r
- def text(self, text):\r
-\r
- """\r
- Text event\r
- text: string\r
- """\r
- pass\r
-\r
-\r
- def copyright(self, text):\r
-\r
- """\r
- Copyright notice\r
- text: string\r
- """\r
- pass\r
-\r
-\r
- def sequence_name(self, text):\r
-\r
- """\r
- Sequence/track name\r
- text: string\r
- """\r
- pass\r
-\r
-\r
- def instrument_name(self, text):\r
-\r
- """\r
- text: string\r
- """\r
- pass\r
-\r
-\r
- def lyric(self, text):\r
-\r
- """\r
- text: string\r
- """\r
- pass\r
-\r
-\r
- def marker(self, text):\r
-\r
- """\r
- text: string\r
- """\r
- pass\r
-\r
-\r
- def cuepoint(self, text):\r
-\r
- """\r
- text: string\r
- """\r
- pass\r
-\r
-\r
- def midi_ch_prefix(self, channel):\r
-\r
- """\r
- channel: midi channel for subsequent data (deprecated in the spec)\r
- """\r
- pass\r
-\r
-\r
- def midi_port(self, value):\r
-\r
- """\r
- value: Midi port (deprecated in the spec)\r
- """\r
- pass\r
-\r
-\r
- def tempo(self, value):\r
-\r
- """\r
- value: 0-2097151\r
- tempo in us/quarternote\r
- (to calculate value from bpm: int(60,000,000.00 / BPM))\r
- """\r
- pass\r
-\r
-\r
- def smtp_offset(self, hour, minute, second, frame, framePart):\r
-\r
- """\r
- hour,\r
- minute,\r
- second: 3 bytes specifying the hour (0-23), minutes (0-59) and \r
- seconds (0-59), respectively. The hour should be \r
- encoded with the SMPTE format, just as it is in MIDI \r
- Time Code.\r
- frame: A byte specifying the number of frames per second (one \r
- of : 24, 25, 29, 30).\r
- framePart: A byte specifying the number of fractional frames, \r
- in 100ths of a frame (even in SMPTE-based tracks \r
- using a different frame subdivision, defined in the \r
- MThd chunk).\r
- """\r
- pass\r
-\r
-\r
-\r
- def time_signature(self, nn, dd, cc, bb):\r
-\r
- """\r
- nn: Numerator of the signature as notated on sheet music\r
- dd: Denominator of the signature as notated on sheet music\r
- The denominator is a negative power of 2: 2 = quarter \r
- note, 3 = eighth, etc.\r
- cc: The number of MIDI clocks in a metronome click\r
- bb: The number of notated 32nd notes in a MIDI quarter note \r
- (24 MIDI clocks) \r
- """\r
- pass\r
-\r
-\r
-\r
- def key_signature(self, sf, mi):\r
-\r
- """\r
- sf: is a byte specifying the number of flats (-ve) or sharps \r
- (+ve) that identifies the key signature (-7 = 7 flats, -1 \r
- = 1 flat, 0 = key of C, 1 = 1 sharp, etc).\r
- mi: is a byte specifying a major (0) or minor (1) key.\r
- """\r
- pass\r
-\r
-\r
-\r
- def sequencer_specific(self, data):\r
-\r
- """\r
- data: The data as byte values\r
- """\r
- pass\r
-\r
-\r
-\r
-\r
- #####################\r
- ## realtime events\r
-\r
- def timing_clock(self):\r
-\r
- """\r
- No values passed\r
- """\r
- pass\r
-\r
-\r
-\r
- def song_start(self):\r
-\r
- """\r
- No values passed\r
- """\r
- pass\r
-\r
-\r
-\r
- def song_stop(self):\r
-\r
- """\r
- No values passed\r
- """\r
- pass\r
-\r
-\r
-\r
- def song_continue(self):\r
-\r
- """\r
- No values passed\r
- """\r
- pass\r
-\r
-\r
-\r
- def active_sensing(self):\r
-\r
- """\r
- No values passed\r
- """\r
- pass\r
-\r
-\r
-\r
- def system_reset(self):\r
-\r
- """\r
- No values passed\r
- """\r
- pass\r
-\r
-\r
-\r
-if __name__ == '__main__':\r
-\r
- midiOut = MidiOutStream()\r
- midiOut.update_time(0,0)\r
- midiOut.note_on(0, 63, 127)\r
- midiOut.note_off(0, 63, 127)\r
-\r
-
\ No newline at end of file