PyObject *PyMidiMessage___eq__(PyObject *self, PyObject *other, int op) { PyObject *result = NULL; if(other == Py_None) { result = Py_False; } else if(!PyMidiMessage_Check(other)) { result = Py_False; } else { MidiMessage &me = *((PyMidiMessage *) self)->m; MidiMessage &him = *((PyMidiMessage *) other)->m; switch (op) { case Py_EQ: result = (me == him) ? Py_True : Py_False; break; case Py_NE: result = (me == him) ? Py_False : Py_True; break; case Py_LT: case Py_LE: case Py_GT: case Py_GE: default: result = Py_NotImplemented; break; } } Py_XINCREF(result); return result; }
static PyObject * MidiOut_sendMessage(MidiOut *self, PyObject *args) { PyObject *a0 = NULL; if(PyArg_ParseTuple(args, "O", &a0) == 0) return NULL; if(!PyMidiMessage_Check(a0)) { PyErr_SetString(RtMidiError, "argument 1 must be of type MidiMessage"); return NULL; } PyMidiMessage *midi = (PyMidiMessage *) a0; std::vector<unsigned char> outMessage; uint8 *data = midi->m->getRawData(); for(int i=0; i < midi->m->getRawDataSize(); ++i) outMessage.push_back((unsigned char) data[i]); try { self->rtmidi->sendMessage(&outMessage); } catch(RtError &error) { PyErr_SetString(RtMidiError, error.getMessageString()); return NULL; } Py_RETURN_NONE; }
static PyObject * MidiOut_sendMessage(MidiOut *self, PyObject *args) { PyObject *a0 = NULL; if(PyArg_ParseTuple(args, "O", &a0) == 0) return NULL; MidiMessage *created = NULL; // delete if set MidiMessage *midi = NULL; if(PyMidiMessage_Check(a0)) { midi = ((PyMidiMessage *) a0)->m; } else if(PyLong_Check(a0)) { PyErr_SetString(rtmidi_Error, "long ctor args not supported yet."); return NULL; /* int i0 = (int) PyLong_AsUnsignedLong(a0); printf("MidiOut_sendMessage: %i\n", i0); midi = created = new MidiMessage(i0); */ } else { PyErr_SetString(rtmidi_Error, "argument 1 must be of type MidiMessage or a number."); return NULL; } std::vector<unsigned char> outMessage; uint8 *data = midi->getRawData(); for(int i=0; i < midi->getRawDataSize(); ++i) outMessage.push_back((unsigned char) data[i]); try { self->rtmidi->sendMessage(&outMessage); } catch(RtMidiError &error) { PyErr_SetString(rtmidi_Error, error.what()); if(created) delete created; return NULL; } if(created) delete created; Py_RETURN_NONE; }
static PyObject * PyMidiMessage_new(PyTypeObject *type, PyObject *args, PyObject *) { PyMidiMessage *self; PyObject *bytes = NULL; char *bytesStr = NULL; int iNumBytes = NULL; double timeStamp = NULL; PyObject *a1 = NULL, *a2 = NULL, *a3 = NULL; self = (PyMidiMessage *)type->tp_alloc(type, 0); if(self == NULL) return NULL; if(args) { if(PyTuple_GET_SIZE(args) == 1) { // either bytes as raw data or copy ctor a1 = PyTuple_GET_ITEM(args, 0); if(PyBytes_Check(a1)) { bytes = a1; bytesStr = PyBytes_AsString(bytes); iNumBytes = PyBytes_GET_SIZE(bytes); self->m = new MidiMessage((const uint8 *) bytesStr, (const int) iNumBytes); } else if(PyMidiMessage_Check(a1)) { self->m = new MidiMessage(0xb0, 123 & 127, 0); // all notes off (dummy) PyMidiMessage *pyOther = (PyMidiMessage *) a1; *(self->m) = *(pyOther->m); } else { PyArg_ParseTuple(args, "O|O", &a1, &a2, &a3); // just set exception return NULL; } } else if(PyTuple_GET_SIZE(args) == 2) { if(!PyArg_ParseTuple(args, "Sd", &bytes, &timeStamp)) { return NULL; } bytesStr = PyBytes_AsString(bytes); iNumBytes = PyBytes_GET_SIZE(bytes); self->m = new MidiMessage((const uint8 *) bytesStr, (const int) iNumBytes, (const double) timeStamp); } else { self->m = new MidiMessage(0xb0, 123 & 127, 0); // all notes off } } else { self->m = new MidiMessage(0xb0, 123 & 127, 0); // all notes off } return (PyObject *)self; /* a1 = PyTuple_GET_ITEM(args, 0); if(PyBytes_Check(a1)) { char *s = PyBytes_AsString(a1); } PyArg_ParseTuple(args, "S", data, &timeStamp); } else if(PyTuple_GET_SIZE(args) == 2) { if(PyBytes_Check(a1)) { int size = PyBytes_GET_SIZE(a1); char *s = PyBytes_AsString(a1); self->m = new MidiMessage((const uint8 *) s, (const int) size, (const double) timeStamp); } self->m = new MidiMessage((const uint8 *) s, (const int) size, (const double) timeStamp); PyArg_ParseTuple(args, "Sd", data, &timeStamp); } } if(args) { printf("here: %p, %i %i\n", args, PyArg_ParseTuple(args, "Si|d", &data, &iNumBytes, &timeStamp), PyArg_ParseTuple(args, "|O", &other)); if(!PyArg_ParseTuple(args, "Si|d", &data, &iNumBytes, &timeStamp) && !PyArg_ParseTuple(args, "|O", &other)) { return NULL; } } else { printf("here: %p\n", args); } // create from default ctor if(args == NULL) { self->m = new MidiMessage(0xb0, 123 & 127, 0); // all notes off } else { // create from raw data if(PyArg_ParseTuple(args, "Si|d", &data, &iNumBytes, &timeStamp)) { char *s = PyByteArray_AsString(data); if(timeStamp) { self->m = new MidiMessage((const uint8 *) s, (const int) iNumBytes, (const double) timeStamp); } else { self->m = new MidiMessage((const uint8 *) s, (const int) iNumBytes); } } else if(PyArg_ParseTuple(args, "|O", &other)) { // create from copy ctor if(other) { if(PyMidiMessage_Check(other)) { printf("here 1\n"); self->m = new MidiMessage(0xb0, 123 & 127, 0); // all notes off (dummy) PyMidiMessage *pyOther = (PyMidiMessage *) other; *self->m = *pyOther->m; printf("here 2: %p\n", self); } else { PyErr_SetString(PyExc_ValueError, "copy constructor argument must be a MidiMessage."); Py_DECREF(self); self = NULL; } } } } printf("return: %p\n", self); return (PyObject *)self; */ }