Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Q&A, Tips, Tricks and Howto

Reply
 
Thread Tools Display Modes
Old 07-05-2022, 01:22 AM   #1
1111Eugene
Human being with feelings
 
Join Date: Mar 2019
Posts: 137
Default Autozoom to content when changing midi item

Hi, I've made a tiny script that should open a midi item (also when changing it inside the midi editor) and zoom to its content.


so with the help of jrk I'm at this point now

Code:
if reaper.GetExtState("Main", "runstate") == "running" then 
  reaper.SetExtState("Main", "runstate", "stopped", false) 
end

last_take = -1;

reaper.Main_OnCommand(40153, 0) -- Item: Open in built-in MIDI editor


function Main()

  this_take = reaper.MIDIEditor_GetTake( reaper.MIDIEditor_GetActive() )

  if this_take ~= last_take then 
     
      reaper.MIDIEditor_OnCommand(reaper.MIDIEditor_GetActive(), 40214) -- unselect all
  
      reaper.MIDIEditor_OnCommand(reaper.MIDIEditor_GetActive(), 40466) -- View: Zoom to content
   
     this_take = last_take
 
  end
   
   reaper.defer(Main)
end


Main()

reaper.SetExtState("Main", "runstate", "running", false)
It does what it's meant to do, BUT here's what's happening now (uploading a video....)
1111Eugene is offline   Reply With Quote
Old 07-05-2022, 01:36 AM   #2
1111Eugene
Human being with feelings
 
Join Date: Mar 2019
Posts: 137
Default

here's the video

https://drive.google.com/file/d/1S8Y...ew?usp=sharing


now when I try to zoom in\out it doesn't let go of the focus because of the defer script... And If I grab the border of an item and make it smaller, it automatically zooms in to content and make the item smaller and smaller in a loop till it becomes a minimum size, etc...

So I think using defer is not for this case? Is there an observer in reaper api to watch for the midi item change? Thank you
1111Eugene is offline   Reply With Quote
Old 07-05-2022, 01:45 AM   #3
1111Eugene
Human being with feelings
 
Join Date: Mar 2019
Posts: 137
Default

sorry, my bad, the problem was with this line

Code:
last_take = this_take
It's the correct version, now everything seems to work
1111Eugene is offline   Reply With Quote
Old 07-05-2022, 02:06 AM   #4
1111Eugene
Human being with feelings
 
Join Date: Mar 2019
Posts: 137
Default

Now the only thing left is to disable undo points creation for it....:thinking:

Last edited by 1111Eugene; 07-05-2022 at 02:23 AM.
1111Eugene is offline   Reply With Quote
Old 07-05-2022, 05:05 AM   #5
1111Eugene
Human being with feelings
 
Join Date: Mar 2019
Posts: 137
Default

also would be great to update zoom to content when changing midi item size (edge)
1111Eugene 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 08:55 AM.


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