]> git.donarmstrong.com Git - lilypond.git/blobdiff - python/midi.c
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / python / midi.c
index f815a2ecba4c8f90bfd28d1b5b224a3180036cab..b5e2f5bf57b1b6a14ca920b124732091abd46b24 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  2001--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 2001--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
             Jan Nieuwenhuizen <janneke@gnu.org>
 
 */
@@ -16,11 +16,28 @@ 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"
 #include <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
 int x = 0;
 int *track = &x;
@@ -35,7 +52,7 @@ static PyObject *Midi_warning;
 static PyObject *
 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);
@@ -264,7 +281,7 @@ midi_parse_track (unsigned char **track, unsigned char *track_end)
   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;
@@ -382,7 +399,7 @@ pymidi_parse (PyObject *self, PyObject *args)
   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;
@@ -400,7 +417,8 @@ static PyMethodDef MidiMethods[] =
   {0, 0}        /* Sentinel */
 };
 
-initmidi ()
+PyMODINIT_FUNC
+initmidi (void)
 {
   PyObject *m, *d;
   m = Py_InitModule ("midi", MidiMethods);
@@ -412,3 +430,4 @@ initmidi ()
   Midi_warning = PyString_FromString ("midi.warning");
   PyDict_SetItemString (d, "warning", Midi_warning);
 }