/* Generated by Cython 0.11.2 on Mon Jun  1 16:21:31 2009 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#endif
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#if PY_VERSION_HEX < 0x02040000
  #define METH_COEXIST 0
  #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
#endif
#if PY_VERSION_HEX < 0x02050000
  typedef int Py_ssize_t;
  #define PY_SSIZE_T_MAX INT_MAX
  #define PY_SSIZE_T_MIN INT_MIN
  #define PY_FORMAT_SIZE_T ""
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)   PyInt_AsLong(o)
  #define PyNumber_Index(o)    PyNumber_Int(o)
  #define PyIndex_Check(o)     PyNumber_Check(o)
#endif
#if PY_VERSION_HEX < 0x02060000
  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
  #define PyVarObject_HEAD_INIT(type, size) \
          PyObject_HEAD_INIT(type) size,
  #define PyType_Modified(t)

  typedef struct {
       void *buf;
       PyObject *obj;
       Py_ssize_t len;
       Py_ssize_t itemsize;
       int readonly;
       int ndim;
       char *format;
       Py_ssize_t *shape;
       Py_ssize_t *strides;
       Py_ssize_t *suboffsets;
       void *internal;
  } Py_buffer;

  #define PyBUF_SIMPLE 0
  #define PyBUF_WRITABLE 0x0001
  #define PyBUF_FORMAT 0x0004
  #define PyBUF_ND 0x0008
  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)

#endif
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
#endif
#if PY_MAJOR_VERSION >= 3
  #define Py_TPFLAGS_CHECKTYPES 0
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyString_Type                PyBytes_Type
  #define PyString_CheckExact          PyBytes_CheckExact
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define PyBytes_Type                 PyString_Type
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyMethod_New(func, self, klass) PyInstanceMethod_New(func)
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#else
  #define _USE_MATH_DEFINES
#endif
#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
#else
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
#endif
#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_NAMESTR(n) ((char *)(n))
  #define __Pyx_DOCSTR(n)  ((char *)(n))
#else
  #define __Pyx_NAMESTR(n) (n)
  #define __Pyx_DOCSTR(n)  (n)
#endif
#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif
#include <math.h>
#define __PYX_HAVE_API__pypm
#include "portmidi.h"
#include "porttime.h"
#define __PYX_USE_C99_COMPLEX defined(_Complex_I)


#ifdef __GNUC__
#define INLINE __inline__
#elif _WIN32
#define INLINE __inline
#else
#define INLINE 
#endif

typedef struct {PyObject **p; char *s; long n; char is_unicode; char intern; char is_identifier;} __Pyx_StringTabEntry; /*proto*/



static int __pyx_skip_dispatch = 0;


/* Type Conversion Predeclarations */

#if PY_MAJOR_VERSION < 3
#define __Pyx_PyBytes_FromString          PyString_FromString
#define __Pyx_PyBytes_FromStringAndSize   PyString_FromStringAndSize
#define __Pyx_PyBytes_AsString            PyString_AsString
#else
#define __Pyx_PyBytes_FromString          PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize   PyBytes_FromStringAndSize
#define __Pyx_PyBytes_AsString            PyBytes_AsString
#endif

#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);

#if !defined(T_PYSSIZET)
#if PY_VERSION_HEX < 0x02050000
#define T_PYSSIZET T_INT
#elif !defined(T_LONGLONG)
#define T_PYSSIZET \
        ((sizeof(Py_ssize_t) == sizeof(int))  ? T_INT  : \
        ((sizeof(Py_ssize_t) == sizeof(long)) ? T_LONG : -1))
#else
#define T_PYSSIZET \
        ((sizeof(Py_ssize_t) == sizeof(int))          ? T_INT      : \
        ((sizeof(Py_ssize_t) == sizeof(long))         ? T_LONG     : \
        ((sizeof(Py_ssize_t) == sizeof(PY_LONG_LONG)) ? T_LONGLONG : -1)))
#endif
#endif

#if !defined(T_SIZET)
#if !defined(T_ULONGLONG)
#define T_SIZET \
        ((sizeof(size_t) == sizeof(unsigned int))  ? T_UINT  : \
        ((sizeof(size_t) == sizeof(unsigned long)) ? T_ULONG : -1))
#else
#define T_SIZET \
        ((sizeof(size_t) == sizeof(unsigned int))          ? T_UINT      : \
        ((sizeof(size_t) == sizeof(unsigned long))         ? T_ULONG     : \
        ((sizeof(size_t) == sizeof(unsigned PY_LONG_LONG)) ? T_ULONGLONG : -1)))
#endif
#endif

static INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);

#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))


#ifdef __GNUC__
/* Test for GCC > 2.95 */
#if __GNUC__ > 2 ||               (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) 
#define likely(x)   __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else /* __GNUC__ > 2 ... */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ > 2 ... */
#else /* __GNUC__ */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ */
    
static PyObject *__pyx_m;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;
static const char **__pyx_f;


#ifdef CYTHON_REFNANNY
typedef struct {
  void (*INCREF)(void*, PyObject*, int);
  void (*DECREF)(void*, PyObject*, int);
  void (*GOTREF)(void*, PyObject*, int);
  void (*GIVEREF)(void*, PyObject*, int);
  void* (*NewContext)(const char*, int, const char*);
  void (*FinishContext)(void**);
} __Pyx_RefnannyAPIStruct;
static __Pyx_RefnannyAPIStruct *__Pyx_Refnanny = NULL;
#define __Pyx_ImportRefcountAPI(name)   (__Pyx_RefnannyAPIStruct *) PyCObject_Import((char *)name, (char *)"RefnannyAPI")
#define __Pyx_INCREF(r) __Pyx_Refnanny->INCREF(__pyx_refchk, (PyObject *)(r), __LINE__)
#define __Pyx_DECREF(r) __Pyx_Refnanny->DECREF(__pyx_refchk, (PyObject *)(r), __LINE__)
#define __Pyx_GOTREF(r) __Pyx_Refnanny->GOTREF(__pyx_refchk, (PyObject *)(r), __LINE__)
#define __Pyx_GIVEREF(r) __Pyx_Refnanny->GIVEREF(__pyx_refchk, (PyObject *)(r), __LINE__)
#define __Pyx_XDECREF(r) if((r) == NULL) ; else __Pyx_DECREF(r)
#define __Pyx_SetupRefcountContext(name)   void* __pyx_refchk = __Pyx_Refnanny->NewContext((name), __LINE__, __FILE__)
#define __Pyx_FinishRefcountContext()   __Pyx_Refnanny->FinishContext(&__pyx_refchk)
#else
#define __Pyx_INCREF(r) Py_INCREF(r)
#define __Pyx_DECREF(r) Py_DECREF(r)
#define __Pyx_GOTREF(r)
#define __Pyx_GIVEREF(r)
#define __Pyx_XDECREF(r) Py_XDECREF(r)
#define __Pyx_SetupRefcountContext(name)
#define __Pyx_FinishRefcountContext()
#endif /* CYTHON_REFNANNY */
#define __Pyx_XGIVEREF(r) if((r) == NULL) ; else __Pyx_GIVEREF(r)
#define __Pyx_XGOTREF(r) if((r) == NULL) ; else __Pyx_GOTREF(r)

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name, PyObject* kw_name); /*proto*/

static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/

static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],     PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,     const char* function_name); /*proto*/


static INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}


#define __Pyx_GetItemInt_List(o, i, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_List_Fast(o, i, size <= sizeof(long)) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, int fits_long) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
            PyObject *r = PyList_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i));
}

#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Tuple_Fast(o, i, size <= sizeof(long)) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, int fits_long) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i));
}


#define __Pyx_GetItemInt(o, i, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Fast(o, i, size <= sizeof(long)) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int fits_long) {
    PyObject *r;
    if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
    }
    else if (PyTuple_CheckExact(o) && ((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
    }
    else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_item && (likely(i >= 0))) {
        r = PySequence_GetItem(o, i);
    }
    else {
        r = __Pyx_GetItemInt_Generic(o, fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i));
    }
    return r;
}

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/

static int __Pyx_Print(PyObject *, int); /*proto*/
#if PY_MAJOR_VERSION >= 3
static PyObject* __pyx_print = 0;
static PyObject* __pyx_print_kwargs = 0;
#endif

static int __Pyx_PrintOne(PyObject *o); /*proto*/

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/

static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

static INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
    if (likely(PyList_CheckExact(L))) {
        if (PyList_Append(L, x) < 0) return NULL;
        Py_INCREF(Py_None);
        return Py_None; /* this is just to have an accurate signature */
    }
    else {
        PyObject *r, *m;
        m = __Pyx_GetAttrString(L, "append");
        if (!m) return NULL;
        r = PyObject_CallFunctionObjArgs(m, x, NULL);
        Py_DECREF(m);
        return r;
    }
}

static INLINE int __Pyx_StrEq(const char *, const char *); /*proto*/

static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);

static INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);

static INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);

static INLINE char __Pyx_PyInt_AsChar(PyObject *);

static INLINE short __Pyx_PyInt_AsShort(PyObject *);

static INLINE int __Pyx_PyInt_AsInt(PyObject *);

static INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);

static INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);

static INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);

static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);

static INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);

static INLINE long __Pyx_PyInt_AsLong(PyObject *);

static INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);

static INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);

static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);

static void __Pyx_AddTraceback(const char *funcname); /*proto*/

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/

/* Type declarations */

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":201
 *     return Pm_Channel(chan-1)
 * 
 * cdef class Output:             # <<<<<<<<<<<<<<
 *     """
 * class Output:
 */

struct __pyx_obj_4pypm_Output {
  PyObject_HEAD
  int i;
  PmStream *midi;
  int debug;
  int _aborted;
};

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":394
 * 
 * 
 * cdef class Input:             # <<<<<<<<<<<<<<
 *     """
 * class Input:
 */

struct __pyx_obj_4pypm_Input {
  PyObject_HEAD
  PmStream *midi;
  int debug;
  int i;
};
/* Module declarations from pypm */

static PyTypeObject *__pyx_ptype_4pypm_Output = 0;
static PyTypeObject *__pyx_ptype_4pypm_Input = 0;
#define __Pyx_MODULE_NAME "pypm"
int __pyx_module_is_main_pypm = 0;

/* Implementation of pypm */
static char __pyx_k_3[] = "0.05";
static PyObject *__pyx_int_0x1;
static PyObject *__pyx_int_0x2;
static PyObject *__pyx_int_0x4;
static PyObject *__pyx_int_0x8;
static PyObject *__pyx_int_0x10;
static PyObject *__pyx_int_0x20;
static PyObject *__pyx_int_0x30;
static PyObject *__pyx_int_0x40;
static PyObject *__pyx_int_0x7F;
static PyObject *__pyx_int_0x80;
static PyObject *__pyx_int_0x100;
static PyObject *__pyx_int_0x200;
static PyObject *__pyx_int_0x300;
static PyObject *__pyx_int_0x400;
static PyObject *__pyx_int_0x800;
static PyObject *__pyx_int_0x1000;
static PyObject *__pyx_int_0x2000;
static PyObject *__pyx_int_0x4000;
static PyObject *__pyx_int_0x8000;
static PyObject *__pyx_int_0x10000;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_4096;
static PyObject *__pyx_int_0xFF;
static PyObject *__pyx_int_16;
static PyObject *__pyx_int_0xFF0000;
static PyObject *__pyx_int_8;
static PyObject *__pyx_int_0xFF00;
static PyObject *__pyx_int_1024;
static char __pyx_k___main__[] = "__main__";
static PyObject *__pyx_kp___main__;
static char __pyx_k___init__[] = "__init__";
static PyObject *__pyx_kp___init__;
static char __pyx_k___dealloc__[] = "__dealloc__";
static PyObject *__pyx_kp___dealloc__;
static char __pyx_k__check_open[] = "_check_open";
static PyObject *__pyx_kp__check_open;
static char __pyx_k_Close[] = "Close";
static PyObject *__pyx_kp_Close;
static char __pyx_k_Abort[] = "Abort";
static PyObject *__pyx_kp_Abort;
static char __pyx_k_Write[] = "Write";
static PyObject *__pyx_kp_Write;
static char __pyx_k_WriteShort[] = "WriteShort";
static PyObject *__pyx_kp_WriteShort;
static char __pyx_k_WriteSysEx[] = "WriteSysEx";
static PyObject *__pyx_kp_WriteSysEx;
static char __pyx_k_SetFilter[] = "SetFilter";
static PyObject *__pyx_kp_SetFilter;
static char __pyx_k_SetChannelMask[] = "SetChannelMask";
static PyObject *__pyx_kp_SetChannelMask;
static char __pyx_k_Poll[] = "Poll";
static PyObject *__pyx_kp_Poll;
static char __pyx_k_Read[] = "Read";
static PyObject *__pyx_kp_Read;
static char __pyx_k_i[] = "i";
static PyObject *__pyx_kp_i;
static char __pyx_k_err[] = "err";
static PyObject *__pyx_kp_err;
static char __pyx_k_chan[] = "chan";
static PyObject *__pyx_kp_chan;
static char __pyx_k_OutputDevice[] = "OutputDevice";
static PyObject *__pyx_kp_OutputDevice;
static char __pyx_k_latency[] = "latency";
static PyObject *__pyx_kp_latency;
static char __pyx_k_data[] = "data";
static PyObject *__pyx_kp_data;
static char __pyx_k_status[] = "status";
static PyObject *__pyx_kp_status;
static char __pyx_k_1[] = "data1";
static PyObject *__pyx_kp_1;
static char __pyx_k_2[] = "data2";
static PyObject *__pyx_kp_2;
static char __pyx_k_when[] = "when";
static PyObject *__pyx_kp_when;
static char __pyx_k_msg[] = "msg";
static PyObject *__pyx_kp_msg;
static char __pyx_k_InputDevice[] = "InputDevice";
static PyObject *__pyx_kp_InputDevice;
static char __pyx_k_buffersize[] = "buffersize";
static PyObject *__pyx_kp_buffersize;
static char __pyx_k_filters[] = "filters";
static PyObject *__pyx_kp_filters;
static char __pyx_k_mask[] = "mask";
static PyObject *__pyx_kp_mask;
static char __pyx_k_length[] = "length";
static PyObject *__pyx_kp_length;
static char __pyx_k___version__[] = "__version__";
static PyObject *__pyx_kp___version__;
static char __pyx_k_array[] = "array";
static PyObject *__pyx_kp_array;
static char __pyx_k_FILT_ACTIVE[] = "FILT_ACTIVE";
static PyObject *__pyx_kp_FILT_ACTIVE;
static char __pyx_k_FILT_SYSEX[] = "FILT_SYSEX";
static PyObject *__pyx_kp_FILT_SYSEX;
static char __pyx_k_FILT_CLOCK[] = "FILT_CLOCK";
static PyObject *__pyx_kp_FILT_CLOCK;
static char __pyx_k_FILT_PLAY[] = "FILT_PLAY";
static PyObject *__pyx_kp_FILT_PLAY;
static char __pyx_k_4[] = "FILT_F9";
static PyObject *__pyx_kp_4;
static char __pyx_k_FILT_TICK[] = "FILT_TICK";
static PyObject *__pyx_kp_FILT_TICK;
static char __pyx_k_FILT_FD[] = "FILT_FD";
static PyObject *__pyx_kp_FILT_FD;
static char __pyx_k_FILT_UNDEFINED[] = "FILT_UNDEFINED";
static PyObject *__pyx_kp_FILT_UNDEFINED;
static char __pyx_k_FILT_RESET[] = "FILT_RESET";
static PyObject *__pyx_kp_FILT_RESET;
static char __pyx_k_FILT_REALTIME[] = "FILT_REALTIME";
static PyObject *__pyx_kp_FILT_REALTIME;
static char __pyx_k_FILT_NOTE[] = "FILT_NOTE";
static PyObject *__pyx_kp_FILT_NOTE;
static char __pyx_k_5[] = "FILT_CHANNEL_AFTERTOUCH";
static PyObject *__pyx_kp_5;
static char __pyx_k_6[] = "FILT_POLY_AFTERTOUCH";
static PyObject *__pyx_kp_6;
static char __pyx_k_FILT_AFTERTOUCH[] = "FILT_AFTERTOUCH";
static PyObject *__pyx_kp_FILT_AFTERTOUCH;
static char __pyx_k_FILT_PROGRAM[] = "FILT_PROGRAM";
static PyObject *__pyx_kp_FILT_PROGRAM;
static char __pyx_k_FILT_CONTROL[] = "FILT_CONTROL";
static PyObject *__pyx_kp_FILT_CONTROL;
static char __pyx_k_FILT_PITCHBEND[] = "FILT_PITCHBEND";
static PyObject *__pyx_kp_FILT_PITCHBEND;
static char __pyx_k_FILT_MTC[] = "FILT_MTC";
static PyObject *__pyx_kp_FILT_MTC;
static char __pyx_k_FILT_SONG_POSITION[] = "FILT_SONG_POSITION";
static PyObject *__pyx_kp_FILT_SONG_POSITION;
static char __pyx_k_FILT_SONG_SELECT[] = "FILT_SONG_SELECT";
static PyObject *__pyx_kp_FILT_SONG_SELECT;
static char __pyx_k_FILT_TUNE[] = "FILT_TUNE";
static PyObject *__pyx_kp_FILT_TUNE;
static char __pyx_k_FALSE[] = "FALSE";
static PyObject *__pyx_kp_FALSE;
static char __pyx_k_TRUE[] = "TRUE";
static PyObject *__pyx_kp_TRUE;
static char __pyx_k_Exception[] = "Exception";
static PyObject *__pyx_kp_Exception;
static char __pyx_k_IndexError[] = "IndexError";
static PyObject *__pyx_kp_IndexError;
static char __pyx_k_range[] = "range";
static PyObject *__pyx_kp_range;
static char __pyx_k_19[] = "B";
static PyObject *__pyx_kp_19;
static char __pyx_k_tostring[] = "tostring";
static PyObject *__pyx_kp_tostring;
static char __pyx_k_append[] = "append";
static PyObject *__pyx_kp_append;
static PyObject *__pyx_kp_3;
static PyObject *__pyx_builtin_Exception;
static PyObject *__pyx_builtin_IndexError;
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_kp_7;
static PyObject *__pyx_kp_8;
static PyObject *__pyx_kp_9;
static char __pyx_k_7[] = "Opening Midi Output";
static char __pyx_k_8[] = "Unable to open Midi OutputDevice=";
static char __pyx_k_9[] = " err=";
static PyObject *__pyx_kp_10;
static char __pyx_k_10[] = "Closing MIDI output stream and destroying instance";
static PyObject *__pyx_kp_11;
static PyObject *__pyx_kp_12;
static char __pyx_k_11[] = "midi Output not open.";
static char __pyx_k_12[] = "midi Output aborted.  Need to call Close after Abort.";
static PyObject *__pyx_kp_13;
static PyObject *__pyx_kp_14;
static PyObject *__pyx_kp_15;
static PyObject *__pyx_kp_16;
static PyObject *__pyx_kp_17;
static char __pyx_k_13[] = "maximum list length is 1024";
static char __pyx_k_14[] = " arguments in event list";
static char __pyx_k_15[] = " : ";
static char __pyx_k_16[] = " : ";
static char __pyx_k_17[] = "writing to midi buffer";
static PyObject *__pyx_kp_18;
static char __pyx_k_18[] = "Writing to MIDI buffer";
static PyObject *__pyx_kp_20;
static char __pyx_k_20[] = "MIDI input opened.";
static PyObject *__pyx_kp_21;
static char __pyx_k_21[] = "Closing MIDI input stream and destroying instance";
static PyObject *__pyx_kp_22;
static char __pyx_k_22[] = "midi Input not open.";
static PyObject *__pyx_kp_23;
static PyObject *__pyx_kp_24;
static char __pyx_k_23[] = "maximum buffer length is 1024";
static char __pyx_k_24[] = "minimum buffer length is 1";

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":132
 * TRUE=1
 * 
 * def Initialize():             # <<<<<<<<<<<<<<
 *     """
 * Initialize: call this first
 */

static PyObject *__pyx_pf_4pypm_Initialize(PyObject *__pyx_self, PyObject *unused); /*proto*/
static char __pyx_doc_4pypm_Initialize[] = "\nInitialize: call this first\n    ";
static PyObject *__pyx_pf_4pypm_Initialize(PyObject *__pyx_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  __Pyx_SetupRefcountContext("Initialize");
  __pyx_self = __pyx_self;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":136
 * Initialize: call this first
 *     """
 *     Pm_Initialize()             # <<<<<<<<<<<<<<
 *     Pt_Start(1, NULL, NULL) # /[inserted by cython to avoid comment start]* equiv to TIME_START: start timer w/ ms accuracy *[inserted by cython to avoid comment closer]/
 * 
 */
  Pm_Initialize();

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":137
 *     """
 *     Pm_Initialize()
 *     Pt_Start(1, NULL, NULL) # /[inserted by cython to avoid comment start]* equiv to TIME_START: start timer w/ ms accuracy *[inserted by cython to avoid comment closer]/             # <<<<<<<<<<<<<<
 * 
 * def Terminate():
 */
  Pt_Start(1, NULL, NULL);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":139
 *     Pt_Start(1, NULL, NULL) # /[inserted by cython to avoid comment start]* equiv to TIME_START: start timer w/ ms accuracy *[inserted by cython to avoid comment closer]/
 * 
 * def Terminate():             # <<<<<<<<<<<<<<
 *     """
 * Terminate: call this to clean up Midi streams when done.
 */

