|
|
|
04-08-2017, 03:18 PM
|
#1
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
It drives me nuts! Why does this fail!? :/
Hello!
Add in a new project a single midi item and run this code:
Code:
local function Main()
reaper.Undo_BeginBlock()
reaper.ClearConsole()
local show = 1
-- Check if there is any take with no visible vol envelope in project
local item_cnt = reaper.CountMediaItems(0)
for i = 0, item_cnt-1 do
reaper.ShowConsoleMsg("item nr: "..i.."\n")
local item = reaper.GetMediaItem(0, i)
local take_cnt = reaper.CountTakes(item)
if take_cnt > 0 then
for j = 0, take_cnt-1 do
reaper.ShowConsoleMsg("take nr: "..j.."\n")
local take = reaper.GetMediaItemTake(item, j)
local VolEnv = reaper.GetTakeEnvelopeByName(take,"Volume")
reaper.ShowConsoleMsg("VolEnv: "..tostring(VolEnv).."\n\n")
if VolEnv == nil then show = 0 goto RESULT
else
local BR_Env = reaper.BR_EnvAlloc(VolEnv, 0)
local _,visible,_,_,_,_,_,_,_,_,_ = reaper.BR_EnvGetProperties(BR_Env)
if not visible then
reaper.BR_EnvFree(BR_Env, 1)
show = 0
goto RESULT
end
end
end
end
end
::RESULT::
reaper.ShowConsoleMsg("show is: "..show)
reaper.Undo_EndBlock("Toggle show all take vol envelopes", -1)
end
Main()
It works!
Now, run action "Take: Toggle take volume envelope" and run again the code.
It works!
Now, run again "Take: Toggle take volume envelope" and run once again the code.
It fails! :/
..and I cannot understand why!.. Please, help! Thanks!
|
|
|
04-08-2017, 04:19 PM
|
#2
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Looks like yet another BR function misbehaving to me.
The good news is, you can do it using the envelope's state chunk instead:
Code:
local function Main()
reaper.Undo_BeginBlock()
reaper.ClearConsole()
local show = 1
-- Check if there is any take with no visible vol envelope in project
local item_cnt = reaper.CountMediaItems(0)
for i = 0, item_cnt-1 do
reaper.ShowConsoleMsg("item nr: "..i.."\n")
local item = reaper.GetMediaItem(0, i)
local take_cnt = reaper.CountTakes(item)
if take_cnt > 0 then
for j = 0, take_cnt-1 do
reaper.ShowConsoleMsg("take nr: "..j.."\n")
local take = reaper.GetMediaItemTake(item, j)
local VolEnv = reaper.GetTakeEnvelopeByName(take,"Volume")
reaper.ShowConsoleMsg("VolEnv: "..tostring(VolEnv).."\n\n")
if VolEnv == nil then show = 0 goto RESULT
else
--[[
local BR_Env = reaper.BR_EnvAlloc(VolEnv, 0)
local _,visible,_,_,_,_,_,_,_,_,_ = reaper.BR_EnvGetProperties(BR_Env)
]]--
-- retval, strNeedBig reaper.GetEnvelopeStateChunk( env, strNeedBig, isundoOptional )
local ret, chunk = reaper.GetEnvelopeStateChunk( VolEnv, "")
if ret then
reaper.ShowConsoleMsg("chunk =\n"..tostring(chunk).."\n")
local vis = string.match(chunk, "\nVIS (%d).-\n")
if vis == "0" then
show = 0
goto RESULT
end
end
end
end
end
end
::RESULT::
reaper.ShowConsoleMsg("show is: "..show)
reaper.Undo_EndBlock("Toggle show all take vol envelopes", -1)
end
Main()
|
|
|
04-08-2017, 04:28 PM
|
#3
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Thank you so much Lokasenna!
I'll report the bug to SWS..
Is getting the chunks a lot slower? (for example when having 1000+ items)
|
|
|
04-08-2017, 04:42 PM
|
#4
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
I removed the ConsoleMsg functions and tried the code with 9728 items.. It takes about a second, which I guess is ok for that amount of items
|
|
|
04-08-2017, 04:55 PM
|
#5
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
And now.. I cannot reproduce the problem I was experiencing with my code..
:S
|
|
|
04-08-2017, 06:26 PM
|
#6
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Could it have something to do with the number of items in the project?
Edit: I whipped up a script to measure the time for both methods. I'll let you know if there's a difference whenever it... um... finishes. It's been a few minutes already.
Maybe checking 72 items' volume envelopes 2000 times wasn't the best idea.
Last edited by Lokasenna; 04-08-2017 at 06:46 PM.
|
|
|
04-08-2017, 07:21 PM
|
#7
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
72*2000.... :O :O :O
Hope you know in 2017 :P
... I haven't found the way to reproduce the problem 100% of the times.. Sometimes, it happens, others not...
|
|
|
04-08-2017, 08:00 PM
|
#8
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Bit of a surprising result - getting the envelope's state chunk and parsing it took 1/26th as long as using BR_EnvGetProperties. I can check the visibility of 72 items x 1000 in twenty seconds.
I can't say if the same speed advantage holds for any more complicated stuff.
Here's the test code if it's of any interest:
Code:
local function Msg(str)
reaper.ShowConsoleMsg(tostring(str).."\n")
end
local s_time = reaper.time_precise()
local function get_env(i)
local item = reaper.GetMediaItem(0, i)
local take = reaper.GetMediaItemTake(item, 0)
local env = reaper.GetTakeEnvelopeByName(take, "Volume")
return env
end
local iter = 100
local item_cnt = reaper.CountMediaItems(0)
local br_time = 0
for j = 1, iter do
local t = reaper.time_precise()
for i = 0, item_cnt - 1 do
local env = get_env(i)
if env then
local br_env = reaper.BR_EnvAlloc(env, 0)
local vis = reaper.BR_EnvGetProperties(br_env)
reaper.BR_EnvFree( br_env, false )
end
end
Msg("finished br x"..j)
br_time = br_time + (reaper.time_precise() - t)
end
br_time = br_time / iter
local ch_time = 0
for j = 1, iter do
local t = reaper.time_precise()
for i = 0, item_cnt - 1 do
local env = get_env(i)
if env then
local ret, chunk = reaper.GetEnvelopeStateChunk(env, "")
if ret then
local vis = string.match(chunk, "\nVIS (%d).-\n")
end
end
end
Msg("finished ch x"..j)
ch_time = ch_time + (reaper.time_precise() - t)
end
ch_time = ch_time / iter
Msg("br_time = "..tostring(br_time))
Msg("ch_time = "..tostring(ch_time))
Msg("elapsed = "..tostring( (reaper.time_precise() - s_time) ))
|
|
|
04-09-2017, 04:17 AM
|
#9
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Thanks for the test!
I'll repeat it without the Msg("finished.."), because this, ie updating the GUI, is what is the most time consuming
Results:
br_time = 5.9616242067518
ch_time = 5.9820414981685
elapsed = 1194.3734292385
item_cnt = 33140
Last edited by amagalma; 04-09-2017 at 04:54 AM.
|
|
|
04-09-2017, 08:32 AM
|
#10
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Did those items have volume envelopes? If the envelope is nil (i.e. hasn't been created yet) then both methods will skip the time-consuming part.
Edit: The discrepancy also increases with more items. I removed the Msg calls just to be sure, and I'm getting results like this:
Code:
Checking 560 items...
br_time = 0.75445919306949
ch_time = 0.018486561649479
br took 41 times as long as ch
elapsed = 7.7349594817497
Checking 2240 items...
br_time = 5.2738511407049
ch_time = 0.12188094678568
br took 43 times as long as ch
elapsed = 53.961620731745
Last edited by Lokasenna; 04-09-2017 at 02:11 PM.
|
|
|
04-09-2017, 02:41 PM
|
#11
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
No, they didn't have...
Code:
br_time = 5.9616242067518
ch_time = 5.9820414981685
elapsed = 1194.3734292385
item_cnt = 33140
The total elapsed time was about 20 minutes. br_time and ch_time show the elapsed time of one iteration, that is the time required to check all 33140 items once.
In my measurement br_time seems to be 0.34% faster (which ofcourse is negligible). I don't know why there is this difference with your measurement. I am going to check with items with envelopes and post back..
|
|
|
04-09-2017, 02:58 PM
|
#12
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Results:
Code:
br_time = 0.95377019715499
ch_time = 0.11324362851057
elapsed = 106.71037973904
item count = 1000
Br_function way is 8.422 times slower than chunk way... Nice to know that for when having to deal with so many items
But ofcourse, the br_function is a lot more easier to use..
|
|
|
04-09-2017, 06:11 PM
|
#13
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Thanks for directing me to chunks Lokasenna!
I created the action I wanted:
"Toggle active take volume envelope visible for selected item(s)"
Soon in ReaPack
|
|
|
04-09-2017, 09:15 PM
|
#14
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Here is a test project with 1000 items.. (Just having some fun with ReaNoir :P )
|
|
|
04-09-2017, 10:45 PM
|
#15
|
Human being with feelings
Join Date: Jan 2009
Location: New Zealand
Posts: 2,912
|
Who said beings never existed on other planets!
My first glimpse...
Fascinating guy's!
Kudos
Grinder
|
|
|
10-16-2017, 04:10 PM
|
#16
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
It seems that there is a bug in GetTakeEnvelopeByName.
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)
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.
100% reproducible
Last edited by amagalma; 10-16-2017 at 04:24 PM.
|
|
|
10-16-2017, 04:24 PM
|
#17
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
I just filed a bug report
|
|
|
10-16-2017, 04:26 PM
|
#18
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Quote:
Originally Posted by Lokasenna
Looks like yet another BR function misbehaving to me.
|
It isn't! It is a reaper bug. I just had to say this in order to be fair
P.S. I miss Breeder...
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 05:25 PM.
|