[Solved] Help LUA: function to create a Group with two Tracks, one col

I’m starting with LUA language. I would like to make the following tool:

-- GROUP + TWO TRACKS, ONE COLLAPSED

function insert_gt()
  local song = renoise.song()
-- insert new Group: (Note: I need put the two tracks inside this group)
    song:insert_group_at(song.selected_track_index + 1)

-- insert two Tracks or more...:
    song:track(song.selected_track_index).name = "TRACK 1" -- & the name of GROUP????
  local track = song:track(song.selected_track_index)
    track.visible_effect_columns = 0
    track.visible_note_columns = 12
    track.volume_column_visible = false
    track:set_column_name(1, "NOTE 1")
    track:set_column_name(2, "NOTE 2")

    song:track(song.selected_track_index).name = "TRACK 2"
  local track = song:track(song.selected_track_index)
    track.visible_effect_columns = 0
    track.visible_note_columns = 12
    track.volume_column_visible = false
    track:set_column_name(1, "NOTE 1")
    track:set_column_name(2, "NOTE 2")
    -- Note: Code for collapse the entire TRACK 2?????
end

renoise.tool():add_menu_entry {
  name = "Pattern Editor:Expand Group & 2 Tracks",
  invoke = function() insert_gt() end
}

Basically, I want to create a tool to create with a single mouse click a group and within two runways (one collapsed), in the Pattern Editor. As is the code creates two tracks and a group separately. I need the two tracks (or more) appear within the group.

Besides, I want to know what the code for a track made out collapsed (one expanded and other collapsed). This will serve to create a more complex tool.

Can you help?

The result would be this:

6754 group&2traks.png

I think the key to your mystery is renoise.song():add_track_to_group(int track_index, int group_index)

-- GROUP + TWO TRACKS, ONE COLLAPSED

function insert_gt()
  local song = renoise.song()
-- insert new Group: (Note: I need put the two tracks inside this group)
    song:add_track_to_group(int track_index, int group_index)
    song:insert_group_at(song.selected_track_index + 1)

-- insert two Tracks or more...:
    song:track(song.selected_track_index).name = "TRACK 1" -- & the name of GROUP????
  local track = song:track(song.selected_track_index)
    track.visible_effect_columns = 0
    track.visible_note_columns = 12
    track.volume_column_visible = false
    track:set_column_name(1, "NOTE 1")
    track:set_column_name(2, "NOTE 2")

    song:track(song.selected_track_index).name = "TRACK 2"
  local track = song:track(song.selected_track_index)
    track.visible_effect_columns = 0
    track.visible_note_columns = 12
    track.volume_column_visible = false
    track:set_column_name(1, "NOTE 1")
    track:set_column_name(2, "NOTE 2")
    -- Note: Code for collapse the entire TRACK 2?????
end

renoise.tool():add_menu_entry {
  name = "Pattern Editor:Expand Group & 2 Tracks",
  invoke = function() insert_gt() end
}

error in Terminal: *** main.lua:6: ‘)’ expected near ‘track_index’.

I know that code needed to add to define it.But I do not know how it goes… :unsure:

This works I think.

function insert_gt()
 local song = renoise.song()
 song:insert_track_at(1)
 song:insert_track_at(1)
 song:insert_group_at(3)
 song:add_track_to_group(1, 3)
 song:add_track_to_group(1, 3)
end

insert_gt()

Thanks joule for the help! I will try to fix it… :wacko: :slight_smile:

Disregard. This seems to work?

So, what is happening is that song:add_track_to_group(a, b ) is inserting a group at position b, and automatically adding the previous track to it. track #a is also being added to the group. The function is a bit stupid/buggy in that way, it seems.

function insert_gt()
local song = renoise.song()
song:insert_track_at(1)
song:add_track_to_group(1, 2)
end

insert_gt()

Thereby yes!

function insert_gt()
  local song = renoise.song()
  song:insert_track_at(1)
  song:insert_track_at(2)
  song:insert_track_at(3)
  song:add_track_to_group(1, 2, 3)
end

insert_gt()

It seems to take 1 as the value of the group. To output two tracks need three numbers.I like the clean code!I need now collapsing one of the two tracks

No, that doesn’t work. Do what I updated above.

song:add_track_to_group(track_index, group_index) is the syntax. Do that after inserting an empty group.

PS. For bonus: do it the proper way (in regards to selected_track_index) not allowing any errors in edge cases, for example when you only have one group and one master track in your song.

Here is probably what you want to do.

function insert_track(index, name, is_collapsed)
  renoise.song():insert_track_at(index)
  local track = renoise.song():track(index)
  track.name = name
  track.visible_effect_columns = 0
  track.visible_note_columns = 12
  track.volume_column_visible = false
  for note_column = 1, 12 do
    track:set_column_name(note_column, "NOTE " .. note_column)
  end
  track.collapsed = is_collapsed
end
    
function insert_gt()
  local song = renoise.song()
  insert_track(song.selected_track_index, "TRACK 1", false)
  insert_track(song.selected_track_index, "TRACK 2", true)
  song:insert_group_at(song.selected_track_index + 2)
  song:add_track_to_group(song.selected_track_index + 1 , song.selected_track_index + 2)
  song:add_track_to_group(song.selected_track_index, song.selected_track_index + 2)
