25namespace juce::universal_midi_packets
33template <
size_t numWords>
39 template <
size_t w = numWords, std::enable_if_t<w == 1,
int> = 0>
43 jassert (Utils::getNumWordsForMessageType (a) == 1);
46 template <
size_t w = numWords, std::enable_if_t<w == 2,
int> = 0>
47 Packet (uint32_t a, uint32_t b)
48 : contents { { a, b } }
50 jassert (Utils::getNumWordsForMessageType (a) == 2);
53 template <
size_t w = numWords, std::enable_if_t<w == 3,
int> = 0>
54 Packet (uint32_t a, uint32_t b, uint32_t c)
55 : contents { { a, b, c } }
57 jassert (Utils::getNumWordsForMessageType (a) == 3);
60 template <
size_t w = numWords, std::enable_if_t<w == 4,
int> = 0>
61 Packet (uint32_t a, uint32_t b, uint32_t c, uint32_t d)
62 : contents { { a, b, c, d } }
64 jassert (Utils::getNumWordsForMessageType (a) == 4);
67 template <
size_t w, std::enable_if_t<w == numWords,
int> = 0>
69 : contents (fullPacket)
71 jassert (Utils::getNumWordsForMessageType (fullPacket.
front()) == numWords);
74 Packet withMessageType (uint8_t type)
const noexcept
76 return withU4<0> (type);
79 Packet withGroup (uint8_t group)
const noexcept
81 return withU4<1> (group);
84 Packet withStatus (uint8_t status)
const noexcept
86 return withU4<2> (status);
89 Packet withChannel (uint8_t channel)
const noexcept
91 return withU4<3> (channel);
94 uint8_t getMessageType() const noexcept {
return getU4<0>(); }
96 uint8_t getGroup() const noexcept {
return getU4<1>(); }
98 uint8_t getStatus() const noexcept {
return getU4<2>(); }
100 uint8_t getChannel() const noexcept {
return getU4<3>(); }
102 template <
size_t index>
103 Packet withU4 (uint8_t value)
const noexcept
105 constexpr auto word = index / 8;
107 std::get<word> (
copy.contents) = Utils::U4<index % 8>::set (
copy.template getU32<word>(), value);
111 template <
size_t index>
112 Packet withU8 (uint8_t value)
const noexcept
114 constexpr auto word = index / 4;
116 std::get<word> (
copy.contents) = Utils::U8<index % 4>::set (
copy.template getU32<word>(), value);
120 template <
size_t index>
121 Packet withU16 (uint16_t value)
const noexcept
123 constexpr auto word = index / 2;
125 std::get<word> (
copy.contents) = Utils::U16<index % 2>::set (
copy.template getU32<word>(), value);
129 template <
size_t index>
130 Packet withU32 (uint32_t value)
const noexcept
133 std::get<index> (
copy.contents) = value;
137 template <
size_t index>
140 return Utils::U4<index % 8>::get (this->
template getU32<index / 8>());
143 template <
size_t index>
146 return Utils::U8<index % 4>::get (this->
template getU32<index / 4>());
149 template <
size_t index>
152 return Utils::U16<index % 2>::get (this->
template getU32<index / 2>());
155 template <
size_t index>
158 return std::get<index> (contents);
164 using const_iterator =
typename Contents::const_iterator;
166 const_iterator
begin() const noexcept {
return contents.begin(); }
167 const_iterator
cbegin() const noexcept {
return contents.begin(); }
169 const_iterator
end() const noexcept {
return contents.end(); }
170 const_iterator
cend() const noexcept {
return contents.end(); }
172 const uint32_t*
data() const noexcept {
return contents.data(); }
174 const uint32_t& front() const noexcept {
return contents.front(); }
175 const uint32_t& back() const noexcept {
return contents.back(); }
177 const uint32_t& operator[] (
size_t index)
const noexcept {
return contents[index]; }
180 Contents contents { {} };
183using PacketX1 = Packet<1>;
184using PacketX2 = Packet<2>;
185using PacketX3 = Packet<3>;
186using PacketX4 = Packet<4>;
@ copy
The command ID that should be used to send a "Copy to clipboard" command.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...