|
|
|
10-13-2016, 07:32 AM
|
#1
|
Human being with feelings
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
|
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 ...
|
|
|
10-13-2016, 08:20 AM
|
#2
|
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
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")
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
|
|
|
10-13-2016, 09:31 AM
|
#3
|
Human being with feelings
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
|
^^^^
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 ...
|
|
|
10-13-2016, 09:41 AM
|
#4
|
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
Quote:
Originally Posted by DarkStar
^^^^
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?
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
|
|
|
10-14-2016, 03:29 AM
|
#5
|
Human being with feelings
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
|
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 ...
|
|
|
10-15-2016, 03:59 AM
|
#6
|
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
Quote:
Originally Posted by DarkStar
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?
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
|
|
|
10-15-2016, 11:07 AM
|
#7
|
Human being with feelings
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
|
Sure do (and some other stuff too)
>>> 1 MB gif: https://i.imgur.com/XFIw5UY.gif
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 11:59 PM.
|