[Solved] Help: use a Checkbox (True/False) to control some properties

I have a problem with LUA that I do not know very well how to explain.I faced him last summer and did not solve it. I try again now.

I want to control some properties of the Tracks through a Checkbox with true/false.The code that I have at the time is the following:

Function for notifier of checkbox_peet_trvol (¿?):

function show_trvol(idx)

end

The checkbox = checkbox_peet_trvol (for control the " volume_column_visible" of a especific track):

checkbox_peet_trvol = vb:checkbox { id = 'cbox_peet_trvol', value = false, notifier = function(idx) show_trvol(idx) end, tooltip = 'Volume Column Track' }

Note: focus attention on " value" and " notifier".Here is the problem.

Propieties of track:

local track = {}
  track.solo_string = { name = 'Solo String' , color = PEET.TR.CR_RD01 , color_blend = 14 , collapsed = FALSE , volume_column_visible = checkbox_peet_trvol.value }

Note: focus attention on " volume_column_visible".Here is the rest of the problem, With the theme of the true and false.

Function to insert a track:

function in_tr( tid , track_setting )
  local song = renoise.song()
  local tid = song.selected_track_index + 1
  song:insert_track_at( tid )
  for parameter_name, parameter_value in pairs( track_setting ) do
    song:track( tid )[parameter_name] = parameter_value
  end
  song:track( tid ).visible_effect_columns = 0 , 1 , false
  song.selected_track_index = song.selected_track_index + 1
end

Function to insert the trackthrough a popup:

function peet_fn_A01( popup ) -- ( x03 )
  local function peet_fn_A01_01()
    local song = renoise.song()
    local tid = song.selected_track_index
    in_tr( tid , track.solo_string )
  end
  
  local function peet_fn_A01_02()
    --content
  end
  
  local function peet_fn_A01_03()
    --content
  end

  if popup == 1 then peet_fn_A01_01()
  elseif popup == 2 then peet_fn_A01_02()
  elseif popup == 3 then peet_fn_A01_03()
  end
end

Through a drop-down list (popup) and a button I invoke specific functions to insert tracks (and groups) with certain characteristics.My idea is to use several checkbox to be able to change the true and false properties of the track to be inserted.For example:

  • Track property --> volume_column_visible = true or false
  • The checkbox can change your " valor" true or false through your notifier (“false” by default).

The case is that I want with the mouse click to activate through the tool the checkbox (value true ), so that the property volume_column_visible takes the value true…and vice versa.

Is there any way to do this?

Actually, I want to use up to 4 checkboxes, to control:

  1. volume_column_visible
  2. panning_column_visible
  3. delay_column_visible
  4. sample_effects_column_visible

Some related information:

--Pattern editor columns (Renoise.Song.API.lua).
renoise.song().tracks[].volume_column_visible, _observable
  -> [boolean]
renoise.song().tracks[].panning_column_visible, _observable
  -> [boolean]
renoise.song().tracks[].delay_column_visible, _observable
  -> [boolean]
renoise.song().tracks[].sample_effects_column_visible, _observable
  -> [boolean]

--renoise.Views.CheckBox (Renoise.ViewBuilder.API.lua)
checkbox.value
  -> [boolean]

-- Valid in the construction table only: Set up a value notifier.
checkbox.notifier
  -> [function(boolean_value)]

-- Valid in the construction table only: Bind the view's value to a
-- renoise.Document.ObservableBoolean object. Will change the Observable
-- value as soon as the views value changes, and change the view's value as
-- soon as the Observable's value changes - automatically keeps both values
-- in sync.
-- Notifiers can be added to either the view or the Observable object.
checkbox.bind
  -> [ObservableBoolean Object]

Any ideas?

I have no idea how your code is laid out, but I guess you’re either (1) iterating through all tracks, presenting checkboxes for each one, or (2) you have some sort of popup that allows you to choose which track.
In any case, you need to know both the checkbox value and the track index before you can call your “show/hide column” method.

