Jack2: JackALSARawMidiSendQueue.cpp Source File

Jack2 1.9.12

JackALSARawMidiSendQueue.cpp
1 /*
2 Copyright (C) 2011 Devin Anderson
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
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 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <cassert>
21
22 #include "JackALSARawMidiSendQueue.h"
23 #include "JackMidiUtil.h"
24 #include "JackError.h"
25
26 using Jack::JackALSARawMidiSendQueue;
27
28 JackALSARawMidiSendQueue::JackALSARawMidiSendQueue(snd_rawmidi_t *rawmidi,
29 size_t bytes_per_poll)
30 {
31 assert(bytes_per_poll > 0);
32 this->bytes_per_poll = bytes_per_poll;
33 this->rawmidi = rawmidi;
34 blocked = false;
35 bytes_available = bytes_per_poll;
36 }
37
38 Jack::JackMidiWriteQueue::EnqueueResult
39 JackALSARawMidiSendQueue::EnqueueEvent(jack_nframes_t time, size_t size,
40 jack_midi_data_t *buffer)
41 {
42 assert(size == 1);
43 if (time > GetCurrentFrame()) {
44 return EVENT_EARLY;
45 }
46 if (! bytes_available) {
47 return BUFFER_FULL;
48 }
49 ssize_t result = snd_rawmidi_write(rawmidi, buffer, 1);
50 switch (result) {
51 case 1:
52 blocked = false;
53 bytes_available--;
54 return OK;
55 case -EWOULDBLOCK:
56 blocked = true;
57 return BUFFER_FULL;
58 }
59 jack_error("JackALSARawMidiSendQueue::EnqueueEvent - snd_rawmidi_write: "
60 "%s", snd_strerror(result));
61 return EN_ERROR;
62 }
63
64 bool
65 JackALSARawMidiSendQueue::IsBlocked()
66 {
67 return blocked;
68 }
69
70 void
71 JackALSARawMidiSendQueue::ResetPollByteCount()
72 {
73 bytes_available = bytes_per_poll;
74 }
Jack::JackALSARawMidiSendQueue::EnqueueEvent
JackMidiWriteQueue::EnqueueResult EnqueueEvent(jack_nframes_t time, size_t size, jack_midi_data_t *buffer)
Definition: JackALSARawMidiSendQueue.cpp:39
jack_error
SERVER_EXPORT void jack_error(const char *fmt,...)
Definition: JackError.cpp:92
Jack::JackALSARawMidiSendQueue
Definition: JackALSARawMidiSendQueue.h:29