Control Surface
main
MIDI Control Surface library for Arduino
Toggle main menu visibility
Loading...
Searching...
No Matches
src
MIDI_Interfaces
BLEMIDI
ThreadedBLEMIDISender.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
Settings/NamespaceSettings.hpp
>
4
5
#include <chrono>
6
#include <condition_variable>
7
#include <mutex>
8
#include <thread>
9
10
#include "
BLEAPI.hpp
"
11
#include <
MIDI_Interfaces/BLEMIDI/BLEMIDIPacketBuilder.hpp
>
12
13
BEGIN_CS_NAMESPACE
14
16
template
<
class
Derived>
17
class
ThreadedBLEMIDISender
{
18
public
:
19
ThreadedBLEMIDISender
() =
default
;
20
ThreadedBLEMIDISender
(
const
ThreadedBLEMIDISender
&) =
delete
;
21
ThreadedBLEMIDISender
&
operator=
(
const
ThreadedBLEMIDISender
&) =
delete
;
22
~ThreadedBLEMIDISender
();
23
25
void
begin
();
26
27
struct
ProtectedBuilder;
28
33
ProtectedBuilder
acquirePacket
();
36
void
releasePacketAndNotify
(ProtectedBuilder &lck);
37
39
void
sendNow
(ProtectedBuilder &lck);
40
43
void
updateMTU
(uint16_t mtu);
45
uint16_t
getMinMTU
()
const
{
return
min_mtu
; }
47
void
forceMinMTU
(uint16_t mtu);
48
51
void
setTimeout
(std::chrono::milliseconds
timeout
);
52
53
private
:
55
void
sendData
(
BLEDataView
) =
delete
;
// should be implemented by subclass
56
61
bool
handleSendEvents
();
62
63
private
:
64
struct
{
66
BLEMIDIPacketBuilder
packet
;
68
bool
stop
=
false
;
70
bool
flush
=
false
;
73
std::chrono::milliseconds
timeout
{10};
75
std::mutex
mtx
;
76
}
shared
{};
80
std::condition_variable
cv
;
82
using
lock_t
= std::unique_lock<std::mutex>;
84
std::thread
send_thread
;
85
86
private
:
88
std::atomic_uint_fast16_t
min_mtu
{23};
92
std::atomic_uint_fast16_t
force_min_mtu
{515};
93
94
public
:
95
struct
ProtectedBuilder
{
96
BLEMIDIPacketBuilder
*
packet
;
97
lock_t
lck
;
98
};
99
};
100
101
END_CS_NAMESPACE
102
103
#include "ThreadedBLEMIDISender.ipp"
BLEAPI.hpp
Type definitions and callback interfaces for communication between the low-level BLE stacks and highe...
BLEMIDIPacketBuilder.hpp
NamespaceSettings.hpp
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition
Settings/NamespaceSettings.hpp:14
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition
Settings/NamespaceSettings.hpp:11
BLEMIDIPacketBuilder
Class for building MIDI over Bluetooth Low Energy packets.
Definition
BLEMIDIPacketBuilder.hpp:10
ThreadedBLEMIDISender< ESP32BLEBackend >::packet
BLEMIDIPacketBuilder packet
Definition
ThreadedBLEMIDISender.hpp:66
ThreadedBLEMIDISender::sendData
void sendData(BLEDataView)=delete
Actually perform the BLE notification with the given data.
ThreadedBLEMIDISender< ESP32BLEBackend >::cv
std::condition_variable cv
Definition
ThreadedBLEMIDISender.hpp:80
ThreadedBLEMIDISender::getMinMTU
uint16_t getMinMTU() const
Get the minimum MTU of all connected clients.
Definition
ThreadedBLEMIDISender.hpp:45
ThreadedBLEMIDISender< ESP32BLEBackend >::lock_t
std::unique_lock< std::mutex > lock_t
Definition
ThreadedBLEMIDISender.hpp:82
ThreadedBLEMIDISender< ESP32BLEBackend >::timeout
std::chrono::milliseconds timeout
Definition
ThreadedBLEMIDISender.hpp:73
ThreadedBLEMIDISender::setTimeout
void setTimeout(std::chrono::milliseconds timeout)
Set the timeout, the number of milliseconds to buffer the outgoing MIDI messages.
ThreadedBLEMIDISender::handleSendEvents
bool handleSendEvents()
Function that waits for BLE packets and sends them in the background.
ThreadedBLEMIDISender::forceMinMTU
void forceMinMTU(uint16_t mtu)
Force the MTU to an artificially small value (used for testing).
ThreadedBLEMIDISender::operator=
ThreadedBLEMIDISender & operator=(const ThreadedBLEMIDISender &)=delete
ThreadedBLEMIDISender< ESP32BLEBackend >::stop
bool stop
Definition
ThreadedBLEMIDISender.hpp:68
ThreadedBLEMIDISender< ESP32BLEBackend >::force_min_mtu
std::atomic_uint_fast16_t force_min_mtu
Definition
ThreadedBLEMIDISender.hpp:92
ThreadedBLEMIDISender::ThreadedBLEMIDISender
ThreadedBLEMIDISender(const ThreadedBLEMIDISender &)=delete
ThreadedBLEMIDISender::acquirePacket
ProtectedBuilder acquirePacket()
Acquire exclusive access to the buffer to be sent by the timer.
ThreadedBLEMIDISender::shared
struct ThreadedBLEMIDISender::@361307330222120137105303366211377223340036235154 shared
ThreadedBLEMIDISender< ESP32BLEBackend >::flush
bool flush
Definition
ThreadedBLEMIDISender.hpp:70
ThreadedBLEMIDISender::begin
void begin()
Start the background thread.
ThreadedBLEMIDISender::releasePacketAndNotify
void releasePacketAndNotify(ProtectedBuilder &lck)
Release exclusive access to the buffer and notify the sender thread that data is available.
ThreadedBLEMIDISender::ThreadedBLEMIDISender
ThreadedBLEMIDISender()=default
ThreadedBLEMIDISender< ESP32BLEBackend >::send_thread
std::thread send_thread
Definition
ThreadedBLEMIDISender.hpp:84
ThreadedBLEMIDISender< ESP32BLEBackend >::mtx
std::mutex mtx
Definition
ThreadedBLEMIDISender.hpp:75
ThreadedBLEMIDISender::updateMTU
void updateMTU(uint16_t mtu)
Set the maximum transmission unit of the Bluetooth link.
ThreadedBLEMIDISender< ESP32BLEBackend >::min_mtu
std::atomic_uint_fast16_t min_mtu
Definition
ThreadedBLEMIDISender.hpp:88
ThreadedBLEMIDISender::~ThreadedBLEMIDISender
~ThreadedBLEMIDISender()
ThreadedBLEMIDISender::sendNow
void sendNow(ProtectedBuilder &lck)
Sends the data immediately without waiting for the timeout.
BLEDataView
Non-owning, std::span-style read-only view of BLE data.
Definition
BLEAPI.hpp:42
ThreadedBLEMIDISender::ProtectedBuilder
Definition
ThreadedBLEMIDISender.hpp:95
ThreadedBLEMIDISender::ProtectedBuilder::lck
lock_t lck
Definition
ThreadedBLEMIDISender.hpp:97
ThreadedBLEMIDISender::ProtectedBuilder::packet
BLEMIDIPacketBuilder * packet
Definition
ThreadedBLEMIDISender.hpp:96
Generated by
1.17.0