checkbox_peet_trvol = vb:checkbox { id = ‘cbox_peet_trvol’, value = false, notifier = function( idx ) show_trvol( idx ) end, tooltip = ‘Volume Column Track’ }

Have you tried running this code? I’m pretty sure that “idx” does not (cannot) carry the index of your track, since it’s a standard notifier method associated with a checkbox.
It just does what the usual checkbox notifier does, give you the value of the checkbox state.

Instead, you need to obtain the index from somewhere. If you’re (1) iterating through all tracks, you can obtain it from the loop itself.

for track_idx = 1, number_of_tracks do
 -- create checkbox
 vb.checkbox{
  notifier = function(val)
    print(track_idx,val)
  end
 }
end

Otherwise, if you’re (2) using a popup/selector of some kind, it’s a question of obtaining the value in the checkbox notifier method

vb.checkbox{
 notifier = function(val)
  local track_idx = vb.views["my_track_selector"].value
  print(track_idx,val)
 end
}

Both examples give you the track index and value, which should be all you need?

Before going deeper into the code, I’ll explain it another way, because maybe what I intend is not possible, or yes.

PEST module Too (provisional name):

7091 GT16-Colors-PEST-module-tool-1.png

I’m working on a new tool module for GT16-Colors called PEST, “Pattern Editor Specific Templates” (Actually, I’m playing with two new modules: AMIC and PEST bhot for GT16-Colors, when I get bored with one, I go with the other, and alternate).

Basically, PEST consists of several lists and a selection button.

Each list option includes several tracks within a group (or specific distribution).You select an option and press the button. Insert this option in the Pattern Editor.All of this works perfectly with my code, although it’s a little convoluted to shorten.

My problem comes down of tool with the checkboxes:

  • Vol,

  • Pan,

  • Dly,

  • SFx,

  • GFx

  • What I intend is, if Vol checkbox is actived (True), the option of the selected list inserts all tracks (imagine that there are 4 tracks within a group at the same time)with the volume column visible.

  • The same. If Vol checkbox is deactived (False),the option of the selected list inserts all tracks with the volume column hidden.

  • The same for rest of checkbox…Pan, Dly, SFx, GFx.I guess that would repeat the same code correctly.

So, changing with the mouse click influences all the tracks that can be inserted together, with the options of each list.

Example of various properties of each track (this list is going to be very long):

--track_setting
local track = {}
  track.solo_string = { name = 'Solo String' , color = PEST.TR.CR_RD01 , color_blend = 14 , collapsed = F , volume_column_visible = checkbox_peet_trvol.value }
  track.first_violins = { name = '1st Violins' , color = PEST.TR.CR_RD02 , color_blend = 14 , collapsed = F , volume_column_visible = checkbox_peet_trvol.value }
  track.second_violins = { name = '2nd Violins' , color = PEST.TR.CR_RD03 , color_blend = 14 , collapsed = F , volume_column_visible = True }
  track.violas = { name = 'Violas' , color = PEST.TR.CR_RD04 , color_blend = 14 , collapsed = F , volume_column_visible = True }
  track.cellos = { name = 'Cellos' , color = PEST.TR.CR_RD05 , color_blend = 14 , collapsed = F , volume_column_visible = False }
  track.double_basses = { name = 'Double Basses' , color = PEST.TR.CR_RD06 , color_blend = 14 , collapsed = F , volume_column_visible = False }

“volume_column_visible = True”, or"volume_column_visible = False". I intend to control this value of all tracks (within “local track = {}” ), all, using only one checkbox (the Vol checkbox that you can see under the tool). This checkbox is activated or deactivated before insert the choice of the chosen list through the green button.

…Once this is done, I will add the rest of the parameters:

Panning_column_visible

Delay_column_visible

Sample_effects_column_visible

with your related checkbox…

This weekend I will look in depth at what you tell me, and I will continue, It’s the second time I try, since last summer… :blush:I just want to make clear what I intend to do with this code.I could use for many things!

