How to identify a component by its name?

Home Forums General Programming How to identify a component by its name?

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #68643
    goodweather
    Participant
      • Topics: 45
      • Replies: 550
      • Total: 595
      • ★★★

      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…)!

      #68644
      atom
      Keymaster
        • Topics: 159
        • Replies: 2945
        • Total: 3104
        • ★★★★★

        comp:getOwner():getName()

        components don’t have names, only modulators do, each component has an owner it’s modulator.

        #68647
        goodweather
        Participant
          • Topics: 45
          • Replies: 550
          • Total: 595
          • ★★★

          Thx 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 defined

          Any further hint?

          #68690
          goodweather
          Participant
            • Topics: 45
            • Replies: 550
            • Total: 595
            • ★★★

            Any help? Thx

            #68691
            dasfaker
            Keymaster
              • Topics: 80
              • Replies: 793
              • Total: 873
              • ★★★

              Try the following

              sName = comp:getOwner():getName()
              console("Name: "..L(sName))
              #68694
              Possemo
              Participant
                • Topics: 14
                • Replies: 638
                • Total: 652
                • ★★★

                That 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)
                end

                I 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)

                • This reply was modified 8 years, 1 month ago by Possemo.
                • This reply was modified 8 years, 1 month ago by Possemo.
                #68718
                goodweather
                Participant
                  • Topics: 45
                  • Replies: 550
                  • Total: 595
                  • ★★★

                  Thx 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…

                  #68726
                  Possemo
                  Participant
                    • Topics: 14
                    • Replies: 638
                    • Total: 652
                    • ★★★

                    @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.

                  Viewing 8 posts - 1 through 8 (of 8 total)
                  • The forum ‘Programming’ is closed to new topics and replies.
                  There is currently 0 users and 127 guests online
                  No users are currently active
                  Forum Statistics
                  Threads: 2,495, Posts: 17,374, Members: 77,605
                  Most users ever online was 12 on January 22, 2019 3:47 pm
                  Ctrlr