Page 1 of 1
Decoding encoded Sysex
Posted: 16 Oct 2013 14:55
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?
Re: Decoding encoded Sysex
Posted: 16 Oct 2013 15:52
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?
Re: Decoding encoded Sysex
Posted: 16 Oct 2013 22:27
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
Re: Decoding encoded Sysex
Posted: 16 Oct 2013 23:51
by electrofux
Hi,
thx for the help. I was already trying to build ASCII tables and loop through it
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?
Re: Decoding encoded Sysex
Posted: 17 Oct 2013 01:11
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
Re: Decoding encoded Sysex
Posted: 17 Oct 2013 10:02
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.
Re: Decoding encoded Sysex
Posted: 17 Oct 2013 10:52
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
Re: Decoding encoded Sysex
Posted: 18 Oct 2013 10:25
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.
Re: Decoding encoded Sysex
Posted: 18 Oct 2013 16:20
by Phil999
wow, this is very cool.
Re: Decoding encoded Sysex
Posted: 19 Oct 2013 10:58
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.