Old 02-18-2018, 10:36 AM   #1
bFooz
Human being with feelings
 
Join Date: Jul 2010
Location: Slovakia
Posts: 2,588
Default Fast way to find the last adjusted ITEM?

Hi, is there any fast way how to find the last adjusted item?

I have tried storing track chunks for all tracks and then compare them with current chunks, this is too slow. Also I've tried not finding any particular item and do the script over all the items, which is as slow as the chunks method.

What the script does is it automatically creates empty items in folders over all children items, iterating each project state change (like Studio1/Cubase).

Thanks for any idea.
bFooz is online now   Reply With Quote
Old 02-18-2018, 03:03 PM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

Not possible. There is no timecode set in the .rpp after an adjustement.
X-Raym is offline   Reply With Quote
Old 02-18-2018, 03:20 PM   #3
junh1024
Human being with feelings
 
Join Date: Feb 2014
Posts: 240
Default

what about via undo handlers?
junh1024 is offline   Reply With Quote
Old 02-18-2018, 03:25 PM   #4
bFooz
Human being with feelings
 
Join Date: Jul 2010
Location: Slovakia
Posts: 2,588
Default

Quote:
Originally Posted by junh1024 View Post
what about via undo handlers?
How can that be accessed?
bFooz is online now   Reply With Quote
Old 02-19-2018, 12:30 PM   #5
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

It depends.

I would not use track-state-chunks, as they are really too slow, but use item-state-chunks instead(much faster).
In addition to that, I would only use the ones, that are selected, using GetSelectedMediaItem(ReaProject proj, int selitem), as they are probably the most likely ones that are being changed, especially using the mouse.
That way, you can also reduce the number of checks, resulting in even faster processing.

This should help for most(maybe all?) usecases....

PS: I think you already use it, but if not: use reaper.GetProjectStateChangeCount(ReaProject proj) to determine, if something has changed at all and reduce processing-workload even more...

Last edited by Meo-Ada Mespotine; 02-19-2018 at 12:40 PM.
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-19-2018, 01:18 PM   #6
bFooz
Human being with feelings
 
Join Date: Jul 2010
Location: Slovakia
Posts: 2,588
Default

Quote:
Originally Posted by mespotine View Post
I would not use track-state-chunks, as they are really too slow, but use item-state-chunks instead(much faster).
Thanks, I'll try it with item chunks. I'll need to check all items since for moving edges the item does not need to be selected (at least in my config).
bFooz is online now   Reply With Quote
Old 02-19-2018, 01:31 PM   #7
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

If it's mostly for changed item-edges, altered using mouse, I'd suggest to check using reaper.BR_GetMouseCursorContext_Item()

That way you can concentrate on the edges of that one item.

In addition to that, you can use BR_GetMouseCursorContext_Track() and BR_GetMouseCursorContext_Position() to find the items surrounding the mouse-position, who are most likely to be altered and check only them.

You need to call BR_GetMouseCursorContext() everytime first, though, as otherwise, the other functions I suggested aren't updated.
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-22-2018, 08:50 AM   #8
bFooz
Human being with feelings
 
Join Date: Jul 2010
Location: Slovakia
Posts: 2,588
Default

I have found that getting the track or item chunk is ok. The slow thing was WRITING into the item chunk.

I wanted to stretch item notes. Any ideas if this is possible faster? The code I use for this is:
Code:
local _,chunk =  reaper.GetItemStateChunk(item, "", 0)
chunk = string.gsub(chunk, ">", "<NOTES\n|"..textLong.."\n>\nIMGRESOURCEFLAGS 2\n>")
reaper.SetItemStateChunk(item, chunk, 0)
(these are not my own lines)

Thanks.
bFooz is online now   Reply With Quote
Old 02-22-2018, 09:40 AM   #9
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by junh1024 View Post
what about via undo handlers?
Quote:
Originally Posted by bFooz View Post
How can that be accessed?
Like this I guess, but there's no way to see which item is resized:

