Home › Forums › General › Programming › Lua in Ctrlr – list of frequently used commands
- This topic has 7 replies, 7 voices, and was last updated 9 years, 2 months ago by m.tarenskeen.
-
AuthorPosts
-
December 20, 2012 at 8:18 pm #5217
I sometimes take breaks from working on panels etc and tend to forget some of the basics when digging back in to where I left off. I’ve kept this list of frequently used scripts and figured what the heck, I’ll share with everyone as it might be really helpful for people besides just myself. I don’t know why but some of these tend to slip my memory so it helps to just reference my list of…
COMMONLY USED LUA SCRIPTS
—————————————————————————————————————get value of a modulator, assign it to a variable:
variableName = panel:getModulatorByName(“Modulator Name”):getModulatorValue()—————————————————————————————————————
get a modulator and assign a value to it:
panel:getModulatorByName(“ModulatorName”):setModulatorValue((2), false, true, false)
panel:getModulatorByName(“ModulatorName”):setModulatorValue((variableName), false, true, false)—————————————————————————————————————
print some message in the console:
console (“this is my message that will appear in the console…”)—————————————————————————————————————
print the value of something in the console:
console (string.format (“this is a number %d”, number ))—————————————————————————————————————
Print value to console:
a = 10
console(“a = “..a)—————————————————————————————————————
call some other script to run:
scriptNameToRun()—————————————————————————————————————
display the value of a variable on a uiLabel
label = panel:getComponent(“label”)
if label ~= nil then
label:setPropertyString (“uiLabelText”, “text”)
endor by using the special component method
label:setComponentText (string.format(“my text”))
—————————————————————————————————————
Write variables to string:
a = “a”
b = 10
c = string.format(“%s%s”,a,b)
console(“c = “..c)——————————————–
——————————————–
Those are some of the basics that I tend to frequently use and for some reason tend to frequently forget the exact syntax so sometimes a cheat-sheet like this helps. Hopefully it helps you, I’ll probably add some stuff here later, if others want to add some too that’s cool.
Happy Holidays 🙂
- This topic was modified 11 years, 3 months ago by msepsis.
Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen
December 21, 2012 at 11:39 am #5236Good idea!
I am using alot of sysex and i use these all the time:
Insert values into a hexstring:
val1 = 1
val2 = 10
hexstring = string.format(“f0 18 21 %.2x 55 01 02 5f 01 %.2x 00 6b f7″, val1, val2)produces:
f0 18 21 01 55 01 02 5f 01 0a 00 6b f7Of course you can also get values from modulators and use those
val = panel:getModulatorByName(“myModulator”):getModulatorValue()
_______________________________________________________________________
Grabbing values from an incoming hexstring
Suppose this is the string you received:
f0 18 21 01 55 01 02 5f 01 0a 00 6b f7
Now to extract the byte with value 55:
extractedByte = midi:getLuaData():getByte(4)
Notice that although 01 is on the 5th place it is infact the 4th byte, as ctrlr starts counting AFTER the header “f0” .
You can also extract a range of bytes:
rangeOfBytes = midi:getLuaData():getRange(3, 7)
this will store the values “01 55 01 02 5f” in rangeOfBytes
_____________________________________________________________________
To check the results of these operations in console you need to do some conversion or you get errors like “sting expected, received number”:
string1 = string.format(someHexString)
console(string.format(string1))_______________________________________________________________________
Will add more in time
January 18, 2013 at 8:00 am #5634Thought I would add one —
panel:sendMidiMessageNow(CtrlrMidiMessage(“f0 11 63 7d 3d 00 00 00 f7”))
Sends message to Synth
January 18, 2013 at 1:37 pm #5640Tehre is a lot of useful shortcuts, handy lua tricks in the latest DEMO panel
March 14, 2013 at 6:28 pm #7185- This reply was modified 10 years, 10 months ago by zeoka.
October 12, 2013 at 10:56 pm #14112OK, I have a couple of useful functions that can be applied to strings containing patch names for instance.
—————————————————————————————————————
The following Function extracts a piece of the string from characters 1 to 16function edit (s) return (string.sub(s,1,16)) end nameEdit = (edit(myString))
—————————————————————————————————————
The following Function removes whitespace (spaces) from either end of a stringfunction trim (s) return (string.gsub(s, "^%s*(.-)%s*$", "%1")) end nameTrim = (trim(myString))
—————————————————————————————————————
Hope these prove useful to others.
Here is some noise I organised into an acceptable format:
https://soundcloud.com/lfo2vco/a-dark-crystalMay 20, 2014 at 12:14 pm #23678Hi
add this example : a shared textbox parameter name/value linked to one/several
mods + a default color for default value (here 64)-- -- Called when a modulator value changes -- @mod http://ctrlr.org/api/class_ctrlr_modulator.html -- @value new numeric value of the modulator -- Slidval64 = function(mod, newValue) sl64 = mod:getComponent() function ValueCallback(timerId) if timer ~= nil then timer:stopTimer(40) end panel:getComponent("my label text"):setText(mod:getModulatorName()) end panel:getComponent("my label text"):setText(sl64:getComponentText()) if newValue ~= 64 then sl64:setProperty("uiSliderThumbColour",col1:toString(),false) sl64:setProperty("uiSliderTrackColour",col2:toString(),false) sl64:setProperty("uiSliderValueTextColour",col5:toString(),false) else sl64:setProperty("uiSliderThumbColour",col3:toString(),false) sl64:setProperty("uiSliderTrackColour",col4:toString(),false) sl64:setProperty("uiSliderValueTextColour",col6:toString(),false) end timer:setCallback (40,ValueCallback) timer:startTimer(40,500) end
colors are defined elsewhere(Called when the panel is created).ex col4 = Colour(0x5dc68e6c)
It is possible to share parameter name/value directly on the modulator too : just use the adequate properties
January 10, 2015 at 1:51 pm #35285This old thread is still very useful – but hard to find – for starting panel designers like me. Unfortunately I found these posts *after* I already found out how things like this work 🙂
Maybe a “Lua in Ctrlr – list of frequently used commands” page can be added to the “Documentation” section of this website.
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.