end

insert_gt()

The above code works!I’ll try this code more extensive now…

Thanks joule

Instead of inserting 2 tracks, as it would be 5 tracks within the group and rename the group?

this will help me understand the numbers!

How to structure that code depends on what you ultimately want to do. Especially the loops…

A group, inside 10 tracks

  • 1,2,3,4 collapsed
  • 5,6 expanded
  • 7,8,9,10 collapsed

and change the name of group. With the codeable to create more tools… for example

A group, inside 5 tracks

  • 1,2 collapsed
  • 3 expanded
  • 4,5 collapsed

Things like that

name of group:

song:insert_group_at(song.selected_track_index + 2).name = "GROUP 1"

:slight_smile: with 3 traks!

function insert_gt()
  local song = renoise.song()
  insert_track(song.selected_track_index, "TRACK 1", true)
  insert_track(song.selected_track_index, "TRACK 2", false)
  insert_track(song.selected_track_index, "TRACK 3", true)
  song:insert_group_at(song.selected_track_index + 3).name = "GROUP 1"
  song:add_track_to_group(song.selected_track_index + 2, song.selected_track_index + 3)
  song:add_track_to_group(song.selected_track_index + 1, song.selected_track_index + 3)
  song:add_track_to_group(song.selected_track_index, song.selected_track_index + 3) 
end

with 4 tracks:

function insert_gt()
  local song = renoise.song()
  insert_track(song.selected_track_index, "TRACK 1", true)
  insert_track(song.selected_track_index, "TRACK 2", false)
  insert_track(song.selected_track_index, "TRACK 3", true)
  insert_track(song.selected_track_index, "TRACK 4", true)
  song:insert_group_at(song.selected_track_index + 4).name = "GROUP 1"
  song:add_track_to_group(song.selected_track_index + 3, song.selected_track_index + 4)
  song:add_track_to_group(song.selected_track_index + 2, song.selected_track_index + 4)
  song:add_track_to_group(song.selected_track_index + 1, song.selected_track_index + 4)
  song:add_track_to_group(song.selected_track_index, song.selected_track_index + 4) 
end

I think I get it well!!!

Thank you very much!!!

Hi people!

function insert_track(index, name, is_collapsed)
  renoise.song():insert_track_at(index)
  local track = renoise.song():track(index)
  track.color_blend = 20 <-------------------
  track.name = name
  track.visible_effect_columns = 0
  track.visible_note_columns = 12
  track.volume_column_visible = false
  for note_column = 1, 12 do
    track:set_column_name(note_column, "NOTE " .. note_column)
  end
  track.collapsed = is_collapsed
end
    
function insert_gt()
  local song = renoise.song()
  insert_track(song.selected_track_index, "TRACK 1", false)
  insert_track(song.selected_track_index, "TRACK 2", true)
  song:insert_group_at(song.selected_track_index + 2)
  song:add_track_to_group(song.selected_track_index + 1 , song.selected_track_index + 2)
  song:add_track_to_group(song.selected_track_index, song.selected_track_index + 2)
end

insert_gt()

I agree a line (line:4):

track.color_blend = 20

With this code the Tracks can be colored in 20%, but not the main Group.How I can colored the main Group?I like to colored with an intensity of 40%, for example.Can you help me with the code?

Thanks!

Basically, I need to solve two things, to end the code I’m doing for a tool:

  1. Agree the color_blend in the Main Group
  2. Agree the collapse FX column in the Main Group (…the right column FX in Group)

All the options for the tracks is solvet. Where I are problems is the options in the Group (color_blend and collapse FX column).In the coming days to see if I can finish.

Please help!

Raul: Would adding these two lines in your ‘insert_gt’ do the trick? Like this:

function insert_track(index, name, is_collapsed)
  renoise.song():insert_track_at(index)
  local track = renoise.song():track(index)
  track.color_blend = 20
  track.name = name
  track.visible_effect_columns = 0
  track.visible_note_columns = 12
  track.volume_column_visible = false
  for note_column = 1, 12 do
     track:set_column_name(note_column, "NOTE " .. note_column)
  end
  track.collapsed = is_collapsed
end
        
function insert_gt()
  local song = renoise.song()
  insert_track(song.selected_track_index, "TRACK 1", false)
  insert_track(song.selected_track_index, "TRACK 2", true)
  song:insert_group_at(song.selected_track_index + 2)
  song:add_track_to_group(song.selected_track_index + 1 , song.selected_track_index + 2)
  song:add_track_to_group(song.selected_track_index, song.selected_track_index + 2)

  --Additional lines
  song.tracks[1].group_parent.color_blend = 40
  song.tracks[1].group_parent.collapsed = true

end

@Raul,

Did you know that you can “browse” the renoise.song() values available? This way, you can investigate what is available quite easily.

  1. In the terminal, type oprint(renoise.song()) and hit enter.

  2. There you see, for example, “patterns”. Let’s go further into the tree and see what is in patterns. Patterns is a table, and if you want to list a table you need to type rprint(renoise.song().patterns) instead. For everything else, oprint works.