Code:
local reaper = reaper
local last_proj_change_count
local undo_hist = ""

function on_media_item_resize(last_action)
  gfx.x = 10
  gfx.y = 10
  undo_hist = undo_hist .. last_action .. "\n"
  gfx.drawstr(undo_hist)
end

function init()
  gfx.init("")
  gfx.set(1,1,1,1)
  last_proj_change_count = reaper.GetProjectStateChangeCount(0)
end


function mainloop()
  local proj_change_count = reaper.GetProjectStateChangeCount(0)
  if proj_change_count > last_proj_change_count then
    local last_action = reaper.Undo_CanUndo2(0)
    if last_action == "Resize media items" then
      on_media_item_resize(last_action)
    end
    last_proj_change_count = proj_change_count
  end
  if char~=-1 then reaper.defer(mainloop) end
  gfx.update()
end

init()
mainloop()
spk77 is offline   Reply With Quote
Old 02-22-2018, 03:03 PM   #10
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

If you want to change the Notes, you can also use the SWS-functions:

string reaper.ULT_GetMediaItemNote(MediaItem item)

reaper.ULT_SetMediaItemNote(MediaItem item, string note)

This should be faster, though I haven't tested them...
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-22-2018, 03:25 PM   #11
bFooz
Human being with feelings
 
Join Date: Jul 2010
Location: Slovakia
Posts: 2,588
Default

Quote:
Originally Posted by mespotine View Post
If you want to change the Notes, you can also use the SWS-functions:

string reaper.ULT_GetMediaItemNote(MediaItem item)

reaper.ULT_SetMediaItemNote(MediaItem item, string note)

This should be faster, though I haven't tested them...
Thanks. And what about setting the item's notes to stretch the available space in the item. That is actually the raeson I am writing into the chunk itself.
bFooz is online now   Reply With Quote
Old 02-22-2018, 03:59 PM   #12
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Is your slow code actually working and doing, what you want? If yes, could you please post a short gif that shows, what you mean by stretching the available space in the notes?
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-22-2018, 04:23 PM   #13
bFooz
Human being with feelings
 
Join Date: Jul 2010
Location: Slovakia
Posts: 2,588
Default

The size of text in the empty item I want:



The size I don't want:

bFooz is online now   Reply With Quote
Old 03-01-2018, 08:11 PM   #14
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Oh, you can change the size of the text? Interesting....

Edit:
The keyfactor to the big size of the text is not the text itself, but the "IMGRESOURCEFLAGS 2" you're adding into the statechunk in your example code.

Solution is: Make the statechunk, as you did in your code, but only ONCE(!) for each MediaItem:

Code:
-- Get the Statechunk of the Item
  local _,chunk =  reaper.GetItemStateChunk(item, "", 0)                               
-- add the notes and it's "text-resize-behaviour"
  chunk = string.gsub(chunk, ">", "<NOTES\n|"..textLong.."\n>\nIMGRESOURCEFLAGS 2\n>") 
-- add the new statechunk to the item
  reaper.SetItemStateChunk(item, chunk, 0)

after that, update the notes only using:

Code:
reaper.ULT_SetMediaItemNote(item,textLong) -- change the text of the item's notes
reaper.UpdateArrange()                     -- Update the ArrangeView to display the changed text
which should be much faster now and keeps the size of the text.

Keep in mind, that the size of the text depends on how many lines you include. The hugest text is a oneliner, but if you include linebreakes like \n into it, the textsize will become smaller, being sized in a way to fit and fill all it's available space in the item.

Means, the more lines, the smaller the text becomes. The length of the lines have no effect on the size, but longer lines will be truncated and ended with ...

It may be a good idea to end the notes with a \n, or parts of the text may slip below the bottom of the item(usually with three and more-line-texts).

Last edited by Meo-Ada Mespotine; 03-01-2018 at 08:33 PM.
Meo-Ada Mespotine 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 11:42 AM.


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