Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 05-12-2016, 08:19 AM   #41
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

edit....

Last edited by Sexan; 05-25-2016 at 05:11 AM.
Sexan is offline   Reply With Quote
Old 05-12-2016, 10:27 AM   #42
snooks
Human being with feelings
 
Join Date: Sep 2015
Posts: 1,639
Default

That doesn't store userdata either, but does functions which pickle.lua doesn't.

loadstring is deprecated so maybe changing loadstring to load would fix that error in those other functions. I had to change a couple of things in pickle.lua to make it 5.3 compatible too, it's something to be aware of anyway.

The way you are doing this is interesting and it would be great if you could get a serialization function that does metatables, userdata and functions. I don't know of any that do userdata anyway.

If such a thing doesn't exist you'll need to change something in your code.
snooks is offline   Reply With Quote
Old 05-12-2016, 02:16 PM   #43
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

would this thing work?
https://github.com/bakpakin/binser
dont know how to use it,I'm a kind a "if do print" guy haha don't know how to use this things
Sexan is offline   Reply With Quote
Old 05-13-2016, 06:39 AM   #44
snooks
Human being with feelings
 
Join Date: Sep 2015
Posts: 1,639
Default

The format it uses doesn't look like it's compatible with Reaper's ExtState... it stores and recalls (you need to change a loadstring to a load in binser.lua as well) fine apart from when you put the chunk in an ExtState where it still recalls variables in a table, but not functions.

It's interesting though, thanks for sharing. The way it uses serialize/unserialize methods to get around not being able to directly do this with userdata is clever.

Somebody could try converting the chunk to Base64 and back to see if that solves the issue. It might be worth exploring since there are a fixed number of types of userdata in ReaScript and a bit of exploration could have automagic serialization at our fingertips.

edit: converting to base64 works with ProjExtState and the userdata functionality does too. Metatables don't seem to be recalled though and that's an essential part of what you are trying to achieve.

Last edited by snooks; 05-13-2016 at 06:11 PM.
snooks is offline   Reply With Quote
Old 05-16-2016, 06:34 AM   #45
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

if any guru can share some light or idea (other approach) how to store this into projextstate or this project will sadly be abandoned....
Sexan is offline   Reply With Quote
Old 05-19-2016, 02:24 PM   #46
musicbynumbers
Human being with feelings
 
musicbynumbers's Avatar
 
Join Date: Jun 2009
Location: brighton, uk
Posts: 12,779
Default

Quote:
Originally Posted by Sexan View Post
if any guru can share some light or idea (other approach) how to store this into projextstate or this project will sadly be abandoned....
nooooooooo!

I don't know how to do it myself but if you save something like the sws snapshot, that gets saved as a compressed hex text chunk at the end of the project file so maybe looking at that might help?

Either that or could the text file not be saved alongside the project or in a folder like audio is?
__________________
subproject FRs click here
note: don't search for my pseudonym on the web. The "musicbynumbers" you find is not me or the name I use for my own music.
musicbynumbers is offline   Reply With Quote
Old 05-19-2016, 06:05 PM   #47
Garrick
Human being with feelings
 
Garrick's Avatar
 
Join Date: Jul 2009
Location: Wellington
Posts: 4,554
Default

Man this could be rocking.

Well done for what you've done so far Sexan
Garrick is offline   Reply With Quote
Old 05-20-2016, 03:18 AM   #48
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

Some saving works but not full ,some code in the script cannot be saved in with methods I've tried
Sexan is offline   Reply With Quote
Old 05-21-2016, 08:04 AM   #49
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

edit...

Last edited by Sexan; 05-22-2016 at 07:03 AM.
Sexan is offline   Reply With Quote
Old 05-21-2016, 08:07 AM   #50
musicbynumbers
Human being with feelings
 
musicbynumbers's Avatar
 
Join Date: Jun 2009
Location: brighton, uk
Posts: 12,779
Default

Glad to hear that!
__________________
subproject FRs click here
note: don't search for my pseudonym on the web. The "musicbynumbers" you find is not me or the name I use for my own music.
musicbynumbers is offline   Reply With Quote
Old 05-21-2016, 08:27 AM   #51
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

Me also ! https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=43s
Sexan is offline   Reply With Quote
Old 05-21-2016, 10:47 AM   #52
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

EDIT.....

Last edited by Sexan; 05-25-2016 at 05:58 AM.
Sexan is offline   Reply With Quote
Old 05-21-2016, 11:25 AM   #53
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

edit...

Last edited by Sexan; 05-25-2016 at 05:58 AM.
Sexan is offline   Reply With Quote
Old 05-21-2016, 04:28 PM   #54
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

edit...

