Help LUA: some questions about specific functions. Building a tool...

Hi.During my free time I’m building a tool, piecewise… I am very proud to build.I lack little to end, but there is always some specific function that I can not build.

Please, help!

  1. Question 01 “function to desploy popup”

A function 01 to desploy a popup.I do not know if it is possible.I want to use it with a button and a key.I only need the function to desploy poput.The rest is already solved.

The popup (3 items or more):

vb:popup { id = 'popup_one', width = '100%' , height = 24, value = 1, items = {'line 1','line 2','line 3'} }

The key (return):

if (key.name == 'return')
  then choice_via_shortcut = 'Desploy_Poput_One' vb.views['popup_one'].value = 1
end

With “.value = 1” select the first value in the list (line 1). But I need desploy the list, not select. Graphically, the popup has a triangleon the right, todeploy using the mouse. I need a function to do the same.

  1. Question 02 “function to select or jump to first track in pattern editor (and last)”

Yes, I’m going crazy with this nonsense: A function to select the first track in Pattern Editor (same than Shift + Control + Home), regardless of the number of tracks or groups. With “renoise.song():track(index)”, what would be the exact code?

With “renoise.song():select_previous_track()” “renoise.song():select_next_track()”,I can navigate, but I can not make a jump.Is there a way to also jump to the last track? (immediate left of the master track)

  1. Question 03 “condition not erase the first and individual track”

With this function:

local function del(index)
    local song = renoise.song()
    if (song.selected_track.type == renoise.Track.TRACK_TYPE_SEQUENCER) or (song.selected_track.type == renoise.Track.TRACK_TYPE_GROUP) then
      song:delete_track_at(song.selected_track_index)
    end
  end

…erase individuallyall tracks or groups in pattern editor, except Master Track and Sxx Tracks. The problem is the first track. If only has a “Track 01”, the function return the error:

*** std::logic_error: 'the given track can not be deleted.'
*** stack traceback:
*** [C]: in function 'delete_track_at'
*** main.lua:5351: in function 'del'
*** main.lua:5739: in function <main.lua:5739>

Lack a elseif conditionto avoid error. Prevent apply “delete_track_at”, if only has a track (or group).

I have trouble trying “the index” in pattern editor. Functions for jump first track, jump last last track (ignoring Master and Sxx Tracks), select a specified track, etc, etc…

They are three pieces of code will help to finish my tool. If I have any more questions I will add here not to open more topics…

Thanks in advance! Please, help!

  1. Solved!It serves to create two buttons to navigatebetween extremes of tracks.
local function navt_first()
    local song = renoise.song()
      song.selected_track_index = song.sequencer_track_count - song.sequencer_track_count + 1 
  end

  local function navt_last()
    local song = renoise.song()
      song.selected_track_index = song.sequencer_track_count
  end
  1. Solved! It serves to create a button to delete tracks or groups (not Master or Send).
local function navt_del()
    local song = renoise.song()
    --print(song.sequencer_track_count)
    if song.sequencer_track_count == 1 then
    elseif (song.selected_track.type == renoise.Track.TRACK_TYPE_SEQUENCER) or (song.selected_track.type == renoise.Track.TRACK_TYPE_GROUP) then
      song:delete_track_at(song.selected_track_index)         
    end
  end

I need to solve the question 1) A function to desploy a popup

Danoise, can you help me, please?

You mean, to open a popup and navigate it using the keyboard?
Unfortunately this is not possible, the Viewbuilder API doesn’t offer much in terms of key-navigation and focus.

If it’s a matter of choosing some value from the popup, you could add your own shortcut to the dialogs keyboard handler function and use that to raise or lower the value of the popup. Here is some code to demonstrate how to do this, while avoid values which are outside the accepted range of the popup.

local vb_popup = vb.views["my_popup"]
if (raise) then
  vb_popup.value = math.min(#vb_popup.items,vb_popup.value+1)
elseif (lower) then
  vb_popup.value = math.max(1,vb_popup.value-1)
end

You mean, to open a popup and navigate it using the keyboard?
Unfortunately this is not possible, the Viewbuilder API doesn’t offer much in terms of key-navigation and focus.

Yes, that is the intention.Too bad it is not possible. But…

If it’s a matter of choosing some value from the popup, you could add your own shortcut to the dialogs keyboard handler function and use that to raise or lower the value of the popup. Here is some code to demonstrate how to do this, while avoid values which are outside the accepted range of the popup.

local vb_popup = vb.views["my_popup"]
if (raise) then
vb_popup.value = math.min(#vb_popup.items,vb_popup.value+1)
elseif (lower) then
vb_popup.value = math.max(1,vb_popup.value-1)
end

This solution would be great.I mention exactly my situation:

A) I have a popup with various items.I want to control this poput with the buttons “up”, “down”.

B ) I have a horizontal switch of 16 items.I want to control this switch with the buttons “right”, “left”.

In theory I could use these two codes:

For popup ( A ) ):

local vb_popup = vb.views["my_popup"]
if (raise) then
  vb_popup.value = math.min(#vb_popup.items,vb_popup.value+1)
elseif (lower) then
  vb_popup.value = math.max(1,vb_popup.value-1)
end

For switch ( B )):

local vb_switch = vb.views["my_switch"]
if (raise) then
  vb_switch.value = math.min(#vb_switch.items,vb_switch.value+1)
elseif (lower) then
  vb_switch.value = math.max(1,vb_switch.value-1)
end

All is correct?

All is correct?

I dunno, if you can make it work then yes :wink:

Notice that the keyhandler checks for repeated keys too. So you should be able to press and hold to quickly cycle through items too.

Actually, it takes a little extra work_not_take repeated keys work this way…

I dunno, if you can make it work then yes :wink:

Notice that the keyhandler checks for repeated keys too. So you should be able to press and hold to quickly cycle through items too.

Actually, it takes a little extra work_not_take repeated keys work this way…

Hi Danoise.I managed to make it work all the switches and pop ups with keys.So all the tool can be used only with the keyboard, or the keyboard and mouse, or only with the mouse.

Now I’m on the subject of compressing and cutting code to optimize some functions.

Thank you very much for the help!

Do you know this topic? https://forum.renoise.com/t/solved-help-lua-function-to-create-a-group-with-two-tracks-one-col/46138

If you read below you will see the problem. If you have time, I would like to help finish it. It is a script to sort the notes by octaves.It is another tool that is incomplete.

When I have time, I’ll open a new topic to try to finish this tool…

EDIT : this issue is now solved!

Danoise, I have a new question…

How I can show in real time the number of the track or group of the Pattern Editor, in a floating window (a tool).

A scheme:


| title tool x |

|__________________________|

| |

| |

| [12] | <— Track or Group: 12 (in the index)

| |

| |

|__________________________|

Change the track in Pattern Editor, and the number changes in this floating window.Any simple code to do this?