Merge pull request #23 from jackaudio/device_reservation_fixes
[jack2.git] / linux / firewire / JackFFADOMidiSendQueue.cpp
blob97fdf17d512c3fa4e5bbc6d2a234d1df4f2c20c9
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 #include <cassert>
22 #include "JackFFADOMidiSendQueue.h"
23 #include "JackMidiUtil.h"
25 using Jack::JackFFADOMidiSendQueue;
27 JackFFADOMidiSendQueue::JackFFADOMidiSendQueue()
29 // Empty
32 Jack::JackMidiWriteQueue::EnqueueResult
33 JackFFADOMidiSendQueue::EnqueueEvent(jack_nframes_t time, size_t size,
34 jack_midi_data_t *buffer)
36 assert(size == 1);
37 jack_nframes_t relative_time = (time < last_frame) ? 0 : time - last_frame;
38 if (index < relative_time) {
39 index = (relative_time % 8) ?
40 (relative_time & (~ ((jack_nframes_t) 7))) + 8 : relative_time;
42 if (index >= length) {
43 return BUFFER_FULL;
45 output_buffer[index] = 0x01000000 | ((uint32_t) *buffer);
46 index += 8;
47 return OK;
50 jack_nframes_t
51 JackFFADOMidiSendQueue::GetNextScheduleFrame()
53 return last_frame + index;
56 void
57 JackFFADOMidiSendQueue::ResetOutputBuffer(uint32_t *output_buffer,
58 jack_nframes_t length)
60 index = 0;
61 last_frame = GetLastFrame();
62 this->length = length;
63 this->output_buffer = output_buffer;