Home › Forums › General › Programming › How to identify a component by its name?
- This topic has 7 replies, 4 voices, and was last updated 8 years, 1 month ago by Possemo.
-
AuthorPosts
-
March 17, 2016 at 1:47 pm #68643
I’d like to use the same method for several similar listboxes. Basically, populating an uiLabel with the name of the clicked listbox (just an example).
The OnClick method has CtrlrComponent “comp” as argument.
I would like to use the same method but proceed with different actions according to the clicked listbox.
I’m using the following code (just for testing):OnClick = function(--[[ CtrlrComponent --]] comp, --[[ MouseEvent --]] event) sName= comp:getName() console("Name"..sName) end
but this doesn’t work.
When put at “When Item is clicked” I get
“At line [-1]: [C]
Error message: No such operator defined”
When put at “When Mouse is down on this component” I get
“At line [2]: [string “Bank_OnClick”]
Error message: [string “Bank_OnClick”]:2: attempt to call method ‘getName’ (a nil value)”Using Ctrlr 5.3.186
Thx for your help (probably something easy…)!
March 17, 2016 at 2:02 pm #68644comp:getOwner():getName()
components don’t have names, only modulators do, each component has an owner it’s modulator.
March 17, 2016 at 7:55 pm #68647Thx Atom for the clarification.
I remember I tested this without success, hence my post. Anyway I tested it again and got the following.OnClick = function(--[[ CtrlrComponent --]] comp, --[[ MouseEvent --]] event) sName= comp:getOwner():getName() console("Name"..sName) end
Error in console:
At line [-1]: [C]
Error message: No such operator definedAny further hint?
March 20, 2016 at 8:23 pm #68690Any help? Thx
March 20, 2016 at 10:40 pm #68691Try the following
sName = comp:getOwner():getName() console("Name: "..L(sName))
March 20, 2016 at 11:10 pm #68694That seems to do the trick, nice. Can someone explain what L(…) actually does?
btw I would even do it this way:
getname=function(comp)
sName= L(comp:getOwner():getName())
console(“Name “..sName)
endI used it to get a Patchname from an uiLabel without knowing what it does (copied from another panel):
— GET the Patch Name
PatchName=L(panel:getModulatorByName(“PatchName”):getComponent():getProperty
(“uiLabelText”))— Make all characters UPPERCASE. The SuperJX cannot display lowercase characters
PatchNameUp=string.upper(PatchName)— from ASCII to numerical code
char1 =string.byte(PatchNameUp, 1)
char2 =string.byte(PatchNameUp, 2)
char3 =string.byte(PatchNameUp, 3)
char4 =string.byte(PatchNameUp, 4)
char5 =string.byte(PatchNameUp, 5)
char6 =string.byte(PatchNameUp, 6)
char7 =string.byte(PatchNameUp, 7)
char8 =string.byte(PatchNameUp, 8)
char9 =string.byte(PatchNameUp, 9)
char10=string.byte(PatchNameUp,10)
char11=string.byte(PatchNameUp,11)
char12=string.byte(PatchNameUp,12)
char13=string.byte(PatchNameUp,13)
char14=string.byte(PatchNameUp,14)
char15=string.byte(PatchNameUp,15)
char16=string.byte(PatchNameUp,16)
char17=string.byte(PatchNameUp,17)
char18=string.byte(PatchNameUp,18)— Check for empty chars and put each char value in PatchDataValuesTable
if char1 == nil then char1 =32 end PatchDataValuesTable[8] =string.format(“%.2x”, char1)
if char2 == nil then char2 =32 end PatchDataValuesTable[9] =string.format(“%.2x”, char2)
if char3 == nil then char3 =32 end PatchDataValuesTable[10]=string.format(“%.2x”, char3)
if char4 == nil then char4 =32 end PatchDataValuesTable[11]=string.format(“%.2x”, char4)
if char5 == nil then char5 =32 end PatchDataValuesTable[12]=string.format(“%.2x”, char5)
if char6 == nil then char6 =32 end PatchDataValuesTable[13]=string.format(“%.2x”, char6)
if char7 == nil then char7 =32 end PatchDataValuesTable[14]=string.format(“%.2x”, char7)
if char8 == nil then char8 =32 end PatchDataValuesTable[15]=string.format(“%.2x”, char8)
if char9 == nil then char9 =32 end PatchDataValuesTable[16]=string.format(“%.2x”, char9)
if char10== nil then char10=32 end PatchDataValuesTable[17]=string.format(“%.2x”,char10)
if char11== nil then char11=32 end PatchDataValuesTable[18]=string.format(“%.2x”,char11)
if char12== nil then char12=32 end PatchDataValuesTable[19]=string.format(“%.2x”,char12)
if char13== nil then char13=32 end PatchDataValuesTable[20]=string.format(“%.2x”,char13)
if char14== nil then char14=32 end PatchDataValuesTable[21]=string.format(“%.2x”,char14)
if char15== nil then char15=32 end PatchDataValuesTable[22]=string.format(“%.2x”,char15)
if char16== nil then char16=32 end PatchDataValuesTable[23]=string.format(“%.2x”,char16)
if char17== nil then char17=32 end PatchDataValuesTable[24]=string.format(“%.2x”,char17)
if char18== nil then char18=32 end PatchDataValuesTable[25]=string.format(“%.2x”,char18)March 22, 2016 at 5:56 pm #68718Thx dasfaker and Possemo!
It works great! This will allow me to have only one method instead of several (one by type of parameter).Possemo, for your patch name handling, I wonder if it would not be simpler to use Lua table and/or Memoryblock getRange methods…
March 23, 2016 at 9:27 pm #68726@goodweather, this is just an excerpt of a procedure that puts all modulator-values including the patchname into a Lua table that will later be converted into a memoryblock. It can then be saved to disk or sent to the synth as sysex dump.
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.