static PyObject *__pyx_pf_4pypm_Terminate(PyObject *__pyx_self, PyObject *unused); /*proto*/
static char __pyx_doc_4pypm_Terminate[] = "\nTerminate: call this to clean up Midi streams when done.\nIf you do not call this on Windows machines when you are\ndone with MIDI, your system may crash.\n    ";
static PyObject *__pyx_pf_4pypm_Terminate(PyObject *__pyx_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  __Pyx_SetupRefcountContext("Terminate");
  __pyx_self = __pyx_self;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":145
 * done with MIDI, your system may crash.
 *     """
 *     Pm_Terminate()             # <<<<<<<<<<<<<<
 * 
 * def GetDefaultInputDeviceID():
 */
  Pm_Terminate();

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":147
 *     Pm_Terminate()
 * 
 * def GetDefaultInputDeviceID():             # <<<<<<<<<<<<<<
 *     return Pm_GetDefaultInputDeviceID()
 * 
 */

static PyObject *__pyx_pf_4pypm_GetDefaultInputDeviceID(PyObject *__pyx_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_4pypm_GetDefaultInputDeviceID(PyObject *__pyx_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_SetupRefcountContext("GetDefaultInputDeviceID");
  __pyx_self = __pyx_self;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":148
 * 
 * def GetDefaultInputDeviceID():
 *     return Pm_GetDefaultInputDeviceID()             # <<<<<<<<<<<<<<
 * 
 * def GetDefaultOutputDeviceID():
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(Pm_GetDefaultInputDeviceID()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pypm.GetDefaultInputDeviceID");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":150
 *     return Pm_GetDefaultInputDeviceID()
 * 
 * def GetDefaultOutputDeviceID():             # <<<<<<<<<<<<<<
 *     return Pm_GetDefaultOutputDeviceID()
 * 
 */

static PyObject *__pyx_pf_4pypm_GetDefaultOutputDeviceID(PyObject *__pyx_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_4pypm_GetDefaultOutputDeviceID(PyObject *__pyx_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_SetupRefcountContext("GetDefaultOutputDeviceID");
  __pyx_self = __pyx_self;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":151
 * 
 * def GetDefaultOutputDeviceID():
 *     return Pm_GetDefaultOutputDeviceID()             # <<<<<<<<<<<<<<
 * 
 * def CountDevices():
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(Pm_GetDefaultOutputDeviceID()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pypm.GetDefaultOutputDeviceID");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":153
 *     return Pm_GetDefaultOutputDeviceID()
 * 
 * def CountDevices():             # <<<<<<<<<<<<<<
 *     return Pm_CountDevices()
 * 
 */

static PyObject *__pyx_pf_4pypm_CountDevices(PyObject *__pyx_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_4pypm_CountDevices(PyObject *__pyx_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_SetupRefcountContext("CountDevices");
  __pyx_self = __pyx_self;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":154
 * 
 * def CountDevices():
 *     return Pm_CountDevices()             # <<<<<<<<<<<<<<
 * 
 * def GetDeviceInfo(i):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(Pm_CountDevices()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pypm.CountDevices");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":156
 *     return Pm_CountDevices()
 * 
 * def GetDeviceInfo(i):             # <<<<<<<<<<<<<<
 *     """
 * GetDeviceInfo(<device number>): returns 5 parameters
 */

static PyObject *__pyx_pf_4pypm_GetDeviceInfo(PyObject *__pyx_self, PyObject *__pyx_v_i); /*proto*/
static char __pyx_doc_4pypm_GetDeviceInfo[] = "\nGetDeviceInfo(<device number>): returns 5 parameters\n  - underlying MIDI API\n  - device name\n  - TRUE iff input is available\n  - TRUE iff output is available\n  - TRUE iff device stream is already open\n    ";
static PyObject *__pyx_pf_4pypm_GetDeviceInfo(PyObject *__pyx_self, PyObject *__pyx_v_i) {
  PmDeviceInfo *__pyx_v_info;
  PyObject *__pyx_r = NULL;
  PmDeviceID __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_SetupRefcountContext("GetDeviceInfo");
  __pyx_self = __pyx_self;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":168
 * 
 *     # disregarding the constness from Pm_GetDeviceInfo, since pyrex doesn't do const.
 *     info = <PmDeviceInfo *>Pm_GetDeviceInfo(i)             # <<<<<<<<<<<<<<
 * 
 *     if info <> NULL: return info.interf, info.name, info.input, info.output, info.opened
 */
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_info = ((PmDeviceInfo *)Pm_GetDeviceInfo(__pyx_t_1));

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":170
 *     info = <PmDeviceInfo *>Pm_GetDeviceInfo(i)
 * 
 *     if info <> NULL: return info.interf, info.name, info.input, info.output, info.opened             # <<<<<<<<<<<<<<
 *     else: return
 * 
 */
  __pyx_t_2 = (__pyx_v_info != NULL);
  if (__pyx_t_2) {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_info->interf); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyBytes_FromString(__pyx_v_info->name); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyInt_FromLong(__pyx_v_info->input); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyInt_FromLong(__pyx_v_info->output); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyInt_FromLong(__pyx_v_info->opened); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = PyTuple_New(5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_8));
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_t_5 = 0;
    __pyx_t_6 = 0;
    __pyx_t_7 = 0;
    __pyx_r = ((PyObject *)__pyx_t_8);
    __pyx_t_8 = 0;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":171
 * 
 *     if info <> NULL: return info.interf, info.name, info.input, info.output, info.opened
 *     else: return             # <<<<<<<<<<<<<<
 * 
 * def Time():
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }
  __pyx_L5:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("pypm.GetDeviceInfo");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":173
 *     else: return
 * 
 * def Time():             # <<<<<<<<<<<<<<
 *     """
 * Time() returns the current time in ms
 */

static PyObject *__pyx_pf_4pypm_Time(PyObject *__pyx_self, PyObject *unused); /*proto*/
static char __pyx_doc_4pypm_Time[] = "\nTime() returns the current time in ms\nof the PortMidi timer\n    ";
static PyObject *__pyx_pf_4pypm_Time(PyObject *__pyx_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_SetupRefcountContext("Time");
  __pyx_self = __pyx_self;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":178
 * of the PortMidi timer
 *     """
 *     return Pt_Time()             # <<<<<<<<<<<<<<
 * 
 * def GetErrorText(err):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(Pt_Time()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pypm.Time");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":180
 *     return Pt_Time()
 * 
 * def GetErrorText(err):             # <<<<<<<<<<<<<<
 *     """
 * GetErrorText(<err num>) returns human-readable error
 */

static PyObject *__pyx_pf_4pypm_GetErrorText(PyObject *__pyx_self, PyObject *__pyx_v_err); /*proto*/
static char __pyx_doc_4pypm_GetErrorText[] = "\nGetErrorText(<err num>) returns human-readable error\nmessages translated from error numbers\n    ";
static PyObject *__pyx_pf_4pypm_GetErrorText(PyObject *__pyx_self, PyObject *__pyx_v_err) {
  PyObject *__pyx_r = NULL;
  PmError __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_SetupRefcountContext("GetErrorText");
  __pyx_self = __pyx_self;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":185
 * messages translated from error numbers
 *     """
 *     return Pm_GetErrorText(err)             # <<<<<<<<<<<<<<
 * 
 * def Channel(chan):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PmError)PyInt_AsLong(__pyx_v_err)); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyBytes_FromString(Pm_GetErrorText(__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pypm.GetErrorText");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":187
 *     return Pm_GetErrorText(err)
 * 
 * def Channel(chan):             # <<<<<<<<<<<<<<
 *     """
 * Channel(<chan>) is used with ChannelMask on input MIDI streams.
 */

static PyObject *__pyx_pf_4pypm_Channel(PyObject *__pyx_self, PyObject *__pyx_v_chan); /*proto*/
static char __pyx_doc_4pypm_Channel[] = "\nChannel(<chan>) is used with ChannelMask on input MIDI streams.\nExample: to receive input on channels 1 and 10 on a MIDI\n         stream called MidiIn:\nMidiIn.SetChannelMask(pypm.Channel(1) | pypm.Channel(10))\n\nnote: PyPortMidi Channel function has been altered from\n      the original PortMidi c call to correct for what\n      seems to be a bug --- i.e. channel filters were\n      all numbered from 0 to 15 instead of 1 to 16.\n    ";
static PyObject *__pyx_pf_4pypm_Channel(PyObject *__pyx_self, PyObject *__pyx_v_chan) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  __Pyx_SetupRefcountContext("Channel");
  __pyx_self = __pyx_self;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":199
 *       all numbered from 0 to 15 instead of 1 to 16.
 *     """
 *     return Pm_Channel(chan-1)             # <<<<<<<<<<<<<<
 * 
 * cdef class Output:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyNumber_Subtract(__pyx_v_chan, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyInt_FromLong(Pm_Channel(__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pypm.Channel");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":214
 *     cdef int _aborted
 * 
 *     def __init__(self, OutputDevice, latency=0):             # <<<<<<<<<<<<<<
 * 
 *         cdef PmError err
 */

static int __pyx_pf_4pypm_6Output___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_4pypm_6Output___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_OutputDevice = 0;
  PyObject *__pyx_v_latency = 0;
  PmError __pyx_v_err;
  PmTimeProcPtr __pyx_v_PmPtr;
  PyObject *__pyx_v_s;
  int __pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  long __pyx_t_4;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_OutputDevice,&__pyx_kp_latency,0};
  __Pyx_SetupRefcountContext("__init__");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    values[1] = __pyx_int_0;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_OutputDevice);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_latency);
        if (unlikely(value)) { values[1] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_OutputDevice = values[0];
    __pyx_v_latency = values[1];
  } else {
    __pyx_v_latency = __pyx_int_0;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_latency = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_OutputDevice = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pypm.Output.__init__");
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_s = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":220
 *         cdef PmTimeProcPtr PmPtr
 * 
 *         self.i = OutputDevice             # <<<<<<<<<<<<<<
 *         self.debug = 0
 *         self._aborted = 0
 */
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_OutputDevice); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->i = __pyx_t_1;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":221
 * 
 *         self.i = OutputDevice
 *         self.debug = 0             # <<<<<<<<<<<<<<
 *         self._aborted = 0
 * 
 */
  ((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->debug = 0;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":222
 *         self.i = OutputDevice
 *         self.debug = 0
 *         self._aborted = 0             # <<<<<<<<<<<<<<
 * 
 *         if latency == 0:
 */
  ((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->_aborted = 0;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":224
 *         self._aborted = 0
 * 
 *         if latency == 0:             # <<<<<<<<<<<<<<
 *             PmPtr = NULL
 *         else:
 */
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_latency, __pyx_int_0, Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":225
 * 
 *         if latency == 0:
 *             PmPtr = NULL             # <<<<<<<<<<<<<<
 *         else:
 *             PmPtr = <PmTimeProcPtr>&Pt_Time
 */
    __pyx_v_PmPtr = NULL;
    goto __pyx_L6;
  }
  /*else*/ {

    /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":227
 *             PmPtr = NULL
 *         else:
 *             PmPtr = <PmTimeProcPtr>&Pt_Time             # <<<<<<<<<<<<<<
 *         if self.debug: print "Opening Midi Output"
 * 	# Why is bufferSize 0 here?
 */
    __pyx_v_PmPtr = ((PmTimestamp (*)(void *))(&Pt_Time));
  }
  __pyx_L6:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":228
 *         else:
 *             PmPtr = <PmTimeProcPtr>&Pt_Time
 *         if self.debug: print "Opening Midi Output"             # <<<<<<<<<<<<<<
 * 	# Why is bufferSize 0 here?
 *         err = Pm_OpenOutput(&(self.midi), self.i, NULL, 0, PmPtr, NULL, latency)
 */
  __pyx_t_1 = ((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->debug;
  if (__pyx_t_1) {
    if (__Pyx_PrintOne(__pyx_kp_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":230
 *         if self.debug: print "Opening Midi Output"
 * 	# Why is bufferSize 0 here?
 *         err = Pm_OpenOutput(&(self.midi), self.i, NULL, 0, PmPtr, NULL, latency)             # <<<<<<<<<<<<<<
 *         if err < 0:
 *                 s = Pm_GetErrorText(err)
 */
  __pyx_t_4 = __Pyx_PyInt_AsLong(__pyx_v_latency); if (unlikely((__pyx_t_4 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_err = Pm_OpenOutput((&((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->midi), ((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->i, NULL, 0, __pyx_v_PmPtr, NULL, __pyx_t_4);

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":231
 * 	# Why is bufferSize 0 here?
 *         err = Pm_OpenOutput(&(self.midi), self.i, NULL, 0, PmPtr, NULL, latency)
 *         if err < 0:             # <<<<<<<<<<<<<<
 *                 s = Pm_GetErrorText(err)
 *                 # Something's amiss here - if we try to throw an Exception
 */
  __pyx_t_3 = (__pyx_v_err < 0);
  if (__pyx_t_3) {

    /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":232
 *         err = Pm_OpenOutput(&(self.midi), self.i, NULL, 0, PmPtr, NULL, latency)
 *         if err < 0:
 *                 s = Pm_GetErrorText(err)             # <<<<<<<<<<<<<<
 *                 # Something's amiss here - if we try to throw an Exception
 *                	# here, we crash.
 */
    __pyx_t_2 = __Pyx_PyBytes_FromString(Pm_GetErrorText(__pyx_v_err)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_v_s);
    __pyx_v_s = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":235
 *                 # Something's amiss here - if we try to throw an Exception
 *                	# here, we crash.
 *                 if not err == -10000:             # <<<<<<<<<<<<<<
 *                         raise Exception,s
 *                 else:
 */
    __pyx_t_3 = (!(__pyx_v_err == -10000));
    if (__pyx_t_3) {

      /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":236
 *                	# here, we crash.
 *                 if not err == -10000:
 *                         raise Exception,s             # <<<<<<<<<<<<<<
 *                 else:
 *                         print "Unable to open Midi OutputDevice=",OutputDevice," err=",s
 */
      __Pyx_Raise(__pyx_builtin_Exception, __pyx_v_s, 0);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L9;
    }
    /*else*/ {

      /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":238
 *                         raise Exception,s
 *                 else:
 *                         print "Unable to open Midi OutputDevice=",OutputDevice," err=",s             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
      __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __Pyx_INCREF(__pyx_kp_8);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_8);
      __Pyx_GIVEREF(__pyx_kp_8);
      __Pyx_INCREF(__pyx_v_OutputDevice);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_OutputDevice);
      __Pyx_GIVEREF(__pyx_v_OutputDevice);
      __Pyx_INCREF(__pyx_kp_9);
      PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_kp_9);
      __Pyx_GIVEREF(__pyx_kp_9);
      __Pyx_INCREF(__pyx_v_s);
      PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_s);
      __Pyx_GIVEREF(__pyx_v_s);
      if (__Pyx_Print(((PyObject *)__pyx_t_2), 1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    }
    __pyx_L9:;
    goto __pyx_L8;
  }
  __pyx_L8:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pypm.Output.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_s);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":240
 *                         print "Unable to open Midi OutputDevice=",OutputDevice," err=",s
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         if self.debug: print "Closing MIDI output stream and destroying instance"
 *         #err = Pm_Abort(self.midi)
 */

static void __pyx_pf_4pypm_6Output___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pf_4pypm_6Output___dealloc__(PyObject *__pyx_v_self) {
  PyObject *__pyx_v_err;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PmError __pyx_t_4;
  __Pyx_SetupRefcountContext("__dealloc__");
  __pyx_v_err = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":241
 * 
 *     def __dealloc__(self):
 *         if self.debug: print "Closing MIDI output stream and destroying instance"             # <<<<<<<<<<<<<<
 *         #err = Pm_Abort(self.midi)
 *         #if err < 0: raise Exception, Pm_GetErrorText(err)
 */
  __pyx_t_1 = ((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->debug;
  if (__pyx_t_1) {
    if (__Pyx_PrintOne(__pyx_kp_10) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":244
 *         #err = Pm_Abort(self.midi)
 *         #if err < 0: raise Exception, Pm_GetErrorText(err)
 *         err = Pm_Close(self.midi)             # <<<<<<<<<<<<<<
 *         if err < 0: raise Exception, Pm_GetErrorText(err)
 * 
 */
  __pyx_t_2 = PyInt_FromLong(Pm_Close(((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->midi)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_v_err);
  __pyx_v_err = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":245
 *         #if err < 0: raise Exception, Pm_GetErrorText(err)
 *         err = Pm_Close(self.midi)
 *         if err < 0: raise Exception, Pm_GetErrorText(err)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_err, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {
    __pyx_t_4 = ((PmError)PyInt_AsLong(__pyx_v_err)); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __Pyx_PyBytes_FromString(Pm_GetErrorText(__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_builtin_Exception, __pyx_t_2, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pypm.Output.__dealloc__");
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_err);
  __Pyx_FinishRefcountContext();
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":248
 * 
 * 
 *     def _check_open(self):             # <<<<<<<<<<<<<<
 *         """ checks to see if the midi is open, and if not, raises an error.
 *         """
 */

static PyObject *__pyx_pf_4pypm_6Output__check_open(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_4pypm_6Output__check_open[] = " checks to see if the midi is open, and if not, raises an error.\n        ";
static PyObject *__pyx_pf_4pypm_6Output__check_open(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_SetupRefcountContext("_check_open");

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":252
 *         """
 * 
 *         if self.midi == NULL:             # <<<<<<<<<<<<<<
 *             raise Exception, "midi Output not open."
 * 
 */
  __pyx_t_1 = (((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->midi == NULL);
  if (__pyx_t_1) {

    /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":253
 * 
 *         if self.midi == NULL:
 *             raise Exception, "midi Output not open."             # <<<<<<<<<<<<<<
 * 
 *         if self._aborted:
 */
    __Pyx_Raise(__pyx_builtin_Exception, __pyx_kp_11, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":255
 *             raise Exception, "midi Output not open."
 * 
 *         if self._aborted:             # <<<<<<<<<<<<<<
 *             raise Exception, "midi Output aborted.  Need to call Close after Abort."
 * 
 */
  __pyx_t_2 = ((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->_aborted;
  if (__pyx_t_2) {

    /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":256
 * 
 *         if self._aborted:
 *             raise Exception, "midi Output aborted.  Need to call Close after Abort."             # <<<<<<<<<<<<<<
 * 
 *     def Close(self):
 */
    __Pyx_Raise(__pyx_builtin_Exception, __pyx_kp_12, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pypm.Output._check_open");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":258
 *             raise Exception, "midi Output aborted.  Need to call Close after Abort."
 * 
 *     def Close(self):             # <<<<<<<<<<<<<<
 *         """
 * Close()
 */

static PyObject *__pyx_pf_4pypm_6Output_Close(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_4pypm_6Output_Close[] = "\nClose()\n    closes a midi stream, flushing any pending buffers.\n    (PortMidi attempts to close open streams when the application\n    exits -- this is particularly difficult under Windows.)\n        ";
static PyObject *__pyx_pf_4pypm_6Output_Close(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_v_err;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PmError __pyx_t_3;
  __Pyx_SetupRefcountContext("Close");
  __pyx_v_err = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":268
 *         #    return
 * 
 *         err = Pm_Close(self.midi)             # <<<<<<<<<<<<<<
 *         if err < 0:
 *             raise Exception, Pm_GetErrorText(err)
 */
  __pyx_t_1 = PyInt_FromLong(Pm_Close(((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->midi)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_v_err);
  __pyx_v_err = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":269
 * 
 *         err = Pm_Close(self.midi)
 *         if err < 0:             # <<<<<<<<<<<<<<
 *             raise Exception, Pm_GetErrorText(err)
 *         #self.midi = NULL
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_err, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":270
 *         err = Pm_Close(self.midi)
 *         if err < 0:
 *             raise Exception, Pm_GetErrorText(err)             # <<<<<<<<<<<<<<
 *         #self.midi = NULL
 * 
 */
    __pyx_t_3 = ((PmError)PyInt_AsLong(__pyx_v_err)); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = __Pyx_PyBytes_FromString(Pm_GetErrorText(__pyx_t_3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_builtin_Exception, __pyx_t_1, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pypm.Output.Close");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_err);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":274
 * 
 * 
 *     def Abort(self):             # <<<<<<<<<<<<<<
 *         """
 * Abort() terminates outgoing messages immediately
 */

static PyObject *__pyx_pf_4pypm_6Output_Abort(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_4pypm_6Output_Abort[] = "\nAbort() terminates outgoing messages immediately\n    The caller should immediately close the output port;\n    this call may result in transmission of a partial midi message.\n    There is no abort for Midi input because the user can simply\n    ignore messages in the buffer and close an input device at\n    any time.\n        ";
static PyObject *__pyx_pf_4pypm_6Output_Abort(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_v_err;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PmError __pyx_t_3;
  __Pyx_SetupRefcountContext("Abort");
  __pyx_v_err = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":286
 *         #    return
 * 
 *         err = Pm_Abort(self.midi)             # <<<<<<<<<<<<<<
 *         if err < 0:
 *             raise Exception, Pm_GetErrorText(err)
 */
  __pyx_t_1 = PyInt_FromLong(Pm_Abort(((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->midi)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_v_err);
  __pyx_v_err = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":287
 * 
 *         err = Pm_Abort(self.midi)
 *         if err < 0:             # <<<<<<<<<<<<<<
 *             raise Exception, Pm_GetErrorText(err)
 * 
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_err, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":288
 *         err = Pm_Abort(self.midi)
 *         if err < 0:
 *             raise Exception, Pm_GetErrorText(err)             # <<<<<<<<<<<<<<
 * 
 *         self._aborted = 1
 */
    __pyx_t_3 = ((PmError)PyInt_AsLong(__pyx_v_err)); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = __Pyx_PyBytes_FromString(Pm_GetErrorText(__pyx_t_3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_builtin_Exception, __pyx_t_1, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":290
 *             raise Exception, Pm_GetErrorText(err)
 * 
 *         self._aborted = 1             # <<<<<<<<<<<<<<
 * 
 * 
 */
  ((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->_aborted = 1;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pypm.Output.Abort");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_err);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":293
 * 
 * 
 *     def Write(self, data):             # <<<<<<<<<<<<<<
 *         """
 * Write(data)
 */

static PyObject *__pyx_pf_4pypm_6Output_Write(PyObject *__pyx_v_self, PyObject *__pyx_v_data); /*proto*/
static char __pyx_doc_4pypm_6Output_Write[] = "\nWrite(data)\n    output a series of MIDI information in the form of a list:\n         Write([[[status <,data1><,data2><,data3>],timestamp],\n                [[status <,data1><,data2><,data3>],timestamp],...])\n    <data> fields are optional\n    example: choose program change 1 at time 20000 and\n    send note 65 with velocity 100 500 ms later.\n         Write([[[0xc0,0,0],20000],[[0x90,60,100],20500]])\n    notes:\n      1. timestamps will be ignored if latency = 0.\n      2. To get a note to play immediately, send MIDI info with\n         timestamp read from function Time.\n      3. understanding optional data fields:\n           Write([[[0xc0,0,0],20000]]) is equivalent to\n           Write([[[0xc0],20000]])\n        ";
static PyObject *__pyx_pf_4pypm_6Output_Write(PyObject *__pyx_v_self, PyObject *__pyx_v_data) {
  PmEvent __pyx_v_buffer[1024];
  PmError __pyx_v_err;
  int __pyx_v_i;
  PyObject *__pyx_v_loop1;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PmMessage __pyx_t_11;
  PmTimestamp __pyx_t_12;
  __Pyx_SetupRefcountContext("Write");
  __pyx_v_loop1 = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":315
 *         cdef int i
 * 
 *         self._check_open()             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_kp__check_open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":318
 * 
 * 
 *         if len(data) > 1024: raise IndexError, 'maximum list length is 1024'             # <<<<<<<<<<<<<<
 *         else:
 *             for loop1 in range(len(data)):
 */
  __pyx_t_3 = PyObject_Length(__pyx_v_data); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = (__pyx_t_3 > 1024);
  if (__pyx_t_4) {
    __Pyx_Raise(__pyx_builtin_IndexError, __pyx_kp_13, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  /*else*/ {

    /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":320
 *         if len(data) > 1024: raise IndexError, 'maximum list length is 1024'
 *         else:
 *             for loop1 in range(len(data)):             # <<<<<<<<<<<<<<
 *                 if ((len(data[loop1][0]) > 4) |
 *                     (len(data[loop1][0]) < 1)):
 */
    __pyx_t_5 = PyObject_Length(__pyx_v_data); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
      __pyx_t_3 = 0; __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1);
    } else {
      __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    for (;;) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++;
      } else if (likely(PyTuple_CheckExact(__pyx_t_1))) {
        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++;
      } else {
        __pyx_t_2 = PyIter_Next(__pyx_t_1);
        if (!__pyx_t_2) {
          if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      __Pyx_DECREF(__pyx_v_loop1);
      __pyx_v_loop1 = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":321
 *         else:
 *             for loop1 in range(len(data)):
 *                 if ((len(data[loop1][0]) > 4) |             # <<<<<<<<<<<<<<
 *                     (len(data[loop1][0]) < 1)):
 *                     raise IndexError, str(len(data[loop1][0]))+' arguments in event list'
 */
      __pyx_1 = PyObject_GetItem(__pyx_v_data, __pyx_v_loop1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_1);
      __pyx_2 = __Pyx_GetItemInt(__pyx_1, 0, sizeof(long), PyInt_FromLong); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_2);
      __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
      __pyx_t_5 = PyObject_Length(__pyx_2); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_2); __pyx_2 = 0;

      /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":322
 *             for loop1 in range(len(data)):
 *                 if ((len(data[loop1][0]) > 4) |
 *                     (len(data[loop1][0]) < 1)):             # <<<<<<<<<<<<<<
 *                     raise IndexError, str(len(data[loop1][0]))+' arguments in event list'
 *                 buffer[loop1].message = 0
 */
      __pyx_1 = PyObject_GetItem(__pyx_v_data, __pyx_v_loop1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_1);
      __pyx_2 = __Pyx_GetItemInt(__pyx_1, 0, sizeof(long), PyInt_FromLong); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_2);
      __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
      __pyx_t_6 = PyObject_Length(__pyx_2); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_2); __pyx_2 = 0;
      __pyx_t_4 = ((__pyx_t_5 > 4) | (__pyx_t_6 < 1));
      if (__pyx_t_4) {

        /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":323
 *                 if ((len(data[loop1][0]) > 4) |
 *                     (len(data[loop1][0]) < 1)):
 *                     raise IndexError, str(len(data[loop1][0]))+' arguments in event list'             # <<<<<<<<<<<<<<
 *                 buffer[loop1].message = 0
 *                 for i in range(len(data[loop1][0])):
 */
        __pyx_1 = PyObject_GetItem(__pyx_v_data, __pyx_v_loop1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_1);
        __pyx_2 = __Pyx_GetItemInt(__pyx_1, 0, sizeof(long), PyInt_FromLong); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_2);
        __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
        __pyx_t_6 = PyObject_Length(__pyx_2); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_2); __pyx_2 = 0;
        __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_7));
        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)&PyString_Type)), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
        __pyx_t_7 = PyNumber_Add(__pyx_t_2, __pyx_kp_14); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_Raise(__pyx_builtin_IndexError, __pyx_t_7, 0);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L8;
      }
      __pyx_L8:;

      /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":324
 *                     (len(data[loop1][0]) < 1)):
 *                     raise IndexError, str(len(data[loop1][0]))+' arguments in event list'
 *                 buffer[loop1].message = 0             # <<<<<<<<<<<<<<
 *                 for i in range(len(data[loop1][0])):
 *                     buffer[loop1].message = buffer[loop1].message + ((data[loop1][0][i]&0xFF) << (8*i))
 */
      __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_loop1); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      (__pyx_v_buffer[__pyx_t_6]).message = 0;

      /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":325
 *                     raise IndexError, str(len(data[loop1][0]))+' arguments in event list'
 *                 buffer[loop1].message = 0
 *                 for i in range(len(data[loop1][0])):             # <<<<<<<<<<<<<<
 *                     buffer[loop1].message = buffer[loop1].message + ((data[loop1][0][i]&0xFF) << (8*i))
 *                 buffer[loop1].timestamp = data[loop1][1]
 */
      __pyx_1 = PyObject_GetItem(__pyx_v_data, __pyx_v_loop1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_1);
      __pyx_2 = __Pyx_GetItemInt(__pyx_1, 0, sizeof(long), PyInt_FromLong); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_2);
      __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
      __pyx_t_6 = PyObject_Length(__pyx_2); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_2); __pyx_2 = 0;
      for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_6; __pyx_t_8+=1) {
        __pyx_v_i = __pyx_t_8;

        /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":326
 *                 buffer[loop1].message = 0
 *                 for i in range(len(data[loop1][0])):
 *                     buffer[loop1].message = buffer[loop1].message + ((data[loop1][0][i]&0xFF) << (8*i))             # <<<<<<<<<<<<<<
 *                 buffer[loop1].timestamp = data[loop1][1]
 *                 if self.debug: print loop1," : ",buffer[loop1].message," : ",buffer[loop1].timestamp
 */
        __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_loop1); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_7 = PyInt_FromLong((__pyx_v_buffer[__pyx_t_5]).message); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_1 = PyObject_GetItem(__pyx_v_data, __pyx_v_loop1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_1);
        __pyx_2 = __Pyx_GetItemInt(__pyx_1, 0, sizeof(long), PyInt_FromLong); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_2);
        __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
        __pyx_1 = __Pyx_GetItemInt(__pyx_2, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_1);
        __Pyx_DECREF(__pyx_2); __pyx_2 = 0;
        __pyx_t_2 = PyNumber_And(__pyx_1, __pyx_int_0xFF); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
        __pyx_t_9 = PyInt_FromLong((8 * __pyx_v_i)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_10 = PyNumber_Lshift(__pyx_t_2, __pyx_t_9); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_9 = PyNumber_Add(__pyx_t_7, __pyx_t_10); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_11 = __Pyx_PyInt_AsLong(__pyx_t_9); if (unlikely((__pyx_t_11 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_loop1); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        (__pyx_v_buffer[__pyx_t_5]).message = __pyx_t_11;
      }

      /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":327
 *                 for i in range(len(data[loop1][0])):
 *                     buffer[loop1].message = buffer[loop1].message + ((data[loop1][0][i]&0xFF) << (8*i))
 *                 buffer[loop1].timestamp = data[loop1][1]             # <<<<<<<<<<<<<<
 *                 if self.debug: print loop1," : ",buffer[loop1].message," : ",buffer[loop1].timestamp
 *         if self.debug: print "writing to midi buffer"
 */
      __pyx_2 = PyObject_GetItem(__pyx_v_data, __pyx_v_loop1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_2);
      __pyx_1 = __Pyx_GetItemInt(__pyx_2, 1, sizeof(long), PyInt_FromLong); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_1);
      __Pyx_DECREF(__pyx_2); __pyx_2 = 0;
      __pyx_t_12 = __Pyx_PyInt_AsLong(__pyx_1); if (unlikely((__pyx_t_12 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
      __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_loop1); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      (__pyx_v_buffer[__pyx_t_6]).timestamp = __pyx_t_12;

      /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":328
 *                     buffer[loop1].message = buffer[loop1].message + ((data[loop1][0][i]&0xFF) << (8*i))
 *                 buffer[loop1].timestamp = data[loop1][1]
 *                 if self.debug: print loop1," : ",buffer[loop1].message," : ",buffer[loop1].timestamp             # <<<<<<<<<<<<<<
 *         if self.debug: print "writing to midi buffer"
 *         err= Pm_Write(self.midi, buffer, len(data))
 */
      __pyx_t_8 = ((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->debug;
      if (__pyx_t_8) {
        __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_loop1); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_9 = PyInt_FromLong((__pyx_v_buffer[__pyx_t_6]).message); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_loop1); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_10 = PyInt_FromLong((__pyx_v_buffer[__pyx_t_6]).timestamp); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_7 = PyTuple_New(5); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_7));
        __Pyx_INCREF(__pyx_v_loop1);
        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_loop1);
        __Pyx_GIVEREF(__pyx_v_loop1);
        __Pyx_INCREF(__pyx_kp_15);
        PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_kp_15);
        __Pyx_GIVEREF(__pyx_kp_15);
        PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_9);
        __Pyx_INCREF(__pyx_kp_16);
        PyTuple_SET_ITEM(__pyx_t_7, 3, __pyx_kp_16);
        __Pyx_GIVEREF(__pyx_kp_16);
        PyTuple_SET_ITEM(__pyx_t_7, 4, __pyx_t_10);
        __Pyx_GIVEREF(__pyx_t_10);
        __pyx_t_9 = 0;
        __pyx_t_10 = 0;
        if (__Pyx_Print(((PyObject *)__pyx_t_7), 1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
        goto __pyx_L11;
      }
      __pyx_L11:;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __pyx_L5:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":329
 *                 buffer[loop1].timestamp = data[loop1][1]
 *                 if self.debug: print loop1," : ",buffer[loop1].message," : ",buffer[loop1].timestamp
 *         if self.debug: print "writing to midi buffer"             # <<<<<<<<<<<<<<
 *         err= Pm_Write(self.midi, buffer, len(data))
 *         if err < 0: raise Exception, Pm_GetErrorText(err)
 */
  __pyx_t_8 = ((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->debug;
  if (__pyx_t_8) {
    if (__Pyx_PrintOne(__pyx_kp_17) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L12;
  }
  __pyx_L12:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":330
 *                 if self.debug: print loop1," : ",buffer[loop1].message," : ",buffer[loop1].timestamp
 *         if self.debug: print "writing to midi buffer"
 *         err= Pm_Write(self.midi, buffer, len(data))             # <<<<<<<<<<<<<<
 *         if err < 0: raise Exception, Pm_GetErrorText(err)
 * 
 */
  __pyx_t_3 = PyObject_Length(__pyx_v_data); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_err = Pm_Write(((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->midi, __pyx_v_buffer, __pyx_t_3);

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":331
 *         if self.debug: print "writing to midi buffer"
 *         err= Pm_Write(self.midi, buffer, len(data))
 *         if err < 0: raise Exception, Pm_GetErrorText(err)             # <<<<<<<<<<<<<<
 * 
 *     def WriteShort(self, status, data1 = 0, data2 = 0):
 */
  __pyx_t_4 = (__pyx_v_err < 0);
  if (__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyBytes_FromString(Pm_GetErrorText(__pyx_v_err)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_builtin_Exception, __pyx_t_1, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L13;
  }
  __pyx_L13:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __Pyx_XDECREF(__pyx_2);
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("pypm.Output.Write");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_loop1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":333
 *         if err < 0: raise Exception, Pm_GetErrorText(err)
 * 
 *     def WriteShort(self, status, data1 = 0, data2 = 0):             # <<<<<<<<<<<<<<
 *         """
 * WriteShort(status <, data1><, data2>)
 */

static PyObject *__pyx_pf_4pypm_6Output_WriteShort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4pypm_6Output_WriteShort[] = "\nWriteShort(status <, data1><, data2>)\n     output MIDI information of 3 bytes or less.\n     data fields are optional\n     status byte could be:\n          0xc0 = program change\n          0x90 = note on\n          etc.\n          data bytes are optional and assumed 0 if omitted\n     example: note 65 on with velocity 100\n          WriteShort(0x90,65,100)\n        ";
static PyObject *__pyx_pf_4pypm_6Output_WriteShort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_status = 0;
  PyObject *__pyx_v_data1 = 0;
  PyObject *__pyx_v_data2 = 0;
  PmEvent __pyx_v_buffer[1];
  PmError __pyx_v_err;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PmMessage __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_status,&__pyx_kp_1,&__pyx_kp_2,0};
  __Pyx_SetupRefcountContext("WriteShort");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    values[1] = __pyx_int_0;
    values[2] = __pyx_int_0;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_status);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_1);
        if (unlikely(value)) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_2);
        if (unlikely(value)) { values[2] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "WriteShort") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_status = values[0];
    __pyx_v_data1 = values[1];
    __pyx_v_data2 = values[2];
  } else {
    __pyx_v_data1 = __pyx_int_0;
    __pyx_v_data2 = __pyx_int_0;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: __pyx_v_data2 = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: __pyx_v_data1 = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_status = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("WriteShort", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pypm.Output.WriteShort");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":348
 *         cdef PmEvent buffer[1]
 *         cdef PmError err
 *         self._check_open()             # <<<<<<<<<<<<<<
 * 
 *         buffer[0].timestamp = Pt_Time()
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_kp__check_open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":350
 *         self._check_open()
 * 
 *         buffer[0].timestamp = Pt_Time()             # <<<<<<<<<<<<<<
 *         buffer[0].message = ((((data2) << 16) & 0xFF0000) | (((data1) << 8) & 0xFF00) | ((status) & 0xFF))
 *         if self.debug: print "Writing to MIDI buffer"
 */
  (__pyx_v_buffer[0]).timestamp = Pt_Time();

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":351
 * 
 *         buffer[0].timestamp = Pt_Time()
 *         buffer[0].message = ((((data2) << 16) & 0xFF0000) | (((data1) << 8) & 0xFF00) | ((status) & 0xFF))             # <<<<<<<<<<<<<<
 *         if self.debug: print "Writing to MIDI buffer"
 *         err = Pm_Write(self.midi, buffer, 1) # stream, buffer, length
 */
  __pyx_t_2 = PyNumber_Lshift(__pyx_v_data2, __pyx_int_16); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyNumber_And(__pyx_t_2, __pyx_int_0xFF0000); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyNumber_Lshift(__pyx_v_data1, __pyx_int_8); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_2, __pyx_int_0xFF00); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyNumber_Or(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyNumber_And(__pyx_v_status, __pyx_int_0xFF); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyNumber_Or(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyInt_AsLong(__pyx_t_1); if (unlikely((__pyx_t_4 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  (__pyx_v_buffer[0]).message = __pyx_t_4;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":352
 *         buffer[0].timestamp = Pt_Time()
 *         buffer[0].message = ((((data2) << 16) & 0xFF0000) | (((data1) << 8) & 0xFF00) | ((status) & 0xFF))
 *         if self.debug: print "Writing to MIDI buffer"             # <<<<<<<<<<<<<<
 *         err = Pm_Write(self.midi, buffer, 1) # stream, buffer, length
 *         if err < 0 : raise Exception, Pm_GetErrorText(err)
 */
  __pyx_t_5 = ((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->debug;
  if (__pyx_t_5) {
    if (__Pyx_PrintOne(__pyx_kp_18) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":353
 *         buffer[0].message = ((((data2) << 16) & 0xFF0000) | (((data1) << 8) & 0xFF00) | ((status) & 0xFF))
 *         if self.debug: print "Writing to MIDI buffer"
 *         err = Pm_Write(self.midi, buffer, 1) # stream, buffer, length             # <<<<<<<<<<<<<<
 *         if err < 0 : raise Exception, Pm_GetErrorText(err)
 * 
 */
  __pyx_v_err = Pm_Write(((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->midi, __pyx_v_buffer, 1);

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":354
 *         if self.debug: print "Writing to MIDI buffer"
 *         err = Pm_Write(self.midi, buffer, 1) # stream, buffer, length
 *         if err < 0 : raise Exception, Pm_GetErrorText(err)             # <<<<<<<<<<<<<<
 * 
 *     def WriteSysEx(self, when, msg):
 */
  __pyx_t_6 = (__pyx_v_err < 0);
  if (__pyx_t_6) {
    __pyx_t_1 = __Pyx_PyBytes_FromString(Pm_GetErrorText(__pyx_v_err)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_builtin_Exception, __pyx_t_1, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pypm.Output.WriteShort");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":356
 *         if err < 0 : raise Exception, Pm_GetErrorText(err)
 * 
 *     def WriteSysEx(self, when, msg):             # <<<<<<<<<<<<<<
 *         """
 *         WriteSysEx(<timestamp>,<msg>)
 */

static PyObject *__pyx_pf_4pypm_6Output_WriteSysEx(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4pypm_6Output_WriteSysEx[] = "\n        WriteSysEx(<timestamp>,<msg>)\n        writes a timestamped system-exclusive midi message.\n        <msg> can be a *list* or a *string*\n        example:\n            (assuming y is an input MIDI stream)\n            y.WriteSysEx(0,'\\xF0\\x7D\\x10\\x11\\x12\\x13\\xF7')\n                              is equivalent to\n            y.WriteSysEx(pypm.Time,\n            [0xF0, 0x7D, 0x10, 0x11, 0x12, 0x13, 0xF7])\n        ";
static PyObject *__pyx_pf_4pypm_6Output_WriteSysEx(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_when = 0;
  PyObject *__pyx_v_msg = 0;
  PmError __pyx_v_err;
  char *__pyx_v_cmsg;
  PtTimestamp __pyx_v_CurTime;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  char *__pyx_t_5;
  PmTimestamp __pyx_t_6;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_when,&__pyx_kp_msg,0};
  __Pyx_SetupRefcountContext("WriteSysEx");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_when);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_msg);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("WriteSysEx", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "WriteSysEx") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_when = values[0];
    __pyx_v_msg = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_when = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_msg = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("WriteSysEx", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pypm.Output.WriteSysEx");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF(__pyx_v_msg);

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":372
 *         cdef PtTimestamp CurTime
 * 
 *         self._check_open()             # <<<<<<<<<<<<<<
 * 
 *         if type(msg) is list:
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_kp__check_open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":374
 *         self._check_open()
 * 
 *         if type(msg) is list:             # <<<<<<<<<<<<<<
 *             msg = array.array('B',msg).tostring() # Markus Pfaff contribution
 *         cmsg = msg
 */
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_INCREF(__pyx_v_msg);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_msg);
  __Pyx_GIVEREF(__pyx_v_msg);
  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)&PyType_Type)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_3 = (__pyx_t_1 == ((PyObject *)((PyObject*)&PyList_Type)));
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_3) {

    /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":375
 * 
 *         if type(msg) is list:
 *             msg = array.array('B',msg).tostring() # Markus Pfaff contribution             # <<<<<<<<<<<<<<
 *         cmsg = msg
 * 
 */
    __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_array); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_1);
    __pyx_t_1 = PyObject_GetAttr(__pyx_1, __pyx_kp_array); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_INCREF(__pyx_kp_19);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_19);
    __Pyx_GIVEREF(__pyx_kp_19);
    __Pyx_INCREF(__pyx_v_msg);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_msg);
    __Pyx_GIVEREF(__pyx_v_msg);
    __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_GetAttr(__pyx_t_4, __pyx_kp_tostring); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_v_msg);
    __pyx_v_msg = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":376
 *         if type(msg) is list:
 *             msg = array.array('B',msg).tostring() # Markus Pfaff contribution
 *         cmsg = msg             # <<<<<<<<<<<<<<
 * 
 *         CurTime = Pt_Time()
 */
  __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_msg); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_cmsg = __pyx_t_5;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":378
 *         cmsg = msg
 * 
 *         CurTime = Pt_Time()             # <<<<<<<<<<<<<<
 *         err = Pm_WriteSysEx(self.midi, when, <unsigned char *> cmsg)
 *         if err < 0 : raise Exception, Pm_GetErrorText(err)
 */
  __pyx_v_CurTime = Pt_Time();

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":379
 * 
 *         CurTime = Pt_Time()
 *         err = Pm_WriteSysEx(self.midi, when, <unsigned char *> cmsg)             # <<<<<<<<<<<<<<
 *         if err < 0 : raise Exception, Pm_GetErrorText(err)
 *         while Pt_Time() == CurTime: # wait for SysEx to go thru or...my
 */
  __pyx_t_6 = __Pyx_PyInt_AsLong(__pyx_v_when); if (unlikely((__pyx_t_6 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_err = Pm_WriteSysEx(((struct __pyx_obj_4pypm_Output *)__pyx_v_self)->midi, __pyx_t_6, ((unsigned char *)__pyx_v_cmsg));

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":380
 *         CurTime = Pt_Time()
 *         err = Pm_WriteSysEx(self.midi, when, <unsigned char *> cmsg)
 *         if err < 0 : raise Exception, Pm_GetErrorText(err)             # <<<<<<<<<<<<<<
 *         while Pt_Time() == CurTime: # wait for SysEx to go thru or...my
 *             pass                    # win32 machine crashes w/ multiple SysEx
 */
  __pyx_t_3 = (__pyx_v_err < 0);
  if (__pyx_t_3) {
    __pyx_t_4 = __Pyx_PyBytes_FromString(Pm_GetErrorText(__pyx_v_err)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_builtin_Exception, __pyx_t_4, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":381
 *         err = Pm_WriteSysEx(self.midi, when, <unsigned char *> cmsg)
 *         if err < 0 : raise Exception, Pm_GetErrorText(err)
 *         while Pt_Time() == CurTime: # wait for SysEx to go thru or...my             # <<<<<<<<<<<<<<
 *             pass                    # win32 machine crashes w/ multiple SysEx
 * 
 */
  while (1) {
    __pyx_t_3 = (Pt_Time() == __pyx_v_CurTime);
    if (!__pyx_t_3) break;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pypm.Output.WriteSysEx");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_msg);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":404
 *     cdef int i
 * 
 *     def __init__(self, InputDevice, buffersize=4096):             # <<<<<<<<<<<<<<
 *         cdef PmError err
 *         self.i = InputDevice
 */

static int __pyx_pf_4pypm_5Input___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_4pypm_5Input___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_InputDevice = 0;
  PyObject *__pyx_v_buffersize = 0;
  PmError __pyx_v_err;
  int __pyx_r;
  int __pyx_t_1;
  long __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_InputDevice,&__pyx_kp_buffersize,0};
  __Pyx_SetupRefcountContext("__init__");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    values[1] = __pyx_int_4096;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_InputDevice);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_buffersize);
        if (unlikely(value)) { values[1] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_InputDevice = values[0];
    __pyx_v_buffersize = values[1];
  } else {
    __pyx_v_buffersize = __pyx_int_4096;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_buffersize = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_InputDevice = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pypm.Input.__init__");
  return -1;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":406
 *     def __init__(self, InputDevice, buffersize=4096):
 *         cdef PmError err
 *         self.i = InputDevice             # <<<<<<<<<<<<<<
 *         self.debug = 0
 *         err= Pm_OpenInput(&(self.midi),self.i,NULL,buffersize,&Pt_Time,NULL)
 */
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_InputDevice); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_4pypm_Input *)__pyx_v_self)->i = __pyx_t_1;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":407
 *         cdef PmError err
 *         self.i = InputDevice
 *         self.debug = 0             # <<<<<<<<<<<<<<
 *         err= Pm_OpenInput(&(self.midi),self.i,NULL,buffersize,&Pt_Time,NULL)
 *         if err < 0: raise Exception, Pm_GetErrorText(err)
 */
  ((struct __pyx_obj_4pypm_Input *)__pyx_v_self)->debug = 0;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":408
 *         self.i = InputDevice
 *         self.debug = 0
 *         err= Pm_OpenInput(&(self.midi),self.i,NULL,buffersize,&Pt_Time,NULL)             # <<<<<<<<<<<<<<
 *         if err < 0: raise Exception, Pm_GetErrorText(err)
 *         if self.debug: print "MIDI input opened."
 */
  __pyx_t_2 = __Pyx_PyInt_AsLong(__pyx_v_buffersize); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_err = Pm_OpenInput((&((struct __pyx_obj_4pypm_Input *)__pyx_v_self)->midi), ((struct __pyx_obj_4pypm_Input *)__pyx_v_self)->i, NULL, __pyx_t_2, (&Pt_Time), NULL);

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":409
 *         self.debug = 0
 *         err= Pm_OpenInput(&(self.midi),self.i,NULL,buffersize,&Pt_Time,NULL)
 *         if err < 0: raise Exception, Pm_GetErrorText(err)             # <<<<<<<<<<<<<<
 *         if self.debug: print "MIDI input opened."
 * 
 */
  __pyx_t_3 = (__pyx_v_err < 0);
  if (__pyx_t_3) {
    __pyx_t_4 = __Pyx_PyBytes_FromString(Pm_GetErrorText(__pyx_v_err)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_builtin_Exception, __pyx_t_4, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":410
 *         err= Pm_OpenInput(&(self.midi),self.i,NULL,buffersize,&Pt_Time,NULL)
 *         if err < 0: raise Exception, Pm_GetErrorText(err)
 *         if self.debug: print "MIDI input opened."             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __pyx_t_1 = ((struct __pyx_obj_4pypm_Input *)__pyx_v_self)->debug;
  if (__pyx_t_1) {
    if (__Pyx_PrintOne(__pyx_kp_20) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pypm.Input.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":412
 *         if self.debug: print "MIDI input opened."
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         cdef PmError err
 *         if self.debug: print "Closing MIDI input stream and destroying instance"
 */

static void __pyx_pf_4pypm_5Input___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pf_4pypm_5Input___dealloc__(PyObject *__pyx_v_self) {
  PmError __pyx_v_err;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_SetupRefcountContext("__dealloc__");

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":414
 *     def __dealloc__(self):
 *         cdef PmError err
 *         if self.debug: print "Closing MIDI input stream and destroying instance"             # <<<<<<<<<<<<<<
 * 
 *         err = Pm_Close(self.midi)
 */
  __pyx_t_1 = ((struct __pyx_obj_4pypm_Input *)__pyx_v_self)->debug;
  if (__pyx_t_1) {
    if (__Pyx_PrintOne(__pyx_kp_21) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":416
 *         if self.debug: print "Closing MIDI input stream and destroying instance"
 * 
 *         err = Pm_Close(self.midi)             # <<<<<<<<<<<<<<
 *         if err < 0:
 *             raise Exception, Pm_GetErrorText(err)
 */
  __pyx_v_err = Pm_Close(((struct __pyx_obj_4pypm_Input *)__pyx_v_self)->midi);

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":417
 * 
 *         err = Pm_Close(self.midi)
 *         if err < 0:             # <<<<<<<<<<<<<<
 *             raise Exception, Pm_GetErrorText(err)
 * 
 */
  __pyx_t_2 = (__pyx_v_err < 0);
  if (__pyx_t_2) {

    /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":418
 *         err = Pm_Close(self.midi)
 *         if err < 0:
 *             raise Exception, Pm_GetErrorText(err)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_3 = __Pyx_PyBytes_FromString(Pm_GetErrorText(__pyx_v_err)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_builtin_Exception, __pyx_t_3, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pypm.Input.__dealloc__");
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":422
 * 
 * 
 *     def _check_open(self):             # <<<<<<<<<<<<<<
 *         """ checks to see if the midi is open, and if not, raises an error.
 *         """
 */

static PyObject *__pyx_pf_4pypm_5Input__check_open(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_4pypm_5Input__check_open[] = " checks to see if the midi is open, and if not, raises an error.\n        ";
static PyObject *__pyx_pf_4pypm_5Input__check_open(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  __Pyx_SetupRefcountContext("_check_open");

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":426
 *         """
 * 
 *         if self.midi == NULL:             # <<<<<<<<<<<<<<
 *             raise Exception, "midi Input not open."
 * 
 */
  __pyx_t_1 = (((struct __pyx_obj_4pypm_Input *)__pyx_v_self)->midi == NULL);
  if (__pyx_t_1) {

    /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":427
 * 
 *         if self.midi == NULL:
 *             raise Exception, "midi Input not open."             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_Raise(__pyx_builtin_Exception, __pyx_kp_22, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 427; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pypm.Input._check_open");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":430
 * 
 * 
 *     def Close(self):             # <<<<<<<<<<<<<<
 *         """
 * Close()
 */

static PyObject *__pyx_pf_4pypm_5Input_Close(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_4pypm_5Input_Close[] = "\nClose()\n    closes a midi stream, flushing any pending buffers.\n    (PortMidi attempts to close open streams when the application\n    exits -- this is particularly difficult under Windows.)\n        ";
static PyObject *__pyx_pf_4pypm_5Input_Close(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_v_err;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PmError __pyx_t_3;
  __Pyx_SetupRefcountContext("Close");
  __pyx_v_err = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":440
 *         #    return
 * 
 *         err = Pm_Close(self.midi)             # <<<<<<<<<<<<<<
 *         if err < 0:
 *             raise Exception, Pm_GetErrorText(err)
 */
  __pyx_t_1 = PyInt_FromLong(Pm_Close(((struct __pyx_obj_4pypm_Input *)__pyx_v_self)->midi)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_v_err);
  __pyx_v_err = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":441
 * 
 *         err = Pm_Close(self.midi)
 *         if err < 0:             # <<<<<<<<<<<<<<
 *             raise Exception, Pm_GetErrorText(err)
 *         #self.midi = NULL
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_err, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":442
 *         err = Pm_Close(self.midi)
 *         if err < 0:
 *             raise Exception, Pm_GetErrorText(err)             # <<<<<<<<<<<<<<
 *         #self.midi = NULL
 * 
 */
    __pyx_t_3 = ((PmError)PyInt_AsLong(__pyx_v_err)); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = __Pyx_PyBytes_FromString(Pm_GetErrorText(__pyx_t_3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_builtin_Exception, __pyx_t_1, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pypm.Input.Close");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_err);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":447
 * 
 * 
 *     def SetFilter(self, filters):             # <<<<<<<<<<<<<<
 *         """
 *     SetFilter(<filters>) sets filters on an open input stream
 */

static PyObject *__pyx_pf_4pypm_5Input_SetFilter(PyObject *__pyx_v_self, PyObject *__pyx_v_filters); /*proto*/
static char __pyx_doc_4pypm_5Input_SetFilter[] = "\n    SetFilter(<filters>) sets filters on an open input stream\n    to drop selected input types. By default, only active sensing\n    messages are filtered. To prohibit, say, active sensing and\n    sysex messages, call\n    SetFilter(stream, FILT_ACTIVE | FILT_SYSEX);\n\n    Filtering is useful when midi routing or midi thru functionality\n    is being provided by the user application.\n    For example, you may want to exclude timing messages\n    (clock, MTC, start/stop/continue), while allowing note-related\n    messages to pass. Or you may be using a sequencer or drum-machine\n    for MIDI clock information but want to exclude any notes\n    it may play.\n\n    Note: SetFilter empties the buffer after setting the filter,\n    just in case anything got through.\n        ";
static PyObject *__pyx_pf_4pypm_5Input_SetFilter(PyObject *__pyx_v_self, PyObject *__pyx_v_filters) {
  PmEvent __pyx_v_buffer[1];
  PmError __pyx_v_err;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  long __pyx_t_3;
  int __pyx_t_4;
  __Pyx_SetupRefcountContext("SetFilter");

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":469
 *         cdef PmError err
 * 
 *         self._check_open()             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_kp__check_open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":472
 * 
 * 
 *         err = Pm_SetFilter(self.midi, filters)             # <<<<<<<<<<<<<<
 * 
 *         if err < 0: raise Exception, Pm_GetErrorText(err)
 */
  __pyx_t_3 = __Pyx_PyInt_AsLong(__pyx_v_filters); if (unlikely((__pyx_t_3 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_err = Pm_SetFilter(((struct __pyx_obj_4pypm_Input *)__pyx_v_self)->midi, __pyx_t_3);

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":474
 *         err = Pm_SetFilter(self.midi, filters)
 * 
 *         if err < 0: raise Exception, Pm_GetErrorText(err)             # <<<<<<<<<<<<<<
 * 
 *         while(Pm_Poll(self.midi) != pmNoError):
 */
  __pyx_t_4 = (__pyx_v_err < 0);
  if (__pyx_t_4) {
    __pyx_t_2 = __Pyx_PyBytes_FromString(Pm_GetErrorText(__pyx_v_err)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_builtin_Exception, __pyx_t_2, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":476
 *         if err < 0: raise Exception, Pm_GetErrorText(err)
 * 
 *         while(Pm_Poll(self.midi) != pmNoError):             # <<<<<<<<<<<<<<
 * 
 *             err = Pm_Read(self.midi,buffer,1)
 */
  while (1) {
    __pyx_t_4 = (Pm_Poll(((struct __pyx_obj_4pypm_Input *)__pyx_v_self)->midi) != pmNoError);
    if (!__pyx_t_4) break;

    /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":478
 *         while(Pm_Poll(self.midi) != pmNoError):
 * 
 *             err = Pm_Read(self.midi,buffer,1)             # <<<<<<<<<<<<<<
 *             if err < 0: raise Exception, Pm_GetErrorText(err)
 * 
 */
    __pyx_v_err = Pm_Read(((struct __pyx_obj_4pypm_Input *)__pyx_v_self)->midi, __pyx_v_buffer, 1);

    /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":479
 * 
 *             err = Pm_Read(self.midi,buffer,1)
 *             if err < 0: raise Exception, Pm_GetErrorText(err)             # <<<<<<<<<<<<<<
 * 
 *     def SetChannelMask(self, mask):
 */
    __pyx_t_4 = (__pyx_v_err < 0);
    if (__pyx_t_4) {
      __pyx_t_2 = __Pyx_PyBytes_FromString(Pm_GetErrorText(__pyx_v_err)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_Raise(__pyx_builtin_Exception, __pyx_t_2, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L8;
    }
    __pyx_L8:;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pypm.Input.SetFilter");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":481
 *             if err < 0: raise Exception, Pm_GetErrorText(err)
 * 
 *     def SetChannelMask(self, mask):             # <<<<<<<<<<<<<<
 *         """
 *     SetChannelMask(<mask>) filters incoming messages based on channel.
 */

static PyObject *__pyx_pf_4pypm_5Input_SetChannelMask(PyObject *__pyx_v_self, PyObject *__pyx_v_mask); /*proto*/
static char __pyx_doc_4pypm_5Input_SetChannelMask[] = "\n    SetChannelMask(<mask>) filters incoming messages based on channel.\n    The mask is a 16-bit bitfield corresponding to appropriate channels\n    Channel(<channel>) can assist in calling this function.\n    i.e. to set receive only input on channel 1, call with\n    SetChannelMask(Channel(1))\n    Multiple channels should be OR'd together, like\n    SetChannelMask(Channel(10) | Channel(11))\n    note: PyPortMidi Channel function has been altered from\n          the original PortMidi c call to correct for what\n          seems to be a bug --- i.e. channel filters were\n          all numbered from 0 to 15 instead of 1 to 16.\n        ";
static PyObject *__pyx_pf_4pypm_5Input_SetChannelMask(PyObject *__pyx_v_self, PyObject *__pyx_v_mask) {
  PmError __pyx_v_err;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  __Pyx_SetupRefcountContext("SetChannelMask");

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":497
 *         cdef PmError err
 * 
 *         self._check_open()             # <<<<<<<<<<<<<<
 * 
 *         err = Pm_SetChannelMask(self.midi,mask)
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_kp__check_open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":499
 *         self._check_open()
 * 
 *         err = Pm_SetChannelMask(self.midi,mask)             # <<<<<<<<<<<<<<
 *         if err < 0: raise Exception, Pm_GetErrorText(err)
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_v_mask); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_err = Pm_SetChannelMask(((struct __pyx_obj_4pypm_Input *)__pyx_v_self)->midi, __pyx_t_3);

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":500
 * 
 *         err = Pm_SetChannelMask(self.midi,mask)
 *         if err < 0: raise Exception, Pm_GetErrorText(err)             # <<<<<<<<<<<<<<
 * 
 *     def Poll(self):
 */
  __pyx_t_4 = (__pyx_v_err < 0);
  if (__pyx_t_4) {
    __pyx_t_2 = __Pyx_PyBytes_FromString(Pm_GetErrorText(__pyx_v_err)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_builtin_Exception, __pyx_t_2, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pypm.Input.SetChannelMask");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":502
 *         if err < 0: raise Exception, Pm_GetErrorText(err)
 * 
 *     def Poll(self):             # <<<<<<<<<<<<<<
 *         """
 *     Poll tests whether input is available,
 */

static PyObject *__pyx_pf_4pypm_5Input_Poll(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_4pypm_5Input_Poll[] = "\n    Poll tests whether input is available,\n    returning TRUE, FALSE, or an error value.\n        ";
static PyObject *__pyx_pf_4pypm_5Input_Poll(PyObject *__pyx_v_self, PyObject *unused) {
  PmError __pyx_v_err;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  __Pyx_SetupRefcountContext("Poll");

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":508
 *         """
 *         cdef PmError err
 *         self._check_open()             # <<<<<<<<<<<<<<
 * 
 *         err = Pm_Poll(self.midi)
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_kp__check_open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":510
 *         self._check_open()
 * 
 *         err = Pm_Poll(self.midi)             # <<<<<<<<<<<<<<
 *         if err < 0: raise Exception, Pm_GetErrorText(err)
 *         return err
 */
  __pyx_v_err = Pm_Poll(((struct __pyx_obj_4pypm_Input *)__pyx_v_self)->midi);

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":511
 * 
 *         err = Pm_Poll(self.midi)
 *         if err < 0: raise Exception, Pm_GetErrorText(err)             # <<<<<<<<<<<<<<
 *         return err
 * 
 */
  __pyx_t_3 = (__pyx_v_err < 0);
  if (__pyx_t_3) {
    __pyx_t_2 = __Pyx_PyBytes_FromString(Pm_GetErrorText(__pyx_v_err)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_builtin_Exception, __pyx_t_2, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":512
 *         err = Pm_Poll(self.midi)
 *         if err < 0: raise Exception, Pm_GetErrorText(err)
 *         return err             # <<<<<<<<<<<<<<
 * 
 *     def Read(self,length):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyInt_FromLong(__pyx_v_err); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pypm.Input.Poll");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":514
 *         return err
 * 
 *     def Read(self,length):             # <<<<<<<<<<<<<<
 *         """
 * Read(length): returns up to <length> midi events stored in
 */

static PyObject *__pyx_pf_4pypm_5Input_Read(PyObject *__pyx_v_self, PyObject *__pyx_v_length); /*proto*/
static char __pyx_doc_4pypm_5Input_Read[] = "\nRead(length): returns up to <length> midi events stored in\nthe buffer and returns them as a list:\n[[[status,data1,data2,data3],timestamp],\n [[status,data1,data2,data3],timestamp],...]\nexample: Read(50) returns all the events in the buffer,\n         up to 50 events.\n        ";
static PyObject *__pyx_pf_4pypm_5Input_Read(PyObject *__pyx_v_self, PyObject *__pyx_v_length) {
  PmEvent __pyx_v_buffer[1024];
  PyObject *__pyx_v_x;
  PyObject *__pyx_v_NumEvents;
  PyObject *__pyx_v_loop;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  long __pyx_t_4;
  PmError __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  __Pyx_SetupRefcountContext("Read");
  __pyx_v_x = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_NumEvents = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_loop = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":525
 *         cdef PmEvent buffer[1024]
 * 
 *         self._check_open()             # <<<<<<<<<<<<<<
 * 
 *         x = []
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_kp__check_open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":527
 *         self._check_open()
 * 
 *         x = []             # <<<<<<<<<<<<<<
 * 
 *         if length > 1024: raise IndexError, 'maximum buffer length is 1024'
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_DECREF(__pyx_v_x);
  __pyx_v_x = ((PyObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":529
 *         x = []
 * 
 *         if length > 1024: raise IndexError, 'maximum buffer length is 1024'             # <<<<<<<<<<<<<<
 *         if length < 1: raise IndexError, 'minimum buffer length is 1'
 *         NumEvents = Pm_Read(self.midi,buffer,length)
 */
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_length, __pyx_int_1024, Py_GT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {
    __Pyx_Raise(__pyx_builtin_IndexError, __pyx_kp_23, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":530
 * 
 *         if length > 1024: raise IndexError, 'maximum buffer length is 1024'
 *         if length < 1: raise IndexError, 'minimum buffer length is 1'             # <<<<<<<<<<<<<<
 *         NumEvents = Pm_Read(self.midi,buffer,length)
 *         if NumEvents < 0: raise Exception, Pm_GetErrorText(NumEvents)
 */
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_length, __pyx_int_1, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {
    __Pyx_Raise(__pyx_builtin_IndexError, __pyx_kp_24, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":531
 *         if length > 1024: raise IndexError, 'maximum buffer length is 1024'
 *         if length < 1: raise IndexError, 'minimum buffer length is 1'
 *         NumEvents = Pm_Read(self.midi,buffer,length)             # <<<<<<<<<<<<<<
 *         if NumEvents < 0: raise Exception, Pm_GetErrorText(NumEvents)
 *         x=[]
 */
  __pyx_t_4 = __Pyx_PyInt_AsLong(__pyx_v_length); if (unlikely((__pyx_t_4 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyInt_FromLong(Pm_Read(((struct __pyx_obj_4pypm_Input *)__pyx_v_self)->midi, __pyx_v_buffer, __pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_v_NumEvents);
  __pyx_v_NumEvents = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":532
 *         if length < 1: raise IndexError, 'minimum buffer length is 1'
 *         NumEvents = Pm_Read(self.midi,buffer,length)
 *         if NumEvents < 0: raise Exception, Pm_GetErrorText(NumEvents)             # <<<<<<<<<<<<<<
 *         x=[]
 *         if NumEvents >= 1:
 */
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_NumEvents, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {
    __pyx_t_5 = ((PmError)PyInt_AsLong(__pyx_v_NumEvents)); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __Pyx_PyBytes_FromString(Pm_GetErrorText(__pyx_t_5)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_builtin_Exception, __pyx_t_2, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":533
 *         NumEvents = Pm_Read(self.midi,buffer,length)
 *         if NumEvents < 0: raise Exception, Pm_GetErrorText(NumEvents)
 *         x=[]             # <<<<<<<<<<<<<<
 *         if NumEvents >= 1:
 *             for loop in range(NumEvents):
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_DECREF(__pyx_v_x);
  __pyx_v_x = ((PyObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":534
 *         if NumEvents < 0: raise Exception, Pm_GetErrorText(NumEvents)
 *         x=[]
 *         if NumEvents >= 1:             # <<<<<<<<<<<<<<
 *             for loop in range(NumEvents):
 *                  x.append([[buffer[loop].message & 0xff, (buffer[loop].message >> 8) & 0xFF, (buffer[loop].message >> 16) & 0xFF, (buffer[loop].message >> 24) & 0xFF], buffer[loop].timestamp])
 */
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_NumEvents, __pyx_int_1, Py_GE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":535
 *         x=[]
 *         if NumEvents >= 1:
 *             for loop in range(NumEvents):             # <<<<<<<<<<<<<<
 *                  x.append([[buffer[loop].message & 0xff, (buffer[loop].message >> 8) & 0xFF, (buffer[loop].message >> 16) & 0xFF, (buffer[loop].message >> 24) & 0xFF], buffer[loop].timestamp])
 *         return x
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_INCREF(__pyx_v_NumEvents);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_NumEvents);
    __Pyx_GIVEREF(__pyx_v_NumEvents);
    __pyx_t_1 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) {
      __pyx_t_6 = 0; __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2);
    } else {
      __pyx_t_6 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (;;) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_2)) break;
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++;
      } else if (likely(PyTuple_CheckExact(__pyx_t_2))) {
        if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++;
      } else {
        __pyx_t_1 = PyIter_Next(__pyx_t_2);
        if (!__pyx_t_1) {
          if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_DECREF(__pyx_v_loop);
      __pyx_v_loop = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":536
 *         if NumEvents >= 1:
 *             for loop in range(NumEvents):
 *                  x.append([[buffer[loop].message & 0xff, (buffer[loop].message >> 8) & 0xFF, (buffer[loop].message >> 16) & 0xFF, (buffer[loop].message >> 24) & 0xFF], buffer[loop].timestamp])             # <<<<<<<<<<<<<<
 *         return x
 */
      __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_v_loop); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = PyInt_FromLong(((__pyx_v_buffer[__pyx_t_7]).message & 0xff)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_v_loop); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_8 = PyInt_FromLong((((__pyx_v_buffer[__pyx_t_7]).message >> 8) & 0xFF)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_v_loop); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_9 = PyInt_FromLong((((__pyx_v_buffer[__pyx_t_7]).message >> 16) & 0xFF)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_v_loop); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = PyInt_FromLong((((__pyx_v_buffer[__pyx_t_7]).message >> 24) & 0xFF)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_11 = PyList_New(4); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_11));
      PyList_SET_ITEM(__pyx_t_11, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      PyList_SET_ITEM(__pyx_t_11, 1, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_8);
      PyList_SET_ITEM(__pyx_t_11, 2, __pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_9);
      PyList_SET_ITEM(__pyx_t_11, 3, __pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_10);
      __pyx_t_1 = 0;
      __pyx_t_8 = 0;
      __pyx_t_9 = 0;
      __pyx_t_10 = 0;
      __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_v_loop); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = PyInt_FromLong((__pyx_v_buffer[__pyx_t_7]).timestamp); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_9 = PyList_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_9));
      PyList_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_t_11));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_11));
      PyList_SET_ITEM(__pyx_t_9, 1, __pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_10);
      __pyx_t_11 = 0;
      __pyx_t_10 = 0;
      __pyx_t_10 = __Pyx_PyObject_Append(__pyx_v_x, ((PyObject *)__pyx_t_9)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":537
 *             for loop in range(NumEvents):
 *                  x.append([[buffer[loop].message & 0xff, (buffer[loop].message >> 8) & 0xFF, (buffer[loop].message >> 16) & 0xFF, (buffer[loop].message >> 24) & 0xFF], buffer[loop].timestamp])
 *         return x             # <<<<<<<<<<<<<<
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_x);
  __pyx_r = __pyx_v_x;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("pypm.Input.Read");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_x);
  __Pyx_DECREF(__pyx_v_NumEvents);
  __Pyx_DECREF(__pyx_v_loop);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

static PyObject *__pyx_tp_new_4pypm_Output(PyTypeObject *t, PyObject *a, PyObject *k) {
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  return o;
}

static void __pyx_tp_dealloc_4pypm_Output(PyObject *o) {
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pf_4pypm_6Output___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  (*Py_TYPE(o)->tp_free)(o);
}

static struct PyMethodDef __pyx_methods_4pypm_Output[] = {
  {__Pyx_NAMESTR("_check_open"), (PyCFunction)__pyx_pf_4pypm_6Output__check_open, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_4pypm_6Output__check_open)},
  {__Pyx_NAMESTR("Close"), (PyCFunction)__pyx_pf_4pypm_6Output_Close, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_4pypm_6Output_Close)},
  {__Pyx_NAMESTR("Abort"), (PyCFunction)__pyx_pf_4pypm_6Output_Abort, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_4pypm_6Output_Abort)},
  {__Pyx_NAMESTR("Write"), (PyCFunction)__pyx_pf_4pypm_6Output_Write, METH_O, __Pyx_DOCSTR(__pyx_doc_4pypm_6Output_Write)},
  {__Pyx_NAMESTR("WriteShort"), (PyCFunction)__pyx_pf_4pypm_6Output_WriteShort, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_4pypm_6Output_WriteShort)},
  {__Pyx_NAMESTR("WriteSysEx"), (PyCFunction)__pyx_pf_4pypm_6Output_WriteSysEx, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_4pypm_6Output_WriteSysEx)},
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_Output = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION >= 3
  0, /*reserved*/
  #else
  0, /*nb_long*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX)
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_Output = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_Output = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_Output = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_4pypm_Output = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pypm.Output"), /*tp_name*/
  sizeof(struct __pyx_obj_4pypm_Output), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_4pypm_Output, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_Output, /*tp_as_number*/
  &__pyx_tp_as_sequence_Output, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_Output, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_Output, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/
  __Pyx_DOCSTR("\nclass Output:\n    define an output MIDI stream. Takes the form:\n        x = pypm.Output(MidiOutputDevice, latency)\n    latency is in ms.\n    If latency = 0 then timestamps for output are ignored.\n    "), /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_4pypm_Output, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_4pypm_6Output___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_4pypm_Output, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
};

static PyObject *__pyx_tp_new_4pypm_Input(PyTypeObject *t, PyObject *a, PyObject *k) {
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  return o;
}

static void __pyx_tp_dealloc_4pypm_Input(PyObject *o) {
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pf_4pypm_5Input___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  (*Py_TYPE(o)->tp_free)(o);
}

static struct PyMethodDef __pyx_methods_4pypm_Input[] = {
  {__Pyx_NAMESTR("_check_open"), (PyCFunction)__pyx_pf_4pypm_5Input__check_open, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_4pypm_5Input__check_open)},
  {__Pyx_NAMESTR("Close"), (PyCFunction)__pyx_pf_4pypm_5Input_Close, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_4pypm_5Input_Close)},
  {__Pyx_NAMESTR("SetFilter"), (PyCFunction)__pyx_pf_4pypm_5Input_SetFilter, METH_O, __Pyx_DOCSTR(__pyx_doc_4pypm_5Input_SetFilter)},
  {__Pyx_NAMESTR("SetChannelMask"), (PyCFunction)__pyx_pf_4pypm_5Input_SetChannelMask, METH_O, __Pyx_DOCSTR(__pyx_doc_4pypm_5Input_SetChannelMask)},
  {__Pyx_NAMESTR("Poll"), (PyCFunction)__pyx_pf_4pypm_5Input_Poll, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_4pypm_5Input_Poll)},
  {__Pyx_NAMESTR("Read"), (PyCFunction)__pyx_pf_4pypm_5Input_Read, METH_O, __Pyx_DOCSTR(__pyx_doc_4pypm_5Input_Read)},
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_Input = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION >= 3
  0, /*reserved*/
  #else
  0, /*nb_long*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX)
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_Input = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_Input = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_Input = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_4pypm_Input = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pypm.Input"), /*tp_name*/
  sizeof(struct __pyx_obj_4pypm_Input), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_4pypm_Input, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_Input, /*tp_as_number*/
  &__pyx_tp_as_sequence_Input, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_Input, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_Input, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/
  __Pyx_DOCSTR("\nclass Input:\n    define an input MIDI stream. Takes the form:\n        x = pypm.Input(MidiInputDevice)\n    "), /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_4pypm_Input, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_4pypm_5Input___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_4pypm_Input, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
};

static struct PyMethodDef __pyx_methods[] = {
  {__Pyx_NAMESTR("Initialize"), (PyCFunction)__pyx_pf_4pypm_Initialize, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_4pypm_Initialize)},
  {__Pyx_NAMESTR("Terminate"), (PyCFunction)__pyx_pf_4pypm_Terminate, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_4pypm_Terminate)},
  {__Pyx_NAMESTR("GetDefaultInputDeviceID"), (PyCFunction)__pyx_pf_4pypm_GetDefaultInputDeviceID, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("GetDefaultOutputDeviceID"), (PyCFunction)__pyx_pf_4pypm_GetDefaultOutputDeviceID, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("CountDevices"), (PyCFunction)__pyx_pf_4pypm_CountDevices, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("GetDeviceInfo"), (PyCFunction)__pyx_pf_4pypm_GetDeviceInfo, METH_O, __Pyx_DOCSTR(__pyx_doc_4pypm_GetDeviceInfo)},
  {__Pyx_NAMESTR("Time"), (PyCFunction)__pyx_pf_4pypm_Time, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_4pypm_Time)},
  {__Pyx_NAMESTR("GetErrorText"), (PyCFunction)__pyx_pf_4pypm_GetErrorText, METH_O, __Pyx_DOCSTR(__pyx_doc_4pypm_GetErrorText)},
  {__Pyx_NAMESTR("Channel"), (PyCFunction)__pyx_pf_4pypm_Channel, METH_O, __Pyx_DOCSTR(__pyx_doc_4pypm_Channel)},
  {0, 0, 0, 0}
};

static void __pyx_init_filenames(void); /*proto*/

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    __Pyx_NAMESTR("pypm"),
    0, /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp___main__, __pyx_k___main__, sizeof(__pyx_k___main__), 1, 1, 1},
  {&__pyx_kp___init__, __pyx_k___init__, sizeof(__pyx_k___init__), 1, 1, 1},
  {&__pyx_kp___dealloc__, __pyx_k___dealloc__, sizeof(__pyx_k___dealloc__), 1, 1, 1},
  {&__pyx_kp__check_open, __pyx_k__check_open, sizeof(__pyx_k__check_open), 1, 1, 1},
  {&__pyx_kp_Close, __pyx_k_Close, sizeof(__pyx_k_Close), 1, 1, 1},
  {&__pyx_kp_Abort, __pyx_k_Abort, sizeof(__pyx_k_Abort), 1, 1, 1},
  {&__pyx_kp_Write, __pyx_k_Write, sizeof(__pyx_k_Write), 1, 1, 1},
  {&__pyx_kp_WriteShort, __pyx_k_WriteShort, sizeof(__pyx_k_WriteShort), 1, 1, 1},
  {&__pyx_kp_WriteSysEx, __pyx_k_WriteSysEx, sizeof(__pyx_k_WriteSysEx), 1, 1, 1},
  {&__pyx_kp_SetFilter, __pyx_k_SetFilter, sizeof(__pyx_k_SetFilter), 1, 1, 1},
  {&__pyx_kp_SetChannelMask, __pyx_k_SetChannelMask, sizeof(__pyx_k_SetChannelMask), 1, 1, 1},
  {&__pyx_kp_Poll, __pyx_k_Poll, sizeof(__pyx_k_Poll), 1, 1, 1},
  {&__pyx_kp_Read, __pyx_k_Read, sizeof(__pyx_k_Read), 1, 1, 1},
  {&__pyx_kp_i, __pyx_k_i, sizeof(__pyx_k_i), 1, 1, 1},
  {&__pyx_kp_err, __pyx_k_err, sizeof(__pyx_k_err), 1, 1, 1},
  {&__pyx_kp_chan, __pyx_k_chan, sizeof(__pyx_k_chan), 1, 1, 1},
  {&__pyx_kp_OutputDevice, __pyx_k_OutputDevice, sizeof(__pyx_k_OutputDevice), 1, 1, 1},
  {&__pyx_kp_latency, __pyx_k_latency, sizeof(__pyx_k_latency), 1, 1, 1},
  {&__pyx_kp_data, __pyx_k_data, sizeof(__pyx_k_data), 1, 1, 1},
  {&__pyx_kp_status, __pyx_k_status, sizeof(__pyx_k_status), 1, 1, 1},
  {&__pyx_kp_1, __pyx_k_1, sizeof(__pyx_k_1), 1, 1, 1},
  {&__pyx_kp_2, __pyx_k_2, sizeof(__pyx_k_2), 1, 1, 1},
  {&__pyx_kp_when, __pyx_k_when, sizeof(__pyx_k_when), 1, 1, 1},
  {&__pyx_kp_msg, __pyx_k_msg, sizeof(__pyx_k_msg), 1, 1, 1},
  {&__pyx_kp_InputDevice, __pyx_k_InputDevice, sizeof(__pyx_k_InputDevice), 1, 1, 1},
  {&__pyx_kp_buffersize, __pyx_k_buffersize, sizeof(__pyx_k_buffersize), 1, 1, 1},
  {&__pyx_kp_filters, __pyx_k_filters, sizeof(__pyx_k_filters), 1, 1, 1},
  {&__pyx_kp_mask, __pyx_k_mask, sizeof(__pyx_k_mask), 1, 1, 1},
  {&__pyx_kp_length, __pyx_k_length, sizeof(__pyx_k_length), 1, 1, 1},
  {&__pyx_kp___version__, __pyx_k___version__, sizeof(__pyx_k___version__), 1, 1, 1},
  {&__pyx_kp_array, __pyx_k_array, sizeof(__pyx_k_array), 1, 1, 1},
  {&__pyx_kp_FILT_ACTIVE, __pyx_k_FILT_ACTIVE, sizeof(__pyx_k_FILT_ACTIVE), 1, 1, 1},
  {&__pyx_kp_FILT_SYSEX, __pyx_k_FILT_SYSEX, sizeof(__pyx_k_FILT_SYSEX), 1, 1, 1},
  {&__pyx_kp_FILT_CLOCK, __pyx_k_FILT_CLOCK, sizeof(__pyx_k_FILT_CLOCK), 1, 1, 1},
  {&__pyx_kp_FILT_PLAY, __pyx_k_FILT_PLAY, sizeof(__pyx_k_FILT_PLAY), 1, 1, 1},
  {&__pyx_kp_4, __pyx_k_4, sizeof(__pyx_k_4), 1, 1, 1},
  {&__pyx_kp_FILT_TICK, __pyx_k_FILT_TICK, sizeof(__pyx_k_FILT_TICK), 1, 1, 1},
  {&__pyx_kp_FILT_FD, __pyx_k_FILT_FD, sizeof(__pyx_k_FILT_FD), 1, 1, 1},
  {&__pyx_kp_FILT_UNDEFINED, __pyx_k_FILT_UNDEFINED, sizeof(__pyx_k_FILT_UNDEFINED), 1, 1, 1},
  {&__pyx_kp_FILT_RESET, __pyx_k_FILT_RESET, sizeof(__pyx_k_FILT_RESET), 1, 1, 1},
  {&__pyx_kp_FILT_REALTIME, __pyx_k_FILT_REALTIME, sizeof(__pyx_k_FILT_REALTIME), 1, 1, 1},
  {&__pyx_kp_FILT_NOTE, __pyx_k_FILT_NOTE, sizeof(__pyx_k_FILT_NOTE), 1, 1, 1},
  {&__pyx_kp_5, __pyx_k_5, sizeof(__pyx_k_5), 1, 1, 1},
  {&__pyx_kp_6, __pyx_k_6, sizeof(__pyx_k_6), 1, 1, 1},
  {&__pyx_kp_FILT_AFTERTOUCH, __pyx_k_FILT_AFTERTOUCH, sizeof(__pyx_k_FILT_AFTERTOUCH), 1, 1, 1},
  {&__pyx_kp_FILT_PROGRAM, __pyx_k_FILT_PROGRAM, sizeof(__pyx_k_FILT_PROGRAM), 1, 1, 1},
  {&__pyx_kp_FILT_CONTROL, __pyx_k_FILT_CONTROL, sizeof(__pyx_k_FILT_CONTROL), 1, 1, 1},
  {&__pyx_kp_FILT_PITCHBEND, __pyx_k_FILT_PITCHBEND, sizeof(__pyx_k_FILT_PITCHBEND), 1, 1, 1},
  {&__pyx_kp_FILT_MTC, __pyx_k_FILT_MTC, sizeof(__pyx_k_FILT_MTC), 1, 1, 1},
  {&__pyx_kp_FILT_SONG_POSITION, __pyx_k_FILT_SONG_POSITION, sizeof(__pyx_k_FILT_SONG_POSITION), 1, 1, 1},
  {&__pyx_kp_FILT_SONG_SELECT, __pyx_k_FILT_SONG_SELECT, sizeof(__pyx_k_FILT_SONG_SELECT), 1, 1, 1},
  {&__pyx_kp_FILT_TUNE, __pyx_k_FILT_TUNE, sizeof(__pyx_k_FILT_TUNE), 1, 1, 1},
  {&__pyx_kp_FALSE, __pyx_k_FALSE, sizeof(__pyx_k_FALSE), 1, 1, 1},
  {&__pyx_kp_TRUE, __pyx_k_TRUE, sizeof(__pyx_k_TRUE), 1, 1, 1},
  {&__pyx_kp_Exception, __pyx_k_Exception, sizeof(__pyx_k_Exception), 1, 1, 1},
  {&__pyx_kp_IndexError, __pyx_k_IndexError, sizeof(__pyx_k_IndexError), 1, 1, 1},
  {&__pyx_kp_range, __pyx_k_range, sizeof(__pyx_k_range), 1, 1, 1},
  {&__pyx_kp_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 1, 0},
  {&__pyx_kp_tostring, __pyx_k_tostring, sizeof(__pyx_k_tostring), 1, 1, 1},
  {&__pyx_kp_append, __pyx_k_append, sizeof(__pyx_k_append), 1, 1, 1},
  {&__pyx_kp_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 0},
  {&__pyx_kp_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 0},
  {&__pyx_kp_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 0},
  {&__pyx_kp_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 0},
  {&__pyx_kp_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 0},
  {&__pyx_kp_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 0},
  {&__pyx_kp_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 0, 0},
  {&__pyx_kp_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 0},
  {&__pyx_kp_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 0},
  {&__pyx_kp_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 0},
  {&__pyx_kp_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 0},
  {&__pyx_kp_17, __pyx_k_17, sizeof(__pyx_k_17), 0, 0, 0},
  {&__pyx_kp_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 0},
  {&__pyx_kp_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 0, 0},
  {&__pyx_kp_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 0},
  {&__pyx_kp_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 0},
  {&__pyx_kp_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 0, 0},
  {&__pyx_kp_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 0},
  {0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_Exception = __Pyx_GetName(__pyx_b, __pyx_kp_Exception); if (!__pyx_builtin_Exception) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_kp_IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_kp_range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitGlobals(void) {
  __pyx_int_0x1 = PyInt_FromLong(0x1); if (unlikely(!__pyx_int_0x1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x2 = PyInt_FromLong(0x2); if (unlikely(!__pyx_int_0x2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x4 = PyInt_FromLong(0x4); if (unlikely(!__pyx_int_0x4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x8 = PyInt_FromLong(0x8); if (unlikely(!__pyx_int_0x8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x10 = PyInt_FromLong(0x10); if (unlikely(!__pyx_int_0x10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x20 = PyInt_FromLong(0x20); if (unlikely(!__pyx_int_0x20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x30 = PyInt_FromLong(0x30); if (unlikely(!__pyx_int_0x30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x40 = PyInt_FromLong(0x40); if (unlikely(!__pyx_int_0x40)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x7F = PyInt_FromLong(0x7F); if (unlikely(!__pyx_int_0x7F)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x80 = PyInt_FromLong(0x80); if (unlikely(!__pyx_int_0x80)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x100 = PyInt_FromLong(0x100); if (unlikely(!__pyx_int_0x100)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x200 = PyInt_FromLong(0x200); if (unlikely(!__pyx_int_0x200)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x300 = PyInt_FromLong(0x300); if (unlikely(!__pyx_int_0x300)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x400 = PyInt_FromLong(0x400); if (unlikely(!__pyx_int_0x400)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x800 = PyInt_FromLong(0x800); if (unlikely(!__pyx_int_0x800)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x1000 = PyInt_FromLong(0x1000); if (unlikely(!__pyx_int_0x1000)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x2000 = PyInt_FromLong(0x2000); if (unlikely(!__pyx_int_0x2000)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x4000 = PyInt_FromLong(0x4000); if (unlikely(!__pyx_int_0x4000)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x8000 = PyInt_FromLong(0x8000); if (unlikely(!__pyx_int_0x8000)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x10000 = PyInt_FromLong(0x10000); if (unlikely(!__pyx_int_0x10000)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_4096 = PyInt_FromLong(4096); if (unlikely(!__pyx_int_4096)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0xFF = PyInt_FromLong(0xFF); if (unlikely(!__pyx_int_0xFF)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_16 = PyInt_FromLong(16); if (unlikely(!__pyx_int_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0xFF0000 = PyInt_FromLong(0xFF0000); if (unlikely(!__pyx_int_0xFF0000)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_8 = PyInt_FromLong(8); if (unlikely(!__pyx_int_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0xFF00 = PyInt_FromLong(0xFF00); if (unlikely(!__pyx_int_0xFF00)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_1024 = PyInt_FromLong(1024); if (unlikely(!__pyx_int_1024)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initpypm(void); /*proto*/
PyMODINIT_FUNC initpypm(void)
#else
PyMODINIT_FUNC PyInit_pypm(void); /*proto*/
PyMODINIT_FUNC PyInit_pypm(void)
#endif
{
  PyObject *__pyx_1 = 0;
  #ifdef CYTHON_REFNANNY
  void* __pyx_refchk = NULL;
  __Pyx_Refnanny = __Pyx_ImportRefcountAPI("refnanny");
  if (!__Pyx_Refnanny) {
      PyErr_Clear();
      __Pyx_Refnanny = __Pyx_ImportRefcountAPI("Cython.Runtime.refnanny");
      if (!__Pyx_Refnanny)
          Py_FatalError("failed to import refnanny module");
  }
  __pyx_refchk = __Pyx_Refnanny->NewContext("PyMODINIT_FUNC PyInit_pypm(void)", __LINE__, __FILE__);
  #endif
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Library function declarations ---*/
  __pyx_init_filenames();
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4(__Pyx_NAMESTR("pypm"), __pyx_methods, 0, 0, PYTHON_API_VERSION);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  #if PY_MAJOR_VERSION < 3
  Py_INCREF(__pyx_m);
  #endif
  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__pyx_module_is_main_pypm) {
    if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_kp___main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_skip_dispatch = 0;
  /*--- Global init code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  if (PyType_Ready(&__pyx_type_4pypm_Output) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "Output", (PyObject *)&__pyx_type_4pypm_Output) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_4pypm_Output = &__pyx_type_4pypm_Output;
  if (PyType_Ready(&__pyx_type_4pypm_Input) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "Input", (PyObject *)&__pyx_type_4pypm_Input) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_4pypm_Input = &__pyx_type_4pypm_Input;
  /*--- Type import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":7
 * # harrison@media.mit.edu
 * # written in Pyrex
 * __version__="0.05"             # <<<<<<<<<<<<<<
 * 
 * import array
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp___version__, __pyx_kp_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":9
 * __version__="0.05"
 * 
 * import array             # <<<<<<<<<<<<<<
 * 
 * # CHANGES:
 */
  __pyx_1 = __Pyx_Import(__pyx_kp_array, 0); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_array, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":108
 *     PtTimestamp Pt_Time()
 * 
 * FILT_ACTIVE=0x1             # <<<<<<<<<<<<<<
 * FILT_SYSEX=0x2
 * FILT_CLOCK=0x4
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FILT_ACTIVE, __pyx_int_0x1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":109
 * 
 * FILT_ACTIVE=0x1
 * FILT_SYSEX=0x2             # <<<<<<<<<<<<<<
 * FILT_CLOCK=0x4
 * FILT_PLAY=0x8
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FILT_SYSEX, __pyx_int_0x2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":110
 * FILT_ACTIVE=0x1
 * FILT_SYSEX=0x2
 * FILT_CLOCK=0x4             # <<<<<<<<<<<<<<
 * FILT_PLAY=0x8
 * FILT_F9=0x10
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FILT_CLOCK, __pyx_int_0x4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":111
 * FILT_SYSEX=0x2
 * FILT_CLOCK=0x4
 * FILT_PLAY=0x8             # <<<<<<<<<<<<<<
 * FILT_F9=0x10
 * FILT_TICK=0x10
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FILT_PLAY, __pyx_int_0x8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":112
 * FILT_CLOCK=0x4
 * FILT_PLAY=0x8
 * FILT_F9=0x10             # <<<<<<<<<<<<<<
 * FILT_TICK=0x10
 * FILT_FD=0x20
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_4, __pyx_int_0x10) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":113
 * FILT_PLAY=0x8
 * FILT_F9=0x10
 * FILT_TICK=0x10             # <<<<<<<<<<<<<<
 * FILT_FD=0x20
 * FILT_UNDEFINED=0x30
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FILT_TICK, __pyx_int_0x10) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":114
 * FILT_F9=0x10
 * FILT_TICK=0x10
 * FILT_FD=0x20             # <<<<<<<<<<<<<<
 * FILT_UNDEFINED=0x30
 * FILT_RESET=0x40
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FILT_FD, __pyx_int_0x20) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":115
 * FILT_TICK=0x10
 * FILT_FD=0x20
 * FILT_UNDEFINED=0x30             # <<<<<<<<<<<<<<
 * FILT_RESET=0x40
 * FILT_REALTIME=0x7F
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FILT_UNDEFINED, __pyx_int_0x30) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":116
 * FILT_FD=0x20
 * FILT_UNDEFINED=0x30
 * FILT_RESET=0x40             # <<<<<<<<<<<<<<
 * FILT_REALTIME=0x7F
 * FILT_NOTE=0x80
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FILT_RESET, __pyx_int_0x40) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":117
 * FILT_UNDEFINED=0x30
 * FILT_RESET=0x40
 * FILT_REALTIME=0x7F             # <<<<<<<<<<<<<<
 * FILT_NOTE=0x80
 * FILT_CHANNEL_AFTERTOUCH=0x100
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FILT_REALTIME, __pyx_int_0x7F) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":118
 * FILT_RESET=0x40
 * FILT_REALTIME=0x7F
 * FILT_NOTE=0x80             # <<<<<<<<<<<<<<
 * FILT_CHANNEL_AFTERTOUCH=0x100
 * FILT_POLY_AFTERTOUCH=0x200
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FILT_NOTE, __pyx_int_0x80) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":119
 * FILT_REALTIME=0x7F
 * FILT_NOTE=0x80
 * FILT_CHANNEL_AFTERTOUCH=0x100             # <<<<<<<<<<<<<<
 * FILT_POLY_AFTERTOUCH=0x200
 * FILT_AFTERTOUCH=0x300
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_5, __pyx_int_0x100) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":120
 * FILT_NOTE=0x80
 * FILT_CHANNEL_AFTERTOUCH=0x100
 * FILT_POLY_AFTERTOUCH=0x200             # <<<<<<<<<<<<<<
 * FILT_AFTERTOUCH=0x300
 * FILT_PROGRAM=0x400
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_6, __pyx_int_0x200) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":121
 * FILT_CHANNEL_AFTERTOUCH=0x100
 * FILT_POLY_AFTERTOUCH=0x200
 * FILT_AFTERTOUCH=0x300             # <<<<<<<<<<<<<<
 * FILT_PROGRAM=0x400
 * FILT_CONTROL=0x800
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FILT_AFTERTOUCH, __pyx_int_0x300) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":122
 * FILT_POLY_AFTERTOUCH=0x200
 * FILT_AFTERTOUCH=0x300
 * FILT_PROGRAM=0x400             # <<<<<<<<<<<<<<
 * FILT_CONTROL=0x800
 * FILT_PITCHBEND=0x1000
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FILT_PROGRAM, __pyx_int_0x400) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":123
 * FILT_AFTERTOUCH=0x300
 * FILT_PROGRAM=0x400
 * FILT_CONTROL=0x800             # <<<<<<<<<<<<<<
 * FILT_PITCHBEND=0x1000
 * FILT_MTC=0x2000
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FILT_CONTROL, __pyx_int_0x800) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":124
 * FILT_PROGRAM=0x400
 * FILT_CONTROL=0x800
 * FILT_PITCHBEND=0x1000             # <<<<<<<<<<<<<<
 * FILT_MTC=0x2000
 * FILT_SONG_POSITION=0x4000
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FILT_PITCHBEND, __pyx_int_0x1000) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":125
 * FILT_CONTROL=0x800
 * FILT_PITCHBEND=0x1000
 * FILT_MTC=0x2000             # <<<<<<<<<<<<<<
 * FILT_SONG_POSITION=0x4000
 * FILT_SONG_SELECT=0x8000
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FILT_MTC, __pyx_int_0x2000) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":126
 * FILT_PITCHBEND=0x1000
 * FILT_MTC=0x2000
 * FILT_SONG_POSITION=0x4000             # <<<<<<<<<<<<<<
 * FILT_SONG_SELECT=0x8000
 * FILT_TUNE=0x10000
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FILT_SONG_POSITION, __pyx_int_0x4000) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":127
 * FILT_MTC=0x2000
 * FILT_SONG_POSITION=0x4000
 * FILT_SONG_SELECT=0x8000             # <<<<<<<<<<<<<<
 * FILT_TUNE=0x10000
 * FALSE=0
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FILT_SONG_SELECT, __pyx_int_0x8000) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":128
 * FILT_SONG_POSITION=0x4000
 * FILT_SONG_SELECT=0x8000
 * FILT_TUNE=0x10000             # <<<<<<<<<<<<<<
 * FALSE=0
 * TRUE=1
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FILT_TUNE, __pyx_int_0x10000) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":129
 * FILT_SONG_SELECT=0x8000
 * FILT_TUNE=0x10000
 * FALSE=0             # <<<<<<<<<<<<<<
 * TRUE=1
 * 
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_FALSE, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":130
 * FILT_TUNE=0x10000
 * FALSE=0
 * TRUE=1             # <<<<<<<<<<<<<<
 * 
 * def Initialize():
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_TRUE, __pyx_int_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/rene/dev/pygame/pygame/trunk/src/pypm.pyx":514
 *         return err
 * 
 *     def Read(self,length):             # <<<<<<<<<<<<<<
 *         """
 * Read(length): returns up to <length> midi events stored in
 */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __Pyx_AddTraceback("pypm");
  Py_DECREF(__pyx_m); __pyx_m = 0;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

static const char *__pyx_filenames[] = {
  "pypm.pyx",
};

/* Runtime support code */

static void __pyx_init_filenames(void) {
  __pyx_f = __pyx_filenames;
}

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AS_STRING(kw_name));
        #endif
}

static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *number, *more_or_less;

    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    number = (num_expected == 1) ? "" : "s";
    PyErr_Format(PyExc_TypeError,
        #if PY_VERSION_HEX < 0x02050000
            "%s() takes %s %d positional argument%s (%d given)",
        #else
            "%s() takes %s %zd positional argument%s (%zd given)",
        #endif
        func_name, more_or_less, num_expected, number, num_found);
}

static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;

    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
        } else {
            #if PY_MAJOR_VERSION < 3
            if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
            #else
            if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) {
            #endif
                goto invalid_keyword_type;
            } else {
                for (name = first_kw_arg; *name; name++) {
                    #if PY_MAJOR_VERSION >= 3
                    if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                        PyUnicode_Compare(**name, key) == 0) break;
                    #else
                    if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                        _PyString_Eq(**name, key)) break;
                    #endif
                }
                if (*name) {
                    values[name-argnames] = value;
                } else {
                    /* unexpected keyword found */
                    for (name=argnames; name != first_kw_arg; name++) {
                        if (**name == key) goto arg_passed_twice;
                        #if PY_MAJOR_VERSION >= 3
                        if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                            PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice;
                        #else
                        if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                            _PyString_Eq(**name, key)) goto arg_passed_twice;
                        #endif
                    }
                    if (kwds2) {
                        if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
                    } else {
                        goto invalid_keyword;
                    }
                }
            }
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, **name);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}


static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
    PyObject *__import__ = 0;
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    __import__ = __Pyx_GetAttrString(__pyx_b, "__import__");
    if (!__import__)
        goto bad;
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    module = PyObject_CallFunctionObjArgs(__import__,
        name, global_dict, empty_dict, list, NULL);
bad:
    Py_XDECREF(empty_list);
    Py_XDECREF(__import__);
    Py_XDECREF(empty_dict);
    return module;
}

#if PY_MAJOR_VERSION < 3
static PyObject *__Pyx_GetStdout(void) {
    PyObject *f = PySys_GetObject((char *)"stdout");
    if (!f) {
        PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
    }
    return f;
}

static int __Pyx_Print(PyObject *arg_tuple, int newline) {
    PyObject *f;
    PyObject* v;
    int i;

    if (!(f = __Pyx_GetStdout()))
        return -1;
    for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) {
        if (PyFile_SoftSpace(f, 1)) {
            if (PyFile_WriteString(" ", f) < 0)
                return -1;
        }
        v = PyTuple_GET_ITEM(arg_tuple, i);
        if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
            return -1;
        if (PyString_Check(v)) {
            char *s = PyString_AsString(v);
            Py_ssize_t len = PyString_Size(v);
            if (len > 0 &&
                isspace(Py_CHARMASK(s[len-1])) &&
                s[len-1] != ' ')
                    PyFile_SoftSpace(f, 0);
        }
    }
    if (newline) {
        if (PyFile_WriteString("\n", f) < 0)
            return -1;
        PyFile_SoftSpace(f, 0);
    }
    return 0;
}

#else /* Python 3 has a print function */

static int __Pyx_Print(PyObject *arg_tuple, int newline) {
    PyObject* kwargs = 0;
    PyObject* result = 0;
    PyObject* end_string;
    if (!__pyx_print) {
        __pyx_print = __Pyx_GetAttrString(__pyx_b, "print");
        if (!__pyx_print)
            return -1;
    }
    if (!newline) {
        if (!__pyx_print_kwargs) {
            __pyx_print_kwargs = PyDict_New();
            if (!__pyx_print_kwargs)
                return -1;
            end_string = PyUnicode_FromStringAndSize(" ", 1);
            if (!end_string)
                return -1;
            if (PyDict_SetItemString(__pyx_print_kwargs, "end", end_string) < 0) {
                Py_DECREF(end_string);
                return -1;
            }
            Py_DECREF(end_string);
        }
        kwargs = __pyx_print_kwargs;
    }
    result = PyObject_Call(__pyx_print, arg_tuple, kwargs);
    if (!result)
        return -1;
    Py_DECREF(result);
    return 0;
}

#endif

#if PY_MAJOR_VERSION < 3

static int __Pyx_PrintOne(PyObject *o) {
    PyObject *f;
    if (!(f = __Pyx_GetStdout()))
        return -1;
    if (PyFile_SoftSpace(f, 0)) {
        if (PyFile_WriteString(" ", f) < 0)
            return -1;
    }
    if (PyFile_WriteObject(o, f, Py_PRINT_RAW) < 0)
        return -1;
    if (PyFile_WriteString("\n", f) < 0)
        return -1;
    return 0;
    /* the line below is just to avoid compiler
     * compiler warnings about unused functions */
    return __Pyx_Print(NULL, 0);
}

#else /* Python 3 has a print function */

static int __Pyx_PrintOne(PyObject *o) {
    int res;
    PyObject* arg_tuple = PyTuple_New(1);
    if (unlikely(!arg_tuple))
        return -1;
    Py_INCREF(o);
    PyTuple_SET_ITEM(arg_tuple, 0, o);
    res = __Pyx_Print(arg_tuple, 1);
    Py_DECREF(arg_tuple);
    return res;
}

#endif

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
    PyObject *result;
    result = PyObject_GetAttr(dict, name);
    if (!result)
        PyErr_SetObject(PyExc_NameError, name);
    return result;
}

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    Py_XINCREF(type);
    Py_XINCREF(value);
    Py_XINCREF(tb);
    /* First, check the traceback argument, replacing None with NULL. */
    if (tb == Py_None) {
        Py_DECREF(tb);
        tb = 0;
    }
    else if (tb != NULL && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto raise_error;
    }
    /* Next, replace a missing value with None */
    if (value == NULL) {
        value = Py_None;
        Py_INCREF(value);
    }
    #if PY_VERSION_HEX < 0x02050000
    if (!PyClass_Check(type))
    #else
    if (!PyType_Check(type))
    #endif
    {
        /* Raising an instance.  The value should be a dummy. */
        if (value != Py_None) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        /* Normalize to raise <class>, <instance> */
        Py_DECREF(value);
        value = type;
        #if PY_VERSION_HEX < 0x02050000
            if (PyInstance_Check(type)) {
                type = (PyObject*) ((PyInstanceObject*)type)->in_class;
                Py_INCREF(type);
            }
            else {
                type = 0;
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception must be an old-style class or instance");
                goto raise_error;
            }
        #else
            type = (PyObject*) Py_TYPE(type);
            Py_INCREF(type);
            if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception class must be a subclass of BaseException");
                goto raise_error;
            }
        #endif
    }
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}

static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();

#if PY_MAJOR_VERSION >= 3
    /* Note: this is a temporary work-around to prevent crashes in Python 3.0 */
    if ((tstate->exc_type != NULL) & (tstate->exc_type != Py_None)) {
        tmp_type = tstate->exc_type;
        tmp_value = tstate->exc_value;
        tmp_tb = tstate->exc_traceback;
        PyErr_NormalizeException(&type, &value, &tb);
        PyErr_NormalizeException(&tmp_type, &tmp_value, &tmp_tb);
        tstate->exc_type = 0;
        tstate->exc_value = 0;
        tstate->exc_traceback = 0;
        PyException_SetContext(value, tmp_value);
        Py_DECREF(tmp_type);
        Py_XDECREF(tmp_tb);
    }
#endif

    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}

static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;

    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}


static INLINE int __Pyx_StrEq(const char *s1, const char *s2) {
     while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
     return *s1 == *s2;
}

static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
    if (sizeof(unsigned char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned char)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (unsigned char)-1;
            if (unlikely(val < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned char");
                return (unsigned char)-1;
            }
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to unsigned char");
            return (unsigned char)-1;
        }
        return (unsigned char)val;
    }
    return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
}

static INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
    if (sizeof(unsigned short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned short)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (unsigned short)-1;
            if (unlikely(val < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned short");
                return (unsigned short)-1;
            }
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to unsigned short");
            return (unsigned short)-1;
        }
        return (unsigned short)val;
    }
    return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
}

static INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
    if (sizeof(unsigned int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned int)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (unsigned int)-1;
            if (unlikely(val < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned int");
                return (unsigned int)-1;
            }
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to unsigned int");
            return (unsigned int)-1;
        }
        return (unsigned int)val;
    }
    return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
}

static INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
    if (sizeof(char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(char)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (char)-1;
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to char");
            return (char)-1;
        }
        return (char)val;
    }
    return (char)__Pyx_PyInt_AsLong(x);
}

static INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
    if (sizeof(short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(short)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (short)-1;
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to short");
            return (short)-1;
        }
        return (short)val;
    }
    return (short)__Pyx_PyInt_AsLong(x);
}

static INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (int)-1;
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to int");
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
    if (sizeof(signed char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed char)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (signed char)-1;
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to signed char");
            return (signed char)-1;
        }
        return (signed char)val;
    }
    return (signed char)__Pyx_PyInt_AsSignedLong(x);
}

static INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
    if (sizeof(signed short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed short)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (signed short)-1;
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to signed short");
            return (signed short)-1;
        }
        return (signed short)val;
    }
    return (signed short)__Pyx_PyInt_AsSignedLong(x);
}

static INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
    if (sizeof(signed int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed int)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (signed int)-1;
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to signed int");
            return (signed int)-1;
        }
        return (signed int)val;
    }
    return (signed int)__Pyx_PyInt_AsSignedLong(x);
}

static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return (unsigned long)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        if (unlikely(Py_SIZE(x) < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return PyLong_AsUnsignedLong(x);
    } else {
        unsigned long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned long)-1;
        val = __Pyx_PyInt_AsUnsignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return (unsigned PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        if (unlikely(Py_SIZE(x) < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return PyLong_AsUnsignedLongLong(x);
    } else {
        unsigned PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        return (long)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        return PyLong_AsLong(x);
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long)-1;
        val = __Pyx_PyInt_AsLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        return (PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        return PyLong_AsLongLong(x);
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        return (signed long)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        return PyLong_AsLong(x);
    } else {
        signed long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed long)-1;
        val = __Pyx_PyInt_AsSignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        return (signed PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        return PyLong_AsLongLong(x);
    } else {
        signed PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsSignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"

static void __Pyx_AddTraceback(const char *funcname) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyObject *py_globals = 0;
    PyObject *empty_string = 0;
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;

    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(__pyx_filename);
    #else
    py_srcfile = PyUnicode_FromString(__pyx_filename);
    #endif
    if (!py_srcfile) goto bad;
    if (__pyx_clineno) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    #if PY_MAJOR_VERSION < 3
    empty_string = PyString_FromStringAndSize("", 0);
    #else
    empty_string = PyBytes_FromStringAndSize("", 0);
    #endif
    if (!empty_string) goto bad;
    py_code = PyCode_New(
        0,            /*int argcount,*/
        #if PY_MAJOR_VERSION >= 3
        0,            /*int kwonlyargcount,*/
        #endif
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        empty_string, /*PyObject *code,*/
        __pyx_empty_tuple,  /*PyObject *consts,*/
        __pyx_empty_tuple,  /*PyObject *names,*/
        __pyx_empty_tuple,  /*PyObject *varnames,*/
        __pyx_empty_tuple,  /*PyObject *freevars,*/
        __pyx_empty_tuple,  /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        __pyx_lineno,   /*int firstlineno,*/
        empty_string  /*PyObject *lnotab*/
    );
    if (!py_code) goto bad;
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        py_globals,          /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = __pyx_lineno;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    Py_XDECREF(empty_string);
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode && (!t->is_identifier)) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else  /* Python 3+ has unicode identifiers */
        if (t->is_identifier || (t->is_unicode && t->intern)) {
            *t->p = PyUnicode_InternFromString(t->s);
        } else if (t->is_unicode) {
            *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

/* Type Conversion Functions */

static INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   if (x == Py_True) return 1;
   else if ((x == Py_False) | (x == Py_None)) return 0;
   else return PyObject_IsTrue(x);
}

static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_VERSION_HEX < 0x03000000
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return Py_INCREF(x), x;
  m = Py_TYPE(x)->tp_as_number;
#if PY_VERSION_HEX < 0x03000000
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_VERSION_HEX < 0x03000000
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%s__ returned non-%s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}

static INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject* x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}

static INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
#if PY_VERSION_HEX < 0x02050000
   if (ival <= LONG_MAX)
       return PyInt_FromLong((long)ival);
   else {
       unsigned char *bytes = (unsigned char *) &ival;
       int one = 1; int little = (int)*(unsigned char*)&one;
       return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
   }
#else
   return PyInt_FromSize_t(ival);
#endif
}

static INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
   unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
   if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
       return (size_t)-1;
   } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
       PyErr_SetString(PyExc_OverflowError,
                       "value too large to convert to size_t");
       return (size_t)-1;
   }
   return (size_t)val;
}


