Merge branch 'master' into develop
[jack2.git] / common / JackMidiAsyncWaitQueue.h
blob72df48c506885fb7562eaca5ffe33ac22995be4f
1 /*
2 Copyright (C) 2010 Devin Anderson
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef __JackMidiAsyncWaitQueue__
21 #define __JackMidiAsyncWaitQueue__
23 #include "JackMidiAsyncQueue.h"
25 namespace Jack {
27 /**
28 * This is an asynchronous wait queue that allows a thread to wait for a
29 * message, either indefinitely or for a specified time. This is one
30 * example of a way that the `JackMidiAsyncQueue` class can be extended so
31 * that process threads can interact with non-process threads to send MIDI
32 * events.
34 * XXX: As of right now, this code hasn't been tested. Also, note the
35 * warning in the JackMidiAsyncWaitQueue.cpp about semaphore wait
36 * resolution.
39 class SERVER_EXPORT JackMidiAsyncWaitQueue: public JackMidiAsyncQueue {
41 private:
43 JackSynchro semaphore;
45 public:
47 using JackMidiAsyncQueue::EnqueueEvent;
49 /**
50 * Creates a new asynchronous MIDI wait message queue. The queue can
51 * store up to `max_messages` MIDI messages and up to `max_bytes` of
52 * MIDI data before it starts rejecting messages.
55 JackMidiAsyncWaitQueue(size_t max_bytes=4096,
56 size_t max_messages=1024);
58 ~JackMidiAsyncWaitQueue();
60 /**
61 * Dequeues and returns a MIDI event. Returns '0' if there are no MIDI
62 * events available right now.
65 jack_midi_event_t *
66 DequeueEvent();
68 /**
69 * Waits a specified time for a MIDI event to be available, or
70 * indefinitely if the time is negative. Returns the MIDI event, or
71 * '0' if time runs out and no MIDI event is available.
74 jack_midi_event_t *
75 DequeueEvent(long usecs);
77 /**
78 * Waits until the specified frame for a MIDI event to be available.
79 * Returns the MIDI event, or '0' if time runs out and no MIDI event is
80 * available.
83 jack_midi_event_t *
84 DequeueEvent(jack_nframes_t frame);
86 /**
87 * Enqueues the MIDI event specified by the arguments. The return
88 * value indicates whether or not the event was successfully enqueued.
91 EnqueueResult
92 EnqueueEvent(jack_nframes_t time, size_t size,
93 jack_midi_data_t *buffer);
99 #endif