source file of the GNU LilyPond music typesetter
- (c) 2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ (c) 2001--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
Jan Nieuwenhuizen <janneke@gnu.org>
*/
/*
-python2
+python
import midi
s = open ("s.midi").read ()
midi.parse_track (s)
midi.parse (s)
+
+returns a MIDI file as the tuple
+
+ (format, division, TRACKLIST)
+
+each track is an EVENTLIST, where EVENT is
+
+ (time, (type, ARG1, [ARG2]))
+
*/
-#include "config.h"
-
-/* urg */
-#if HAVE_PYTHON2_PYTHON_H
-#include <python2/Python.h>
-#elif HAVE_PYTHON2_2_PYTHON_H
-#include <python2.2/Python.h>
-#elif HAVE_PYTHON2_1_PYTHON_H
-#include <python2.1/Python.h>
-#elif HAVE_PYTHON2_0_PYTHON_H
-#include <python2.0/Python.h>
-#elif HAVE_PYTHON1_5_PYTHON_H
-#include <python1.5/Python.h>
-#elif HAVE_PYTHON_PYTHON_H
-#define assert(x)
-#include <python/Python.h>
-#elif HAVE_PYTHON_H
-#define assert(x)
#include <Python.h>
-#else
-#error Need Python.h
+
+/* PyMIDINIT_FUNC isn't defined in Python < 2.3 */
+#ifndef PyMODINIT_FUNC
+# if defined(__cplusplus)
+# define PyMODINIT_FUNC extern "C" void
+# else /* __cplusplus */
+# define PyMODINIT_FUNC void
+# endif /* __cplusplus */
#endif
#if 0
static PyObject *Midi_warning;
static PyObject *
-midi_error (char * func, char *s)
+midi_error (char const *func, char *s)
{
- char*dest = (char*) malloc (sizeof (char) * (strlen (func) + strlen (s) + 1));
+ char *dest = (char*) malloc (sizeof (char) * (strlen (func) + strlen (s) + 1));
strcpy (dest, func);
strcat (dest, s);
PyErr_SetString (Midi_error, dest);
}
static PyObject *
-midi_warning (char *s)
+midi_warning (char const *s)
{
PyErr_SetString (Midi_warning, s);
return 0;
track_size = track_end - *track;
debug_print ("%s", "\n");
- if (strcmp (*track, "MTrk"))
+ if (memcmp (*track, "MTrk", 4))
return midi_error (__FUNCTION__, ": MTrk expected");
*track += 4;
if (!PyArg_ParseTuple (args, "s#", &midi, &midi_size))
return 0;
- if (strcmp (midi, "MThd"))
+ if (memcmp (midi, "MThd", 4))
return midi_error (__FUNCTION__, ": MThd expected");
midi += 4;
{0, 0} /* Sentinel */
};
-initmidi ()
+PyMODINIT_FUNC
+initmidi (void)
{
PyObject *m, *d;
m = Py_InitModule ("midi", MidiMethods);
Midi_warning = PyString_FromString ("midi.warning");
PyDict_SetItemString (d, "warning", Midi_warning);
}
+