You get the idea. You can get the same info in more detail from https://github.com/renoise/xrnx/blob/master/Documentation/Renoise.Song.API.lua , but I have personally learnt the most by using the terminal. Soon enough you will get a general understanding of where to find certain values.

Depending on what you want to do, this might be pretty.

local track_settings = {

Setting_1 = {
  group_name = "GROUP - Setting 1",
  group_blend = 50,
  { name = "TRACK 1", collapsed = true, blend = 20 },
  { name = "TRACK 2", collapsed = true, blend = 20 },
  { name = "TRACK 3", collapsed = true, blend = 20 },
  { name = "TRACK 4", collapsed = true, blend = 20 },
  { name = "TRACK 5", collapsed = true, blend = 20 },
  { name = "TRACK 6", collapsed = true, blend = 20 },
            },

Setting_2 = {
  group_name = "GROUP - Setting 2",
  group_blend = 10,
  { name = "TRACK 1", collapsed = true, blend = 20 },
  { name = "TRACK 2", collapsed = false, blend = 20 },
  { name = "TRACK 3", collapsed = true, blend = 80 },
  { name = "TRACK 4", collapsed = false, blend = 10 },
  { name = "TRACK 5", collapsed = true, blend = 20 },
  { name = "TRACK 6", collapsed = true, blend = 20 },
            },
}

function insert_track(track_index, group_index, name, is_collapsed, blend)
  renoise.song():insert_track_at(track_index)
  local track = renoise.song():track(track_index)
  track.color_blend = blend                     
  track.name = name
  track.visible_effect_columns = 0
  track.visible_note_columns = 12
  track.volume_column_visible = false
  track.collapsed = is_collapsed
  for note_column = 1, 12 do
    track:set_column_name(note_column, "NOTE " .. note_column)
  end
  renoise.song():add_track_to_group(track_index, group_index)
end
        
function insert_gt(track_setting)
  local song, i = renoise.song(), 1
  local group_index = song.selected_track_index + 1
  song:insert_group_at(group_index)
  song:track(group_index).name = track_settings[track_setting].group_name
  song:track(group_index).color_blend = track_settings[track_setting].group_blend  
  for val, track_setting in ipairs(track_settings[track_setting]) do
    local group_index = group_index + i
    insert_track(song.selected_track_index, group_index, track_setting.name, track_setting.collapsed, track_setting.blend)
    i = i + 1
  end
end
     
insert_gt("Setting_2")

Joule, you probably also need the option to automatically collapse the group to hide the group FX column:

local track_settings = {

Setting_1 = {
  group_name = "GROUP - Setting 1",
  group_blend = 50,
  group_collapse = false,
  { name = "TRACK 1", collapsed = true, blend = 20 },
  { name = "TRACK 2", collapsed = true, blend = 20 },
  { name = "TRACK 3", collapsed = true, blend = 20 },
  { name = "TRACK 4", collapsed = true, blend = 20 },
  { name = "TRACK 5", collapsed = true, blend = 20 },
  { name = "TRACK 6", collapsed = true, blend = 20 },
            },

Setting_2 = {
  group_name = "GROUP - Setting 2",
  group_blend = 10,
  group_collapse = true,
  { name = "TRACK 1", collapsed = true, blend = 20 },
  { name = "TRACK 2", collapsed = false, blend = 20 },
  { name = "TRACK 3", collapsed = true, blend = 80 },
  { name = "TRACK 4", collapsed = false, blend = 10 },
  { name = "TRACK 5", collapsed = true, blend = 20 },
  { name = "TRACK 6", collapsed = true, blend = 20 },
            },
}

function insert_track(track_index, group_index, name, is_collapsed, blend)
  renoise.song():insert_track_at(track_index)
  local track = renoise.song():track(track_index)
  track.color_blend = blend                     
  track.name = name
  track.visible_effect_columns = 0
  track.visible_note_columns = 12
  track.volume_column_visible = false
  track.collapsed = is_collapsed
  for note_column = 1, 12 do
    track:set_column_name(note_column, "NOTE " .. note_column)
  end
  renoise.song():add_track_to_group(track_index, group_index)
end
        
function insert_gt(track_setting)
  local song, i = renoise.song(), 1
  local group_index = song.selected_track_index + 1
  song:insert_group_at(group_index)
  song:track(group_index).name = track_settings[track_setting].group_name
  song:track(group_index).color_blend = track_settings[track_setting].group_blend
  for val, track_setting in ipairs(track_settings[track_setting]) do
    local group_index = group_index + i
    insert_track(song.selected_track_index, group_index, track_setting.name, track_setting.collapsed, track_setting.blend)
    i = i + 1
  end
  song:track(group_index).group_parent.collapsed = track_settings[track_setting].group_collapse
end
     
insert_gt("Setting_2")

@joule and @4Tey, Thanks!!! :slight_smile:

Let’s see if I have time and I get to implement.I’m learning more quickly than I thought at first, all thanks to your help!

I love it!!!