It means that the variable “tool_name” within the keybinding is missing in the code.
Just add a line to the top of the script, which declares the variable and assigns the tool name to it
local tool_name = 'The name of the tool I am editing'
Instead of assigning a name directly to it, you could read the string between the line with “…” of the manifest.xml
local manifest = RenoiseScriptingTool()
local tool_name = manifest:property("Name").value
renoise.tool():add_keybinding {
name = "Global:Tools:" .. tool_name.."...",
invoke = show_dialog
}
renoise.tool():add_menu_entry{
name = “Main Menu:Tools:MP Hogacz:Velocity Randomizer”,
invoke = function() run() end
}
local manifest = RenoiseScriptingTool()
local tool_name = manifest:property(“Name”).value
function get_params()
local ret = {
min = MIN_VELOCITY,
max = MAX_VELOCITY,
how_many_percent = HOW_MANY_PERCENT
}
local vb = renoise.ViewBuilder()
local DEFAULT_MARGIN = renoise.ViewBuilder.DEFAULT_CONTROL_MARGIN
local column_view = vb:column{}
local dialog_content = vb:column{margin = DEFAULT_MARGIN}
local dialog_buttons = {“OK”, “Cancel”}
local choice
local valbox_row_range = vb:row{
vb:text{text = "Velocity range " },
vb:valuebox{min = MIN_VELOCITY, max = MAX_VELOCITY, value = ret.min,
notifier = function(value) ret.min = value end},
vb:valuebox{min = MIN_VELOCITY, max = MAX_VELOCITY, value = ret.max,
notifier = function(value) ret.max = value end }
}
local valbox_row_howmany = vb:row{
vb:text{text = "Percent of notes to modify "},
vb:valuebox{min = 0, max = 100, value = ret.how_many_percent,
notifier = function(value) ret.how_many_percent = value end}
}
column_view.margin = DEFAULT_MARGIN
column_view.style = “group”
column_view:add_child(valbox_row_range)
column_view:add_child(valbox_row_howmany)
dialog_content:add_child(column_view)
choice = renoise.app():show_custom_prompt(“Velocity randomization”,
dialog_content, dialog_buttons)
if choice == “Cancel” then
return(nil)
end
if ret.min > ret.max then
ret.min, ret.max = ret.max, ret.min
end
return(ret)
end
function get_notes(sel)
local notes = {}
local track_obj
for track_no = sel.start_track, sel.end_track do
track_obj = renoise.song().selected_pattern.tracks[track_no]
for line_no = sel.start_line, sel.end_line do
for col_no, one_note_column in ipairs(track_obj.lines[line_no].note_columns) do
if (track_no == sel.start_track) and (col_no < sel.start_column) then
– print(“Column should be skipped.”)
elseif (track_no == sel.end_track) and (col_no > sel.end_column) then
– print(“Column should be skipped.”)
elseif not one_note_column.is_empty then
table.insert(notes, one_note_column)
end
end
end
end
return notes
end
function math_round(val, decimal)
if decimal == nil then decimal = 0 end
return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
end
function table_shuffle(array)
for i = #array, 2, -1 do
local j = math.random(1, i)
array[i], array[j] = array[j], array[i]
end
return(array)
end
function randomize_data(shuffled_list, vel_params)
local num_entries = #shuffled_list
local num_to_process = math_round(vel_params.how_many_percent / 100 * num_entries)
for idx = 1, num_to_process do
shuffled_list[idx].volume_value = math.random(vel_params.min, vel_params.max)
end
end
function run()
local vel_params
local track_obj
local notes
local sel = renoise.song().selection_in_pattern
if sel == nil then
renoise.app():show_error(“Please select some area.”)
return
end
math.randomseed(os.time() + (os.clock() % 1))
math.random() – “throw away” first number (weak randomness fix (?))
vel_params = get_params()
if vel_params == nil then
return
end
Instead of “invoke=showdialog” you have to copy the function call of the original tool “invoke=function() run() end”.
There were also some definitions of the manifest missing, I was assuming the tool used the Create tool tool
Please find the complete source below; the only change is the addition of the code after the function run().
MIN_VELOCITY = 0
MAX_VELOCITY = 127
HOW_MANY_PERCENT = 100
renoise.tool():add_menu_entry{
name = "Main Menu:Tools:MP Hogacz:Velocity Randomizer",
invoke = function() run() end
}
function get_params()
local ret = {
min = MIN_VELOCITY,
max = MAX_VELOCITY,
how_many_percent = HOW_MANY_PERCENT
}
local vb = renoise.ViewBuilder()
local DEFAULT_MARGIN = renoise.ViewBuilder.DEFAULT_CONTROL_MARGIN
local column_view = vb:column{}
local dialog_content = vb:column{margin = DEFAULT_MARGIN}
local dialog_buttons = {"OK", "Cancel"}
local choice
local valbox_row_range = vb:row{
vb:text{text = "Velocity range " },
vb:valuebox{min = MIN_VELOCITY, max = MAX_VELOCITY, value = ret.min,
notifier = function(value) ret.min = value end},
vb:valuebox{min = MIN_VELOCITY, max = MAX_VELOCITY, value = ret.max,
notifier = function(value) ret.max = value end }
}
local valbox_row_howmany = vb:row{
vb:text{text = "Percent of notes to modify "},
vb:valuebox{min = 0, max = 100, value = ret.how_many_percent,
notifier = function(value) ret.how_many_percent = value end}
}
column_view.margin = DEFAULT_MARGIN
column_view.style = "group"
column_view:add_child(valbox_row_range)
column_view:add_child(valbox_row_howmany)
dialog_content:add_child(column_view)
choice = renoise.app():show_custom_prompt("Velocity randomization",
dialog_content, dialog_buttons)
if choice == "Cancel" then
return(nil)
end
if ret.min > ret.max then
ret.min, ret.max = ret.max, ret.min
end
return(ret)
end
function get_notes(sel)
local notes = {}
local track_obj
for track_no = sel.start_track, sel.end_track do
track_obj = renoise.song().selected_pattern.tracks[track_no]
for line_no = sel.start_line, sel.end_line do
for col_no, one_note_column in ipairs(track_obj.lines[line_no].note_columns) do
if (track_no == sel.start_track) and (col_no < sel.start_column) then
-- print("Column should be skipped.")
elseif (track_no == sel.end_track) and (col_no > sel.end_column) then
-- print("Column should be skipped.")
elseif not one_note_column.is_empty then
table.insert(notes, one_note_column)
end
end
end
end
return notes
end
function math_round(val, decimal)
if decimal == nil then decimal = 0 end
return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
end
function table_shuffle(array)
for i = #array, 2, -1 do
local j = math.random(1, i)
array[i], array[j] = array[j], array[i]
end
return(array)
end
function randomize_data(shuffled_list, vel_params)
local num_entries = #shuffled_list
local num_to_process = math_round(vel_params.how_many_percent / 100 * num_entries)
for idx = 1, num_to_process do
shuffled_list[idx].volume_value = math.random(vel_params.min, vel_params.max)
end
end
function run()
local vel_params
local track_obj
local notes
local sel = renoise.song().selection_in_pattern
if sel == nil then
renoise.app():show_error("Please select some area.")
return
end
math.randomseed(os.time() + (os.clock() % 1))
math.random() -- "throw away" first number (weak randomness fix (?))
vel_params = get_params()
if vel_params == nil then
return
end
notes = table_shuffle(get_notes(sel))
randomize_data(notes, vel_params)
end
-- Read from the manifest.xml file.
class "RenoiseScriptingTool" (renoise.Document.DocumentNode)
function RenoiseScriptingTool:__init()
renoise.Document.DocumentNode.__init(self)
self:add_property("Name", "Untitled Tool")
self:add_property("Id", "Unknown Id")
end
local manifest = RenoiseScriptingTool()
local ok,err = manifest:load_from("manifest.xml")
local tool_name = manifest:property("Name").value
renoise.tool():add_keybinding {
name = "Global:Tools:" .. tool_name.."...",
invoke = function() run() end
}