Post by redheronmusic on Apr 21, 2023 16:07:17 GMT
Recent user question on MIDIDesigner Forums - is it possible to read a text string in a SysEx message and take action in MDP2 based on a text match?
Yes, MDP2 (with StreamByter) can:
- Query hardware for the SysEx message
- Read an inbound SysEx for a text string
- Test if that matches a stored text string, returning the string number if there is a match
- Take action in MD based on the matched string number, such as jumping to a specific page
See the sample layout here: mididr.com/qa/9594
StreamByter code:
Yes, MDP2 (with StreamByter) can:
- Query hardware for the SysEx message
- Read an inbound SysEx for a text string
- Test if that matches a stored text string, returning the string number if there is a match
- Take action in MD based on the matched string number, such as jumping to a specific page
See the sample layout here: mididr.com/qa/9594
StreamByter code:
# April 19, 2023
# Red Heron Music
# Given input SysEx with embedded text, search W array for a match
# If match, set MatchValid flag, return position in W array - 0-127,
# If no match, clear MatchValid flag, position has no meaning if flag is clear
# Strings are 16 char, you can choose to match shorter length
IF LOAD
Define StartPos $7 # search start string pos in SysEx, 0 based
Define NumStr $128 # number of defined strings, min 1 - max 128
Define NumPos $16 # number of positions to check, max 16, see NOTE
# NOTE - due to bug in SB loop counter, MUST be a factor of 128
# so NumPos can be 1, 2, 4, 8, or 16
# Otherwise results become anomalous
Alias I0 LoopV # vertical looper 0-127
Alias I1 W_ptr # current test in W array
Alias I2 LoopH # horizontal looper 0-15
Alias I3 Match # Match flag
Alias I4 M_ptr # current test in input Message
Alias I5 MatchStrNr # Return String number
# Define match strings.
# For demo, these are the first 128 RD2000 program names
# Spreadsheet provided to simplify loading
# Due to loop limitations, 128 is hard max on number of test strings
Ass W0 = 53 74 61 67 65 20 47 72 61 6E 64 20 20 20 20 20 # Stage Grand
Ass W10 = 44 65 65 70 20 43 6F 6E 63 65 72 74 20 20 20 20 # Deep Concert
# ...
Ass W7E0 = 53 74 61 67 65 20 45 50 20 32 20 20 20 20 20 20 # Stage EP 2
Ass W7F0 = 53 74 61 67 65 20 45 50 20 54 72 6D 20 20 20 20 # Stage EP Trm
End
# Start by testing for the hardware specific SysEx header of desired message
# Testing up to four positions at a time
# Sample case header is F0 06 10 07 1A 7F 7F
If M0 == F0 06 10 07
If M04 == 1A 7F 7F
# Passed header screen, start searching the W array
Ass LoopV = 0
Ass W_ptr = 0
While LoopV < NumStr
Ass M_ptr = StartPos
Ass Match = 1
Ass LoopH = 0
While LoopH < NumPos
If MI4 != WI1 # effectively M(M_ptr) != W(W_ptr), but indirect doesn’t work with alias
Ass Match = 0 # test failed, clear tentative match flag
# We could exit here, but the SB Loop bug will cause anomalous results
# so process remaining positions so we maintain factor of 128 loops
End
# increment to test next horizontal position
Mat W_ptr = W_ptr + 1
Mat M_ptr = M_ptr + 1
Mat LoopH = LoopH + 1
End
If Match == 1 # if still 1, all characters matched
Ass MatchStrNr = LoopV # Save match location
Ass LoopV = NumStr # Success, skip remaining names
End
# Increment to test next
Mat LoopV = LoopV + 1
Mat W_ptr = LoopV * $16
End
# Match and MatchStrNr are now valid, implement desired action here
# for Stand alone SB, display results:
Set Lb0 Match
Set Lb1 MatchStrNr
# For MDP2 demo, send to input processing with SB wrap around
Snd F0 00 01 7E 77 01 Match F7
If Match != 0 # Only send when valid
Snd F0 00 01 7E 77 02 MatchStrNr F7
End
End
End