Skip to content

Commit 8109c6e

Browse files
committed
feat: add set_buffer_size method to MidiIn class
Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
1 parent e81ec0b commit 8109c6e

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

src/_rtmidi.pyx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ cdef extern from "RtMidi.h":
194194
double getMessage(vector[unsigned char] *message) except *
195195
void ignoreTypes(bool midiSysex, bool midiTime, bool midiSense) except *
196196
void setCallback(RtMidiCallback callback, void *data) except *
197+
void setBufferSize(unsigned int size, unsigned int count) except *
197198

198199
cdef cppclass RtMidiOut(RtMidi):
199200
Api RtMidiOut(Api rtapi, string clientName) except +
@@ -923,14 +924,8 @@ cdef class MidiIn(MidiBase):
923924
buffer overflows.
924925
925926
**Windows note:** the Windows Multi Media API uses fixed size buffers
926-
for the reception of sysex messages, whose number and size is set at
927-
compile time. Sysex messages longer than the buffer size can not be
928-
received properly when using the Windows Multi Media API.
929-
930-
The default distribution of python-rtmidi sets the number of sysex
931-
buffers to four and the size of each to 8192 bytes. To change these
932-
values, edit the ``RT_SYSEX_BUFFER_COUNT`` and ``RT_SYSEX_BUFFER_SIZE``
933-
preprocessor defines in ``RtMidi.cpp`` and recompile.
927+
for the reception of sysex messages. You can change the number and
928+
size of the buffers with the ``set_buffer_size`` method.
934929
935930
"""
936931
self.thisptr.ignoreTypes(sysex, timing, active_sense)
@@ -960,6 +955,10 @@ cdef class MidiIn(MidiBase):
960955
self._callback = (func, data)
961956
self.thisptr.setCallback(&_cb_func, <void *>self._callback)
962957

958+
def set_buffer_size(self, size, count):
959+
"""Set the size and number of MIDI input buffers."""
960+
self.thisptr.setBufferSize(size, count)
961+
963962

964963
cdef class MidiOut(MidiBase):
965964
"""Midi output client interface.

tests/test_rtmidi.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ def callback(event, data):
120120
time.sleep(self.DELAY)
121121
self.assertEqual(messages, [])
122122

123+
def test_set_buffer_size(self):
124+
self.midi_in.set_buffer_size(1024, 4)
125+
self.test_callback()
126+
123127
def set_up_loopback(self):
124128
# TODO: find better solution than this hack-ish strategy to find out
125129
# the port number of the virtual output port, which we have to use,

0 commit comments

Comments
 (0)