I have been looking at several scenarios to use external files to read or save data, to be able to read them later (read user preferences or save preferences of the tool):
1. ** Save and read your own tool preferences (preferences.xml): The Renoise API seems to have its own XML interpreter?, so you can create a name.xml in the root of the installation folder of the tool (or subfolder) to save and then read your preferences. You can even use tables. To save the values in the table, it automatically create something like this<table_name_item>VALUE</table_name_item> for the name of each value, and you can access the name with table_name[NUMBER].value**.
--LUA----------------------
table_name = { VALUE_1, VALUE_2, VALUE_3, VALUE_4, VALUE_5 }
--XML----------------------
<table_name>
<table_name_item>VALUE_1</table_name_item>
<table_name_item>VALUE_2</table_name_item>
<table_name_item>VALUE_3</table_name_item>
<table_name_item>VALUE_4</table_name_item>
<table_name_item>VALUE_5</table_name_item>
</table_name>
Tables are most useful for saving multiple values, for example, RGB color settings.The documentation is this (Renoise.ScriptingTool.API.lua):
--[[
Get or set an optional renoise.Document.DocumentNode object, which will be
used as set of persistent "options" or preferences for your tool.
By default nil. When set, the assigned document object will automatically be
loaded and saved by Renoise, to retain the tools state.
The preference XML file is saved/loaded within the tool bundle as
"com.example.your_tool.xrnx/preferences.xml".
A simple example:
-- create a document
my_options = renoise.Document.create("ScriptingToolPreferences") {
some_option = true,
some_value = "string_value"
}
Or:
-- create a document
class "ExampleToolPreferences"(renoise.Document.DocumentNode)
function ExampleToolPreferences:__init()
renoise.Document.DocumentNode.__init(self)
self:add_property("some_option", true)
self:add_property("some_value", "string_value")
end
my_options = ExampleToolPreferences()
-- values can be accessed (read, written) via
my_options.some_option.value, my_options.some_value.value
-- also notifiers can be added to listen to changes to the values
-- done by you, or after new values got loaded or a view changed the value:
my_options.some_option:add_notifier(function() end)
And assign it:
-- 'my_options' will be loaded/saved automatically with the tool now:
renoise.tool().preferences = my_options
]]
-- Please see Renoise.Document.API for more info about renoise.DocumentNode
-- and for info on Documents in general.
renoise.tool().preferences
-> [renoise.Document.DocumentNode object or nil]
The first way seems simpler (it’s the one I use).Then, to save and read data, it is best to use XML following this method.
2. You want to read the data from other XML files that Renoise uses (read only, without modify). For example, the Config.xml (C:\Users\NAME_USER\AppData\Roaming\Renoise\V3.1.1\Config.xml).This file is on a "strange route"and, apparently, the tool will need an interpreter to read these files. I’m not sure.But it would be interesting to be able to access this data to adapt the tool if necessary. You never modify the user’s preferences, you only read the data.For example, access of the color of the button selection:
<SkinColors>
...
...
<Selected_Button_Back>255,181,35</Selected_Button_Back>
...
...
</SkinColors>
How to read this data?Get print the table { 255,181,35 } ? In this case, it seems to be necessary to install an additional XML interpreter? Personally, it is a bit messy, just for wanting to access a few data.
**3.Use an LUA file (preferences.lua) to save data?**I wonder why is it necessary to use an XML file to save data (preferences.xml)?It is not possible to use a preferences.lua file, through require(“name”)? The preferences.lua should save the changed data when closing the tool.It would be the simplest thing, instead of using an XML file.Does not LUA save modified data in a file .lua?I think this would be less complicated to program.That is, it always uses the same programming language (LUA) for everything. Do not mix two languages.