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 ?