Last edited by Sexan; 05-21-2016 at 04:48 PM.
Sexan is offline   Reply With Quote
Old 05-22-2016, 02:24 AM   #55
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

Here is the reaper native save version (projextstate)
https://stash.reaper.fm/27655/TrackLi...ojExtState.Lua
I would appreciate if someone more experienced could look into code and see if I implemented the saving and restoring the right way (save_tracks() and restore() functions)
As far as I've tested it with many project it works good.the only thing that bugs me is when opening new project,script needs to be terminated and opened in order to work.
but major success for me so far

Post #1 updated

Last edited by Sexan; 05-22-2016 at 05:29 AM.
Sexan is offline   Reply With Quote
Old 05-22-2016, 09:29 AM   #56
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

........

Last edited by Sexan; 05-24-2016 at 01:16 AM.
Sexan is offline   Reply With Quote
Old 05-22-2016, 01:30 PM   #57
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

edit......

Last edited by Sexan; 05-24-2016 at 01:16 AM.
Sexan is offline   Reply With Quote
Old 05-24-2016, 01:18 AM   #58
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

Last question :
What is the best way to extract track chunks?
I'm interested in Track name , guid and some else, and whole Item section (it starts with <ITEM)
Sexan is offline   Reply With Quote
Old 05-24-2016, 09:15 AM   #59
musicbynumbers
Human being with feelings
 
musicbynumbers's Avatar
 
Join Date: Jun 2009
Location: brighton, uk
Posts: 12,779
Default

Just to say Sexan, although I'm not good enough at code to give answers. I've been here all the way through with my fingers crossed that someone will come along and help you as I'd hate to see such an amazing script get this far and then hit a wall!

I'm basically like a mute cheerleader in the background silently cheering you on! lol
__________________
subproject FRs click here
note: don't search for my pseudonym on the web. The "musicbynumbers" you find is not me or the name I use for my own music.
musicbynumbers is offline   Reply With Quote
Old 05-24-2016, 12:43 PM   #60
stereolost
Human being with feelings
 
stereolost's Avatar
 
Join Date: Mar 2015
Location: Moscow, Russia
Posts: 206
Default

I'm checking the thread everyday too!
stereolost is offline   Reply With Quote
Old 05-24-2016, 01:30 PM   #61
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

