Slider And Valuebox Interaction

Can anybody out there do me a massive favour and post up some code that will create a GUI window with a Slider and a ValueBox which both operate on the same variable and update in tandem to each other? The GUI Builder in general is something I have struggled with and this has completely defeated me for a while.

Even if you can’t get the Slider and ValueBox to work in tandem I would accept a Slider and a TextBox displaying the value of the Slider which updates when it moves (so you can see the actual value but still only one way to actually change it, ie dragging the slider.)

This is the only thing that has as yet stopped me releasing version 0.2 of the little Tempo Tool (which I am going to rename to Tempo Nudge as that’s all it really does) so help on this little matter will be hugely appreciated.

This worked for me in the test pad. See if it works for you?

  
--bound GUI example  
  
--essentials  
local rs = renoise.song()  
local vb = renoise.ViewBuilder()  
  
  
--the document node creation  
local gui_vals = renoise.Document.create("my_gui_vals"){  
 my_value_1 = 1,  
 my_value_1_min = 0,  
 my_value_1_max = 100,  
 --[[  
 my_value_2 = 2,  
 my_value_2_min = 0,  
 my_value_2_max = 100,  
 --..etc--]]  
}  
  
  
--gui contents  
local title = "TITLE"  
local content = vb:column{  
 vb:row{  
 vb:slider{  
 min = gui_vals.my_value_1_min.value,  
 max = gui_vals.my_value_1_max.value,  
 bind = gui_vals.my_value_1 --the "bind" property is pointed to the observable, not the value!  
 }  
 },  
 vb:row{  
 vb:valuebox{  
 min = gui_vals.my_value_1_min.value,  
 max = gui_vals.my_value_1_max.value,  
 bind = gui_vals.my_value_1 --the "bind" property is pointed to the observable, not the value!  
 }  
 }  
}  
  
  
--show gui  
local dialog = renoise.app():show_custom_dialog(title, content)  
  

EDIT: This is how I’d do it anyway. The document nodes are somewhat mysterious for me still, but I’ve done it like this due trial and error.
…and…heh, I noticed btw that the local value rs is not needed here. It’s just something I tend to slap into everything…

EDIT2: Oh, and one thing to notice when using these document nodes is that you cannot get or set their value directly in the similar manner as normal variables. When you want to do something like using the document node value for calculating something you must not do:

  
--this will not work  
local result = gui_vals.my_value_1 / 2  
  

but you must instead reference to the “value” property of said document node

  
--this should work  
local result = gui_vals.my_value_1.value / 2  
  

AFAIK this also applies when you want to set the value. So don’t do:

  
--this will not work  
gui_vals.my_value_1 = 42  
  

but again, use the value property of the document node:

  
--this should work  
gui_vals.my_value_1.value = 42  
  

Edited for clarity. last edit. promise.

Thanks I will give it a try when I have some time :)

What would be a good way to do this with a table?, i.e. if you want to iterate through a group of objects and draw each with two controls bound to the same value (a slider and valuebox like here for instance).

Doing

bind = SomeClass.sometable[i][1].value

or

bind = SomeClass.sometable[i][1]

doesn’t seem to work, but what’s the proper (or best) way to handle something like that?

Not had a chance to look at this for the tool I want to yet I’m afraid. Been a lot on my plate recently!