Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Bug Reports

Reply
 
Thread Tools Display Modes
Old 10-02-2017, 06:08 PM   #1
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,450
Default [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
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 10-17-2017, 06:45 PM   #2
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,450
Default

A small bump, since the devs are still working on automation items..
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 10-18-2017, 07:48 AM   #3
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,956
Default

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.
mpl is offline   Reply With Quote
Old 10-19-2017, 04:49 PM   #4
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,450
Default

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"?
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 10-20-2017, 12:25 AM   #5
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,866
Default

@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
X-Raym is offline   Reply With Quote
Old 10-20-2017, 03:59 AM   #6
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,450
Default

Oh, yes!... I read the code and missed it :S ... Does this affect performance?
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 10-20-2017, 04:13 AM   #7
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,733
Default

Fixing the bug, thanks.
schwa is offline   Reply With Quote
Old 10-20-2017, 10:25 AM   #8
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,450
Default

Quote:
Originally Posted by schwa View Post
Fixing the bug, thanks.
Thanks!
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 10-20-2017, 10:42 AM   #9
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,733
Default

Quote:
Originally Posted by X-Raym View Post
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.
schwa is offline   Reply With Quote
Old 09-18-2018, 07:00 PM   #10
Robert Randolph
Human being with feelings
 
Robert Randolph's Avatar
 
Join Date: Apr 2017
Location: St. Petersburg, FL
Posts: 880
Default

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.
Robert Randolph is offline   Reply With Quote
Old 09-18-2018, 07:59 PM   #11
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 15,716
Default

Quote:
Originally Posted by Robert Randolph View Post
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
Justin is offline   Reply With Quote
Old 09-18-2018, 08:03 PM   #12
Robert Randolph
Human being with feelings
 
Robert Randolph's Avatar
 
Join Date: Apr 2017
Location: St. Petersburg, FL
Posts: 880
Default

Quote:
Originally Posted by Justin View Post
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.
Robert Randolph is offline   Reply With Quote
Old 09-18-2018, 08:16 PM   #13
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 15,716
Default

Quote:
Originally Posted by Robert Randolph View Post
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!
Justin is offline   Reply With Quote
Old 09-19-2018, 06:13 AM   #14
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 15,716
Default

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).
Justin is offline   Reply With Quote
Old 09-19-2018, 07:49 AM   #15
Robert Randolph
Human being with feelings
 
Robert Randolph's Avatar
 
Join Date: Apr 2017
Location: St. Petersburg, FL
Posts: 880
Default

Quote:
Originally Posted by Justin View Post
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.
Robert Randolph is offline   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 03:26 AM.


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