[Solved] Help LUA: scripts to navigate/jump per groups in Pattern Edit

I create this last code for navigate/jump per groups in Pattern Editor, but it is incomplete:

(ignore the prints, are for tests with the terminal…)

PREVIOUS JUMP PER GROUPS:

-- renoise.song():select_previous_track()
-- renoise.song():select_next_track()
-- song.sequencer_track_count

function tool_03_G01( i , A , B ) -- Navigate per Groups toward left
 print ( '\nSTART PREVIOUS ---- ---- ---- ---- ---- ---- ---- ----' )
 local song = renoise.song()
 local selected_track = song.tracks[song.selected_track_index] -- object
 local sel_tr = song.selected_track_index -- number
 print ( 'select: ---> ' ..sel_tr )
 print ( 'first: 1' )

 -- loop
 if ( selected_track.type == renoise.Track.TRACK_TYPE_GROUP or selected_track.type == renoise.Track.TRACK_TYPE_SEQUENCER ) then 
  for i = sel_tr , 1 , - 1 do -- loop: of the selected to first Track/Group
   i = i - 1
   print ( '---- ---- \n ' )
   print ( 'loop i : ' ..i ) 
     A = song.tracks[i] -- object = number (Group)
   B = song.tracks[i - 1] -- object = number (Track)
     print ('i: ' ..i) -- number
     print ('A : ') print ( A ) -- object
     print ('B : ') print ( B ) -- object
   if ( A.type == renoise.Track.TRACK_TYPE_GROUP and B.type == renoise.Track.TRACK_TYPE_SEQUENCER ) then
      return ----<<<< HERE!!!
   
      end
  end -- for i
 end -- if
 print ( 'END ---- ---- ---- ---- ---- ---- ---- ----\n ' )
end

NEXT JUMP PER GROUPS:

function tool_03_G02( i , A , B ) -- Navigate per Groups toward right
 print ( '\nSTART NEXT ---- ---- ---- ---- ---- ---- ---- ----' )
 local song = renoise.song()
 local selected_track = song.tracks[song.selected_track_index] -- object
 local sel_tr = song.selected_track_index -- number
 print ( 'select: ---> ' ..sel_tr )
 print ( 'last: ' ..song.sequencer_track_count )

 -- loop
 if ( selected_track.type == renoise.Track.TRACK_TYPE_GROUP or selected_track.type == renoise.Track.TRACK_TYPE_SEQUENCER ) then
  for i = sel_tr , song.sequencer_track_count do -- loop: of the selected to last Track/Group
     i = i + 1
   print ( '---- ---- \n ' )
   print ( 'loop i : ' ..i )
 
     A = song.tracks[i] -- object = number (Group)
   B = song.tracks[i - 1] -- object = number (Track)
     print ('i: ' ..i) -- number
     print ('A : ') print ( A ) -- object
     print ('B : ') print ( B ) -- object
   if ( A.type == renoise.Track.TRACK_TYPE_GROUP and B.type == renoise.Track.TRACK_TYPE_SEQUENCER ) then
      return ----<<<< HERE!!!

   end
  end -- for loop
 end -- if 
 print ( 'END ---- ---- ---- ---- ---- ---- ---- ----\n ' )
end

I think I need a line to finish in ----<<<< HERE!!! in both codes.

“renoise.song():select_previous_track()” and “renoise.song():select_next_track()” can they serve here?

The desired result is simple: jump to a group with a track inside (index - 1).

Are there any simple code to do this?

It may be silly, but please help to finish…

One simple way of doing it:

-- jump to previous group 
function jump_to_previous_group()
  local rns = renoise.song()
  local trk_idx = rns.selected_track_index-1
  local track = rns.tracks[trk_idx]
  while track and (track.type ~= renoise.Track.TRACK_TYPE_GROUP) do
    trk_idx = trk_idx-1
    track = rns.tracks[trk_idx]
  end
  if track then
    rns.selected_track_index = trk_idx
  end
end

Edit: I see now that I’ve just made it jump between group tracks, and not ‘group tracks with a track inside’.
Here is another version which takes that into consideration. First time I’ve used the ‘repeat…until’ control structure in lua B)

