|
Post by espiegel123 on Aug 26, 2019 4:24:24 GMT
I need to create a lookup table that will map an incoming single-byte index and provide a two-byte value that will be used in an outgoing message.
Can two-byte values be stored in lookup tables?
I need to split the two-byte value into two bytes after retrieval because a checksum operation needs to be performed on them.
Here is a pseudocode example.
Let's say my lookup table is L and it is setup like this
ASS L0 = llmm ASS L1 = nnpp ASS L2 = qqrr
where llmm is a two-byte number that will eventually be split into ll mm
# incoming message will be something like F0 F1 F1 zz vv F7 # where M0-M2 are a header # M3 (zz) is the index used for the lookup and vv is a value passed out
if M0 == F0 F1 F1 #construct a new message to send in this form # where 32 32 45 is a header byte newMessage = F0 32 32 45 LM3a LM3b M4 checksum F7 #where checksum is a roland style checksum performed on the non-header bytes
# and where LM3a is the first byte of the the value stored in LM3 and LM3b is the second byte.
end
|
|
nic
Soapbox Supremo
Troublemaker
Press any key to continue
Posts: 2,011
|
Post by nic on Aug 26, 2019 6:51:41 GMT
Hi espiegel123, The easiest way to do this is to store your two values across 2 arrays, like so: # 2 byte lookup table in I0-7F and J0-7F ASS I0 = 01 02 03 04 ASS J0 = 11 12 13 14
# use M3 to determine sysex # header via I/J lookup IF M0 == F0 IM3 JM3 ... ENDThe OCD part of me would probably try and store the lookup table in just one array with byte 1 in positions 0 to 127 and byte 2 in positions 128 to 255 and add 127 to the index to get the second byte. Regards, Nic.
|
|
|
Post by espiegel123 on Aug 26, 2019 14:46:46 GMT
Nic,
Thanks for the prompt response. For a number of reasons it would be good to keep both bytes together in the same table -- not least of which is to make it straightforward to create and edit the codes that make up the table. But also because there will be several lookup tables. If each gets split between two separate arrays, I will run out of arrays to use.
Are there byte operations one could perform that would split a two-byte value into individual bytes? The docs mention a few byte operators for MAT but doesn't mention what operations they map to. I am assuming these are the same as in C.
I am rusty on bitwise operations. So, maybe there is something obvious that I am overlooking.
MATH OPERATIONS ON LOOKUP TABLE INDICES? A related question. Is there a way if you have an index into a lookup table -- lets say in M2 -- to perform a math operation to add an offset to that index or do a multiply.
For example, let's say my M3 has a value of 0x14 and I am using L0 to store two sets of data for each index. Is there a way, with M3 to retrieve a value from L at M3+1 or L at M3*2. For example, if the array notation were L[index, I want to be able to access L[M3+1] or L[M*2]
Thanks
|
|
nic
Soapbox Supremo
Troublemaker
Press any key to continue
Posts: 2,011
|
Post by nic on Aug 26, 2019 15:11:27 GMT
Hi espiegel123 , We can indeed store two bytes in each slot and pull them out as follows: IF LOAD # A0B0 A1B1 ASS L0 = 1234 5678 END
# extract byte a and b of slot n (n is in I0) # from 'L', into I1 and I2 MAT I1 = LI0 / 100 # byte A (shift 8 bits right) MAT I2 = LI0 & 0F # byte B (mask top 8 bits)If I0 contained '1', then I1 would resolve to 56 and I2 would resolve to 78 in the above table > For example, let's say my M3 has a value of 0x14 and I am using L0 to store two sets of data for each index. Is there a way, with M3 to retrieve a value from L at M3+1 or L at M3*2. For example, if the array notation were L[index, I want to be able to access L[M3+1] or L[M*2]Yes, you just setup the correct index in a temporary variable and then use that: # get L[M3 + 1] into I1 MAT I0 = M3 + 1 ASS I1 = LI0
# get L[M3*2] into I2 MAT I0 = M3 * 2 ASS I2 = LI0If you're using the AU some of this stuff could be in subroutines. (new SB extensions for MidiFire currently work in progress) BTW, if you're looking to calculate Roland checksums, this post has the code for that (if you haven't found it already) Regards, Nic.
|
|
|
Post by espiegel123 on Aug 26, 2019 16:37:49 GMT
|
|
|
Post by espiegel123 on Aug 26, 2019 16:59:52 GMT
I will be using this in MidiDesigner Pro. Does their Streambyter plug-in support subroutines?
|
|
nic
Soapbox Supremo
Troublemaker
Press any key to continue
Posts: 2,011
|
Post by nic on Aug 26, 2019 17:34:49 GMT
Hi espiegel123, I'm afraid the StreamByter in MDP is an older version, so none of the recent extensions (subroutines included) are included. All the code above should work fine in MDP/AU and MidiFire though; I made that in standard/concise format. Regards, Nic.
|
|
|
Post by espiegel123 on Aug 26, 2019 17:52:25 GMT
Will MIDIFire and the MDP plugin be updated at some point with the new extensions?
|
|
nic
Soapbox Supremo
Troublemaker
Press any key to continue
Posts: 2,011
|
Post by nic on Aug 26, 2019 19:35:18 GMT
Current dev. version of MidiFire has it already. Should be going into beta testing very soon.
As for MDP, that's one to ask Dan.
Regards, Nic.
|
|
|
Post by espiegel123 on Aug 27, 2019 0:19:22 GMT
Got my code all written up. It installs fine in the the Streambyter AU but in MDP, I get an error on two lines: BLOCK and ELSE
Are block and else not supported in the MDP version of streambyter?
|
|
|
Post by espiegel123 on Aug 27, 2019 4:05:38 GMT
Got my code all written up. It installs fine in the the Streambyter AU but in MDP, I get an error on two lines: BLOCK and ELSE Are block and else not supported in the MDP version of streambyter? Btw, I now how to work around those. I was just wondering if they were supposed to work in the MDP Streambyter.
|
|
nic
Soapbox Supremo
Troublemaker
Press any key to continue
Posts: 2,011
|
Post by nic on Aug 27, 2019 6:29:11 GMT
Hi espiegel123 , ELSE and BLOCK are both part of the recent language improvements and are currently only in StreamByter app/AU. For me, the lack of ELSE is something I really have to keep in mind. Regards, Nic.
|
|