Old 06-04-2020, 03:08 AM   #1
Reno.thestraws
Human being with feelings
 
Reno.thestraws's Avatar
 
Join Date: Nov 2009
Location: Belgium
Posts: 10,474
Default Zoom with focus on mouse for mousewheel

Code:
-- @description Horizontal zoom for mousewheel focusing on mouse pointer
-- @author  ReNo
-- @changelog
--  + init

local r = reaper; local function nothing() end; 
local function bla() r.defer(nothing) end

function act(id) r.Main_OnCommand(id, 0) end
_,_,_,_,_,_,val = r.get_action_context()

hzmode = reaper.SNM_GetIntConfigVar("zoommode",0 ) -- get user prefs
vzmode = reaper.SNM_GetIntConfigVar("vzoommode",0 )-- get user prefs


r.Undo_BeginBlock()



  if val > 0 then 
reaper.SNM_SetIntConfigVar("zoommode",3) -- focus zoom on mouse
act(reaper.NamedCommandLookup("1012")) -- zoom in H
reaper.SNM_SetIntConfigVar("zoommode",hzmode) else -- restore user prefs
reaper.SNM_SetIntConfigVar("zoommode",3) -- focus zoom on mouse
act(reaper.NamedCommandLookup("1011")) -- Zoom out H
reaper.SNM_SetIntConfigVar("zoommode",hzmode) end -- restore user prefs


bla()
r.Undo_EndBlock('Horizontal zoom focus on mouse', 2)
SWS NEEDED!!!


The only goal of this script is to replace the orignal action "View: Zoom horizontally (MIDI CC relative/mousewheel)"

Add the mousewheel + modifier to the script instead and the zoom will focus on mouse pointer no matter what option of "horizontal zoom center" you choose in preferences -> editing behavior

Now you can have the best of both world

mousewheel zoom -> focus on mouse
keyshortcut zoom -> depend on preferences


Here's the equivalent for vertical zoom

Code:
-- @description Vertical zoom for mousewheel focus on mouse
-- @version 1
-- @author  ReNo
-- @changelog
--  + init

local r = reaper; local function nothing() end; 
local function bla() r.defer(nothing) end

function act(id) r.Main_OnCommand(id, 0) end
_,_,_,_,_,_,val = r.get_action_context()

hzmode = reaper.SNM_GetIntConfigVar("zoommode",0 ) -- get user prefs
vzmode = reaper.SNM_GetIntConfigVar("vzoommode",0 )-- get user prefs


r.Undo_BeginBlock()



  if val > 0 then 
reaper.SNM_SetIntConfigVar("vzoommode",3) -- focus zoom on mouse
act(reaper.NamedCommandLookup("40111")) -- zoom in V
reaper.SNM_SetIntConfigVar("vzoommode",vzmode) else -- restore user prefs
reaper.SNM_SetIntConfigVar("vzoommode",3) -- focus zoom on mouse
act(reaper.NamedCommandLookup("40112")) -- Zoom out V
reaper.SNM_SetIntConfigVar("vzoommode",vzmode) end -- restore user prefs


bla()
r.Undo_EndBlock('Vertical zoom focus on mouse', 2)
__________________
http://www.residenceemilia.com
Reno.thestraws is offline   Reply With Quote
Old 06-04-2020, 04:42 AM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,900
Default

Code:
local function nothing() end; 
local function bla() r.defer(nothing) end
 bla()
This litteraly do nothing :P
EDIT: Though, it doesn't create undo points in the end so it technically works as expected (aka it prevent undo points creation).


Consider deleting Undo functions, and put the main code in a Main function which will be caled via reaper.defer(Main). This would a cleaner way to not have undo points.
X-Raym is offline   Reply With Quote
Old 06-04-2020, 04:46 AM   #3
Reno.thestraws
Human being with feelings
 
Reno.thestraws's Avatar
 
Join Date: Nov 2009
Location: Belgium
Posts: 10,474
Default

Salut X Raym

Je ne suis pas formé du tout en scripting ni en programmation
Je prends des bouts de code existant pour faire les miens.

Quand ça marche, je ne vais pas plus loin

EDIT : si t'as envie de modifier en mieux, vas-y cordialement
__________________
http://www.residenceemilia.com

Last edited by Reno.thestraws; 06-04-2020 at 04:52 AM.
Reno.thestraws is offline   Reply With Quote
Old 06-04-2020, 06:07 AM   #4
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,900
Default

Quote:
Je ne suis pas formé du tout en scripting ni en programmation
Je prends des bouts de code existant pour faire les miens.

On a tous commencé comme ça :P Tant que ça marche !
Les optimisations proposées étaient juste sur la lecture du code mais côté performance ça ne va rien changer donc à la rigueur ce n'est pas si important.
X-Raym 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 09:56 AM.


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