There is a bug in
GetTakeEnvelopeByName.
Bug: GetTakeEnvelopeByName keeps returning an envelope even if that envelope does not exist any more!
Test code:
Code:
local function Main()
reaper.ClearConsole()
local item = reaper.GetSelectedMediaItem( 0, 0 )
if item then
local take = reaper.GetActiveTake( item )
if take then
reaper.ShowConsoleMsg("active take: ".. tostring(take) .. "\n")
local VolEnv = reaper.GetTakeEnvelopeByName(take,"Volume")
if VolEnv then
reaper.ShowConsoleMsg("VolEnv: "..tostring(VolEnv).."\n\n\nENVELOPE CHUNK:\n\n")
local _, chunk = reaper.GetEnvelopeStateChunk( VolEnv, "", true )
reaper.ShowConsoleMsg(chunk .. "\n\nITEM CHUNK:\n\n")
local _, chunk2 = reaper.GetItemStateChunk( item, "", true )
reaper.ShowConsoleMsg(chunk2)
else
reaper.ShowConsoleMsg("No Volume Env exists for this take")
end
end
end
end
Main()
reaper.defer(function () end)
How to Reproduce:
1) Select an item that
never had a volume envelope(important!) and run the code. You will get the message:
"No Volume Env exists for this take"
2) Now run action "Take: Toggle take volume envelope" (40693) and then again the code. You will get the envelope chunk and the item chunk. You can clearly see that the envelope chunk exists at the end of the item chunk.
3) Now run again action 40693 and run again the code.
BUG:
You still get the envelope chunk although it doesn't exist any more, as can be clearly seen in the item chunk.