|
|
|
10-02-2017, 06:08 PM
|
#1
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,450
|
[5.51] Pooled automation items created by the API are empty (FIXED)
I create pooled copies of the automation item via the API (0:06). As you see, they are empty.
I add a point in the original item (0:15) and then they get updated.
Then I undo the point insertion (0:20) and.. my original AI empties as well!
test code:
Code:
local reaper = reaper
local done = false
local timeStart, timeEnd = reaper.GetSet_LoopTimeRange( false, false, 0, 0, false )
local sel_env = reaper.GetSelectedEnvelope( 0 )
local track_cnt = reaper.CountSelectedTracks( 0 )
-- proceed if time selection exists and there is a selected envelope
if sel_env and timeStart ~= timeEnd then
local sel_env_track = reaper.Envelope_GetParentTrack( sel_env )
local _, env_name = reaper.GetEnvelopeName( sel_env, "" )
local ai_cnt = reaper.CountAutomationItems( sel_env )
local pool_id
for i = 0, ai_cnt-1 do
local pos = reaper.GetSetAutomationItemInfo( sel_env, i, "D_POSITION" , 0, false )
if pos == timeStart then
pool_id = reaper.GetSetAutomationItemInfo( sel_env, i, "D_POOL_ID" , 0, false )
break
end
end
for i = 0, track_cnt-1 do
local track = reaper.GetSelectedTrack( 0, i )
if track ~= sel_env_track then
local env = reaper.GetTrackEnvelopeByName( track, env_name )
if env then
reaper.InsertAutomationItem( env, pool_id, timeStart, timeEnd-timeStart )
done = true
end
end
end
end
reaper.UpdateArrange()
if done then
reaper.GetSet_LoopTimeRange( true, false, 0, 0, false )
reaper.Undo_OnStateChangeEx2( 0, "Insert pooled instances of one automation item for selected tracks", 1|8 , -1 )
end
|
|
|
10-17-2017, 06:45 PM
|
#2
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,450
|
A small bump, since the devs are still working on automation items..
|
|
|
10-18-2017, 07:48 AM
|
#3
|
Human being with feelings
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,956
|
trying recode with no luck
Code:
for key in pairs(reaper) do _G[key]=reaper[key] end
-----------------------------------------------------
function main() local ret
local timeStart, timeEnd = GetSet_LoopTimeRange( false, false, 0, 0, false )
if timeStart == timeEnd then return end
local sel_env = GetSelectedEnvelope( 0 )
if not sel_env then return end
AI_t = {}
for AI_idx = 1, CountAutomationItems( sel_env ) do
local AI_pos = GetSetAutomationItemInfo( sel_env, AI_idx-1, "D_POSITION" , 0, false )
if AI_pos > timeStart-0.001 and AI_pos < timeEnd then
AI_t[#AI_t+1] = {pool_id = GetSetAutomationItemInfo( sel_env, AI_idx-1, "D_POOL_ID" , 0, false ),
pos=AI_pos,
len = GetSetAutomationItemInfo( sel_env, AI_idx-1, "D_LENGTH" , 0, false )}
end
end
if #AI_t == 0 then return end
local parent_tr = Envelope_GetParentTrack( sel_env )
local env_name = ({GetEnvelopeName( sel_env, "" )})[2]
for tr_id = 1, CountSelectedTracks( 0 ) do
local tr = GetSelectedTrack( 0,tr_id-1)
if parent_tr ~= tr then
local env = GetTrackEnvelopeByName( tr, env_name )
if env then
for i = 1, #AI_t do
AI_id = InsertAutomationItem( env, AI_t[i].pool_id, AI_t[i].pos, AI_t[i].len)
Envelope_SortPointsEx( env, AI_id-1)
ret = true
end
end
end
end
UpdateArrange()
return ret
end
-----------------------------------------------------
if main() then
--GetSet_LoopTimeRange( true, false, 0, 0, false )
Undo_OnStateChangeEx2( 0, "Insert pooled instances of automation items for selected tracks", 1|8 , -1 )
end
Issues:
- EnvelopeSortPointsEx doesn`t sort points
- sometimes when creating AI it creates random additional point somewhere in destination envelope
So seems you found a bug.
|
|
|
10-19-2017, 04:49 PM
|
#4
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,450
|
Thanks for confirming
Irrelevant question: what does this code do?:
Code:
for key in pairs(reaper) do _G[key]=reaper[key] end
Is it like "local reaper = reaper"?
|
|
|
10-20-2017, 12:25 AM
|
#5
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,866
|
@amalgama
It puts all reaper. function in the global scope so you dont have to prefix them. Just a matter of taste and typing efficiency :P
|
|
|
10-20-2017, 03:59 AM
|
#6
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,450
|
Oh, yes!... I read the code and missed it :S ... Does this affect performance?
|
|
|
10-20-2017, 04:13 AM
|
#7
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 15,733
|
Fixing the bug, thanks.
|
|
|
10-20-2017, 10:25 AM
|
#8
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,450
|
Quote:
Originally Posted by schwa
Fixing the bug, thanks.
|
Thanks!
|
|
|
10-20-2017, 10:42 AM
|
#9
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 15,733
|
Quote:
Originally Posted by X-Raym
It puts all reaper. function in the global scope so you dont have to prefix them. Just a matter of taste and typing efficiency
|
FWIW this does work but I would not recommend it. If any function or built-in variable in the reaper module collides with any object in the global namespace, the global object will be masked and unavailable. Even if there are no current collisions, later additions to the REAPER API might introduce some.
|
|
|
09-18-2018, 07:00 PM
|
#10
|
Human being with feelings
Join Date: Apr 2017
Location: St. Petersburg, FL
Posts: 880
|
Was there a regression or perhaps a related bug?
If I use something very simple like this:
Code:
for i = 0,4 do
reaper.InsertAutomationItem( reaper.GetSelectedEnvelope( 0 ) , 10, i+1, 0.75 )
end
I get 5 completely empty automation items that are not pooled.
In fact, I can't seem to create new pooled items at all.
|
|
|
09-18-2018, 07:59 PM
|
#11
|
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 15,716
|
Quote:
Originally Posted by Robert Randolph
Was there a regression or perhaps a related bug?
If I use something very simple like this:
Code:
for i = 0,4 do
reaper.InsertAutomationItem( reaper.GetSelectedEnvelope( 0 ) , 10, i+1, 0.75 )
end
I get 5 completely empty automation items that are not pooled.
In fact, I can't seem to create new pooled items at all.
|
You can't just create pools with an arbitrary ID, the first one needs to be created using a pool ID of -1. So something like this:
Code:
for i = 0,4 do
if i == 0 then
x = reaper.InsertAutomationItem( reaper.GetSelectedEnvelope( 0 ) , -1, i+1, 0.75 )
id = reaper.GetSetAutomationItemInfo(reaper.GetSelectedEnvelope(0),x,"D_POOL_ID",0,false)
else
reaper.InsertAutomationItem( reaper.GetSelectedEnvelope( 0 ) , id, i+1, 0.75 )
end
end
|
|
|
09-18-2018, 08:03 PM
|
#12
|
Human being with feelings
Join Date: Apr 2017
Location: St. Petersburg, FL
Posts: 880
|
Quote:
Originally Posted by Justin
You can't just create pools with an arbitrary ID, the first one needs to be created using a pool ID of -1. So something like this:
Code:
for i = 0,4 do
if i == 0 then
x = reaper.InsertAutomationItem( reaper.GetSelectedEnvelope( 0 ) , -1, i+1, 0.75 )
id = reaper.GetSetAutomationItemInfo(reaper.GetSelectedEnvelope(0),x,"D_POOL_ID",0,false)
else
reaper.InsertAutomationItem( reaper.GetSelectedEnvelope( 0 ) , id, i+1, 0.75 )
end
end
|
I see, thank you for the response.
Could this info be added to the doc string? It's rather difficult to figure out otherwise.
|
|
|
09-18-2018, 08:16 PM
|
#13
|
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 15,716
|
Quote:
Originally Posted by Robert Randolph
I see, thank you for the response.
Could this info be added to the doc string? It's rather difficult to figure out otherwise.
|
Sure, thanks!
|
|
|
09-19-2018, 06:13 AM
|
#14
|
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 15,716
|
Actually thinking about this more, InsertAutomationItem() could also add the pool if it does not exist, doing this now (though it will leave the pool state empty rather than moving envelope points to it, to somewhat preserve the existing functionality).
|
|
|
09-19-2018, 07:49 AM
|
#15
|
Human being with feelings
Join Date: Apr 2017
Location: St. Petersburg, FL
Posts: 880
|
Quote:
Originally Posted by Justin
Actually thinking about this more, InsertAutomationItem() could also add the pool if it does not exist, doing this now (though it will leave the pool state empty rather than moving envelope points to it, to somewhat preserve the existing functionality).
|
This is how I initially expected it to work. In the first scratch draft of the code I'm working on, I first created the AI and added a point, then created new pooled items.
I asked MPL about this behaviour before I posted, and that was his first attempt as well.
It seems intuitive to me at least.
Thank you again for addressing this.
|
|
|
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 03:26 AM.
|