This is a bit advanced. I am trying to improve the behavior of a 270º turn knob (physical), to avoid the jump that can occur from a knob or fader when the user changes a value from Renoise and then it is controlled from the physical knob or fader of a MIDI keyboard or controller.
A concrete case is the following one:
vb:valuebox {
id = "PHT_VB_SEL_TRK_1",
height = 25,
width = 54,
min = 0,
max = 999,
value = 0,
tostring = function( number ) return pht_tostring_track_1( number ) end,
tonumber = function( string ) return pht_tonumber_track_1( string ) end,
notifier = function( value ) pht_sel_trk_1() pht_anchor_track_1( value ) end,
midi_mapping = "Tools:PhraseTouch:Panel_1:Track & Instrument:Track Selector Valuebox",
tooltip = "Choose a track number\n[SEL = default selected track]"
}
This valuebox shows the value of the selected track (is an example of many). The user can change the value in 3 ways:
- From the valuebox with the mouse.
- From the MIDI in linked with this valuebox.
- From Renoise by changing the track selection (keyboard commands, mouse).
The MIDI input is defined with its midi_mappingand the nextrenoise.tool():add_midi_mapping { } :
---
renoise.tool():add_midi_mapping {
name = "Tools:PhraseTouch:Panel_1:Track & Instrument:Track Selector Valuebox",
invoke = function( message )
if message:is_abs_value() then
local val = math.floor( message.int_value * ( vws.PHT_VB_SEL_TRK_1.max + 1 )/128 )
if ( val <= 128 ) then
vws.PHT_VB_SEL_TRK_1.value = val
else
return
end
end
end
}
The matter is here, within the condition: if message:is_abs_value() then bla, bla bla, end
By turning the knob, you will always be synchronized with the valuebox. The local val is shielded in case the maximum number of tracks changes.So, the 128 values of message.int_value always adjust to the maximum number of tracks in each execution.
But there is a very specific case, which is when the user selects a track from Renoise. The knob is not motorized, it remains fixed in place, just like the valuebox, but the value of the selected track has changed. Then, if the user uses the knob, there will be a sudden jump in the selection and this is exactly what I want to avoid, at least from the knob (or fader).
Does anyone think of how to solve this?
vws.PHT_VB_SEL_TRK_1.value = val is the one that updates the selection of the track.In theory, changing this line would be possible.I have tried the following, but it seems incoherent, and it does not work:
if ( vws.PHT_VB_SEL_TRK_1.value == val ) then
vws.PHT_VB_SEL_TRK_1.value = val
end
What I thought was: do not change the value of the valuebox until the value of the knob is the same.But this does not work like that, it’s just the other way around:
if ( vws.PHT_VB_SEL_TRK_1.value ~= val ) then
vws.PHT_VB_SEL_TRK_1.value = val
end
That is the same as not putting the condition. It is the same as this:
vws.PHT_VB_SEL_TRK_1.value = val
It needs to be unequal, so you can change the value.So, how to force the knob to do nothing, until it reaches the value of the current selection?The objective is to avoid the jumps that occur in the knobs or faders.
This issue can be useful in many cases…
Can someone help me here?