Deluge Firmware
1.3.0
Build date: 2026.10.14
Toggle main menu visibility
Loading...
Searching...
No Matches
midi_queue.h
1
/*
2
* Copyright © 2026 Synthstrom Audible Limited
3
*
4
* This file is part of The Synthstrom Audible Deluge Firmware.
5
*
6
* The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
7
* terms of the GNU General Public License as published by the Free Software Foundation,
8
* either version 3 of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
* See the GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License along with this program.
15
* If not, see <https://www.gnu.org/licenses/>.
16
*/
17
18
#pragma once
19
20
#include "OSLikeStuff/timers_interrupts/clock_type.h"
21
#include "definitions_cxx.hpp"
22
#include "model/midi/message.h"
23
#include <cstddef>
24
#include <cstdint>
25
#include <etl/queue_spsc_atomic.h>
26
28
constexpr
uint32_t kSystemTicksPerSampleQ8 = ((uint64_t)DELUGE_CLOCKS_PER << 8) / kSampleRate;
29
32
int32_t samplesTilWindowOffsetPlays(int32_t samplesBeforeLappingPlayHead, int32_t offset);
33
36
uint32_t dueAtWindowOffset(uint32_t windowStartTicks, int32_t samplesBeforeLappingPlayHead, int32_t offset);
37
38
struct
QueuedMIDI
{
39
MIDIMessage
message;
40
int16_t filter;
41
bool
usb;
42
bool
din;
43
uint32_t
due
;
44
};
45
static_assert
(
sizeof
(
QueuedMIDI
) == 12);
46
49
class
MIDIQueue
{
50
public
:
51
static
constexpr
size_t
kCapacity = 256;
53
static
constexpr
int32_t
kMaxTicksAhead
= DELUGE_CLOCKS_PER / 100;
54
58
bool
push
(
MIDIMessage
message, int32_t filter,
bool
usb,
bool
din, uint32_t due, uint32_t now);
59
62
bool
popDue
(
QueuedMIDI
& out, uint32_t now,
bool
all =
false
);
63
66
bool
popOldest
(
QueuedMIDI
& out);
67
69
bool
nextDue
(uint32_t& due);
70
71
[[nodiscard]]
bool
empty()
const
{
return
queue_.empty(); }
72
[[nodiscard]]
bool
full()
const
{
return
queue_.full(); }
73
[[nodiscard]]
size_t
size()
const
{
return
queue_.size(); }
74
75
private
:
76
etl::queue_spsc_atomic<QueuedMIDI, kCapacity> queue_;
77
};
MIDIQueue
Definition
midi_queue.h:49
MIDIQueue::popOldest
bool popOldest(QueuedMIDI &out)
Definition
midi_queue.cpp:48
MIDIQueue::push
bool push(MIDIMessage message, int32_t filter, bool usb, bool din, uint32_t due, uint32_t now)
Definition
midi_queue.cpp:32
MIDIQueue::popDue
bool popDue(QueuedMIDI &out, uint32_t now, bool all=false)
Definition
midi_queue.cpp:40
MIDIQueue::kMaxTicksAhead
static constexpr int32_t kMaxTicksAhead
Due times are never legitimately more than an audio buffer or so ahead.
Definition
midi_queue.h:53
MIDIQueue::nextDue
bool nextDue(uint32_t &due)
Consumer only. Get the due time of the oldest queued MIDI. Returns false if nothing's queued.
Definition
midi_queue.cpp:52
MIDIMessage
Definition
message.h:30
QueuedMIDI
Definition
midi_queue.h:38
QueuedMIDI::due
uint32_t due
system timer ticks, see getSystemTicks()
Definition
midi_queue.h:43