@Danoise.Thanks for the help!
Ok.I have been able to solve the MIDI input for most of my sliders. I think I have everything I need to complete my tool. But I would like to know if it is possible that with the absolute value it is possible to have an exact resolution for a range of 0 to 255. I know the range of the input value is 0 to 127. I have used a multiplier of 2.01 so that it reaches All range from 0 to 255 , but obviously not accurate. Not able to return half of the values. Is there any way to be exactly accurate with this range?
This is my “midi_input.lua”:
-----------------------------------------------------------------------------------
---CLASS "MIDI_IN"
-----------------------------------------------------------------------------------
class = "MIDI_IN"
MIDI_IN = {
--slider
NOT_SLIDER = "Tools:VPD:1. Slider:1. Note:Insert/Change Note Value [Set]",
VOL_SLIDER = "Tools:VPD:1. Slider:2. Volume:Insert/Change Volume Value [Set]",
PAN_SLIDER = "Tools:VPD:1. Slider:3. Panning:Insert/Change Panning Value [Set]",
DLY_SLIDER = "Tools:VPD:1. Slider:4. Delay:Insert/Change Delay Value [Set]",
EFF_SLIDER = "Tools:VPD:1. Slider:5. Effect:Insert/Change Effect Amount [Set]",
--popup
GUI_SFX_POPUP = "Tools:VPD:2. Popup:5.1 Sample Effect:Insert/Change Sample Effect Value (SFX) [Set]",
GUI_TFX_POPUP = "Tools:VPD:2. Popup:5.2 Track Effect:Insert/Change Track Effect Value (TFX) [Set]",
--button
}
-----------------------------------------------------------------------------------
---FUNCTIONS MIDI INPUT FOR SLIDER
-----------------------------------------------------------------------------------
--clamp_value
function clamp_value( value, min_value, max_value )
return math.min( max_value, math.max(value, min_value) )
end
--message_value_with_offset
function message_value_with_offset_1( message, value, offset, min_value, max_value )
if ( message:is_abs_value() ) then return clamp_value( message.int_value + offset, min_value, max_value )
elseif ( message:is_rel_value() ) then return clamp_value( value + message.int_value, min_value, max_value )
else
return value
end
end
function message_value_with_offset_2( message, value, offset, min_value, max_value )
if ( message:is_abs_value() ) then return clamp_value( (message.int_value + offset )*2.01, min_value, max_value ) --> Is greater accuracy possible ??????
elseif ( message:is_rel_value() ) then return clamp_value( value + message.int_value, min_value, max_value )
else
return value
end
end
function message_value_with_offset_3( message, value, offset, min_value, max_value )
if ( message:is_abs_value() ) then return clamp_value( (message.int_value + offset )/6, min_value, max_value )
elseif ( message:is_rel_value() ) then return clamp_value( value + message.int_value, min_value, max_value )
else
return value
end
end
function message_value_with_offset_4( message, value, offset, min_value, max_value )
if ( message:is_abs_value() ) then return clamp_value( (message.int_value + offset )/3, min_value, max_value )
elseif ( message:is_rel_value() ) then return clamp_value( value + message.int_value, min_value, max_value )
else
return value
end
end
--message_value
function message_value_1( message, value, min_value, max_value )
return message_value_with_offset_1( message, value, 0, min_value, max_value )
end
function message_value_2( message, value, min_value, max_value )
return message_value_with_offset_2( message, value, 0, min_value, max_value )
end
function message_value_3( message, value, min_value, max_value )
return message_value_with_offset_3( message, value, 0, min_value, max_value )
end
function message_value_4( message, value, min_value, max_value )
return message_value_with_offset_4( message, value, 0, min_value, max_value )
end
-----------------------------------------------------------------------------------
---ADD MIDI MAPPING
-----------------------------------------------------------------------------------
--slider controller
renoise.tool():add_midi_mapping {
name = MIDI_IN.NOT_SLIDER,
invoke = function(message) if message:is_abs_value() then vb.views["NOT_SLIDER"].value = message_value_1( message, vb.views["NOT_SLIDER"].value, 0, 120 ) end end --OK (Absolute 7 bit) Precise!
}
renoise.tool():add_midi_mapping {
name = MIDI_IN.VOL_SLIDER,
invoke = function(message) if message:is_abs_value() then vb.views["VOL_SLIDER"].value = message_value_1( message, vb.views["VOL_SLIDER"].value, 0, 127 ) end end --OK (Absolute 7 bit) Precise!
}
renoise.tool():add_midi_mapping {
name = MIDI_IN.PAN_SLIDER,
invoke = function(message) if message:is_abs_value() then vb.views["PAN_SLIDER"].value = message_value_1( message, vb.views["PAN_SLIDER"].value, 0, 127 ) end end --OK (Absolute 7 bit) Precise!
}
renoise.tool():add_midi_mapping {
name = MIDI_IN.DLY_SLIDER,
invoke = function(message) if message:is_abs_value() then vb.views["DLY_SLIDER"].value = message_value_2( message, vb.views["DLY_SLIDER"].value, 0, 255 ) end end --OK (Absolute 7 bit) Only half of values!!!
}
renoise.tool():add_midi_mapping {
name = MIDI_IN.EFF_SLIDER,
invoke = function(message) if message:is_abs_value() then vb.views["EFF_SLIDER"].value = message_value_2( message, vb.views["EFF_SLIDER"].value, 0, 255 ) end end --OK (Absolute 7 bit) Only half of values!!!
}
--popup controller
renoise.tool():add_midi_mapping {
name = MIDI_IN.GUI_SFX_POPUP,
invoke = function(message) if message:is_abs_value() then vb.views["GUI_SFX_POPUP"].value = message_value_3( message, vb.views["GUI_SFX_POPUP"].value, 1, 19 ) end end --OK (Absolute 7 bit) Precise!
}
renoise.tool():add_midi_mapping {
name = MIDI_IN.GUI_TFX_POPUP,
invoke = function(message) if message:is_abs_value() then vb.views["GUI_TFX_POPUP"].value = message_value_4( message, vb.views["GUI_TFX_POPUP"].value, 1, 30 ) end end --OK (Absolute 7 bit) Precise!
}
--button controller
Am I doing the right steps with the code?I think it’s everything.Can you check it?It’s the first time I built it with sliders…
I’m going to control 5 sliders and 2 popup ( and many buttons) with MIDI input.I have checked that this setting works with my MIDI keyboard (Novation Lanchkey 61). With popup I not have problems…
The only problem is the precision of sliders with ID: “DLY_SLIDER” (for delay values) and “EFF_SLIDER” (for amount values of effects), that both use the same range: 0 to 255.
renoise.tool():add_midi_mapping {
name = MIDI_IN.DLY_SLIDER,
invoke = function(message) if message:is_abs_value() then vb.views["DLY_SLIDER"].value = message_value_2( message, vb.views["DLY_SLIDER"].value, 0, 255 ) end end --OK (Absolute 7 bit) Only half of values!!!
}
renoise.tool():add_midi_mapping {
name = MIDI_IN.EFF_SLIDER,
invoke = function(message) if message:is_abs_value() then vb.views["EFF_SLIDER"].value = message_value_2( message, vb.views["EFF_SLIDER"].value, 0, 255 ) end end --OK (Absolute 7 bit) Only half of values!!!
}
I am very happy with the results. Too bad these two sliders do not have the exact accuracy. Is there any way to fix it?The slider that worries me the most is theEFF_SLIDER, because there are some effects that need an exact amount…