Hi, I’m not sure whether this is a specific Lua question, or specific to the Guru tool. I’m pretty new to Lua, though not programming
Basically I need it to work like this: I need to form a sysex message that has 3 variable parts, but each message needs to be comprised of the state of all 3. I’m using a ‘global’ table to store values in from the parameters callback functions - theprintGlobalModVals() function just prints the values that I’m storing correctly (just a helper func). But theglobalModVals[1], globalModVals[2], globalModVals[3] part of thesysex_message_template doesn’t pick any values up. Weirdly though, if I initialise the local globalModVals table, sysex_message_template picks up them up (according to the midi out console).
Gets me thinking that I’m creating 2 tables and not referencing one global one. Could this be the case?Should the below be working?
Or maybe there is a better way to do this?!
thanks
function printGlobalModVals()
for k, v in pairs(globalModVals) do
print(k, v)
end
end
function scaleMod63(param)
local val
if param.value <= 31 then val = 65 + (param.value)
else val = param.value
end
return val
end
local globalModVals = {0,0,0}
local group_matrix_slot1 = Group {
name = "Modulation 1",
sysex_message_template = {0xF0, 0x10, 0x06, 0x0B, 0x00, globalModVals[1], globalModVals[2], globalModVals[3], 0xF7},
Parameter {
id = "mtx1_src",
name = "Source",
number = 1,
items = {"None", "Env 1", "Env 2", "LFO 1", "LFO 2", "Noise", "Vibrato", "Ramp 1", "Ramp 2", "Keyboard", "Portamento", "Tracking Gen", "Keyboard Gate", "Velocity", "Release Velocity", "Aftertouch", "Pedal 1", "Pedal 2", "Pitch Bend", "Vibrato", "Rev Vibrato"},
item_values = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
gui_type = "dropdown",
value_callback = function(param)
globalModVals[1] = param.value
printGlobalModVals()
return param.value
end
},
Parameter {
id = "mtx1_amt1",
name = "Amount",
number = 2000,
min_value = 0,
max_value = 63,
default_value = 31,
display_min_value = -31,
display_max_value = 31,
value_callback = function(param)
local val = scaleMod63(param)
globalModVals[2] = val
printGlobalModVals()
return val
end
},
Parameter {
id = "mtx1_dest",
name = "Destination",
number = 3000,
items = {"None", "OSC 1 Frequency", "OSC 1 Pulse Width", "OSC 1 Waveshape", "OSC 2 Frequency", "OSC 2 Pulse Width", "OSC 2 Waveshape", "OSC Mix Level", "VCF FM Amount", "VCF Frequency", "VCF Resonance", "VCA 1 Level", "VCA 2 Level", "ENV 1 Delay", "ENV 1 Attack", "ENV 1 Decay", "ENV 1 Release", "ENV 1 Amplitude", "ENV 2 Delay", "ENV 2 Attack", "ENV 2 Decay", "ENV 2 Release", "ENV 2 Amplitude", "ENV 3 Delay", "ENV 3 Attack", "ENV 3 Decay", "ENV 3 Release", "ENV 3 Amplitude", "LFO 1 Rate", "LFO 1 Amplitude", "LFO 2 Rate", "LFO 2 Amplitude", "Portamento Rate"},
gui_type = "dropdown",
value_callback = function(param)
globalModVals[3] = param.value
printGlobalModVals()
return param.value
end
},
}