87 deluge::l10n::String
load(std::span<std::byte> stream) {
88 using deluge::l10n::String;
89 const std::byte* pos = stream.data();
91 size_t minMsgSize = 163;
93 if (stream.size() < minMsgSize) {
94 std::ranges::copy(stream, &voiceData[6]);
95 return String::STRING_FOR_DX_ERROR_FILE_TOO_SMALL;
98 if (pos[0] != std::byte{0xF0}) {
100 std::copy_n(pos, 4096, &voiceData[6]);
101 return String::STRING_FOR_DX_ERROR_NO_SYSEX_START;
106 for (i = 0; i < stream.size(); ++i) {
107 if (pos[i] == std::byte{0xF7}) {
111 if (i == stream.size()) {
112 return String::STRING_FOR_DX_ERROR_NO_SYSEX_END;
117 if (msgSize != kSysexSize && msgSize != kSmallSysexSize) {
118 return String::STRING_FOR_DX_ERROR_INVALID_LEN;
121 std::copy_n(pos, msgSize, voiceData.begin());
122 size_t dataSize = (msgSize == kSysexSize) ? 4096 : 155;
123 if (sysexChecksum({&voiceData[6], dataSize}) != pos[msgSize - 2]) {
124 return String::STRING_FOR_DX_ERROR_CHECKSUM_FAIL;
127 if (voiceData[1] != std::byte{67} || (voiceData[3] != std::byte{9} && voiceData[3] != std::byte{0})) {
128 return String::STRING_FOR_DX_ERROR_SYSEX_ID;
131 return String::EMPTY_STRING;