Set The Number Of Lines In A Pattern

Title pretty much says it all. I’d like to be able to set the number of lines in a pattern by script.

I found these docs (am I barking up the right tree?):

The userdata type “renoise.PatternTrack” looks useful, but I don’t see a documented method for setting line count.

Moreover, renoise.song().transport.song_length seems to report useful-ish data, but is read-only.

As a n00b, I’m very likely missing something obvious.

Thanks in advance for your time,
-Harold

  
-- get a valid pattern index  
local index = renoise.song().selected_pattern_index  
  
-- get pattern length  
local num_lines = renoise.song().patterns[index].number_of_lines  
  
-- process num_lines in some way  
-- set to a random number of lines from 1 to 512  
num_lines = 1 + math.floor(math.random() * 511)  
  
-- set pattern length  
renoise.song().patterns[index].number_of_lines = num_lines  
  

Kind thanks.

I see it’s on the pattern and not the patternTrack.

renoise.song().selected_pattern.number_of_lines = 8  

-Harold

Yep. PatternTrack refers to a single track within a pattern. If you want to access automations or note data, then you can find these within the PatternTrack object.

If you want to access properties of the entire pattern, such as the number of lines, pattern name, the track objects within the pattern, etc., then you can find these within the Pattern object.

You can use the oprint() function to inspect each object and find out what properties and methods it has.

For example:

  
>>> oprint(renoise.song().selected_pattern)  
  
class: Pattern  
 properties:  
 is_empty  
 name  
 name_observable  
 number_of_lines  
 number_of_lines_observable  
 tracks  
 methods:  
 __STRICT  
 __eq  
 add_line_notifier  
 clear  
 copy_from  
 has_line_notifier  
 remove_line_notifier  
 track  
  
  
>>> oprint(renoise.song().selected_pattern.tracks[1])  
  
class: PatternTrack  
 properties:  
 automation  
 automation_observable  
 color  
 color_observable  
 is_empty  
 is_empty_observable  
 lines  
 methods:  
 __STRICT  
 __eq  
 clear  
 copy_from  
 create_automation  
 delete_automation  
 find_automation  
 line  
 lines_in_range