-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtmidimodule.cpp
919 lines (747 loc) · 21 KB
/
rtmidimodule.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
/*
# Copyright (C) 2011 by Patrick Stinson
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "RtMidi.h"
#include "PyMidiMessage.h"
#include <Python.h>
#include <queue>
#ifndef Py_RETURN_NONE
#define Py_RETURN_NONE Py_INCREF(Py_None); return Py_None;
#endif
#ifdef __APPLE__
#define PK_WINDOWS 0
#endif
#ifdef __LINUX__
#define PK_WINDOWS 0
#endif
#ifdef __WINDOWS__
#define PK_WINDOWS 1
#endif
#if PY_MAJOR_VERSION == 3
#define PK_PYTHON3 1
#else
#define PK_PYTHON3 0
#endif
static PyObject *RtMidiError;
typedef struct
{
PyObject_HEAD
RtMidiIn *rtmidi;
PyObject *callback;
long calling_thread_id;
std::queue<MidiMessage *> *m_q;
#if PK_WINDOWS
HANDLE mutex;
HANDLE cond;
#else
pthread_mutex_t mutex;
pthread_cond_t cond;
bool triggered;
#endif
} MidiIn;
static void MidiIn_callback(double timestamp, std::vector<unsigned char> *message, void *opaque)
{
MidiIn *self = (MidiIn *) opaque;
uint8 *data = (uint8*) malloc(message->size());
for(size_t i=0; i < message->size(); i++)
data[i] = (*message)[i];
MidiMessage inMidi(data, message->size(), timestamp);
free(data);
#if PK_WINDOWS
WaitForSingleObject(self->mutex);
#else
pthread_mutex_lock(&self->mutex);
#endif
if(self->callback) // called too fast to init?
{
PyGILState_STATE gil_state = PyGILState_Ensure();
PyObject *result = NULL;
PyObject *args = NULL;
PyMidiMessage *outMidi = (PyMidiMessage *) PyMidiMessage_new();
(*outMidi->m) = inMidi;
args = Py_BuildValue("(O)", outMidi);
result = PyEval_CallObject(self->callback, args);
if(result == NULL)
{
PyThreadState_SetAsyncExc(self->calling_thread_id, 0);
}
Py_XDECREF(result);
Py_XDECREF(args);
Py_XDECREF(outMidi);
PyGILState_Release(gil_state);
}
else
{
self->m_q->push(new MidiMessage(inMidi));
self->triggered = true;
}
#if PK_WINDOWS
SetEvent(self->cond);
ReleaseMutex(self->mutex);
#else
pthread_cond_signal(&self->cond);
pthread_mutex_unlock(&self->mutex);
#endif
}
static PyObject *
MidiIn_getMessage(MidiIn *self, PyObject *args)
{
PyObject *timeout = NULL;
PyObject *result = NULL;
if(!PyArg_ParseTuple(args, "|O:getMessage", &timeout))
return NULL;
long ms = -1;
if(timeout)
{
if(PyFloat_CheckExact(timeout))
ms = (long) PyFloat_AS_DOUBLE(timeout);
#if ! PK_PYTHON3
else if(PyInt_CheckExact(timeout))
ms = PyInt_AS_LONG(timeout);
#endif
else if(PyLong_CheckExact(timeout))
ms = PyLong_AsLong(timeout);
else
{
PyErr_Format(RtMidiError, "timeout value must be a number, not %s", timeout->ob_type->tp_name);
return NULL;
}
if(ms < 0)
{
PyErr_SetString(RtMidiError, "timeout value must be a positive number");
return NULL;
}
}
#if PK_WINDOWS
WaitForSingleObject(self->mutex);
#else
pthread_mutex_lock(&self->mutex);
#endif
if(ms > -1 && self->triggered == false)
{
PyThreadState *_save = PyEval_SaveThread();
#if PK_WINDOWS
WaitForSingleObject(self->cond, ms < 0 ? INFINITE : ms);
#else
if(ms < 0)
{
pthread_cond_wait(&self->cond, &self->mutex);
}
else
{
struct timeval now;
gettimeofday(&now, 0);
struct timespec time;
TIMEVAL_TO_TIMESPEC(&now, &time);
unsigned long sec = ms / 1000;
unsigned long nsec = (ms % 1000) * 1000000;
time.tv_sec += sec;
time.tv_nsec += nsec;
while(time.tv_nsec >= 1000000000) {
time.tv_sec++;
time.tv_nsec -= 1000000000;
}
pthread_cond_timedwait(&self->cond, &self->mutex, &time);
}
#endif
PyEval_RestoreThread(_save);
}
if(self->m_q->size() > 0)
{
result = (PyObject *) PyMidiMessage_new();
MidiMessage *inMidi = self->m_q->front();
(*((PyMidiMessage *)result)->m) = (*inMidi);
self->m_q->pop();
self->triggered = false;
delete inMidi;
}
#if PK_WINDOWS
ReleaseMutex(self->mutex);
#else
pthread_mutex_unlock(&self->mutex);
#endif
if(result)
return result;
Py_RETURN_NONE;
}
static PyObject *
MidiIn_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
char *name = NULL;
if(!PyArg_ParseTuple(args, "|s", &name))
return NULL;
MidiIn *self;
self = (MidiIn *) type->tp_alloc(type, 0);
if(self != NULL)
{
if (name == NULL)
{
try
{
self->rtmidi = new RtMidiIn;
}
catch(RtError &error)
{
PyErr_SetString(RtMidiError, error.getMessageString());
Py_DECREF(self);
return NULL;
}
}
else
{
try
{
self->rtmidi = new RtMidiIn(name);
}
catch(RtError &error)
{
PyErr_SetString(RtMidiError, error.getMessageString());
Py_DECREF(self);
return NULL;
}
}
}
#if PK_WINDOWS
self->mutex = CreateMutex (0, FALSE, 0);
self->cond = CreateEvent (0, FALSE, FALSE, 0);
#else
pthread_cond_init (&self->cond, 0);
pthread_mutex_init (&self->mutex, 0);
#endif
self->m_q = new std::queue<MidiMessage *>;
self->callback = 0;
self->calling_thread_id = -1;
return (PyObject *) self;
}
static void
MidiIn_dealloc(MidiIn *self)
{
#if PK_WINDOWS
WaitForSingleObject(self->mutex, INFINITE);
#else
pthread_mutex_lock(&self->mutex);
#endif
self->rtmidi->closePort();
delete self->rtmidi;
delete self->m_q;
self->m_q = NULL;
Py_XDECREF(self->callback);
self->callback = NULL;
self->ob_type->tp_free((PyObject *) self);
#if PK_WINDOWS
ReleaseMutex(self->mutex);
CloseHandle (self->mutex);
CloseHandle (self->cond);
#else
pthread_mutex_unlock(&self->mutex);
pthread_mutex_destroy(&self->mutex);
pthread_cond_destroy(&self->cond);
#endif
}
static int
MidiIn_init(MidiIn *self, PyObject *args, PyObject *kwds)
{
return 0;
}
static PyObject *
MidiIn_openPort(MidiIn *self, PyObject *args)
{
int port;
char *name = NULL;
if(!PyArg_ParseTuple(args, "i|s", &port, &name))
return NULL;
if (name == NULL)
{
try
{
self->rtmidi->openPort(port);
}
catch(RtError &error)
{
PyErr_SetString(RtMidiError, error.getMessageString());
return NULL;
}
}
else
{
try
{
self->rtmidi->openPort(port,name);
}
catch(RtError &error)
{
PyErr_SetString(RtMidiError, error.getMessageString());
return NULL;
}
}
self->rtmidi->setCallback(MidiIn_callback, self);
self->calling_thread_id = PyThreadState_Get()->thread_id;
Py_RETURN_NONE;
}
static PyObject *
MidiIn_openVirtualPort(MidiIn *self, PyObject *args)
{
char *name = NULL;
if(!PyArg_ParseTuple(args, "|s", &name))
return NULL;
if(name == NULL)
{
try
{
self->rtmidi->openVirtualPort();
}
catch(RtError &error)
{
PyErr_SetString(RtMidiError, error.getMessageString());
return NULL;
}
}
else
{
try
{
self->rtmidi->openVirtualPort(name);
}
catch(RtError &error)
{
PyErr_SetString(RtMidiError, error.getMessageString());
return NULL;
}
}
self->rtmidi->setCallback(MidiIn_callback, self);
self->calling_thread_id = PyThreadState_Get()->thread_id;
Py_RETURN_NONE;
}
static PyObject *
MidiIn_setCallback(MidiIn *self, PyObject *args)
{
PyObject *callback = NULL;
if(!PyArg_ParseTuple(args, "O:setCallback", &callback))
return NULL;
if(!PyCallable_Check(callback))
{
PyErr_SetString(PyExc_TypeError, "parameter must be a callable object");
return NULL;
}
// delete the old one if set
Py_XDECREF(self->callback);
// install the new one
self->callback = callback;
Py_INCREF(self->callback);
Py_RETURN_NONE;
}
static PyObject *
MidiIn_cancelCallback(MidiIn *self, PyObject *)
{
self->rtmidi->cancelCallback();
if(self->callback)
{
Py_DECREF(self->callback);
self->callback = NULL;
}
Py_RETURN_NONE;
}
static PyObject *
MidiIn_closePort(MidiIn *self, PyObject *)
{
self->rtmidi->closePort();
Py_RETURN_NONE;
}
static PyObject *
MidiIn_getPortCount(MidiIn *self, PyObject *)
{
return PyInt_FromLong(self->rtmidi->getPortCount());
}
static PyObject *
MidiIn_getPortName(MidiIn *self, PyObject *args)
{
int port;
std::string name;
if(!PyArg_ParseTuple(args, "i", &port))
return NULL;
try
{
name = self->rtmidi->getPortName(port);
}
catch(RtError &error)
{
PyErr_SetString(RtMidiError, error.getMessageString());
return NULL;
}
return Py_BuildValue("s", name.c_str());
}
static PyObject *
MidiIn_setQueueSizeLimit(MidiIn *self, PyObject *args)
{
unsigned int queueSize;
if(!PyArg_ParseTuple(args, "I", &queueSize))
return NULL;
self->rtmidi->setQueueSizeLimit(queueSize);
Py_RETURN_NONE;
}
static PyObject *
MidiIn_ignoreTypes(MidiIn *self, PyObject *args)
{
PyObject *omidiSysex = Py_True;
PyObject *omidiTime = Py_True;
PyObject *omidiSense = Py_True;
bool midiSysex;
bool midiTime;
bool midiSense;
if(!PyArg_ParseTuple(args, "|OOO", &omidiSysex, &omidiTime, &omidiSense))
return NULL;
midiSysex = PyObject_IsTrue(omidiSysex);
midiTime = PyObject_IsTrue(omidiTime);
midiSense = PyObject_IsTrue(omidiSense);
self->rtmidi->ignoreTypes(midiSysex, midiTime, midiSense);
Py_RETURN_NONE;
}
static PyMethodDef MidiIn_methods[] = {
{"openPort", (PyCFunction) MidiIn_openPort, METH_VARARGS,
"Open a MIDI input connection. openPort(port, blocking=False)\n"
"If the optional blocking parameter is passed getMessage will block until a message is available."},
{"openVirtualPort", (PyCFunction) MidiIn_openVirtualPort, METH_VARARGS,
"Create a virtual input port, with optional name, to allow software "
"connections (OS X and ALSA only)."},
{"setCallback", (PyCFunction) MidiIn_setCallback, METH_VARARGS,
"Set a callback function to be invoked for incoming MIDI messages."},
{"cancelCallback", (PyCFunction) MidiIn_cancelCallback, METH_NOARGS,
"Cancel use of the current callback function (if one exists)."},
{"closePort", (PyCFunction) MidiIn_closePort, METH_NOARGS,
"Close an open MIDI connection (if one exists)."},
{"getPortCount", (PyCFunction) MidiIn_getPortCount, METH_NOARGS,
"Return the number of available MIDI input ports."},
{"getPortName", (PyCFunction) MidiIn_getPortName, METH_VARARGS,
"Return a string identifier for the specified MIDI input port number."},
{"setQueueSizeLimit", (PyCFunction) MidiIn_setQueueSizeLimit, METH_VARARGS,
"Set the maximum number of MIDI messages to be saved in the queue."},
{"ignoreTypes", (PyCFunction) MidiIn_ignoreTypes, METH_VARARGS,
"Specify whether certain MIDI message types should be queued or ignored "
"during input."},
{"getMessage", (PyCFunction) MidiIn_getMessage, METH_VARARGS,
"Return the data bytes for the next available MIDI message in"
"the input queue and return the event delta-time in seconds.\n"
"This method will block if openPort() was called in blocking mode"},
{NULL}
};
static PyTypeObject MidiIn_type = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"midi.RtMidiIn", /*tp_name*/
sizeof(MidiIn), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor) MidiIn_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"Midi input device", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
MidiIn_methods, /* 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 */
(initproc)MidiIn_init, /* tp_init */
0, /* tp_alloc */
MidiIn_new, /* tp_new */
};
typedef struct {
PyObject_HEAD
/* Type-specific fields go here. */
RtMidiOut *rtmidi;
} MidiOut;
static void
MidiOut_dealloc(MidiOut *self)
{
delete self->rtmidi;
self->ob_type->tp_free((PyObject *) self);
}
static PyObject *
MidiOut_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
char *name = NULL;
if(!PyArg_ParseTuple(args, "|s", &name))
return NULL;
MidiOut *self;
self = (MidiOut *) type->tp_alloc(type, 0);
if(self != NULL)
{
if (name == NULL)
{
try
{
self->rtmidi = new RtMidiOut;
}
catch(RtError &error)
{
PyErr_SetString(RtMidiError, error.getMessageString());
Py_DECREF(self);
return NULL;
}
}
else
{
try
{
self->rtmidi = new RtMidiOut(name);
}
catch(RtError &error)
{
PyErr_SetString(RtMidiError, error.getMessageString());
Py_DECREF(self);
return NULL;
}
}
}
return (PyObject *) self;
}
static int
MidiOut_init(MidiOut *self, PyObject *args, PyObject *kwds)
{
return 0;
}
static PyObject *
MidiOut_openPort(MidiOut *self, PyObject *args)
{
int port = 0;
char *name = NULL;
if(!PyArg_ParseTuple(args, "i|s", &port, &name))
return NULL;
if (name == NULL)
try
{
self->rtmidi->openPort(port);
}
catch(RtError &error)
{
PyErr_SetString(RtMidiError, error.getMessageString());
return NULL;
}
else
{
try
{
self->rtmidi->openPort(port,name);
}
catch(RtError &error)
{
PyErr_SetString(RtMidiError, error.getMessageString());
return NULL;
}
}
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
MidiOut_openVirtualPort(MidiOut *self, PyObject *args)
{
char *name = NULL;
if(!PyArg_ParseTuple(args, "|s", &name))
return NULL;
if(name == NULL)
{
try
{
self->rtmidi->openVirtualPort();
}
catch(RtError &error)
{
PyErr_SetString(RtMidiError, error.getMessageString());
return NULL;
}
}
else
{
try
{
self->rtmidi->openVirtualPort(name);
}
catch(RtError &error)
{
PyErr_SetString(RtMidiError, error.getMessageString());
return NULL;
}
}
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
MidiOut_closePort(MidiOut *self, PyObject *args)
{
self->rtmidi->closePort();
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
MidiOut_getPortCount(MidiOut *self, PyObject *args)
{
return Py_BuildValue("i", self->rtmidi->getPortCount());
}
static PyObject *
MidiOut_getPortName(MidiOut *self, PyObject *args)
{
int port;
std::string name;
if(!PyArg_ParseTuple(args, "i", &port))
return NULL;
try
{
name = self->rtmidi->getPortName(port);
}
catch(RtError &error)
{
PyErr_SetString(RtMidiError, error.getMessageString());
return NULL;
}
return Py_BuildValue("s", name.c_str());
}
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 PyMethodDef MidiOut_methods[] = {
{"openPort", (PyCFunction) MidiOut_openPort, METH_VARARGS,
"Open a MIDI input connection."},
{"openVirtualPort", (PyCFunction) MidiOut_openVirtualPort, METH_VARARGS,
"Create a virtual input port, with optional name, to allow software "
"connections (OS X and ALSA only)."},
{"closePort", (PyCFunction) MidiOut_closePort, METH_NOARGS,
"Close an open MIDI connection (if one exists)."},
{"getPortCount", (PyCFunction) MidiOut_getPortCount, METH_NOARGS,
"Return the number of available MIDI output ports."},
{"getPortName", (PyCFunction) MidiOut_getPortName, METH_VARARGS,
"Return a string identifier for the specified MIDI port type and number."},
{"sendMessage", (PyCFunction) MidiOut_sendMessage, METH_VARARGS,
"Immediately send a single message out an open MIDI output port."},
{NULL}
};
static PyTypeObject MidiOut_type = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"midi.RtMidiOut", /*tp_name*/
sizeof(MidiOut), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor) MidiOut_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"Midi output device", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
MidiOut_methods, /* 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 */
(initproc)MidiOut_init, /* tp_init */
0, /* tp_alloc */
MidiOut_new, /* tp_new */
};
static PyMethodDef midi_methods[] = {
{NULL} /* Sentinel */
};
#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
#define PyMODINIT_FUNC void
#endif
PyMODINIT_FUNC
initrtmidi(void)
{
PyEval_InitThreads();
PyObject* module;
if (PyType_Ready(getMidiMessageType()) < 0)
return;
if (PyType_Ready(&MidiIn_type) < 0)
return;
if (PyType_Ready(&MidiOut_type) < 0)
return;
module = Py_InitModule3("rtmidi", midi_methods, "RtMidi wrapper.");
Py_INCREF((PyObject*) getMidiMessageType());
PyModule_AddObject(module, "MidiMessage", (PyObject*) getMidiMessageType());
Py_INCREF(&MidiIn_type);
PyModule_AddObject(module, "RtMidiIn", (PyObject *)&MidiIn_type);
Py_INCREF(&MidiOut_type);
PyModule_AddObject(module, "RtMidiOut", (PyObject *)&MidiOut_type);
char eName[32];
strcpy(eName, "rtmidi.Error");
RtMidiError = PyErr_NewException(eName, NULL, NULL);
Py_INCREF(RtMidiError);
PyModule_AddObject(module, "Error", RtMidiError);
}