-- jump to previous group containing (at least) one sequencer track
function jump_to_previous_group()
  local rns = renoise.song()
  local trk_idx = rns.selected_track_index-1
  local track_grp,track_seq
  repeat 
    trk_idx = trk_idx-1
    track_grp = rns.tracks[trk_idx]
    track_seq = rns.tracks[trk_idx-1]    
  until (track_grp and (track_grp.type == renoise.Track.TRACK_TYPE_GROUP) 
    and track_seq and (track_seq.type == renoise.Track.TRACK_TYPE_SEQUENCER))
    or not track_seq
  if track_grp and track_seq then
    rns.selected_track_index = trk_idx
  end
end

Also, it could be expanded further, to allow “rotating”, just like how TAB works. I would personally like such a detail :slight_smile:

One simple way of doing it: …

Thaaanks!!!

I have already a solution:

function tool_01_G101( A , B ) -- Previous Navigate per Groups
 local function sel_group_previous( track, count )
  local song = renoise.song()
  local sel_tr = song.selected_track_index -- number
  local T = track + 1
  for j = sel_tr, count - 1 , -1 do
   song:select_previous_track()
   if j == T then
    break
   end
  end
 end
 local song = renoise.song()
 local sel_tr = song.selected_track_index -- number
 local selected_track = song.tracks[sel_tr] -- object
 if ( selected_track.type == renoise.Track.TRACK_TYPE_GROUP or selected_track.type == renoise.Track.TRACK_TYPE_SEQUENCER ) then
  for i = sel_tr - 1 , 2 , - 1 do
     A = song.tracks[i]
   B = song.tracks[i - 1]
   if ( A.type == renoise.Track.TRACK_TYPE_GROUP and B.type == renoise.Track.TRACK_TYPE_SEQUENCER ) then
    sel_group_previous( i , 1 )
    break
   end
  end
 end
end
---
function tool_01_G102( A , B ) -- Next Navigate per Groups
 local function sel_group_next( track, count )
 local song = renoise.song()
  local sel_tr = song.selected_track_index -- number
  local T = track - 1
  for j = sel_tr, count - 1 do
   song:select_next_track()
   if j == T then
    break
   end
  end
 end
 local song = renoise.song()
 local sel_tr = song.selected_track_index -- number
 local selected_track = song.tracks[sel_tr] -- object
 if ( selected_track.type == renoise.Track.TRACK_TYPE_GROUP or selected_track.type == renoise.Track.TRACK_TYPE_SEQUENCER ) then
  for i = sel_tr + 1 , song.sequencer_track_count - 1 do
     A = song.tracks[i]
   B = song.tracks[i - 1]
   if ( A.type == renoise.Track.TRACK_TYPE_GROUP and B.type == renoise.Track.TRACK_TYPE_SEQUENCER ) then
    sel_group_next( i , song.sequencer_track_count )
      break
   end
  end
 end
end

…but less optimized, very heavy.I did not like it, because this code has dual function!

I have taken your codeand cut a little:

JUMP GROUPS IN PATTERN EDITOR:

-- tool_01_G01, tool_01_G02 Jump Navigate per Groups
function tool_01_G01( A , B , C ) -- jump to previous Group (with sequencer track)
 local song = renoise.song()
 C = song.selected_track_index
 repeat
  C = C - 1
  A = song.tracks[C]
  B = song.tracks[C - 1]  
 until ( A and ( A.type == renoise.Track.TRACK_TYPE_GROUP ) and B and ( B.type == renoise.Track.TRACK_TYPE_SEQUENCER ) )
 or not B
 if A and B then
  song.selected_track_index = C
 end
end
---
function tool_01_G02( A , B , C ) -- jump to next Group (with sequencer track)
 local song = renoise.song()
 C = song.selected_track_index
 repeat
  C = C + 1
  A = song.tracks[C]
  B = song.tracks[C - 1]  
 until ( A and ( A.type == renoise.Track.TRACK_TYPE_GROUP ) and B and ( B.type == renoise.Track.TRACK_TYPE_SEQUENCER ) )
 or not B
 if A and B then
  song.selected_track_index = C
 end
end

This works much better ^_^.

I’m leaving some functions, for consultations in the forums…

Danoise, thank you very much!

Also, it could be expanded further, to allow “rotating”, just like how TAB works. I would personally like such a detail :slight_smile:

I study to implement it.Perhaps with an additional option.

Currently, I prefer to encase/enclose the Pattern Editor to jumpthe first track to the last track and jumped back, with two buttons ( index = 1, index = sequencer_track_count). My tool workin this way.But may have additional options. :slight_smile: