[Jack-Devel] jack midi event reserve vs. write

Harry van Haaren harryhaaren at gmail.com
Tue Dec 20 13:31:31 CET 2016


On Tue, Dec 20, 2016 at 11:09 AM, ROBERT WOLF <
robert.wolf at hercsmusicsystems.com.au> wrote:

> Dear All,
>

Hi Robert,


> What exactly is the difference between *jack_midi_event_reserve* and
> *jack_midi_event_write* ?
>

>From my understanding:
- event_reserve() takes "size" number of bytes from JACKs internal MIDI
buffers for a particular port, and returns the address to that buffer. Your
application can now write to that pointer, and once the RT callback is
done, JACK will transmit the data.

- event_write() takes a pointer from your application, and copies the data
pointed to into the JACK internal midi buffer. Your application can re-use
or delete the buffer you passed to the event_write() function now, as JACK
has a copy of the data.


> In particular, if I call *jack_midi_event_write*, does it actually copy
> the data from the buffer, which I provide?
> Or does it use that same buffer.
>

See above.


> Another question is how can I send midi events generated from GUI, (which
> does not run in the audio callback)?
> My guess is to cache them somewhere and transmit them inside the callback?
> Am I guessing correctly?
> <http://lists.jackaudio.org/listinfo.cgi/jack-devel-jackaudio.org>
>

In short: Yes. You need to transfer the MIDI data to be sent between two
threads - this can be trivial with mutexs/semaphors/locking systems, but
keep in mind that your real-time thread must *never* block. Personally, I
am a big proponent of message passing, instead of locking based systems.

To answer your question, I would use a ringbuffer (jack has a ringbuffer t)
to move a message (struct with some metadata) to transfer an event (midi
note one) between the GUI to JACK thread.

Hope that helps, -Harry

-- 

http://www.openavproductions.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.linuxaudio.org/archives/jackaudio/attachments/20161220/3592786a/attachment.html>


More information about the Jackaudio mailing list