Old 10-13-2016, 07:32 AM   #1
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 18,058
Default Q: lua: Accessing partially-populated tables?

Next question.

Let's say that I have a table in lua with these entries:
Code:
xx[11], xx[12], xx.[13],
xx[21], xx[22], xx[23], xx[24],
xx[51], xx[52], 
xx[81], xx[82], xx[83], xx[84], xx[85]
You could think of the first digit in the index as the track number and the second as the clip number (assuming <10 clips per track).

What is the best way to access each of the clips for a particular track?

Perhaps start with the track number *10 +1 (e.g 51), then use 'ipairs' which will stop at the first nil value? (With a check that I do not stray into the entries for the next track.)

Or is there a better way?
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is online now   Reply With Quote
Old 10-13-2016, 08:20 AM   #2
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 7,956
Default

Why not just nest tables?

Something like :
Code:
local items={}
for i=0,reaper.CountTracks(0)-1 do
  local track = reaper.GetTrack(0,i)
  local trackitems={}
  for j=0,reaper.CountTrackMediaItems(track)-1 do
    trackitems[j]=reaper.GetTrackMediaItem(track,j)
  end
  items[i]=trackitems
end
local item = items[2][2] -- 3rd item of 3rd track
local take = reaper.GetActiveTake(item)
reaper.ShowConsoleMsg(reaper.GetTakeName(take).."\n")
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :
http://xenakios.wordpress.com/
Xenakios is online now   Reply With Quote
Old 10-13-2016, 09:31 AM   #3
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 18,058
Default

^^^^
Ah, I didn't know about 2-dimensional dynamic arrays. That could do it.

But. how about the case where they are not tracks and clips but elements where I cannot determine how many there are in each chain?
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is online now   Reply With Quote
Old 10-13-2016, 09:41 AM   #4
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 7,956
Default

Quote:
Originally Posted by DarkStar View Post
^^^^
Ah, I didn't know about 2-dimensional dynamic arrays. That could do it.

But. how about the case where they are not tracks and clips but elements where I cannot determine how many there are in each chain?
It would work the same I suppose...Nested tables. (Lua doesn't even have arrays, 1D/2D/otherwise, all data that needs to be in "collections" must be put into tables.)

Unless there was a really good reason to, I wouldn't play around with stuff like trying to use integer indexes in some convoluted fashion. The Lua tables can have for example strings as the table keys, which could probably be used more easily. Can you explain your intended data access pattern in more detail?
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :
http://xenakios.wordpress.com/
Xenakios is online now   Reply With Quote
Old 10-14-2016, 03:29 AM   #5
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 18,058
Default

Sure ...

The basic data to be stored is track number, fx number, param number, param value (let me call that 3-part key and one data value a "chunk") .

And I would like to access all the chunks, in sequence, for any specified track. Also add a new chunk for a specified track, or delete a single chunk. And do all of that efficiently
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is online now   Reply With Quote
Old 10-15-2016, 03:59 AM   #6
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 7,956
Default

Quote:
Originally Posted by DarkStar View Post
Sure ...

The basic data to be stored is track number, fx number, param number, param value (let me call that 3-part key and one data value a "chunk") .

And I would like to access all the chunks, in sequence, for any specified track. Also add a new chunk for a specified track, or delete a single chunk. And do all of that efficiently
Sounds like you just need to do a somewhat more nested table which has a tree like structure. If I make a guess, you want something like being able to store, recall and manage snapshots of fx settings?
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :
http://xenakios.wordpress.com/
Xenakios is online now   Reply With Quote
Old 10-15-2016, 11:07 AM   #7
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 18,058
Default

Sure do (and some other stuff too)

>>> 1 MB gif: https://i.imgur.com/XFIw5UY.gif
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 11:39 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.