Old 07-06-2017, 03:01 AM   #1
me2beats
Human being with feelings
 
me2beats's Avatar
 
Join Date: Jul 2015
Location: Yekaterinburg, Russia
Posts: 400
Default Get/SetTrackStateChunk() issues

Hey guys we (me and eugen2777) found some issues when using
GetTrackStateChunk() and SetTrackStateChunk()

Problems can be if you work with large track chunks (more than 4 mb)

At the moment we have the following solution (by eugen2777):

Code:
function GetTrackChunk(track)
  if not track then return end
  local fast_str, track_chunk
  fast_str = reaper.SNM_CreateFastString("")
  if reaper.SNM_GetSetObjectState(track, fast_str, false, false) then
    track_chunk = reaper.SNM_GetFastString(fast_str)
  end
  reaper.SNM_DeleteFastString(fast_str)  
  return track_chunk
end

function SetTrackChunk(track, track_chunk)
  if not (track and track_chunk) then return end
  local fast_str, ret
  fast_str = reaper.SNM_CreateFastString("")
  if reaper.SNM_SetFastString(fast_str, track_chunk) then
    ret = reaper.SNM_GetSetObjectState(track, fast_str, true, false)
  end
  reaper.SNM_DeleteFastString(fast_str)
  return ret
end
We recommend to use this code instead of GetTrackStateChunk() and SetTrackStateChunk() if possible.
__________________
My Reapack Repo
Donation

Last edited by me2beats; 07-06-2017 at 03:31 AM.
me2beats is offline   Reply With Quote
Old 07-06-2017, 03:54 AM   #2
snooks
Human being with feelings
 
Join Date: Sep 2015
Posts: 1,584
Default

Thanks, good work!
snooks is offline   Reply With Quote
Old 07-06-2017, 03:59 AM   #3
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,273
Default

What is the issue exactly? I remember to have issues in the past forcing me to work on chunks line by line in lua tables instead of strings. But at the end you have to pass a big string to set the chunk. How can o have a chunk so large to test it?.

Thank you and eugen2777 for the workaround.
__________________
HeDaScripts for REAPER
heda is offline   Reply With Quote
Old 07-06-2017, 05:32 AM   #4
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,919
Default

Nice ! Thanks for sharing !

Can you or eugen put in on ReaTeam Templates repo ?
X-Raym is offline   Reply With Quote
Old 07-07-2017, 11:19 AM   #5
me2beats
Human being with feelings
 
me2beats's Avatar
 
Join Date: Jul 2015
Location: Yekaterinburg, Russia
Posts: 400
Default

Quote:
Originally Posted by heda View Post
What is the issue exactly?
For example track may lose several fx at the end of fx chain


Quote:
Originally Posted by X-Raym View Post
Can you or eugen put in on ReaTeam Templates repo ?
Hi X-Raym! I don't know to do this, can you put it to Templates repo yourself pls?
__________________
My Reapack Repo
Donation
me2beats is offline   Reply With Quote
Old 07-10-2017, 07:49 AM   #6
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,486
Default

Thank you for the functions!

Just to note that your workaround is quite a bit slower than the reaper function. For example, getting the chunk from 300 (almost empty) tracks:
- Reaper's function time: 0.013485364965163
- Eugen's function time: 0.18676601076731

Nonetheless, your workaround is invaluable when someone wants to be sure he doesn't encounter problems with tracks with large chunks and we thank you!
amagalma is offline   Reply With Quote
Old 07-10-2017, 03:40 PM   #7
James HE
Human being with feelings
 
James HE's Avatar
 
Join Date: Mar 2007
Location: I'm in a barn
Posts: 4,415
Default

Do we know if this is limited to .lua only? I remember testing some big chunks in eel and not having problems, might not have reached 4mb though.
James HE is online now   Reply With Quote
Old 01-12-2018, 04:21 PM   #8
tufb
Human being with feelings
 
Join Date: Dec 2017
Location: Germany
Posts: 49
Default

Quote:
Originally Posted by heda View Post
What is the issue exactly? I remember to have issues in the past forcing me to work on chunks line by line in lua tables instead of strings. But at the end you have to pass a big string to set the chunk. How can o have a chunk so large to test it?.
If I understand the thread correctly, SetItemStateChunk may give no problems. Is the line by line table approach in Lua safe for large item Gets (I'd guess the answer is no as of the above post)?
tufb is offline   Reply With Quote
Old 01-13-2018, 04:14 PM   #9
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,273
Default

Quote:
Originally Posted by tufb View Post
If I understand the thread correctly, SetItemStateChunk may give no problems. Is the line by line table approach in Lua safe for large item Gets (I'd guess the answer is no as of the above post)?
I have no problems with it. I don't use any instruments that store large chunks. But I would like an answer by developers to this problem. Right now I get nightmares when I think about chunk manipulation.
__________________
HeDaScripts for REAPER
heda is offline   Reply With Quote
Old 01-20-2018, 03:48 AM   #10
eugen2777
Human being with feelings
 
eugen2777's Avatar
 
Join Date: Aug 2012
Posts: 271
Default

The standard function GetChunk don't supports the of chunks more than 4M.
The standard function SetChunk supports the of chunks more than 4M.

As a result, I use a modified function to get chunk > 4m and a standard function to set chunk. It always works well.

Code:
--------------------------------------------------
function GetTrackChunk(track)
  if not track then return end
  -- Try standart function -----
  local ret, track_chunk = reaper.GetTrackStateChunk(track, "", false) -- isundo = false
  if ret and track_chunk and #track_chunk < 4194303 then return track_chunk end
  -- If chunk_size >= max_size, use wdl fast string --
  local fast_str = reaper.SNM_CreateFastString("")
  if reaper.SNM_GetSetObjectState(track, fast_str, false, false) then
    track_chunk = reaper.SNM_GetFastString(fast_str)
  end
  reaper.SNM_DeleteFastString(fast_str)
  return track_chunk
end

--------------------------------------------------
-- Set track chunk(allow > 4MB) ------------------
--------------------------------------------------
function SetTrackChunk(track, track_chunk)
  if not (track and track_chunk) then return end
  return reaper.SetTrackStateChunk(track, track_chunk, false)
end
The same can probably be used for item chunks.
__________________
ReaScripts
eugen2777 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 07:54 AM.


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