Yeah I'm doing it little by little,snipping around and got the needed information,just need to figure things out how to implement.I've got new implementation for saving tracks to projextstate which works better.I've found some code from mpl on his git hub regarding track chunks (my question in a post above),now i need to figure out how to "grab" a chunk from that table (table inserting works well I've got all the chunks I need).So now I need to grab guid,track name and something else (there are not so many examples of this as I've searched).I dont know if I can insert just a part of chunk to the whole chunk or it needs to be a whole chunk.After that the saving will be done and the script will be ready to use on real projects.But if I get some help (any help ,but that is not doing well for me,) to implement removing versions on alt click or anything it would be cool.I've learned alot from doing this script but still the process will be very slow to get to actual finished version.
I've took a pretty huge and complicated script to work on so this is what I get

Here is a current version (restoring is not implemented,its commented out but its written what has to be done in it) is anyone wants to take a look
https://stash.reaper.fm/27678/CurrentReaList.lua

edit: uploaded again...wrong version

Last edited by Sexan; 05-24-2016 at 02:42 PM.
Sexan is offline   Reply With Quote
Old 05-25-2016, 01:58 AM   #62
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

For my dear followers , chunky thing saving/recalling is done,restored buttons don't recall names yet (need to write that part) but everything works fine
https://stash.reaper.fm/27679/ReaList...gFromChunk.lua
Sexan is offline   Reply With Quote
Old 05-25-2016, 10:27 AM   #63
musicbynumbers
Human being with feelings
 
musicbynumbers's Avatar
 
Join Date: Jun 2009
Location: brighton, uk
Posts: 12,779
Default

Quote:
Originally Posted by Sexan View Post
For my dear followers , chunky thing saving/recalling is done,restored buttons don't recall names yet (need to write that part) but everything works fine
https://stash.reaper.fm/27679/ReaList...gFromChunk.lua
Awesome! will try and put time aside soon to give it a heavy test! thanks!
__________________
subproject FRs click here
note: don't search for my pseudonym on the web. The "musicbynumbers" you find is not me or the name I use for my own music.
musicbynumbers is offline   Reply With Quote
Old 05-25-2016, 10:34 AM   #64
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

You are just in a right time,name storing fixed,the script works extremely good,but lack of removing the buttons ATM.Track storing works very well,did not encounter any issues (tested on A LOT of projects) and no problem at all.
https://stash.reaper.fm/27679/ReaList...gFromChunk.lua
Next step is to implement removing on alt click or something
Updated the first post also and I think its save to call it pre beta now haha
Sexan is offline   Reply With Quote
Old 05-25-2016, 01:38 PM   #65
stereolost
Human being with feelings
 
stereolost's Avatar
 
Join Date: Mar 2015
Location: Moscow, Russia
Posts: 206
Default

So now it's ready to test on real projects without risk of losing data?
I love you, Sexan.
stereolost is offline   Reply With Quote
Old 05-25-2016, 01:46 PM   #66
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

Well be careful I cant say for sure because only I tested,but track storing and recalling works without any error (I've tested with large number of tracks and projects),but there is no way currently to remove button from list,but other than that the track stay in list as long you dont remove/delete track.but again be careful make a copy of project and see how it goes so it doesn't do anything to original.
Again please use with care and report problems
Sexan is offline   Reply With Quote
Old 05-25-2016, 02:19 PM   #67
snooks
Human being with feelings
 
Join Date: Sep 2015
Posts: 1,639
Default

This should work for deleting a button when pressing Alt...
Code:
 btn.onClick = function()
                  if gfx.mouse_cap&16==16 then --Alt is pressed
                    for i=1,#Button_TB,1 do
                      if Button_TB[i]==btn then
                        table.remove(Button_TB,i)
                        save_tracks()
                        break
                      end
                    end                        
                    return
                  end                         
                  reaper.SetTrackStateChunk(track, chunk) ---set chunk          
                end
I'd maybe think about not doing the whole chunk too... good work so far though!
snooks is offline   Reply With Quote
Old 05-25-2016, 02:28 PM   #68
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

THANK YOU!!
Yeah this is currently how it is,I'm researching how to deal only with item part of the chunk,but I don't know how to get it from the top to bottom,lua strings are very new to me.But yeah that is what I aim for

First post updated with this new code

btw still dont use it on real projects,I've encountered one error and need to test (tracks got same name and chunk,switching one version switched versions,but I've added some new code (for multiple selected tracks) which is not in uploaded version)

Last edited by Sexan; 05-25-2016 at 03:02 PM.
Sexan is offline   Reply With Quote
Old 05-25-2016, 03:23 PM   #69
musicbynumbers
Human being with feelings
 
musicbynumbers's Avatar
 
Join Date: Jun 2009
Location: brighton, uk
Posts: 12,779
Default

Glad to hear it!

Have you tried with large vst yet like Kontakt that can take up a lot of space to store all their parameters?

I remember this being an issue for snapshots with sws too so maybe it might be here? (fingers crossed it's not!)
__________________
subproject FRs click here
note: don't search for my pseudonym on the web. The "musicbynumbers" you find is not me or the name I use for my own music.
musicbynumbers is offline   Reply With Quote
Old 05-25-2016, 03:54 PM   #70
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

Well I am a really simple man (record live instruments mostly) I very rarely use midi or anything midi related.For now I did not test with anything heavy on tracks.I plan to implement a items only version ( as an option)
Sexan is offline   Reply With Quote
Old 05-25-2016, 04:49 PM   #71
snooks
Human being with feelings
 
Join Date: Sep 2015
Posts: 1,639
Default

Here's a couple of functions that get and set just the items from track chunks with a bit of test code to see if it works. It seems to work here...
Code:
local track = reaper.GetTrack(0,0)


local function getItems(track)
  local ret, chunk = reaper.GetTrackStateChunk(track,"", 0)
  local pattern = "<ITEM.*>"
  return chunk:match(pattern)
end


local function setItems(track,item_chunk)
  local ret, chunk = reaper.GetTrackStateChunk(track,"", 0)
  local pattern = "<ITEM.*>"
  if chunk:match(pattern) ~= nil then
    chunk = chunk:gsub(pattern,item_chunk==nil and "\n>" or item_chunk)
  else
    -- no items on track
    chunk = chunk:sub(1,chunk:len()-2)
    chunk = chunk .. (item_chunk==nil and "\n>\n>" or item_chunk)
  end
  return reaper.SetTrackStateChunk(track,chunk)
end


local items = getItems(track)


-- wait a while so you can mess around
-- with items, then reset original 
local cnt = 0
function wait()
  cnt = cnt+1
  if cnt < 200 then reaper.defer(wait) return end
  setItems(track,items)
end

wait()
If you need a hand with anything, give me a shout!
snooks is offline   Reply With Quote
Old 05-26-2016, 02:12 AM   #72
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 2,562
Default

Track name, guid have dedicated API, why need chunking?
Item chunks: loop track items -> get item chunk. Again, dont understand why need chunking.
Way of matching pattern looks wrong for me since item chunk also has internal chunks like source midi or takes

BTW chunks are dangerous almost everytime. I recommend you to use it only when there's no another way to do something
__________________
SoundCloud | MPL Scripts discussion | ReaPack | Donate

Last edited by mpl; 05-26-2016 at 02:17 AM.
mpl is offline   Reply With Quote
Old 05-26-2016, 03:33 AM   #73
snooks
Human being with feelings
 
Join Date: Sep 2015
Posts: 1,639
Default

The asterix '*' is a greedy match though so '<ITEM.*>' matches the first '<ITEM' up to (and including) the '>' at the end of the RPP. It doesn't matter how many '>'s that are there before the last one.... the greedy match takes everything up to the last. That's why I replace '>'s when there are no items either in the track or the item_chunk - because it's taking everything, including the '>'s at the end of the file that aren't part of the item chunk part of the track chunk.

So it should work, but you are right that using the API is better.
snooks is offline   Reply With Quote
Old 05-26-2016, 03:59 AM   #74
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,589
Default

I agree with mpl. Why use chunks if there is API function? Only use chunks when totally necessary

Please don't use match with chunks.
I had recently to change all chunking code to avoid match patterns with them. Because it crashes REAPER, or hangs it if the chunk string is very large. It happens with certain tracks , certain plugins.
Instead you have to convert the chunk string to a table, line by line as mpl does.
Quote:
local chunklines = split(chunk, "\n")
And then work with the chunk line by line as needed. This is fast and won't hang REAPER.
heda is offline   Reply With Quote
Old 05-26-2016, 04:24 AM   #75
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 2,562
Default

Snooks, not on PC until weekend, so can't check.

OK, imagine we have chunk like
Code:
[[<track
  <item
   <some_other_stuff>
  >
  <next_item
  >
  >
]]
So
Code:
string:match('<item.*>)
should return

Code:
[[
  <item
   <some_other_stuff>
  >
  <next_item
  >
  >
]]
While true item chunk is:

Code:
[[
  <item
   <some_other_stuff>
  >
]]
Right? Maybe I misread something. If so, sorry, I didn't sleep 2 days
__________________
SoundCloud | MPL Scripts discussion | ReaPack | Donate

Last edited by mpl; 05-26-2016 at 05:15 AM.
mpl is offline   Reply With Quote
Old 05-26-2016, 05:10 AM   #76
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

Dont understand this Guid chunk talk,I need to use chunk or how will I store item position for specific track?
I know there is API specific for guid,but when I'm storing the chunk there is already guid inside so why do same thing twice?

Or you want to tell me there is another way to store track item positions without using chunks? or I totally misunderstood everything?

Last edited by Sexan; 05-26-2016 at 05:17 AM.
Sexan is offline   Reply With Quote
Old 05-26-2016, 05:18 AM   #77
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 2,562
Default

You can get item positions via GetMediaItemInfo_Value()
__________________
SoundCloud | MPL Scripts discussion | ReaPack | Donate
mpl is offline   Reply With Quote
Old 05-26-2016, 05:35 AM   #78
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

Yeah I know, but it seem much more complicated (but safer I guess) store all items in track,store all item positions,store items and positions with that track.I will try to modify to that method.Back to pre alpha I guess

Last edited by Sexan; 05-26-2016 at 05:43 AM.
Sexan is offline   Reply With Quote
Old 05-26-2016, 05:41 AM   #79
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,589
Default

For the purpose of this script you must use chunks. Easy way to store all information of the track. Jusr keep in mind to not use match as I said. Chunks can be large. Work line by line.
heda is offline   Reply With Quote
Old 05-26-2016, 05:48 AM   #80
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,530
Default

So I need to use method mpl used to split all chunks into lines and put the in table like this?
Code:
function restore()
local retval, value = reaper.GetProjExtState(0, "Track_Versions","Chunk")
restore_save = split(value, ",")

for k,v in ipairs(restore_save)do
  chunk_temp = string.sub(v, 2)
  close_v1 = string.find(chunk_temp, ">")
     close_v2 = string.find(chunk_temp, "<")
      if close_v2 == nil then close_v2 = 0 end
         close_v = math.min(close_v1, close_v2)
         chunk_part1 = string.sub(chunk_temp, 1, close_v-1 )
         chunk_part2 = "\n"..string.sub(chunk_temp, close_v)     
         if close_v2 == 0 then chunk_part2 = "" end
    
chunk_part_track = {}
chunk_part_item = {}

for line in chunk_part1:gmatch("[^\r\n]+") do table.insert(chunk_part_track, line) end
for line in chunk_part2:gmatch("[^\r\n]+") do table.insert(chunk_part_item, line) end
         end
      end
This code works fine and all lines are per key with 1 value
Sexan 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 02:31 AM.


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