X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=python%2Fmidi.c;h=be06bb66cea0f892ba5ae79d9eb2ae5a7fd06ebb;hb=d2770b58472cb8876072afac36378ac43348e8fc;hp=8ccbaf975857160f10bde37b2cfc2c56f3469a1e;hpb=6d37e68b8d93284b8ce8a17975fe3ac482a02f2d;p=lilypond.git diff --git a/python/midi.c b/python/midi.c index 8ccbaf9758..be06bb66ce 100644 --- a/python/midi.c +++ b/python/midi.c @@ -1,11 +1,22 @@ /* - midi.c -- implement Python midi parser module + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter - - (c) 2001--2006 Han-Wen Nienhuys + Copyright (C) 2001--2010 Han-Wen Nienhuys Jan Nieuwenhuizen + + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ /* @@ -19,7 +30,7 @@ midi.parse (s) returns a MIDI file as the tuple - (format, division, TRACKLIST) + ((format, division), TRACKLIST) each track is an EVENTLIST, where EVENT is @@ -75,47 +86,47 @@ typedef struct message { } message_t; message_t channelVoiceMessages[] = { - 0x80, "NOTE_OFF", - 0x90, "NOTE_ON", - 0xA0, "POLYPHONIC_KEY_PRESSURE", - 0xB0, "CONTROLLER_CHANGE", - 0xC0, "PROGRAM_CHANGE", - 0xD0, "CHANNEL_KEY_PRESSURE", - 0xE0, "PITCH_BEND", - 0,0 + {0x80, "NOTE_OFF"}, + {0x90, "NOTE_ON"}, + {0xA0, "POLYPHONIC_KEY_PRESSURE"}, + {0xB0, "CONTROLLER_CHANGE"}, + {0xC0, "PROGRAM_CHANGE"}, + {0xD0, "CHANNEL_KEY_PRESSURE"}, + {0xE0, "PITCH_BEND"}, + {0,0} }; message_t channelModeMessages[] = { - 0x78, "ALL_SOUND_OFF", - 0x79, "RESET_ALL_CONTROLLERS", - 0x7A, "LOCAL_CONTROL", - 0x7B, "ALL_NOTES_OFF", - 0x7C, "OMNI_MODE_OFF", - 0x7D, "OMNI_MODE_ON", - 0x7E, "MONO_MODE_ON", - 0x7F, "POLY_MODE_ON", - 0,0 + {0x78, "ALL_SOUND_OFF"}, + {0x79, "RESET_ALL_CONTROLLERS"}, + {0x7A, "LOCAL_CONTROL"}, + {0x7B, "ALL_NOTES_OFF"}, + {0x7C, "OMNI_MODE_OFF"}, + {0x7D, "OMNI_MODE_ON"}, + {0x7E, "MONO_MODE_ON"}, + {0x7F, "POLY_MODE_ON"}, + {0,0} }; message_t metaEvents[] = { - 0x00, "SEQUENCE_NUMBER", - 0x01, "TEXT_EVENT", - 0x02, "COPYRIGHT_NOTICE", - 0x03, "SEQUENCE_TRACK_NAME", - 0x04, "INSTRUMENT_NAME", - 0x05, "LYRIC", - 0x06, "MARKER", - 0x07, "CUE_POINT", - 0x20, "MIDI_CHANNEL_PREFIX", - 0x21, "MIDI_PORT", - 0x2F, "END_OF_TRACK", - 0x51, "SET_TEMPO", - 0x54, "SMTPE_OFFSET", - 0x58, "TIME_SIGNATURE", - 0x59, "KEY_SIGNATURE", - 0x7F, "SEQUENCER_SPECIFIC_META_EVENT", - 0xFF, "META_EVENT", - 0,0 + {0x00, "SEQUENCE_NUMBER"}, + {0x01, "TEXT_EVENT"}, + {0x02, "COPYRIGHT_NOTICE"}, + {0x03, "SEQUENCE_TRACK_NAME"}, + {0x04, "INSTRUMENT_NAME"}, + {0x05, "LYRIC"}, + {0x06, "MARKER"}, + {0x07, "CUE_POINT"}, + {0x20, "MIDI_CHANNEL_PREFIX"}, + {0x21, "MIDI_PORT"}, + {0x2F, "END_OF_TRACK"}, + {0x51, "SET_TEMPO"}, + {0x54, "SMTPE_OFFSET"}, + {0x58, "TIME_SIGNATURE"}, + {0x59, "KEY_SIGNATURE"}, + {0x7F, "SEQUENCER_SPECIFIC_META_EVENT"}, + {0xFF, "META_EVENT"}, + {0,0} }; void @@ -148,7 +159,7 @@ unsigned long int get_variable_length_number (unsigned char **str, unsigned char * end_str) { long sum = 0; - int i = 0; + while (*str < end_str) { unsigned char x = **str; @@ -273,7 +284,6 @@ static PyObject * midi_parse_track (unsigned char **track, unsigned char *track_end) { unsigned int time = 0; - unsigned char running_status; unsigned long track_len, track_size; PyObject *pytrack = 0; @@ -305,6 +315,8 @@ midi_parse_track (unsigned char **track, unsigned char *track_end) { PyObject *pytime = PyInt_FromLong (0L); + unsigned char running_status = 0; + while (*track < track_end) { long dt = get_variable_length_number(track, track_end); @@ -330,9 +342,7 @@ static PyObject * pymidi_parse_track (PyObject *self, PyObject *args) { unsigned char *track, *track_end; - unsigned long track_size, track_len; - - PyObject * sobj = PyTuple_GetItem (args, 0); + unsigned long track_size; debug_print ("%s", "\n"); if (!PyArg_ParseTuple (args, "s#", &track, &track_size)) @@ -373,7 +383,7 @@ midi_parse (unsigned char **midi,unsigned char *midi_end) if (division < 0) - /* return midi_error ("can't handle non-metrical time"); */ + /* return midi_error (cannot handle non-metrical time"); */ ; *midi += header_len - 6; @@ -392,10 +402,8 @@ static PyObject * pymidi_parse (PyObject *self, PyObject *args) { unsigned char *midi, *midi_end; - unsigned long midi_size, midi_len; + unsigned long midi_size; - PyObject *sobj = PyTuple_GetItem (args, 0); - debug_print ("%s", "\n"); if (!PyArg_ParseTuple (args, "s#", &midi, &midi_size)) return 0; @@ -430,5 +438,10 @@ initmidi (void) add_constants (d); Midi_warning = PyString_FromString ("midi.warning"); PyDict_SetItemString (d, "warning", Midi_warning); + + /* + FIXME. + */ + (void) midi_warning; }