You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reface MIDI data spec says: The Check-sum is the value that results in a value of 0 for the lower 7 bits when the Model ID, Start Address, Data and Check sum itself are added.
Current implementation is (which does work, so consider this a nit):
defdataBlockFromMessage(message):
ifisOwnSysex(message):
data_len=message[5] <<7|message[6]
iflen(message) ==data_len+9:
data_block=message[8:-2]
check_sum=-0x05fordindata_block:
check_sum-=dif (check_sum&0x7f) ==message[-2]:
# Check sum passedreturndata_blockelse:
raiseException("Checksum error in reface DX data")
raiseException("Got corrupt data block in refaceDX data")
but it seems more correct to do something like:
defdataBlockFromMessage(message):
# Byte Count shows the size of data in blocks from Model ID onward# (up to but not including the checksum).byte_count=message[5] <<7|message[6]
iflen(message) ==byte_count+9:
# The Check-sum is the value that results in a value of 0 for the# lower 7 bits when the Model ID, Start Address, Data and Check sum itself are added.checksum_block=message[0x07:-1]
if ((sum(checksum_block) &0x7f) ==0):
# return "Data" blockreturnmessage[0x0B:-2]
raiseException("Checksum error")
The text was updated successfully, but these errors were encountered:
That code is even older and comes from a never published predecessor to Knobkraft. And strangely, in the same file there is another implementation which is more inline with your version:
int sum = 0;
std::for_each(bulkDump.begin() + 6, bulkDump.end(), [&](uint8 byte) { sum -= byte; });
bulkDump.push_back(sum & 0x7f);
Note that it does subtract instead of add - doesn't make a difference I guess when the result should be 0 in the end after dropping additional bits. I think we can take your version as it certainly is cleaner to read!
Reface MIDI data spec says: The Check-sum is the value that results in a value of 0 for the lower 7 bits when the Model ID, Start Address, Data and Check sum itself are added.
Current implementation is (which does work, so consider this a nit):
but it seems more correct to do something like:
The text was updated successfully, but these errors were encountered: