Old 04-11-2019, 05:04 PM   #1
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default BR_GetNextGridDivision to get next 1/4 grid?

BR_GetNextGridDivision will always get the next grid division based on the grid set in the arrange. However, is there a way to get the next 1/4 grid?
Of course, I could quickly store the arrange grid, set it to 1/4 and then restore it.
But I'm wondering if there's a more elegant solution?
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 04-11-2019, 08:12 PM   #2
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,960
Default

Code:
pos  =  reaper.GetCursorPosition()
fullbeats = ({reaper.TimeMap2_timeToBeats( 0, pos )})[4]+10^-14
reaper.SetEditCurPos( reaper.TimeMap2_beatsToTime( 0, math.ceil(fullbeats) ), false, false )
mpl is offline   Reply With Quote
Old 04-12-2019, 11:49 AM   #3
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default

Many thanks mpl, this is phenomenal! Now, if I only understood the algo
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 04-14-2019, 12:36 AM   #4
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,960
Default

1/4 grid is one beat,
so with
Code:
fullbeats = ({reaper.TimeMap2_timeToBeats( 0, pos )})[4]+10^-14
we convert time in seconds into full beats count (not beats per measure). 10^-14 is the smallest possible increment to say reaper that we always want a next beat. Otherwise if you, say, have edit cursor at exactly 5.0 position, you`ll get 5.0 as next beat (which is the same). So quantizing 5.00000000000001 beat upper give us 6th beat with
Code:
math.ceil(fullbeats)
and
Code:
reaper.TimeMap2_beatsToTime( 0, math.ceil(fullbeats) )
converting full beats into seconds back

Last edited by mpl; 04-14-2019 at 12:42 AM.
mpl is offline   Reply With Quote
Old 04-14-2019, 03:58 AM   #5
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Quote:
Originally Posted by mpl View Post
1/4 grid is one beat,
That's only valid for 4/4 timesignature, not for say 7/8, or?
nofish is offline   Reply With Quote
Old 04-15-2019, 05:01 PM   #6
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default

Thanks mpl for the explanation!
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ 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:15 PM.


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