Decoding encoded Sysex

Discuss problems and solutions.
Post Reply
electrofux
Regular
Posts: 294
Joined: 24 Jan 2012 18:22

Decoding encoded Sysex

Post by electrofux »

I have a Reason Remote codec that encodes the Device names to Sysex with the following algorithm:

Code: Select all

local function stringtosysex(text)
local event=remote.make_midi("f0 11 22 33 10")
start=6
stop=6+string.len(text)-1
for i=start,stop do
sourcePos=i-start+1
event[i] = string.byte(text,sourcePos)
end
event[stop+1] = 247 -- hex f7
Now i am wondering how i decode that in Lemur?
electrofux
Regular
Posts: 294
Joined: 24 Jan 2012 18:22

Re: Decoding encoded Sysex

Post by electrofux »

i mean it is clear how i set up the midi script to receive the sysex string and how to access the different bytes via MIDI_ARGS[]

But how do i decode the alphabetical letter from a byte?
Macciza
Regular
Posts: 1315
Joined: 07 Dec 2011 04:57
Location: Sydney, Australia.

Re: Decoding encoded Sysex

Post by Macciza »

Hi
My reading of it is that it is just sticking the chars into the correct positions in the sysex string . .
I would guess the string.byte() function is returning ascii codes for the letters . . .
So you could use the arraytostring() function in Lemur to convert it back to chars.
Do a quick test to confirm - name your Device as '1' which would give a sysex of "f0 11 22 33 10 49 247" - 49 is ascii for 1 -
So the MIDI_ARGS results would be 11 22 33 10 49 247 as it strips the inital f0
So with script executing on Midi -sysex , if the subarray of the first 4 bytes = 11 22 33 10 then grab the data up to 247 and arraytostring it

Hope that helps
MM
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]
electrofux
Regular
Posts: 294
Joined: 24 Jan 2012 18:22

Re: Decoding encoded Sysex

Post by electrofux »

Hi,

thx for the help. I was already trying to build ASCII tables and loop through it :shock:

There is one little Problem left. When i arraytostring the subarray with scope=artraytostring(MIDI_ARGS,4,length-5) and monitor scope, i get the name of the device correctly but in a monitor it is displayed in "" eg "Thor".
Now i want to use it to switch templates and need to ask eg if(scope=='Thor') but that doesnt work neither does if (scope=='"Thor"){}. I get weird results with the latter. Upon releasing the script it strips the if clause up to the ==, after reloading it accepts the same but blues out (?) the last '" so i assume that isnt conform with the syntax.

How do i go about using the arraytostring in if clauses?
Macciza
Regular
Posts: 1315
Joined: 07 Dec 2011 04:57
Location: Sydney, Australia.

Re: Decoding encoded Sysex

Post by Macciza »

Hi
I guess there are 2 ways to approach this - as ascii or text .. .

1. Work out the ASCII string involved using an ascii table or lemur module ie Thor is {84,104,111,114} - which is what should be returned by your subarray . . .
so if(MIDI_ARGS,4,length-5)=={84,104,111,114} then etc etc . . . Maybe put a comment reminding you what the array stands for . . .

2. Using arraytostring() and text - The "" denotes that it is a string being shown, but in scripts single quotes ' ' delineate strings from variables . . . from memory . .
so if(arraytostring(MIDI_ARGS,4,length-5))=='Thor' then etc etc should work . . .

If you assign the ascii to a var inside the script eg scope=(MIDI_ARGS,4,length-5) then it would be if(arraytostring(scope))=='Thor' etc
You could then do Monitor.value = arraytostring(scope) . . .

Hope this right - noy actually checked for typos or anything . . ..
MM
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]
electrofux
Regular
Posts: 294
Joined: 24 Jan 2012 18:22

Re: Decoding encoded Sysex

Post by electrofux »

thx again, i just read the paragraph about strings as variables and constants in the manual and figured it is going to be a bit more complicated.
I will try your two variants and get this going. I hope i will end up with a really cool Reason template which i will present here shortly.
It was really hard to get the Reason Codec to send the Sysex but now that i have it i can do all sorts of neat stuff in Lemur. :D
Macciza
Regular
Posts: 1315
Joined: 07 Dec 2011 04:57
Location: Sydney, Australia.

Re: Decoding encoded Sysex

Post by Macciza »

Hi
The other option is to have one script to parse the sysex as an OnMIDI script and then call other scripts to deal with the data further
You will have possibly seen this approach in a number of more complex projects
You can separate things out according to a number of criteria this way
MM
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]
electrofux
Regular
Posts: 294
Joined: 24 Jan 2012 18:22

Re: Decoding encoded Sysex

Post by electrofux »

Success :-)

Whenever i change a track in Reason, Lemur now pulls up the correct template. No searching for the right template anymore anything is extremely fluent now.
Next i will get the tracknames into Lemur to also have the channel strips for each synth at hand, then it is done.
Phil999
Regular
Posts: 919
Joined: 11 Jan 2012 01:53

Re: Decoding encoded Sysex

Post by Phil999 »

wow, this is very cool.
Formant+Eurorack, PPG wave 2.2, Korg MS-20, etc., EWI 4000s, QuNeo, etc., Mixbus32c, u-he, MadronaLabs, Samplemodeling, NI, etc., iPad2/4/Pro
electrofux
Regular
Posts: 294
Joined: 24 Jan 2012 18:22

Re: Decoding encoded Sysex

Post by electrofux »

Getting the tracknames now was easy. I also have codedin the connected Mixerchannel into the track names (first 2 numbers correspond to the Mixerchannel) and here i stumbled over the Problem how to convert a eg 14, which comes into Lemur as ['49','52'] to a usable number. But i found a formula (number=('49'-48*10)+('52'-48)) and now i receive everything i want whenever i switch a sequencer track in Reason (Instrument, Sequencer track name, connected SSL Mixer Channel) and i can start coding in some really cool workflow enhancements. Lemur and Reason work really nice together. I hope i can finnish my project soon and deliver something nice.
Post Reply