It’s more than ten times faster here, so if you access it a lot in a big tool it might make a difference. I just wanted to note it since it’s so easy to do it slightly better
You can have a global rns = renoise.song() and update it via a new document observable.
Where and how to put the “new document observable”?
This is the typical structure that I’m used to use in my recent tools:
--
-- tool name
--
--main globals
-------------------------------------------------------------------------------------------------
dialog = nil
vb = renoise.ViewBuilder()
vws = vb.views
song = renoise.song() -------------------> where and how to put the "new document observable"?????????????
rnt = renoise.tool()
rna = renoise.app()
rns_version = renoise.RENOISE_VERSION
api_version = renoise.API_VERSION
--other globals
-------------------------------------------------------------------------------------------------
--require
-------------------------------------------------------------------------------------------------
require ("lua/xxx") -- more song ???????????????????, include many functions and more windows
require ("lua/yyy") -- more song ???????????????????, include many functions and more windows
require ("lua/zzz") -- more song ???????????????????, include many functions and more windows
--functions (many functions)
-------------------------------------------------------------------------------------------------
function name_function_01()
local sti = song.selected_track_index --song ???????????????????
local sii = song.selected_instrument_index --song ???????????????????
--...
--...
end
---
function name_function_90()
rna.window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_INSTRUMENT_PHRASE_EDITOR
song.selected_instrument.phrase_editor_visible = true --song ???????????????????
song.selected_instrument.phrase_playback_mode = renoise.Instrument.PHRASES_PLAY_KEYMAP --song ???????????????????
--...
--...
end
--main content gui
-------------------------------------------------------------------------------------------------
TOOL_GEN_CONTENT = vb:row {
vb:button {
text = "Button"
},
--...
--...
}
--show dialog
-------------------------------------------------------------------------------------------------
function show_tool_dialog()
if ( dialog and dialog.visible ) then dialog:show() return end
dialog = rna:show_custom_dialog( pht_title, TOOL_GEN_CONTENT, pht_keyhandler )
end
--register menu entry
-------------------------------------------------------------------------------------------------
renoise.tool():add_menu_entry {
name = "Main Menu:Tools:Name_Tool...",
invoke = function() show_tool_dialog() end
}
Click to view contents
–
– tool name
–
–main globals
dialog = nil
vb = renoise.ViewBuilder()
vws = vb.views
song = renoise.song() -------------------> where and how to put the “new document observable”???
rnt = renoise.tool()
rna = renoise.app()
rns_version = renoise.RENOISE_VERSION
api_version = renoise.API_VERSION
–other globals
–require
require (“lua/xxx”) – more song???, include many functions and more windows
require (“lua/yyy”) – more song???, include many functions and more windows
require (“lua/zzz”) – more song???, include many functions and more windows
–functions (many functions)
function name_function_01()
local sti = song. selected_track_index --song ???
local sii = song. selected_instrument_index --song ???
–…
–…
end
function name_function_90()
rna.window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_INSTRUMENT_PHRASE_EDITOR
song. selected_instrument.phrase_editor_visible = true --song ???
song. selected_instrument.phrase_playback_mode = renoise.Instrument.PHRASES_PLAY_KEYMAP --song ???
–…
–…
end
–main content gui
TOOL_GEN_CONTENT = vb:row {
vb:button {
text = “Button”
},
–…
–…
}
–show dialog
function show_tool_dialog()
if ( dialog and dialog.visible ) then dialog:show() return end
dialog = rna:show_custom_dialog( pht_title, TOOL_GEN_CONTENT, pht_keyhandler )
end
–register menu entry
renoise.tool():add_menu_entry {
name = “Main Menu:Tools:Name_Tool…”,
invoke = function() show_tool_dialog() end
}
In all my previous tools I have used local song = renoise.song() within each function. But I would like to know how to make a global one to song = renoise.song(), and then within each function use song. or song: where necessary.
So, where to place and how to place the “new document observable” to avoid the loading error?
Note: inside GlobalMidiActions.lua and GlobalOSCActions.lua is usedoutside the functions a local song = renoise.song , and inside the functions is used song(). or **song():**why? Is it 10 times slower?