22#ifndef SBL_PROTOCOL_MIDI_DRAIN_HPP_
23#define SBL_PROTOCOL_MIDI_DRAIN_HPP_
38template<
typename T,
typename =
void>
39struct reads_bytes : std::false_type {};
41struct reads_bytes<T, std::void_t<decltype(T::available()), decltype(T::read_byte())>> : std::true_type {};
43template<
typename T,
typename =
void>
44struct reads_blocks : std::false_type {};
46struct reads_blocks<T, std::void_t<decltype(T::read(std::declval<uint8_t*>(), std::declval<uint32_t>()))>>
62template<
typename Source,
typename Thru>
64 static_assert(detail::reads_blocks<Source>::value || detail::reads_bytes<Source>::value,
65 "SBL ERROR: MIDI source needs read(uint8_t*, uint32_t) or available() and read_byte()");
67 if constexpr (detail::reads_blocks<Source>::value) {
71 thru(
static_cast<const uint8_t*
>(buf), n);
72 parser.
push(buf,
static_cast<uint16_t
>(n));
76 while (Source::available()) {
77 const uint8_t
byte = Source::read_byte();
78 thru(&
byte, uint32_t{1});
93template<
typename Source>
95 return drain<Source>(parser, [](
const uint8_t*, uint32_t) {});
MIDI byte stream parser - state machine with running status.
void push(uint8_t byte)
Feed one byte from UART RX.
MIDI parser, encoder, SMF and sequencer.
uint32_t drain(Parser &parser, Thru &&thru)
Push everything Source has waiting into parser, copying it to a thru.
constexpr uint32_t DRAIN_CHUNK