Logic for infobox to change data/state based on modulator

Home Forums General Programming Logic for infobox to change data/state based on modulator

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #394
    Filch
    Participant
      • Topics: 22
      • Replies: 173
      • Total: 195
      • ★★

      I want an info box to appear when the Clocked button for the LFO is engaged on my panel. The box would then display the time in Bars and Beats based on what value the Speed knob is set to, and then change/update as the knob is turned.

      The values are fixed based on the table set by waldorf. example 0 = 1/32 notes, 127 = 16 bars.

      So I think I would have a method on the Clocked button that would make that block change alpha 0 and max , or maybe change rectangle size from 0,0 to whatever.

      Then have a method on the Speed knob to go through a table based on it’s value and update the text in that box.

      I think that’s the simplest way to go about this…. thoughts?

      #3049
      Filch
      Participant
        • Topics: 22
        • Replies: 173
        • Total: 195
        • ★★

        Okay, I’ve taken a stab at this. Right now I’m just trying to get the text field I’ve created with uiCustomComponent to show the proper bars/beats based on the value of the LFO knob. It grabs the initial value and writes the text, but it’s not changing when I change the LFO value. How do I do that? Here’s the code for the CustomComponent :

        [code:261j67q4]

        — Called when a component needs repainting

        paintBox = function(component,graphics)

        graphics:fillAll (Colour(0xfff0f0f0))
        graphics:setColour (Colour(0xff000000))
        graphics:drawRect (0, 0, component:getWidth(), component:getHeight(), 1)

        a = {[0] = "1280 Bars", "1152 Bars", "1024 Bars", "896 Bars", "768 Bars", "640 Bars", "576 Bars", "512 Bars", "448 Bars",
        "384 Bars", "320 Bars", "288 Bars", "256 Bars", "224 Bars", "192 Bars", "160 Bars", "144 Bars", "128 Bars",
        "112 Bars", "96 Bars", "80 Bars", "72 Bars", "64 Bars", "56 Bars", "48 Bars", "40 Bars", "36 Bars", "32 Bars",
        "28 Bars", "24 Bars", "20 Bars", "18 Bars", "16 Bars", "14 Bars", "12 Bars", "10 Bars", "9 Bars", "8 Bars", "7 Bars",
        "6 Bars", "5 Bars", "4 Bars", "3.5 Bars", "3 Bars", "2.5 Bars", "2 Bars", "1.5 Bars", "1 Bar", "1/2.", "1/1T", "1/2",
        "1/4.", "1/2T", "1/4", "1/8.", "1/4T", "1/8", "1/16.", "1/8T", "1/16", "1/32.", "1/16T", "1/32", "1/48"}

        l = panel:getModulatorByName("LFO 1 Speed")

        if l ~= nil then
        lVal = l:getModulatorValue()
        graphics:setColour (Colour(0xff950000))

        if lVal <= 1 then
        text = a[0]
        else
        text = a[math.floor(lVal/2)]
        end

        graphics:drawText (text, 0, 0, component:getWidth(), component:getHeight(), Justification (Justification.centred), true)
        end

        end
        [/code:261j67q4]

        #3050
        Filch
        Participant
          • Topics: 22
          • Replies: 173
          • Total: 195
          • ★★

          I’ve created a method on the LFO Speed knob to paint the text in the LFO Bar based on it’s value. I think this is how to have the box update realtime as the LFO knob is turned, but I’m getting an error at the graphics:drawText. I know how to tell a modulator to be set to a value, but since this is a Custom Component and graphics is involved, I’m not exactly sure how to do this properly.

          [code:16wsqpcz]
          paintLFO = function(component,graphics)

          –making array begin at 0 instead of 1

          a = {[0] = "1280 Bars", "1152 Bars", "1024 Bars", "896 Bars", "768 Bars", "640 Bars", "576 Bars", "512 Bars", "448 Bars",
          "384 Bars", "320 Bars", "288 Bars", "256 Bars", "224 Bars", "192 Bars", "160 Bars", "144 Bars", "128 Bars",
          "112 Bars", "96 Bars", "80 Bars", "72 Bars", "64 Bars", "56 Bars", "48 Bars", "40 Bars", "36 Bars", "32 Bars",
          "28 Bars", "24 Bars", "20 Bars", "18 Bars", "16 Bars", "14 Bars", "12 Bars", "10 Bars", "9 Bars", "8 Bars", "7 Bars",
          "6 Bars", "5 Bars", "4 Bars", "3.5 Bars", "3 Bars", "2.5 Bars", "2 Bars", "1.5 Bars", "1 Bar", "1/2.", "1/1T", "1/2",
          "1/4.", "1/2T", "1/4", "1/8.", "1/4T", "1/8", "1/16.", "1/8T", "1/16", "1/32.", "1/16T", "1/32", "1/48"}

          l = panel:getModulatorByName("LFO 1 Speed")
          b = panel:getModulatorByName("LFO 1 Box")

          if l ~= nil and b ~= nil then
          lVal = l:getModulatorValue()
          graphics:setColour (Colour(0xff950000))

          if lVal <= 1 then
          text = a[0]
          else
          text = a[math.floor(lVal/2)]

          b:graphics:drawText (text, 0, 0, component:getWidth(), component:getHeight(), Justification (Justification.centred), true)
          end

          end

          end
          [/code:16wsqpcz]

          #3051
          Filch
          Participant
            • Topics: 22
            • Replies: 173
            • Total: 195
            • ★★

            Ah, Just realized. I don’t need the method on the LFO knob. My method on the Box itself is working, but I only see it repaint the text if it’s within the component field of the knob I’m turning. I found this out because I placed the box near my LFO knob, the LFO component window overlapped the BOX window a bit, and the overlapped part was getting redrawn.

            So how do I make this box redraw the text without being inside the component that I’m adjusting?

            I’ve attached a small panel that illustrates what is happening.

            #3052
            Filch
            Participant
              • Topics: 22
              • Replies: 173
              • Total: 195
              • ★★

              ?

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

                Call repaint() on your custom component i guess.
                [code:24e40sga]
                panel:getModulatorByName("my-custom-modulator-name"):getComponent():repaint()
                [/code:24e40sga]

                If you need to display some text only, it might be better to use the uiLabel and do a setProperty() when changing the text, it will be faster that doing paint() stuff and it’s easier.

                #3054
                Filch
                Participant
                  • Topics: 22
                  • Replies: 173
                  • Total: 195
                  • ★★

                  I was thinking a uiLabel before, but I didn’t think I could use a table of different values, but as you clearly point out, setProperty would do this. Thanks Atom!

                  #3055
                  Filch
                  Participant
                    • Topics: 22
                    • Replies: 173
                    • Total: 195
                    • ★★

                    getting "attempt to call method setProperty is a nil value". What am I doing wrong here :

                    [code:2k5mtwef]
                    l = panel:getModulatorByName("LFO 1 Speed")
                    b = panel:getModulatorByName("LFO 1 Box")

                    if l ~= nil and b ~= nil then
                    lVal = l:getModulatorValue()

                    if lVal <= 1 then
                    text = a[0]
                    else
                    text = a[math.floor(lVal/2)]
                    end

                    b:setProperty(uiLabelText, text, false)
                    end
                    [/code:2k5mtwef]

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

                      setStringProperty() api/class_ctrlr_lua_object.html i was just thinking out loud <img decoding=” title=”Smile” />

                    Viewing 9 posts - 1 through 9 (of 9 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