Old 04-29-2019, 08:01 AM   #1
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 8,720
Default TimeMap2() vs. swing grid - help wanted

edit:
Created a bug report here.

=== original post ===

This

Code:
_nextGridPos = reaper.TimeMap2_beatsToTime(0, 0.25, 0)
should, to my understanding, give the position (in time) of the first visible grid line in my project.
It seems to work correctly for non swing grid:




However, when I set a swing grid, and run the script again, the same position is returned and not the actual position of the grid line.



Doesn't this function take swing grid into account or is it a bug in my understanding?

Last edited by nofish; 05-07-2019 at 02:53 PM.
nofish is offline   Reply With Quote
Old 04-29-2019, 08:51 AM   #2
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,227
Default

Ah, so you think TimeMap2_beatsToTime() does not take swing into account?
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is offline   Reply With Quote
Old 04-29-2019, 09:16 AM   #3
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 8,720
Default

I'd think so (to my understanding, that's why I'd like to get a confirmation, or not, i.e. if it's a bug), . Which, if so, would explain why BR_GetNext/PreviousGridDiv doesn't work with swing grid currently I think as it uses these API functions.

Last edited by nofish; 04-29-2019 at 09:24 AM.
nofish is offline   Reply With Quote
Old 04-29-2019, 09:24 AM   #4
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,227
Default

Ah that would indeed make sense and explain it! I hope the devs read this and can give some insight.
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is offline   Reply With Quote
Old 04-30-2019, 06:32 AM   #5
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 8,720
Default

Quote:
Originally Posted by _Stevie_ View Post
I hope the devs read this and can give some insight.
For now I'd as well appreciate if a fellow scripter more familiar with this function could give an opinion so I'd know if I should create an 'official' bug report or not. Anyone?
nofish is offline   Reply With Quote
Old 04-30-2019, 06:41 AM   #6
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,227
Default

Yes! Bump
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is offline   Reply With Quote
Old 05-06-2019, 06:35 AM   #7
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 8,720
Default

So, as Justin says this isn't a bug, anyone knows how to roll our own TimeMap2_beatsToTime(), TimeMap2_timeToBeats() functions which take swing grid into account?

Thoughts I had so far:
- with GetSetProjectGrid()we can get current grid division and swing amount

- swing grid is dpendent on current grid division and moves every odd gridline (if we take measure start as gridline 0), e.g.
- when set to 1/4: gridlines x.2 and x.4 are moved
- when set to 1/8: gridlines x.x.50 are moved and so on

But I think there's too much maths involved here for my simple mind. :/
nofish is offline   Reply With Quote
Old 05-07-2019, 02:38 PM   #8
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,227
Default

Bumping this, I wish I could help, but I'm sure someone who already coded something like that will chime in.
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is offline   Reply With Quote
Old 05-07-2019, 02:56 PM   #9
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 8,720
Default

Thanks Stevie.
I just changed the thread title accordingly.

As I gather, basically every script that uses this could break if a swing grid is set, so it'd be good if we have an alternative.
nofish is offline   Reply With Quote
Old 05-07-2019, 06:51 PM   #10
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 12,070
Default

Here you are:

Code:
function swingbeats(proj, beatpos)
  local retval, division, swing, swingamt = reaper.GetSetProjectGrid(proj,false)
  if swing and swingamt ~= 0 and division > 0 then
    beatpos = beatpos / (division*4)
    local fullb = math.floor(beatpos/2)*2
    beatpos = beatpos - fullb
    -- beatpos is [0..2), swingamt is -1..1, map 1 to 1+swingamt*.5
    beatpos = beatpos + (swingamt*.5)*(1-math.abs(beatpos-1))
    beatpos = (fullb + beatpos) * division * 4
  end
  return beatpos
end
Justin is offline   Reply With Quote
Old 05-08-2019, 06:13 AM   #11
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,227
Default

Ahh Justin, thanks so much for this!
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is offline   Reply With Quote
Old 05-08-2019, 10:44 AM   #12
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 8,720
Default

Thanks from me as well.
nofish is offline   Reply With Quote
Old 05-14-2019, 04:27 PM   #13
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,227
Default

@Justin, if you got 2 minutes, what would the reverse function look like, e.g.
TimeMap2_timetoBeats(), taking swing grid into account?
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is offline   Reply With Quote
Old 05-14-2019, 05:52 PM   #14
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 12,070
Default

Quote:
Originally Posted by _Stevie_ View Post
@Justin, if you got 2 minutes, what would the reverse function look like, e.g.
TimeMap2_timetoBeats(), taking swing grid into account?
What you no like algebra?

Something like this (though I haven't tested this code):
Code:
function unswingbeats(proj, beatpos)
  local retval, division, swing, swingamt = reaper.GetSetProjectGrid(proj,false)
  if swing and swingamt ~= 0 and division > 0 then
    beatpos = beatpos / (division*4)
    swingamt = swingamt*.5
    local fullb = math.floor(beatpos/2)*2
    beatpos = beatpos - fullb

    -- beatpos is [0..2), map 1+swingamt to 1
    local div = 1+swingamt
    if beatpos <= div then
      beatpos = beatpos / div
    else
      beatpos = 1.0 + (beatpos - div) / (2 - div)
    end
    beatpos = (fullb + beatpos) * division * 4
  end
  return beatpos
end
Justin is offline   Reply With Quote
Old 05-14-2019, 05:55 PM   #15
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,227
Default

Thank you Justin! <3
I'm a complete math noob, I'm already surprised by myself that I was able to write some scripts. I really have no idea, how I got this done

Quote:
Originally Posted by Justin View Post
What you no like algebra?

Something like this (though I haven't tested this code):
Code:
function unswingbeats(proj, beatpos)
  local retval, division, swing, swingamt = reaper.GetSetProjectGrid(proj,false)
  if swing and swingamt ~= 0 and division > 0 then
    beatpos = beatpos / (division*4)
    swingamt = swingamt*.5
    local fullb = math.floor(beatpos/2)*2
    beatpos = beatpos - fullb

    -- beatpos is [0..2), map 1+swingamt to 1
    local div = 1+swingamt
    if beatpos <= div then
      beatpos = beatpos / div
    else
      beatpos = 1.0 + (beatpos - div) / (2 - div)
    end
    beatpos = (fullb + beatpos) * division * 4
  end
  return beatpos
end
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_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 10:31 PM.


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