Old 04-11-2018, 11:20 AM   #1
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default Automation items API - questions (FIXED)

FIXED (v5.979)

Two questions about the automation items API:
(renamed thread title as another question came up)

1. SetEnvelopePointEx() - bug with set point selected ?

I have this code for getting properties of first env. point in AI and setting it selected.

Code:
track = reaper.GetTrack(0,0)
env =  reaper.GetTrackEnvelope(track, 0)
retval, time, value, shape, tension, selected = reaper.GetEnvelopePointEx(env, 0, 0)
reaper.SetEnvelopePointEx(env, 0, 0, time, value, shape, tension, true,  false)

reaper.Envelope_SortPointsEx(env, 0)
reaper.UpdateArrange()
When I run it immediately after inserting an AI it works as expected, selecting the first point.
But when I move the point a bit to the right and run the code again, first point doesn't get selected.



Would somebody be so kind and test this or say if I do something wrong ?
(R5.78)

edit:
I have 'Options -> AIs -> 'AIs attach to underlying env. on both sides' set, if that matters.

===

2. How to reliably count points in envelope ?

I have the following for for counting total points in env. (including AIs), only one AI here for testing:

Code:
function msg(m)
  return reaper.ShowConsoleMsg(tostring(m) .. "\n")
end

track = reaper.GetTrack(0,0)
env =  reaper.GetTrackEnvelope( track, 0 )

countPts_underlyingEnv = reaper.CountEnvelopePointsEx(env, -1)
countPtsAI_1 = reaper.CountEnvelopePointsEx(env, 0)

-- Justin's workaround
-- see https://forum.cockos.com/showthread.php?t=199187 posts #6ff
countActualPtsAI_1 = 0
AIpos = reaper.GetSetAutomationItemInfo(env, 0, "D_POSITION", 0, false);
AIend = AIpos + reaper.GetSetAutomationItemInfo(env, 0, "D_LENGTH", 0, false);
for i = 0, countPtsAI_1-1  do
  retval, time, value, shape, tension, selected = reaper.GetEnvelopePointEx(env, 0, i)
  if time >= AIpos and time < AIend then
    countActualPtsAI_1 = countActualPtsAI_1 + 1
  end
end

pointsTotal = countPts_underlyingEnv +  countActualPtsAI_1

msg("Points in underlEnv: " .. countPts_underlyingEnv)
msg("actual Points in AI1: " .. countActualPtsAI_1)
msg("points total: " .. pointsTotal)
Result:


This is with 'AIs attach to underlying env. on both sides' enabled.

Seems like the points at AI edge are accounted for in the underlying env. and the AI (which I think they perhaps shouldn't as they are attached to the underlying env. as per Options ?) which results in a total point count > the actual point count present. (there are no more points on the env. than visible in the pic.)

How can I get the correct actual total point count in this case ?

Last edited by nofish; 06-20-2019 at 08:26 AM.
nofish is offline   Reply With Quote
Old 04-14-2018, 05:47 AM   #2
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

bump

I'm still stuck on these, so any help greatly appreciated.
nofish is offline   Reply With Quote
Old 04-14-2018, 06:36 AM   #3
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by nofish View Post
When I run it immediately after inserting an AI it works as expected, selecting the first point.
But when I move the point a bit to the right and run the code again, first point doesn't get selected.
It seems that AIs have additional points far outside the visible part. I don't know whether this is a bug, or whether the function of points is to make the visible parts of the curves fit properly.

If there is no point precisely at the edge of the AI, REAPER may automatically add additional points. So when you move point 0, it becomes point 1 (or 2) and another point 0 (or even 0 and 1) is added. The added points may be far before the AI, or a fraction of a microsecond before the edge.
juliansader is offline   Reply With Quote
Old 04-14-2018, 09:55 AM   #4
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Quote:
Originally Posted by juliansader View Post
It seems that AIs have additional points far outside the visible part. I don't know whether this is a bug, or whether the function of points is to make the visible parts of the curves fit properly.

If there is no point precisely at the edge of the AI, REAPER may automatically add additional points. So when you move point 0, it becomes point 1 (or 2) and another point 0 (or even 0 and 1) is added. The added points may be far before the AI, or a fraction of a microsecond before the edge.
Thanks.
Seems right I think as Justin said something similar here:
https://forum.cockos.com/showthread.php?t=199187 (posts #7 ff).

This brings up the question for me:
How could I reliably identify / manipulate points by index in AIs if I can't be sure that first visibly present point in an AI is index 0 for example ?

Last edited by nofish; 04-14-2018 at 10:03 AM.
nofish is offline   Reply With Quote
Old 04-15-2018, 04:49 PM   #5
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Just by selecting and moving points I get a different point count.
This can't be right, can it ?



Code:
function msg(m)
  return reaper.ShowConsoleMsg(tostring(m) .. "\n")
end

track = reaper.GetTrack(0,0)
env = reaper.GetTrackEnvelope( track, 0 )
countPts_underlyingEnv = reaper.CountEnvelopePoints(env)

msg("Points in underlEnv: " .. countPts_underlyingEnv)

Last edited by nofish; 04-15-2018 at 04:56 PM.
nofish is offline   Reply With Quote
Old 04-15-2018, 06:18 PM   #6
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by nofish View Post
Just by selecting and moving points I get a different point count.
This can't be right, can it ?
I think REAPER must necessarily add points to the underlying envelope, otherwise there is no node to connect the upward sloping segment to the left with the flat segment to the right.
juliansader is offline   Reply With Quote
Old 11-17-2019, 02:03 PM   #7
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

Is there any API to get set automation points value ?
X-Raym 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 05:50 AM.


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