Loading...
Searching...
No Matches
MidiSysexArena.hpp
1#pragma once
2#include <libremidi/detail/conversion.hpp>
3#include <libremidi/ump.hpp>
4
5#include <algorithm>
6#include <array>
7#include <cstddef>
8#include <cstdint>
9#include <span>
10
11namespace Process
12{
30{
31public:
32 static constexpr std::size_t max_message = 4096;
33 static constexpr std::size_t capacity = 16384;
34 using stream = libremidi::ump_to_midi1_stream<max_message>;
35
36 static bool isSysex(const libremidi::ump& packet) noexcept
37 {
38 return packet.get_type() == libremidi::midi2::message_type::SYSEX7;
39 }
40
43 std::span<const uint8_t> feed(stream& s, const libremidi::ump& packet) noexcept
44 {
45 if(!isSysex(packet))
46 return {};
47
48 const auto dropped_before = s.dropped();
49 const auto message = s.feed(packet);
50 m_dropped += s.dropped() - dropped_before;
51 if(message.empty())
52 return {};
53
54 if(message.size() > capacity - m_used)
55 {
56 ++m_dropped;
57 return {};
58 }
59
60 uint8_t* const dst = m_bytes.data() + m_used;
61 std::copy(message.begin(), message.end(), dst);
62 m_used += message.size();
63 return {dst, message.size()};
64 }
65
66 void clear() noexcept { m_used = 0; }
67
68 std::size_t dropped() const noexcept { return m_dropped; }
69
70private:
71 std::array<uint8_t, capacity> m_bytes;
72 std::size_t m_used{};
73 std::size_t m_dropped{};
74};
75}
Definition MidiSysexArena.hpp:30
std::span< const uint8_t > feed(stream &s, const libremidi::ump &packet) noexcept
Definition MidiSysexArena.hpp:43
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1115