Jack2  1.9.8
JackMidiBufferWriteQueue.cpp
1 /*
2 Copyright (C) 2010 Devin Anderson
3 
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.
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 Lesser General Public License for more details.
13 
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.
17 
18 */
19 
20 #include "JackMidiBufferWriteQueue.h"
21 #include "JackMidiUtil.h"
22 
24 
25 JackMidiBufferWriteQueue::JackMidiBufferWriteQueue()
26 {
27  // Empty
28 }
29 
30 Jack::JackMidiWriteQueue::EnqueueResult
31 JackMidiBufferWriteQueue::EnqueueEvent(jack_nframes_t time, size_t size,
32  jack_midi_data_t *data)
33 {
34  if (time >= next_frame_time) {
35  return EVENT_EARLY;
36  }
37  if (time < last_frame_time) {
38  time = last_frame_time;
39  }
40  jack_midi_data_t *dst = buffer->ReserveEvent(time - last_frame_time, size);
41  if (! dst) {
42  return size > max_bytes ? BUFFER_TOO_SMALL : BUFFER_FULL;
43  }
44  memcpy(dst, data, size);
45  return OK;
46 }
47 
48 void
50  jack_nframes_t frames)
51 {
52  if (! buffer) {
53  jack_error("JackMidiBufferWriteQueue::ResetMidiBuffer - buffer reset "
54  "to NULL");
55  } else if (! buffer->IsValid()) {
56  jack_error("JackMidiBufferWriteQueue::ResetMidiBuffer - buffer reset "
57  "to invalid buffer");
58  } else {
59  this->buffer = buffer;
60  buffer->Reset(frames);
61  last_frame_time = GetLastFrame();
62  max_bytes = buffer->MaxEventSize();
63  next_frame_time = last_frame_time + frames;
64  }
65 }