[solved] How to get display the selected text of an uilistbox somewhere else?

Home Forums General Programming [solved] How to get display the selected text of an uilistbox somewhere else?

Viewing 17 posts - 1 through 17 (of 17 total)
  • Author
    Posts
  • #69383
    iceleben
    Participant
      • Topics: 7
      • Replies: 13
      • Total: 20

      As the title says how do I get the selected text of an Uilistbox displayed somewhere else? The funny thing is that an Ui Label with the “display last selected modulator” checked shows it so it has to be accessible somehow. I can only get the value or the complete List but not the individual selected text…

      • This topic was modified 7 years, 11 months ago by iceleben.
      #69384
      goodweather
      Participant
        • Topics: 45
        • Replies: 550
        • Total: 595
        • ★★★

        Hi,
        I have implemented that in my Pro 2 librarian (soon to be published). I’m using Lua methods to copy the selected item of a uiListbox into a uiLabel.
        I’ll also describe it extensively in the Step by Step guide 2.0.

        If you know the item that has been clicked (I can also give you the code and logic for that), you can use the following statement:
        txtSource:getComponent():setPropertyString ("uiLabelText", L(lbDisk1:getTextForValue(iLastSelectedProgram)))

        where

        • txtSource is your label modulator. I defined txtSource = panel:getModulatorByName(“txtSource”) during panel initialization
        • lbDisk1 is your list box. I defined lbDisk1 = panel:getListBox(“Disk1”) during panel initialization
        • iLastSelectedProgram is your item number in the list box

        Let me know if you need more hints…

        #69386
        iceleben
        Participant
          • Topics: 7
          • Replies: 13
          • Total: 20

          Hi Goodweather,

          Ahhhh me stupid it I get it….iLastSelectedProgram is not a value by Default but one you defined

          xu=panel:getModulatorByName(“FactoryBank1”):getModulatorValue()
          lbDisk1 = panel:getListBox(“FactoryBank1”):getTextForValue(xu)

          panel:getComponent(“LCD10”):setPropertyString (“uiLabelText”,lbDisk1)
          end

          works fine

          Thx so much Goodweather – Ctrlr is getting better Each day I work with it! But then I want to Change a lot of stuff I did before 😉

          • This reply was modified 7 years, 11 months ago by iceleben.
          • This reply was modified 7 years, 11 months ago by iceleben.
          • This reply was modified 7 years, 11 months ago by iceleben.
          • This reply was modified 7 years, 11 months ago by iceleben.
          • This reply was modified 7 years, 11 months ago by iceleben.
          • This reply was modified 7 years, 11 months ago by iceleben.
          #69394
          goodweather
          Participant
            • Topics: 45
            • Replies: 550
            • Total: 595
            • ★★★

            Nice to read!
            Yes, iLastSelectedProgram is a variable containing the selected Item.
            In my Pro 2 implementation, I’m doing the complete management based on mouse clicks. You don’t need to select an actual value with a modulator but just clicking on the program you want to load.
            But that’s another story 🙂

            #69395
            iceleben
            Participant
              • Topics: 7
              • Replies: 13
              • Total: 20

              is there an easy way to convert the lbDisk1 Data from the above example to a string if I have the
              panel:getComponent(“LCD10″):setPropertyString (“uiLabelText”,lbDisk1) set to
              panel:getComponent(“LCD10″):setPropertyString (“uiLabelText”,string.format(“%s”,lbDisk1))

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

                What do you want to do? I don’t follow you.
                The whole content of a uiListBox is already a string…
                You set it with setPropertyString (“uiListBoxContent”, “Your content”) and you get it with getPropertyString (“uiListBoxContent”).

                You can assemble the content of a uiListBox with a loop like:

                for i=0, 98 do
                	if i==0 then
                		sListBoxContent = sListBoxContent..string.format("%s", "P1 "..sTemp)
                	else
                		sListBoxContent = sListBoxContent..string.format("\n%s", "P"..tostring(i+1).." "..sTemp)
                	end
                end

                The first program should not have a return before all the other ones well.
                sTemp is the name of each program (I have removed here the way I’m getting it and you need to replace by your own stuff).

                #69397
                iceleben
                Participant
                  • Topics: 7
                  • Replies: 13
                  • Total: 20

                  What I’d like to do is – I already have an ui LCD Modulator that is showing some stuff

                  panel:getComponent(“ComScreen”):setPropertyString (“uiLabelText”,string.format(“%s %s %s %s %s %s”,lors,ramrom,bnkscreen,bnr,pot,ToneNbr))

                  and in the “pot variable” I’d like to show the clicked selected box text. At the moment with the above example I get the error “string expected got userdata”

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

                    Always easier when you know the goal 🙂

                    Create a method that you can call BankItem_OnClick with type uiListBoxItemClicked.
                    When using it, the variable “value” will contain the number of the selected item.
                    So, in that method you can update your LCD with the code:

                    panel:getComponent(“ComScreen”):setPropertyString (“uiLabelText”,string.format(“%s %s %s %s %s %s”,lors,ramrom,bnkscreen,bnr,value,ToneNbr))

                    Compile the method then select your listbox and set the property “Called when Item is clicked” (somewhere at the bottom of the properties list) to BankItem_OnClick

                    Should work fine…

                    #69402
                    iceleben
                    Participant
                      • Topics: 7
                      • Replies: 13
                      • Total: 20

                      Hi Goodweather,

                      thx again, I tried it with:
                      BankItem_OnClick=function(uiListBoxItemClicked,value)
                      panel:getComponent(“LCD10”):setPropertyString (“uiLabelText”,string.format(“%s”,value))
                      end
                      but then again I get the number displayed but not the text from the List box

                      But finally after a lot of ” I am groot” moments I found a solution that works and might be interesting for userdata Problems

                      TextTestDisplay=function()
                      xu=panel:getModulatorByName(“FactoryBank1”):getModulatorValue()
                      lbDisk1 = panel:getListBox(“FactoryBank1″):getTextForValue(xu)
                      xyz=lbDisk1+”” –this little sucker converts userdata to a string
                      panel:getComponent(“LCD10”):setPropertyString (“uiLabelText”,string.format(“%s”,xyz))
                      end

                      My Brain hurts 😉

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

                        Well… different things

                        • Your method must be (type it exactly like this): BankItem_OnClick = function(–[[ CtrlrModulator –]] modulator, –[[ number –]] value)
                        • within the method code, “value” is the number of the item clicked. If you want to display it, use console(tostring(value)). tostring() is much easier than string.format
                        • if you need the text corresponding to the “value” then use L(lbBank1:getTextForValue(value))

                        Good luck!

                        #69404
                        iceleben
                        Participant
                          • Topics: 7
                          • Replies: 13
                          • Total: 20

                          Goodweather, youre the Scripting hero!
                          works fine:
                          BankItem_OnClick = function(–[[ CtrlrModulator –]] modulator, –[[ number –]] value)
                          xyz=L(panel:getListBox(“FactoryBank1”):getTextForValue(value))
                          panel:getComponent(“LCD10”):setPropertyString (“uiLabelText”,string.format(“%s”,xyz))
                          end
                          So if I understand correctly in the function line there is the reference for modulator with its value being made.
                          And then in the xyz…line the Modulator is ” panel:getListBox(“FactoryBank1″):” with the value being converted to the the Text…what exactly does the L stand for?
                          BtW Im doing a Panel for the MKS80 work in Progress file attached below

                          Attachments:
                          You must be logged in to view attached files.
                          #69406
                          goodweather
                          Participant
                            • Topics: 45
                            • Replies: 550
                            • Total: 595
                            • ★★★

                            Good 🙂

                            BankItem_OnClick is a callback function this means that it will be called each time you click on an item if you assign that function to your uiListbox property “Called when Item is clicked”. Basically, this is what you want to do: refresh your LCD each time an item is clicked…

                            I see you are using panel.getComponent(“LCD10”). Did you initialize all your modulators somewhere? In fact you should create a method containing all your modulators initialization like xyz = panel.getModulatorByName(“Bank1”) and you assign that method to your panel property “Called when panel is loaded”.
                            Then in all your methods, you don’t need to refer to the actual name of the modulator and the performance will be better as Ctrlr doesn’t need to go through the list of modulators to search their names (explained by Atom somewhere in the forum).
                            So, in your methods you simply use: xyz.getComponent().setPropertyString… to reach the component part within the Bank1 modulator.
                            In my Pro 2 panel I define things like lblLCD10 = panel.getModulatorByName(“LCD10”) to indicate it is a label that the user cannot change. I have also modSomething for all buttons; the Something being the same as the actual name of the modulators. Advantage is that I always know what type of component I’m handling (as long as I respect my own rule…).

                            About the L() function, I got the tip from dasfaker who had a similar problem. It is a string conversion function that must be used sometimes when comparing string objects.
                            Quote from Atom:

                            I think this might be a Lua issue in it’s core you are comparing a object of type String() and a string, getLuaName() is an alias to getName() and they both return a String()

                            so in order to compare the actual String() content you should do something like

                            m = panel:getModulatorByName (“very fucked up modulator”)
                            console (m:getName())
                            if L(m:getName()) == “very fucked up modulator” then
                            console (“Yup i got that modulator i needed”)
                            else
                            console (“Nope couldn’t get it”)
                            end
                            That is put the modulator:getName() in a L() function, this changes the String() object to a std::string object that is known to Lua as an object that has a string inside it.

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

                              Forgot to say: very nice panel! Congrats!
                              Keep the good work!
                              On my side, I’m now finishing the Pro 2 panel and will soon release it for testing (busy with the logic of the Load/Save on main panel and the librarian manipulations).
                              Best regards!

                              #69408
                              iceleben
                              Participant
                                • Topics: 7
                                • Replies: 13
                                • Total: 20

                                Thx so much Goodweather,
                                I tried to declare the Modulators in a called when the Panel has finished loading method but then I stumbled in the same Problems you had, tried the timer but still ist Buggy so for now I dropped it, if I see in your Panel how you managed that I’ll implement that as well 😉
                                While you are at the librarian manipulater – maybe you can help me again with something,again with the UiList Box. If I want to change the text from an UIListBox row (e.g. the one being clicked) with something I typed in a Ui Label what would be the Best way to do that? And is it possible to just Show 8 entries from an UiListBox that contains more then that?
                                Cant await your Panel and as well the new Manual, without you I think I had allready given up..

                                • This reply was modified 7 years, 11 months ago by iceleben.
                                #69410
                                iceleben
                                Participant
                                  • Topics: 7
                                  • Replies: 13
                                  • Total: 20

                                  for the 2nd question I found a solution:
                                  newwritetest=function(–[[ CtrlrModulator –]] modulator, –[[ number –]] value)

                                  xvx=L(panel:getListBox(“FactoryBank1”):getTextForValue(0))
                                  xvy=L(panel:getListBox(“FactoryBank1”):getTextForValue(1))
                                  xvz=L(panel:getListBox(“FactoryBank1″):getTextForValue(2))
                                  xtext=tostring(xvx..”\n”..xvy..”\n”..xvz)
                                  panel:getComponent(“FactoryBank1old”):setPropertyString (“uiListBoxContent”,xtext)
                                  end
                                  works, but I´m sure you have a better one 🙂 Still stuck with the first question

                                  • This reply was modified 7 years, 11 months ago by iceleben.
                                  • This reply was modified 7 years, 11 months ago by iceleben.
                                  • This reply was modified 7 years, 11 months ago by iceleben.
                                  #69414
                                  goodweather
                                  Participant
                                    • Topics: 45
                                    • Replies: 550
                                    • Total: 595
                                    • ★★★

                                    Well, not sure I follow you…
                                    Q1: to replace the content of one line, there are different approaches depending on other possibilities of your panel.
                                    On the Pro 2, I implemented a librarian and I can manage full banks or single programs belonging to banks. I took a lazy but easy approach to replace one line: I rebuilt the whole listbox content based on the new content of the bank.
                                    Each bank contains 99 programs having the same 1178 bytes structure. This is stored in a Memoryblock and I know precisely where to find the name of each program.
                                    So it is simply a matter to have a loop reading the 99 names and putting them after each other separated by \n

                                    lbDisk1:setPropertyString ("uiListBoxContent", RefreshBankListBox(mbDisk1))
                                    
                                    RefreshBankListBox = function(mbBank)
                                    
                                    	FileSize = mbBank:getSize()
                                    
                                    	if FileSize == 116622 then
                                    		sListBoxContent = ""
                                    		for i=0, 98 do
                                    			UnpackedTempData = utils.unpackDsiData(mbBank:getRange (438+i*1178, 24))
                                    			sTemp = trim(UnpackedTempData:getRange (0, 20):toString())	-- Remove blanks
                                    			sTemp = sTemp:gsub("'", " ")	-- Replace ' by a space as it gives issues in the listbox
                                    			sTemp = sTemp:gsub("\"", " ")	-- Replace " by a space as it gives issues in the listbox
                                    			if i==0 then
                                    				sListBoxContent = sListBoxContent..string.format("%s", "P1 "..sTemp)
                                    			else
                                    				sListBoxContent = sListBoxContent..string.format("\n%s", "P"..tostring(i+1).." "..sTemp)
                                    				--sListBoxContent = sListBoxContent..", \""..sTemp.."\""
                                    			end
                                    		end
                                    		return sListBoxContent
                                    	else
                                    		utils.warnWindow("Refresh bank list box", "Error: bank data not of correct size. Should be 116622 and is "..FileSize.." bytes.")
                                    	end
                                    
                                    end

                                    trim is not a standard function. DSI data is packed so before reading the name I must first unpack the data and hopefully Atom provided a function in Ctrlr to do it.

                                    Another approach is to search for the n-1 and n “\n”, cut your string (string.sub()) and add your new string in between. I tested this and it works fine.
                                    Look at http://www.lua.org/manual/5.1/manual.html#5.4 for string manipulation and use Google for searching for code examples. Don’t take complex code. Often not needed.

                                    Q2: show only 8 names? Do you mean you have a bank of 100 names for example but for some reason you want only to show 8 of them? Well, you can either make a loop and search for the 8th “\n” then take the part of the string until that position or you can rebuild from 1 to 8.
                                    Lua is strong in string manipulation.
                                    I often test small piece of code at http://www.lua.org/demo.html.
                                    Use “print(some_value)” to see some output.

                                    You will learn a lot by reading (take a lot of time) the end of the .cpp files in https://sourceforge.net/p/ctrlrv4/code/HEAD/tree/nightly/Source/Lua/ and in the different folders including in the parent one.
                                    Also by reading things in the Juce API at https://www.juce.com/doc/classes
                                    and in the forum, the different panels made by users and the DEMO panels provided by Atom.
                                    You can also open the Lua console and type in the bottom part what(some_object or variable) to see all functions it can have.
                                    Try with your listbox! what(FactoryBank1)

                                    I add also issues myself in many things but then left it for a few days then came back, read a bit everywhere and solved the issues or found some workaround.

                                    #69415
                                    iceleben
                                    Participant
                                      • Topics: 7
                                      • Replies: 13
                                      • Total: 20

                                      Got it:
                                      newwritetest=function(–[[ CtrlrModulator –]] modulator, –[[ number –]] value)

                                      textable={}
                                      xvt=panel:getComponent(“RenameTxt2”):getProperty(“uiLabelText”)
                                      xvn=panel:getListBox(“FactoryBank1”):getLastRowSelected()+1

                                      xv0=L(panel:getListBox(“FactoryBank1”):getTextForValue(0)) textable[1]=xv0
                                      xv1=L(panel:getListBox(“FactoryBank1”):getTextForValue(1)) textable[2]=xv1
                                      xv2=L(panel:getListBox(“FactoryBank1”):getTextForValue(2)) textable[3]=xv2
                                      xv3=L(panel:getListBox(“FactoryBank1”):getTextForValue(3)) textable[4]=xv3
                                      xv4=L(panel:getListBox(“FactoryBank1”):getTextForValue(4)) textable[5]=xv4
                                      xv5=L(panel:getListBox(“FactoryBank1”):getTextForValue(5)) textable[6]=xv5
                                      xv6=L(panel:getListBox(“FactoryBank1”):getTextForValue(6)) textable[7]=xv6
                                      xv7=L(panel:getListBox(“FactoryBank1″):getTextForValue(7)) textable[8]=xv7

                                      textable[xvn]=xvt
                                      TestDat=table.concat(textable,” “..”\n”,1,8)

                                      xvtest=console(tostring(TestDat))

                                      panel:getComponent(“FactoryBank1old”):setPropertyString (“uiListBoxContent”,TestDat)
                                      end

                                      oh I see you replied…have to read that
                                      the MKS doesnt have any Tone or patchnames at all( I’m lucky I can skip that part :))but I thought it’ll be nice to have some reference in the Panel
                                      the MKS also works with 8 Banks with 8 tones and patches each thats why I went for 8 first..

                                      • This reply was modified 7 years, 11 months ago by iceleben.
                                      • This reply was modified 7 years, 11 months ago by iceleben.
                                    Viewing 17 posts - 1 through 17 (of 17 total)
                                    • The forum ‘Programming’ is closed to new topics and replies.
                                    There is currently 0 users and 64 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