Presets

I added an option to store presets to “preferences.xml” but I fail to properly access them. Next time I open tool it doesn’t see anything, although the xml is not empty.

local presets = renoise.Document.create("Presets"){}  
presets:load_from("preferences.xml")  
print(presets:property("Preset_1"))  
  
``` This shows "nil". So how can you access data?  
  
EDIT: OMG! Problem solved. I spent a lot of time and Renoise even crashed once but it turned out that the answer is short and simple. Just chooose another filename and it loads easily  

local presets = self:load_file(“Presets.xml”)

  
EDIT: It's not working again. Strange...

I’m sorry I missed the part about “load_from” loading only already existing properties. So to load a preset I have to create dummy tables in the beginning. Like that, right?

local presets = renoise.Document.create("Presets") {}  
  
for i = 1,6,1 do  
  
local preset_dummy = renoise.Document.create("Preset_"..tostring(i)) {  
name = "-",  
--other fake values  
}  
presets:add_property("Preset_"..tostring(i), preset_dummy)  
end  
  
presets:load_from("Presets.xml")  

And to store new preset I have to delete the fake one but I can`t.

presets:remove_property("Preset_"..tostring(preset_index))  

returns error

So what should I do? This is so ridiculously complicated.

Finally! I got this. I guess the code should be

local presets = renoise.Document.create("Presets") {}  
local preset_ = {}  
for i = 1,6 do  
preset_["preset_"..i] = {}  
preset_[i] = renoise.Document.create("Preset_"..i) {   
is_used = false,  
--fake values  
}  
presets:add_property("Preset_"..tostring(i), preset_[i])  
end  

and ```
local function store_preset()
presets:remove_property(preset_[preset_index])
local new_preset = renoise.Document.create(“Preset_”…tostring(preset_index)) {
is_used = true,
–real values
}
presets:add_property(“Preset_”…tostring(preset_index), new_preset)
presets:save_as(“Presets.xml”)
end