TouchOSC template with scrolling songs list


The first official version is ready.
Now you can add and remove sliders, buttons, knobs, labels etc wherever you want, as you like without limits of number.
When the template starts, everything will be recognized automatically, so you won’t need to modify the script.
I recommend, when add a new controller with its name and value labels to insert the “tag” for each one.

New code here:

---Template for GigPerformer 1.0----
--Credits: rank13 from GigPerformer community----

---- controllers grouped by Tag
local Faders={}
local Knobs={}
local Buttons={}
-----Number of controllers
local N_faders = #root:findAllByType(ControlType.FADER, true)
local N_knobs = #root:findAllByType(ControlType.RADIAL, true)
local N_buttons =#root:findAllByType(ControlType.BUTTON, true)
-----grid songs label
local songlist=root:findByName("sng",true)
-----Songs pager position
local songs= self.children.pager.children.SongsPage
local mixer= self.children.pager.children.Main

----function init controllers
 function init_ctrls(num,tag_control)
  local control={}
   for i=1, num do
    control[i]=root:findAllByProperty("tag",""..tag_control..i,true)
   end
  return control
 end
 
 function init()
 sendOSC('/SetList/GetSongList')
 sendOSC('/SelectSongByIndex', 0)
 Faders = init_ctrls(N_faders,"F")
 Knobs = init_ctrls(N_knobs,"K")
 Buttons = init_ctrls(N_buttons, "B")

  --[[ --Use it for Test grid songs list--  
  for i = 1, #songlist.children do
   songlist.children[i].values.text = "song "..i
  end --]]
  
end
--Function Clear All-- 
function clear (obj)
  for i=1 , #obj do 
   for j=1, #obj[i] do 
   obj[i][j].visible=false
   end
  end
end
--Function Show controllers
function show (obj,id)
 for i=1, #obj  do 
   for j=1, #obj[i] do 
    if i==id then 
    obj[i][j].visible=true
    end
   end
 end
end

---callback OSC message
function onReceiveOSC(message,connections)
 local path = message[1]
 local arguments = message[2]
 
 ---send songs list to the songs list grid
 songlist: notify("list", {path, arguments})
  
 ------hide/show objects 
   if path=='/ClearAll' then  
    clear(Faders)
    clear(Knobs) 
    clear(Buttons)
   end
   --show sliders
   if string.find(path, '/Slider%d+Name') then
    local f_id = tonumber(string.match(path,'%d+'))
    show(Faders,f_id)
   end
   --show knobs
   if string.find (path, '/Knob%d+Name' )  then
    local k_id = tonumber(string.match(path,'%d+'))
    show(Knobs,k_id)
   end
   --show buttons
  if string.find (path, '/Button%d+Name' ) then
    local b_id = tonumber(string.match(path,'%d+'))
    show(Buttons,b_id)
   end

        -------Song List by rank13 ----------------
        
  -- If the setlist changes in GP, request the new song list
   if path == '/SetListChanged' then
    sendOSC('/SetList/GetSongList')
   end
  
  -- The last message received will provide the total song count
  if string.find(path, '/SongName') then
    local songCount = tonumber(string.match(path, '%d+')) + 1
    
    -- Store the song count in a label
  songs.children['SongCount'].values.text = tostring(songCount)  
  end
  
  -- Get the currently selected song number and store in a label
  if path == '/CurrentSongIndex' then
    local song =  arguments[1].value + 1
    self.notify(songs.children['CurrentSong'], tostring(song))
    
  --the current song will change its label color
    songlist: notify("songID", tostring(song))  
  end
  
  -- Once the last song name has been received (and total count 
  -- is calculated), hide any song labels that aren't required.
  if path == '/SongListEnd'
     
  then
    local songCount = tonumber(songs.children['SongCount'].values.text)
    
    -- Iterate through all the song labels in the 'songs' group
    -- and set the visibility property. Adding similar controls
    -- to a 'Group' gives them an index, which is useful for processing.
    songlist: notify("hide", songCount)
    
  end
  
  -- Similar to the song count, use LUA string functions to extract
  -- the song part number and store in a hidden label.
  if string.find(path, '/SongPart%d+') then
    local partCount = tonumber(string.match(path, '%d+')) + 1
    songs.children['SongPartCount'].values.text = tostring(partCount)
  end
  
  -- Once the last song part message is received (and total song part
  -- is calculated), hide any song part labels that aren't required.
  if path == '/SongPartsEnd' then
    local partCount = tonumber(songs.children['SongPartCount'].values.text)
    
    -- Iterate through all the song part labels in the 'SongParts' group
    -- and set the visibility property.
    for i = 1, #songs.children['SongParts'].children do
      songs.children['SongParts'].children[i].visible = (i <= partCount)
      mixer.children.parts.children[i].visible = (i <= partCount)
    end
  end
end

GP_Official_1_0.zip (13.0 KB)

GIG preset for test:
touchosc_TEST.gig (1.2 MB)

5 Likes