Aha, so the problem is actually not reading the checkbox value, or to obtain some arbitrary value (such as the track index). Rather, it’s that you want to apply some sort of filtering to the interface (the items displayed in popups) as a result of changing the checkboxes?

I would simply create a function which populate your popups as a result of changing the checkbox state. After all, a the content of a popup is nothing more than a table of strings.

I would then invoke that “item-generating” method when a change happens to the checkbox.

As for the method itself, you can choose to call with arguments or not (arguments such as “should I display volume?”) - this all comes down to personal taste, how you like to structure your code. Personally, I like to separate user interface and application logic, so I would probably hand over some arguments to the method. This would allow the function to exist in a completely different place and not know anything about checkboxes, viewbuilder or anything like that. But of course, it’s also possible to read the values of the checkboxes from within the function too - for example, via vb.views[“some_elements_id”].value, as in my small example above.

I will share the entire tool so you can see the state it is in now…

The checkbox fail:

7093 PEST--vol-checkbox-fail.gif

The gif shows that the checkbox does not work as I wish. The correct code is missing…All inserted tracks should hide or display the volume column at the same time.

The xrnx. The PEST module Tool is in folder: tools / tool_04.lua (the module is integred in GT16-Colors)

7092 ulneiz.GT16-Colors_v1.1.xrnx (warning! This tool is not finished…)

PEST is accessed with tab number 4…

EDIT :Thanks to dblue again for suggesting this program: LICEcap.I love it, simple and effective.

Raul, I’m just guessing as I don’t fully understand what is what, but as an example of what you might be trying to achieve, do you mean…

Ohh :blink:! Thanks you 4Tey!

Raul, I’m just guessing as I don’t fully understand what is what, but as an example of what you might be trying to achieve, do you mean…

You have understood perfectly!This solution is fine. It works perfectly!:

--group_setting
local group = {}
  group.string = { name = 'STRING GROUP' , color = PEST.TR.CR_RD00 , color_blend = 30 , collapsed = F }

--track_setting
local track = {}
  track.solo_string = { name = 'Solo String' , color = PEST.TR.CR_RD01 , color_blend = 14 , collapsed = F , volume_column_visible = T , panning_column_visible = T , delay_column_visible = T }
  track.first_violins = { name = '1st Violins' , color = PEST.TR.CR_RD02 , color_blend = 14 , collapsed = F , volume_column_visible = T , panning_column_visible = T , delay_column_visible = T }
  track.second_violins = { name = '2nd Violins' , color = PEST.TR.CR_RD03 , color_blend = 14 , collapsed = F , volume_column_visible = T , panning_column_visible = T , delay_column_visible = T }
  track.violas = { name = 'Violas' , color = PEST.TR.CR_RD04 , color_blend = 14 , collapsed = F , volume_column_visible = T , panning_column_visible = T , delay_column_visible = T }
  track.cellos = { name = 'Cellos' , color = PEST.TR.CR_RD05 , color_blend = 14 , collapsed = F , volume_column_visible = T , panning_column_visible = T , delay_column_visible = T }
  track.double_basses = { name = 'Double Basses' , color = PEST.TR.CR_RD06 , color_blend = 14 , collapsed = F , volume_column_visible = T , panning_column_visible = T , delay_column_visible = T }

--------------------------------------------------------------------------------
-- CHECKBOX
--------------------------------------------------------------------------------

function show_trvol(i)
  track.solo_string.volume_column_visible = i
  track.first_violins.volume_column_visible = i
  track.second_violins.volume_column_visible = i
  track.violas.volume_column_visible = i
  track.cellos.volume_column_visible = i
  track.double_basses.volume_column_visible = i
end

function show_trpan(i)
  track.solo_string.panning_column_visible = i
  track.first_violins.panning_column_visible = i
  track.second_violins.panning_column_visible = i
  track.violas.panning_column_visible = i
  track.cellos.panning_column_visible = i
  track.double_basses.panning_column_visible = i
end

function show_trdly(i)
  track.solo_string.delay_column_visible = i
  track.first_violins.delay_column_visible = i
  track.second_violins.delay_column_visible = i
  track.violas.delay_column_visible = i
  track.cellos.delay_column_visible = i
  track.double_basses.delay_column_visible = i
end

function show_trsfx(i)
end

function show_grsfx(i)
end

checkbox_pest_trvol = vb:checkbox { id = 'cbox_pest_trvol', value = true, notifier = function(i) show_trvol(i) end, tooltip = 'Volume Column Track' }
checkbox_pest_trpan = vb:checkbox { id = 'cbox_pest_trpan', value = true, notifier = function(i) show_trpan(i) end, tooltip = 'Panning Column Track' }
checkbox_pest_trdly = vb:checkbox { id = 'cbox_pest_trdly', value = true, notifier = function(i) show_trdly(i) end, tooltip = 'Delay Column Track' }
checkbox_pest_trsfx = vb:checkbox { id = 'cbox_pest_trsfx', value = true, notifier = function(i) show_trsfx(i) end, tooltip = 'sfx Column Track' }
checkbox_pest_grsfx = vb:checkbox { id = 'cbox_pest_grsfx', value = true, notifier = function(i) show_grsfx(i) end, tooltip = 'sfx Column Group' }

This is the new code, to have the example here.My main problem is to handle large amount of repeated code, which requires the need to use tricks of code to shorten as much as possible.In spite of it, what matters most to me is that it works.

In this case, look what will happen to me:

function show_trvol(i)
  track.solo_string.volume_column_visible = i
  track.first_violins.volume_column_visible = i
  track.second_violins.volume_column_visible = i
  track.violas.volume_column_visible = i
  track.cellos.volume_column_visible = i
  track.double_basses.volume_column_visible = i
end

Only this function show_trvol(i), will be very long, 100, 200 lines or more, because I’m going to add many more lines of the type track.XXX.volume_column_visible = i , and this must be multiplied x5.

Is there any way to shorten the code? It will be very long.

But it works. I’m very happy!

I’m not sure Raul as I don’t really program lua, but you may be able to replace:

function show_trvol(i)
  track.solo_string.volume_column_visible = i
  track.first_violins.volume_column_visible = i
  track.second_violins.volume_column_visible = i
  track.violas.volume_column_visible = i
  track.cellos.volume_column_visible = i
  track.double_basses.volume_column_visible = i
end
 
function show_trpan(i)
  track.solo_string.panning_column_visible = i
  track.first_violins.panning_column_visible = i
  track.second_violins.panning_column_visible = i
  track.violas.panning_column_visible = i
  track.cellos.panning_column_visible = i
  track.double_basses.panning_column_visible = i
end
 
function show_trdly(i)
  track.solo_string.delay_column_visible = i
  track.first_violins.delay_column_visible = i
  track.second_violins.delay_column_visible = i
  track.violas.delay_column_visible = i
  track.cellos.delay_column_visible = i
  track.double_basses.delay_column_visible = i
end

With just:

function show_trvol(i)
  for n,v in pairs(track) do
    v.volume_column_visible = i
  end
end

function show_trpan(i)
  for n,v in pairs(track) do
    v.panning_column_visible = i
  end
end

function show_trdly(i)
  for n,v in pairs(track) do
    v.delay_column_visible = i
  end
end

to get a similar result.

function show_trvol(i)
for n,v in pairs(track) do
v.volume_column_visible = i
end
end

function show_trpan(i)
for n,v in pairs(track) do
v.panning_column_visible = i
end
end

function show_trdly(i)
for n,v in pairs(track) do
v.delay_column_visible = i
end
end

to get a similar result.

This is just what I need!!!

Thank you very much for the help! It feels good to experiment with LUA+Renoise and have help!