In a custom Application I’ve created a UISlider and inside on_change I want to use “renoise.song().selected_track.prefx_volume.value” to have the slider value set the track volume.
I’m stuck on how to get the slider value into a variable and how to convert it to a format (db or ‘lin’) that prefx_volume will take, any ideas? Not sure what obj.value is coming back as, I tried to output this with TRACE but nothing shows in the Terminal (EDIT: probably my bad, I should be using “print” to send debug messages to the Terminal?)
[EDIT] Ps. I looked at the existing Mixer application and I’m still a bit puzzled on what range a UISlider .value returns and how that maps to the .prefx_volume.value - also the reason I’m going custom on this one is because I’m doing specific dial>channel mapping, if there is a quick/easy way to say “map dial index 1 to mixer channel 3” using Duplex functions I’m up for that…
This may be better in the “Tec: Scripting API Development Q&A” forum, I wasn’t sure as it’s a Duplex related question, but also touches on API/scripting.
Yeah, not really Duplex related but I can give you some general advice: ideally, you want a parameter to go from 0 to 1.
This makes it very easy to adapt it to other ranges that start with 0, because all you need to do is to multiply your value by the target’s maximum number. So, for instance if you are creating a slider for a decibel value, you would multiply the value by 1.4125375747681, since that happens to be the decibel range.
If you have a range of 0-1, but you actually want to control some arbitrary range like 14-78, you have this handy method in Duplex/Globals.lua (it’s standalone - can be called from anywhere, dropped into any script):
-- scale_value: scale a value to a range within a range
-- for example, we could have a range of 0-127, and want
-- to distribute the numbers 1-8 evenly across that range
-- @param value (number) the value we wish to scale
-- @param low_val/high_val (number) the lowest/highest value in 'our' range
-- @param min_val/max_val (number) the lowest/highest possible value
function scale_value(value,low_val,high_val,min_val,max_val)
local incr1 = min_val/(high_val-low_val)
local incr2 = max_val/(high_val-low_val)-incr1
return(((value-low_val)*incr2)+min_val)
end
Note that if you are looking to learn something from the Duplex Mixer, it’s not really a good place to start. The sliders are dynamic/scrollable, with a lot of extra features.
But you could take the Metronome sample application and simply replace the UIToggleButton with a UISlider, a lot easier to understand and experiment with.
Thanks, you just reminded me of the param range in the XML and your comment about scaling makes sense and explains where I was going wrong - I should be able to tie all this together now.
Btw, I did start with a copy+hack of the Metronome application which really helped, I was just reading some of the other .lua for inspiration, getting there. I know a bit about programming and OO concepts but I’m new to LUA, Duplex and the Renoise API.