How do I put enveloper points into pooled Automation Items?
Every time I try to do it, they are either:
1. Doesn't add the points.
2. Adds them, but upon moving the Items, the points literally delete themselves. Which makes no sense at all...
It only works if I don't pool the Automation Items, which in my case is not a good thing to do, makes my resulting envelopes inconvenient to use.
How do I properly do it? I tried many ways, and it's just so frustrating at this point that something this simple just doesn't work...
Here's an example of how I try to do it:
Code:
for index = 0, items_count - 1 do
local item = reaper.GetSelectedMediaItem(0, index)
local item_pos = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
local item_len = reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
-- returns from 0 to 1.
local evaluated_point = found_preset(index, item)
local ai_index = reaper.InsertAutomationItem(
envelope,
index % 2 + 1, -- is either 1 or 2, so we have only two pools
item_pos, item_len
)
-- create points only for first two Automation Items,
-- because we only have two pools.
if index <= 1 then
reaper.InsertEnvelopePointEx(
-- env
envelope,
-- autoitem_idx
index % 2 + 1, -- is ALSO either 1 or 2
-- pos, val
item_pos + item_len / 2, evaluated_point,
-- shape, tension
1, 1,
-- isSelected, noSort
false, true
)
end
end