3 * Copyright (C) 2012-2020 Filipe Coelho <falktx@falktx.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * For a full copy of the GNU General Public License see the COPYING file
18 #ifndef MIDI_QUEUE_HPP_INCLUDED
19 #define MIDI_QUEUE_HPP_INCLUDED
21 #include "CarlaMutex.hpp"
23 template<uint16_t MAX_SIZE
>
27 MIDIEventQueue() noexcept
33 bool isEmpty() const noexcept
38 bool isNotEmpty() const noexcept
43 bool isFull() const noexcept
48 CarlaMutex
& getMutex() noexcept
53 bool put(unsigned char d1
, unsigned char d2
, unsigned char d3
)
55 CARLA_SAFE_ASSERT_RETURN(d1
!= 0, false);
60 for (unsigned short i
=0; i
< MAX_SIZE
; i
++)
68 full
= (i
== MAX_SIZE
-1);
76 bool get(uint8_t& d1
, uint8_t& d2
, uint8_t& d3
)
83 if (data
[index
].d1
== 0)
95 data
[index
].d1
= data
[index
].d2
= data
[index
].d3
= 0;
102 bool tryToCopyDataFrom(MIDIEventQueue
& queue
) noexcept
104 const CarlaMutexTryLocker
cml(queue
.mutex
);
106 if (cml
.wasNotLocked())
109 // copy data from queue
110 carla_copyStruct(data
, queue
.data
);
116 carla_zeroStruct(queue
.data
);
129 : d1(0), d2(0), d3(0) {}
132 MIDIEvent data
[MAX_SIZE
];
134 volatile bool empty
, full
;
139 #endif // MIDI_QUEUE_HPP_INCLUDED