in this thread i’ll dissect and explore existing renoise scripts from http://tools.renoise.com
i’ll begin with the “Convert Instrument Number” script by Ledger – a very useful script that i often find myself reaching for
i hope Ledger won’t mind that i publish it for study purposes here in the forums
in renoise’s scripting terminal and editor, i find that there are two files in this tool: main.lua and manifest.xml
here’s the content of manifest.xml:
Click to view contents
<?xml version="1.0" encoding="UTF-8"?>
<renoisescriptingtool><br>
<apiversion>2.0</apiversion><br>
<id>ledger.scripts.ConvertInstrumentNumber</id><br>
<version>1.0</version><br>
<name>Convert Instrument Number</name><br>
<author>Ledger</author><br>
<description>This tool will take all the current notes instrument numbers, for the chosen range and convert them to the currently selected instrument. Accessed via the right-click menu of the instrument box and available user shortcuts: <br>
"Convert (Track in Pattern) Instruments to Currently Selected", "Convert (Whole Track) Instruments to Currently Selected" and "Convert (Selection in Pattern) Instruments to Currently Selected"<br>
</description><br>
<category>Pattern Editor</category><br>
<homepage></homepage><br>
<br>
</renoisescriptingtool>
this manifest.xml file is obviously just a textfile filled with xml tags and content between the tags, it somehow reminds me of the header tags of html pages that e.g. search engines use to index webpages
it seems to have little to do with the actual lua script content as such, rather these manifest.xml files seem to be more like required description files in a xrnx tool for distribution purposes
let’s return to this .xml file later, but first let’s take a overview look at the the main.lua file:
Click to view contents
-------------------------------------------------------------
--Menus
-------------------------------------------------------------
renoise.tool():add_menu_entry {
name = "Instrument Box:Convert Notes in:Track in Pattern",
invoke = function() change()
end
}
renoise.tool():add_menu_entry {
name = "Instrument Box:Convert Notes in:Track",
invoke = function() change_all()
end
}
renoise.tool():add_menu_entry {
name = "Instrument Box:Convert Notes in:Selection",
invoke = function() change_selection()
end
}
-------------------------------------------------------------
--Key Bindings
-------------------------------------------------------------
renoise.tool():add_keybinding {
name = "Global:Tools:Convert (Track in Pattern) Instruments to Currently Selected",
invoke = function() change() end
}
renoise.tool():add_keybinding {
name = "Global:Tools:Convert (Whole Track) Instruments to Currently Selected",
invoke = function() change_all() end
}
renoise.tool():add_keybinding {
name = "Global:Tools:Convert (Selection in Pattern) Instruments to Currently Selected",
invoke = function() change_selection() end
}
-----------------------------------------------------------------
--main(1) [Pattern Track]
-----------------------------------------------------------------
function change()
local pattern_iter = renoise.song().pattern_iterator
local track_index = renoise.song().selected_track_index
local pattern_index = renoise.song().selected_pattern_index
local inst_number = renoise.song().selected_instrument_index
-- Zero is returned when send/ master selected
if renoise.song().tracks[track_index].visible_note_columns == 0 then
return
end
--iterate:
--over "track in pattern" and change instrument values of all notes
for pos,line in pattern_iter:note_columns_in_pattern_track(pattern_index,track_index) do
if line.instrument_value ~= 255 then
line.instrument_value = (inst_number - 1)
end
end
renoise.app():show_status("Convert Inst. no. Tool: (Instruments Changed in \"Track in Pattern\")")
end --main
-----------------------------------------------------------------------
--main(2) [Whole track]
-----------------------------------------------------------------------
function change_all()
local pattern_iter = renoise.song().pattern_iterator
local track_index = renoise.song().selected_track_index
local inst_number = renoise.song().selected_instrument_index
-- Zero is returned when send/ master selected
if renoise.song().tracks[track_index].visible_note_columns == 0 then
return
end
--iterate:
--over "track in pattern" and change instrument values of all notes
for pos,line in pattern_iter:note_columns_in_track(track_index) do
if line.instrument_value ~= 255 then
line.instrument_value = (inst_number - 1)
end
end
renoise.app():show_status("Convert Inst. no. Tool: (Instruments Changed in \"Track\")")
end --main
-----------------------------------------------------------------------
--main(3) [Pattern Selection]
-----------------------------------------------------------------------
function change_selection()
local pattern_iter = renoise.song().pattern_iterator
local track_index = renoise.song().selected_track_index
local pattern_index = renoise.song().selected_pattern_index
local inst_number = renoise.song().selected_instrument_index
-- Zero is returned when send/ master selected
if renoise.song().tracks[track_index].visible_note_columns == 0 then
return
end
--iterate:
--over "Pattern" and change instrument values of all notes
for pos,line in pattern_iter:note_columns_in_pattern(pattern_index,track_index) do
if line.is_selected then --only selection
if line.instrument_value ~= 255 then
line.instrument_value = (inst_number - 1)
end
end
end
renoise.app():show_status("Convert Inst. no. Tool: (Instruments Changed in \"Selection\")")
end --main
to be continued…