Home › Forums › General › Programming › getByte Question
- This topic has 6 replies, 3 voices, and was last updated 7 years, 7 months ago by Refrochia.
-
AuthorPosts
-
September 16, 2016 at 11:49 pm #70041
Hi
Sorry for the very noob question – my programming in lua book has just arrived so not had chance to read it but no doubt somewhere within there I’d be able to answer this question however I’m impatient lol 🙂
I’m reading in data from a pattern dump request of my Korg ER1. All parameters for each part updating successfully but I’m now working on the patterns. I’ve deciphered and mapped out the sysex dump and written a method that can translate a byte into steps 1-7:
V = programData:getByte(83)
This works and my method sets the steps 1-7 according to the value of V.
The problem I’m having is that I dont want to pass an integer to the getByte method – I want to pass the value of a variable (which will be an integer) instead. But I’m getting function overload errors (which from what I understand means that It thinks I’m calling a different getByte function that doesnt exist? Because its expecting an integer but thats what its not getting?)
I’m initialising an array with each cell containing an integer that is the location within the pattern dump of 7 step segments for synth part 1 – each 7 steps being a byte:
S1SeqArray={83,84,86,87,88,89,90,91}
83 being steps 1-7, 84 being steps 9-15 etc. (Steps 8,16,24,32,40,48,56,64 handled differently)
So I’ve setup a for loop with i as the counter going from 0 to 7 and calling the following each iteration:
— V = programData:getByte(S1SeqArray [ i ] )
It fails 🙁 Sure its just some simple syntax I’m getting wrong – help! Please!
Also- is there any way to monitor the value of variables? I’ve used Lemur and that has a monitor object that you can use for this purpose – anything in CTRLR?
Thanks 🙂
September 17, 2016 at 12:08 am #70044September 17, 2016 at 1:20 am #70047Whilst typing my problem it caused me to think about the problem in a different way that gave me new avenues to explore – new leads you could say. Anyway, as a result, I now understand I was initialising the array wrong. In fact its not an array at all – its a table so I need to initialise a key and value. So instead of:
S1SeqArray={83,84,86,87,88,89,90,91}
I need:
S1SeqArray={}
S1SeqArray[0]=83
S1SeqArray[1]=84
S1SeqArray[2]=86
S1SeqArray[3]=87
S1SeqArray[4]=88
S1SeqArray[5]=89
S1SeqArray[6]=90
S1SeqArray[7]=91Then
V = programData:getByte(S1SeqArray[0])
Works so almost there.
Thanks for listening lol
September 17, 2016 at 9:07 am #70049Hi, you can have a look at my Pro2 panel…
LoadProgramData method + ProgramProceed_OnChange (under Programs library) + methods under Midi
If it doesn’t help, let me know and we can look further 🙂September 17, 2016 at 9:38 am #70050I learned a lot in the luawiki. Here all about tables (resp. arrays):
http://lua-users.org/wiki/TablesTutorial
To monitor variables you can use “console”. I extensively used console for debugging my panels. console can only display a string so you will always have to convert nubers to a string:
console (string.format (“decimal=%d hex=%x”, 83, 83))
this will display the first number as decimal and the second as hexif it is a sring anyway:
console (“hello”)When debugging has been done you should delete or comment them because they can significantly slow down the Lua script.
September 17, 2016 at 10:05 am #70051You can also create one method that you call “Miscellaneous” and where you put things like:
-- -- Returns HEX representation of a DECimal number -- dec2hex = function(num) local hexstr = '0123456789ABCDEF' local s = '' while num > 0 do local mod = math.fmod(num, 16) s = string.sub(hexstr, mod+1, mod+1) .. s num = math.floor(num / 16) end if s == '' then s = '0' end return s end -- -- For the conversion of a DECimal number to anything else -- it is just needed to use the built-in Lua function tonumber(string, base) -- -- print(tonumber("0100",2)) -- 4 -- print(tonumber("3F",16)) -- 63 -- -- Returns HEX representation of a String -- function str2hex(str) local hex = '' while #str > 0 do local hb = dec2hex(string.byte(str, 1, 1)) if #hb < 2 then hb = '0' .. hb end hex = hex .. hb str = string.sub(str, 2) end return hex end
September 17, 2016 at 9:59 pm #70055The for the replies guys – really appreciate it.
Goodweather – actually, I’d downloaded you pro2 patch to see how you used getByte before I posted but your use of getByte is different to what I want. Awesome looking panel though 🙂 makes me want a Pro2 lol (that and the sound of course!). And thanks for the examples – they will come in very useful as I hadn’t started to look at the decimal to hex converstion yet. Thanks!
Possemo – You’ve replied to a few of my posts and as ever – sage advice. As it happens, I’d just stumbled upon that very wiki page between my first and last post last night. Thats what allowed me to make some progress. I’ll check out the console – doesnt sound like it will be as convenient as in lemur where you could have numerous monitors showing variable values although at least its something so thanks! 🙂
Back to it 🙂
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.