Song.patterns_observable sometimes missing some events?

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() }

Maybe this is related, I’m not sure: Uniqueness question

Thanks to 4tey for the heart.

1 Like

Okey cokey :slight_smile:

I don’t know myself if it related or not joule (probably not), but I thought I’d quickly mention it for reference :slight_smile:

The observable is the one that is used internally too, so it’s unlikely to miss some events, but the pattern object isn’t always available to lua within the notifier call. It should. I’ll check why it’s not…

1 Like