81 const auto size = m.bytes.size();
86 const auto* data = m.bytes.data();
87 const auto firstByte = data[0];
89 if (firstByte != std::byte { 0xf0 })
91 const auto mask = [size]() -> uint32_t
95 case 0:
return 0xff000000;
96 case 1:
return 0xffff0000;
97 case 2:
return 0xffffff00;
98 case 3:
return 0xffffffff;
104 const auto extraByte = ((((firstByte & std::byte { 0xf0 }) == std::byte { 0xf0 }) ? std::byte { 0x1 } : std::byte { 0x2 }) << 0x4);
105 const PacketX1 packet { mask &
Utils::bytesToWord (extraByte, data[0], data[1], data[2]) };
106 callback (
View (packet.data()));
110 const auto numSysExBytes = (ssize_t) (size - 2);
112 auto* dataOffset = data + 1;
114 if (numMessages <= 1)
116 const auto packet = Factory::makeSysExIn1Packet (0, (uint8_t) numSysExBytes, dataOffset);
117 callback (
View (packet.data()));
121 constexpr ssize_t byteIncrement = 6;
123 for (
auto i =
static_cast<ssize_t
> (numSysExBytes); i > 0; i -= byteIncrement, dataOffset += byteIncrement)
125 const auto func = [&]
127 if (i == numSysExBytes)
128 return Factory::makeSysExStart;
130 if (i <= byteIncrement)
131 return Factory::makeSysExEnd;
133 return Factory::makeSysExContinue;
136 const auto bytesNow = std::min (byteIncrement, i);
137 const auto packet = func (0, (uint8_t) bytesNow, dataOffset);
138 callback (
View (packet.data()));
172 const auto shifted = (uint32_t) (word7Bit << 0x19);
173 const auto repeat = (uint32_t) (word7Bit & 0x3f);
174 const auto mask = (uint32_t) (word7Bit <= 0x40 ? 0x0 : 0xffffffff);
175 return (uint32_t) (shifted | (((repeat << 19)
179 | (repeat >> 5)) & mask));
218 const auto firstWord = v[0];
220 if (Utils::getMessageType (firstWord) != 0x4)
226 const auto status = Utils::getStatus (firstWord);
227 const auto typeAndGroup = ((std::byte { 0x2 } << 0x4) | std::byte { Utils::getGroup (firstWord) });
236 const auto statusAndChannel = std::byte ((firstWord >> 0x10) & 0xff);
237 const auto byte2 = std::byte ((firstWord >> 0x08) & 0xff);
238 const auto byte3 = std::byte {
scaleTo7 (v[1]) };
242 const auto needsCorrection = status == 0x9 && byte3 == std::byte { 0 };
243 const auto correctedByte = needsCorrection ? std::byte { 1 } : byte3;
245 const auto shouldIgnore = status == 0xb && [&]
247 switch (uint8_t (byte2))
270 callback (
View (packet.data()));
276 const auto statusAndChannel = std::byte ((firstWord >> 0x10) & 0xff);
277 const auto byte2 = std::byte {
scaleTo7 (v[1]) };
283 callback (
View (packet.data()));
290 const auto ccX = status == 0x2 ? std::byte { 101 } : std::byte { 99 };
291 const auto ccY = status == 0x2 ? std::byte { 100 } : std::byte { 98 };
292 const auto statusAndChannel = std::byte ((0xb << 0x4) | Utils::getChannel (firstWord));
295 const PacketX1 packets[]
297 PacketX1 {
Utils::bytesToWord (typeAndGroup, statusAndChannel, ccX, std::byte ((firstWord >> 0x8) & 0x7f)) },
298 PacketX1 {
Utils::bytesToWord (typeAndGroup, statusAndChannel, ccY, std::byte ((firstWord >> 0x0) & 0x7f)) },
299 PacketX1 {
Utils::bytesToWord (typeAndGroup, statusAndChannel, std::byte { 6 }, std::byte ((data >> 0x7) & 0x7f)) },
300 PacketX1 {
Utils::bytesToWord (typeAndGroup, statusAndChannel, std::byte { 38 }, std::byte ((data >> 0x0) & 0x7f)) },
303 for (
const auto& packet : packets)
304 callback (
View (packet.data()));
313 const auto statusAndChannel = std::byte ((0xb << 0x4) | Utils::getChannel (firstWord));
314 const auto secondWord = v[1];
316 const PacketX1 packets[]
318 PacketX1 {
Utils::bytesToWord (typeAndGroup, statusAndChannel, std::byte { 0 }, std::byte ((secondWord >> 0x8) & 0x7f)) },
319 PacketX1 {
Utils::bytesToWord (typeAndGroup, statusAndChannel, std::byte { 32 }, std::byte ((secondWord >> 0x0) & 0x7f)) },
322 for (
const auto& packet : packets)
323 callback (
View (packet.data()));
326 const auto statusAndChannel = std::byte ((0xc << 0x4) | Utils::getChannel (firstWord));
329 std::byte ((v[1] >> 0x18) & 0x7f),
331 callback (
View (packet.data()));
338 const auto statusAndChannel = std::byte ((firstWord >> 0x10) & 0xff);
341 std::byte (data & 0x7f),
342 std::byte ((data >> 7) & 0x7f)) };
343 callback (
View (packet.data()));