I believe that patterns_observable sometimes can break, unless I made some rookie mistake.
My guess of possible cause, kind of: When using the duplicate sequence menu, while having “Keep sequence sorted” enabled, renoise will re-use any empty+non-used patterns that are found in between used patterns. This causes the patterns_observable not to reflect what really happened to the list. (?)
It can be reproduced by loading “DBlue - tension”, enable “keep sequence sorted” and duplicate sequence 15 with the code below (re)loaded.
Example
-- extend table class
table.swap = function(t, index1, index2)
t[index1], t[index2] = t[index2], t[index1]
end
class 'App'
function App:__init(args)
self.song = args.song
self.pattern_list = table.create()
-- add newly inserted pattern to the internal list
self.pattern_init = function(pattern_idx, pattern)
self.pattern_list:insert(pattern_idx, pattern)
rprint(self.pattern_list)
end
-- update the internal list to reflect song.patterns
self.update_pattern_list = function(event)
if event.type == "insert" then
local pattern = self.song:pattern(event.index)
self.pattern_init(event.index, pattern)
elseif event.type == "swap" then
self.pattern_list:swap(event.index1, event.index2)
elseif event.type == "remove" then
self.pattern_list:remove(event.index)
end
end
-- initialize the internal list
for pattern_idx, pattern in ipairs(self.song.patterns) do
self.pattern_init(pattern_idx, pattern)
end
-- add pattern list notifier
self.song.patterns_observable:add_notifier(self.update_pattern_list)
end
local app = App { song = renoise.song() }