|
|
|
04-09-2019, 12:39 PM
|
#1
|
Human being with feelings
Join Date: Nov 2009
Location: Belgium
Posts: 10,474
|
Script : Smart Grid (adaptative grid)
Grid adapt to zoom
https://drive.google.com/open?id=1DH...m29cn-cfgZ53pq
AND :
If grid is frame -> do nothing
if grid is triplet (with sws/aw : toggle triplet grid), triplet grid from 2/3 to 1/48
if swing grid : adaptive swing
In snap/grid settings : if you enable : use the same grid divison in arrange view and MIDI editor -> work in MIDI EDITOR
Feel free to adapt, modify, change, reapack or whatever
Code:
function SetButtonState( set ) -- Set ToolBar Button State
if not set then set = 0 end
local is_new_value, filename, sec, cmd, mode, resolution, val = reaper.get_action_context()
local state = reaper.GetToggleCommandStateEx( sec, cmd )
reaper.SetToggleCommandState( sec, cmd, set ) -- Set ON
reaper.RefreshToolbar2( sec, cmd )
end
function Main()
zoom = reaper.GetHZoomLevel()
grid_state = reaper.GetToggleCommandState(40145)--grid line toggle
frame_state = reaper.GetToggleCommandState(41885)--frame toggle
trip_state = reaper.GetToggleCommandState(reaper.NamedCommandLookup("_SWS_AWTOGGLETRIPLET"))
---GRID 1/128---
if zoom > 1280 and grid_state == 1 and frame_state == 0 and trip_state == 0 then
reaper.Main_OnCommand(41047,0) -- Grid 1/128
end
if zoom > 640 and zoom <= 1279.9999999999 and grid_state == 1 and frame_state == 0 and trip_state == 1 then
reaper.Main_OnCommand(41212,0) -- Grid 1/48
end
--- GRID 1/64---
if zoom > 640 and zoom <= 1279.9999999999 and grid_state == 1 and frame_state == 0 and trip_state == 0 then
reaper.Main_OnCommand(40774,0) -- Grid 1/64
end
if zoom > 640 and zoom <= 1279.9999999999 and grid_state == 1 and frame_state == 0 and trip_state == 1 then
reaper.Main_OnCommand(41212,0) -- Grid 1/48
end
--- GRID 1/32---
if zoom > 320 and zoom <= 639.9999999999 and grid_state == 1 and frame_state == 0 and trip_state == 0 then
reaper.Main_OnCommand(40775,0) -- Grid 1/32
end
if zoom > 320 and zoom <= 639.9999999999 and grid_state == 1 and frame_state == 0 and trip_state == 1 then
reaper.Main_OnCommand(41212,0) -- Grid 1/48
end
--- GRID 1/16---
if zoom > 160 and zoom <= 319.9999999999 and grid_state == 1 and frame_state == 0 and trip_state == 0 then
reaper.Main_OnCommand(40776,0) -- Grid 1/16
end
if zoom > 160 and zoom <= 319.9999999999 and grid_state == 1 and frame_state == 0 and trip_state == 1 then
reaper.Main_OnCommand(41213,0) -- Grid 1/24
end
---GRID 1/8 ---
if zoom > 80 and zoom <= 159.9999999999 and grid_state == 1 and frame_state == 0 and trip_state == 0 then
reaper.Main_OnCommand(40778,0) -- Grid 1/8
end
if zoom > 80 and zoom <= 159.9999999999 and grid_state == 1 and frame_state == 0 and trip_state == 1 then
reaper.Main_OnCommand(40777,0) -- Grid 1/12
end
--- GRID 1/4 ---
if zoom > 40 and zoom <= 79.9999999999 and grid_state == 1 and frame_state == 0 and trip_state == 0 then
reaper.Main_OnCommand(40779,0) -- Grid 1/4
end
if zoom > 40 and zoom <= 79.9999999999 and grid_state == 1 and frame_state == 0 and trip_state == 1 then
reaper.Main_OnCommand(41214,0) -- Grid 1/6
end
--- GRID 1/2 ---
if zoom > 20 and zoom <= 39.9999999999 and grid_state == 1 and frame_state == 0 and trip_state == 0 then
reaper.Main_OnCommand(40780,0) -- Grid 1/2
end
if zoom > 20 and zoom <= 39.9999999999 and grid_state == 1 and frame_state == 0 and trip_state == 1 then
reaper.Main_OnCommand(42000,0) -- Grid 1/3
end
--- GRID 1 ---
if zoom > 10 and zoom <= 19.9999999999 and grid_state == 1 and frame_state == 0 and trip_state == 0 then
reaper.Main_OnCommand(40781,0) -- Grid 1
end
if zoom > 10 and zoom <= 19.9999999999 and grid_state == 1 and frame_state == 0 and trip_state == 1 then
reaper.Main_OnCommand(42007,0) -- Grid 2/3
end
---- GRID 2 ---
if zoom > 2 and zoom <= 9.9999999999 and grid_state == 1 and frame_state == 0 then
reaper.Main_OnCommand(41210,0) -- Grid 2
end
---- GRID 4---
if zoom <= 2 and grid_state == 1 and frame_state == 0 then
reaper.Main_OnCommand(41211,0) -- Grid 4
end
--reaper.ShowConsoleMsg(zoom)
reaper.defer(Main)
end
SetButtonState( 1 )
Main()
reaper.atexit( SetButtonState )
Last edited by Reno.thestraws; 04-10-2019 at 01:20 AM.
|
|
|
04-10-2019, 01:22 AM
|
#2
|
Human being with feelings
Join Date: Nov 2009
Location: Belgium
Posts: 10,474
|
Warning : It's not a zoom tool!
It's a defer "option" (with toggling icon) that works with any kind of horizontal zoom action
|
|
|
04-10-2019, 04:37 AM
|
#3
|
Human being with feelings
Join Date: Dec 2017
Location: Sunny Siberian Islands
Posts: 957
|
Excellent work. Thank you! After using Sonar, I really missed this feature.
|
|
|
04-10-2019, 04:59 AM
|
#4
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,451
|
Thank you Reno.thestraws!
I am afraid there was already a script by mpl doing the same thing though...
Edit: No, it's similar but different.
[mpl_Zoom horizontally, change grid relatively (mousewheel).lua
mpl_Zoom horizontally, change grid relatively, preserve grid visibility and snap state (mousewheel).lua]
|
|
|
04-10-2019, 05:05 AM
|
#5
|
Human being with feelings
Join Date: Nov 2009
Location: Belgium
Posts: 10,474
|
Quote:
Originally Posted by amagalma
Thank you Reno.thestraws!
I am afraid there was already a script by mpl doing the same thing though...
Edit: No, it's similar but different.
[mpl_Zoom horizontally, change grid relatively (mousewheel).lua
mpl_Zoom horizontally, change grid relatively, preserve grid visibility and snap state (mousewheel).lua]
|
Mpl script is an action that zoom AND adapt grid
Mine is just an option (defer) and grid adapt wahtever zoom tool or action you're using
|
|
|
04-10-2019, 05:09 AM
|
#6
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,451
|
Could I add it to Reapack, so everyone can have it easily?
How would you like it to be named?
Reno.thestraws_Grid adapt to zoom ?
|
|
|
04-10-2019, 05:10 AM
|
#7
|
Human being with feelings
Join Date: Aug 2015
Posts: 3,669
|
i love it! thank you. missed this ever since acid pro x.0...in 2007
|
|
|
04-10-2019, 05:11 AM
|
#8
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,451
|
Quote:
Originally Posted by Reno.thestraws
Mpl script is an action that zoom AND adapt grid
Mine is just an option (defer) and grid adapt wahtever zoom tool or action you're using
|
Yes, sorry! I didn't remember well what mpl's scripts were exactly.
|
|
|
04-10-2019, 07:45 AM
|
#9
|
Human being with feelings
Join Date: Nov 2009
Location: Belgium
Posts: 10,474
|
Quote:
Originally Posted by amagalma
Could I add it to Reapack, so everyone can have it easily?
How would you like it to be named?
Reno.thestraws_Grid adapt to zoom ?
|
Yep, it's fine
|
|
|
04-17-2019, 05:24 PM
|
#10
|
Human being with feelings
Join Date: Aug 2015
Posts: 3,669
|
hey, i noticed this doesn't work in the midi editor, too -- any way to make this work in both directions, so that zooming in the MIDI editor changes the arrange view grid etc?
|
|
|
04-17-2019, 11:59 PM
|
#11
|
Human being with feelings
Join Date: Nov 2009
Location: Belgium
Posts: 10,474
|
you have to sync your midi editor to arrange view in midi editor action list and check "use same grid... in grid/snap settings
|
|
|
04-18-2019, 04:36 AM
|
#12
|
Human being with feelings
Join Date: Aug 2015
Posts: 3,669
|
thanks! this is awesome.
i love how you can switch into triplets and it just rolls with it. this is smooth.
|
|
|
06-24-2019, 04:29 AM
|
#13
|
Human being with feelings
Join Date: Aug 2015
Posts: 3,669
|
so obnoxious that i have to go back and set all of my old projects' midi editors to sync to the arrange view. this should be an optional global REAPER setting, as should snap settings. based on this script, i've changed my alt-L snap/grid settings, and i'm having to do it piecemeal for every old track i open.
any way to make the script check to make sure and give a change confirmation? or is this another mespotine rpp editor request?
|
|
|
04-03-2020, 08:04 AM
|
#14
|
Human being with feelings
Join Date: Jan 2013
Posts: 77
|
I'd like to use this but I have no idea how to go about it. Can someone please share step by step how to make it work? Thanks in advance.
|
|
|
04-03-2020, 03:46 PM
|
#15
|
Human being with feelings
Join Date: Jul 2007
Location: New Joisey
Posts: 5,990
|
Quote:
Originally Posted by Reno.thestraws
you have to sync your midi editor to arrange view in midi editor action list and check "use same grid... in grid/snap settings
|
Just tried this out, it works if I zoom in the arrange view but it doesn't work if I zoom in the MIDI editor. So just to be clear, here are the steps:
1. Enable "Grid: Use the same grid division in arrange view and MIDI editor"
2. Enable "Smart Grid script"
3. Zoom horizontal in Arrange view (using Ctrl+scrollwheel here for Horizontal zoom)
Result: MIDI Editor and Arrange View Grids are both in sync. Perfect.
Now...
4. Zoom horizontal in or out the MIDI Editor (using Ctrl+scrollwheel here for Horizontal zoom)
Result: No change to the grid at all no matter how far zoomed in or out you are in the MIDI Editor.
Not sure if this is a Reaper thing or something in the script itself. Ideally, this script would work the same in both, even if it were two independent scripts.
|
|
|
11-12-2020, 07:01 AM
|
#16
|
Human being with feelings
Join Date: Jan 2013
Posts: 1,126
|
I was inspired by Reno's script but took a more streamlined and optimized approach:
1- It has only one call to "reaper.Main_OnCommand" but is all managed using a table internally. That call will only update when the zoom setting changed. Right now, it is called over and over.
2- It is updated even on the initial call
3- It is updated even if snap to grid is off
4- It can be overridden by manually changing the grid if wanted.
Here it is if someone is interested in letting me know it works for them:
Code:
--------------------------------------
----------// HEADER //----------------
--------------------------------------
--[[
* ReaScript Name: LinkZoomAndGrid.lua
* Description: Script running in the background that updates the grid according to the zoom setting
* Instructions: 1- Make sure the option: Grid: Use the same grid division in arrange view and MIDI editor is Enabled.
2- Run the script
3- The Snap to grid setting will be updated according to your zoom setting.
4- Make sure "Snap to grid" is enabled!!!
* Author: Reno.thestraws, Updated by Alex Paquette,
* Forum Thread: https://forum.cockos.com/showthread.php?p=2123190
* Forum Thread URI:
* REAPER: 5
* Extensions: SWS/S&M
* Version: 1.0
--]]
--------------------------------------
----------// INITIAL VALUES //--------
--------------------------------------
local reaper = reaper --- performance
-----|| Variables ||-------------------------------
local action_id,last_action_id,last_zoom
-----|| Tables ||----------------------------------
local gridSetting = {
{ zoomlvl = 1280, cmd_id = 41047}, -- 1: 1/128
{ zoomlvl = 640, cmd_id = 40774}, -- 2: 1/64
{ zoomlvl = 320, cmd_id = 40775, cmd_id_triplets = 41212}, -- 1/32
{ zoomlvl = 160, cmd_id = 40776, cmd_id_triplets = 41213}, -- 1/16
{ zoomlvl = 80, cmd_id = 40778, cmd_id_triplets = 40777}, -- 1/8
{ zoomlvl = 40, cmd_id = 40779, cmd_id_triplets = 41214}, -- 1/4
{ zoomlvl = 20, cmd_id = 40780, cmd_id_triplets = 42000}, -- 1/2
{ zoomlvl = 10, cmd_id = 40781, cmd_id_triplets = 42007}, -- 1
{ zoomlvl = 5, cmd_id = 41210}, -- 15: 2
{ zoomlvl = 0, cmd_id = 41211} -- 16: 4
}
--------------------------------------
----------// FUNCTIONS //-------------
--------------------------------------
local function SetButtonState(set) -- Set ToolBar Button State
local _, _, sec, cmd = reaper.get_action_context()
reaper.SetToggleCommandState( sec, cmd, set or 0 ) -- Set ON
reaper.RefreshToolbar2( sec, cmd )
end
--------------------------------------
local function GetStates()
local states = {}
states.isGrid = reaper.GetToggleCommandState(40145) == 1--grid line toggle
states.isFrame = reaper.GetToggleCommandState(41885) == 1 --frame toggle
states.isTriplet = reaper.GetToggleCommandState(reaper.NamedCommandLookup("_SWS_AWTOGGLETRIPLET")) == 1
return states
end
local function Update(zoomlvl, state)
local action
if not state.isFrame then
local lastZoomLevel = 1280
for i = 1, #gridSetting do
if i > 1 then lastZoomLevel = gridSetting[i-1].zoomlvl end
if zoomlvl > gridSetting[i].zoomlvl and zoomlvl < lastZoomLevel then
action = gridSetting[i].cmd_id
if state.isTriplet then action = gridSetting[i].cmd_id_triplets end
break
end
end
end
return action
end
-----------------------------------------------------------
------------|| INIT ||-------------------------------------
-----------------------------------------------------------
local function Init()
SetButtonState(1)
local zoom = reaper.GetHZoomLevel()
local st = GetStates()
local action = Update(zoom, st)
reaper.Main_OnCommand(action,0)
end
---------------------------------------------------
local function Exit()
SetButtonState(0)
end
------------------------------------------
---------// RUN FUNCTION //--------------
------------------------------------------
local function run()
local zoom = reaper.GetHZoomLevel()
local st = GetStates()
if last_zoom and zoom ~= last_zoom then action_id = Update(zoom, st) end
if action_id and last_action_id and last_action_id ~= action_id then reaper.Main_OnCommand(action_id,0) end
last_zoom = zoom
last_action_id = action_id
reaper.defer(run)
end
------------------------------------------
---------// RUNTIME //-------------------
------------------------------------------
Init()
run()
reaper.atexit(Exit)
Last edited by lexaproductions; 11-12-2020 at 06:00 PM.
Reason: Edit: changed threshold value for 2 Bar and 4 Bars Stage
|
|
|
11-12-2020, 07:08 AM
|
#17
|
Human being with feelings
Join Date: Jun 2006
Posts: 22,567
|
could someone show me what this does? It sounds interesting but im not sure I understand the concept
|
|
|
11-12-2020, 07:35 AM
|
#18
|
Human being with feelings
Join Date: Jan 2013
Posts: 1,126
|
Quote:
Originally Posted by Jae.Thomas
could someone show me what this does? It sounds interesting but im not sure I understand the concept
|
To put it roughly:
Your snap to grid setting will always be in sync with the number of lines visible on your ruler and is changed automatically when you zoom in/out
To use it:
Import it using the "Load Reascript" function in the action window.
Run it. (It will be run in the background. You won't see anything at first)
Change your zoom in the arrange view and see that the Snap To Grid setting is adjusted automatically.
|
|
|
11-12-2020, 07:52 AM
|
#19
|
Human being with feelings
Join Date: Dec 2017
Location: Sunny Siberian Islands
Posts: 957
|
Quote:
Originally Posted by lexaproductions
I was inspired by Reno's script but took a more streamlined and optimized approach:
1- It has only one call to "reaper.Main_OnCommand" but is all managed using a table internally. That call will only update when the zoom setting changed. Right now, it is called over and over.
2- It is updated even on the initial call
3- It is updated even if snap to grid is off
4- It can be overridden by manually changing the grid if wanted.
|
Thank you! Very good coding!
|
|
|
11-12-2020, 08:09 AM
|
#20
|
Human being with feelings
Join Date: Jun 2006
Posts: 22,567
|
Quote:
Originally Posted by lexaproductions
To put it roughly:
Your snap to grid setting will always be in sync with the number of lines visible on your ruler and is changed automatically when you zoom in/out
To use it:
Import it using the "Load Reascript" function in the action window.
Run it. (It will be run in the background. You won't see anything at first)
Change your zoom in the arrange view and see that the Snap To Grid setting is adjusted automatically.
|
oh very interesting!
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 05:07 PM.
|