How to store note values?

Here is a part of code that is placed inside notifier function of a button:

 local notes_in_selection = {}  
 local filled_lines = {}  
 for k = selection.start_line, selection.end_line, 1 do  
 if song.selected_pattern.tracks[selection.start_track].lines[k].note_columns[selection.start_column].note_value < 120 then  
 table.insert(notes_in_selection, song.selected_pattern.tracks[selection.start_track].lines[k].note_columns[selection.start_column])  
 table.insert(filled_lines, k)  
 end  
 end  

I want to create table with all notes in the 1st column of selection, and table with respective numbers of lines. After that goes the code that deletes these notes in pattern, but they are supposed to remain stored in tables. The problem is that they disappear from tables too. How to solve this issue?

EDIT: I guess I should add that I need this tables only during one execution of this function, i.e. store the original notes, then clear selection, then fill it with new notes with values from tables. It’s like quantization.

The problem is that when you fetch the note column like this…

local column = renoise.song():pattern(1):track(1):line(1):note_column(1)  

… then you are actually storing a reference to the note column object itself, not a physical copy of it. So if the original note column data changes after that, then the object you’ve stored in your table will also change, because it’s referencing exactly the same data.

In your situation, your table should hold copies of the actual note column data values (ie. note, volume, panning, etc) instead of a reference to the note column object itself.

1 Like