Home › Forums › General › Programming › Logic for infobox to change data/state based on modulator
- This topic has 8 replies, 2 voices, and was last updated 12 years, 8 months ago by atom.
-
AuthorPosts
-
August 1, 2011 at 9:30 pm #394
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?
August 9, 2011 at 2:32 am #3049Okay, 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)]
endgraphics:drawText (text, 0, 0, component:getWidth(), component:getHeight(), Justification (Justification.centred), true)
endend
[/code:261j67q4]August 9, 2011 at 1:43 pm #3050I’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)
endend
end
[/code:16wsqpcz]August 9, 2011 at 1:56 pm #3051Ah, 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.
August 9, 2011 at 8:42 pm #3052?
August 9, 2011 at 10:04 pm #3053Call 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.
August 9, 2011 at 10:24 pm #3054I 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!
August 9, 2011 at 10:51 pm #3055getting "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)]
endb:setProperty(uiLabelText, text, false)
end
[/code:2k5mtwef]August 10, 2011 at 7:41 am #3056setStringProperty() api/class_ctrlr_lua_object.html i was just thinking out loud ” title=”Smile” />
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.