local Find_TSM_At_Pos = function(Pos) if reaper.FindTempoTimeSigMarker(0,Pos) ~= reaper.FindTempoTimeSigMarker(0,Pos-0.000001) then return reaper.FindTempoTimeSigMarker(0,Pos) else return -1 end end
local MsPos = reaper.BR_PositionAtMouseCursor(1)
function GetTSM(num)
local t = {}
t.num, t.retval, t.timepos, t.measurepos, t.beatpos, t.bpm, t.timesig_num, t.timesig_denom, t.lineartempo = num, reaper.GetTempoTimeSigMarker( 0, num )
t.QNpos = reaper.TimeMap_timeToQN_abs( 0, t.timepos )*60
return t
end
local Find_TSM_At_Pos = function(Pos) if reaper.FindTempoTimeSigMarker(0,Pos) ~= reaper.FindTempoTimeSigMarker(0,Pos-0.000001) then return reaper.FindTempoTimeSigMarker(0,Pos) else return -1 end end
local MsPos = reaper.BR_PositionAtMouseCursor(1)
function Find_Clst_TSM(Pos)
local Left, Right
local Denom = function(f) if f > 0 then return 2 else return math.huge end end
Left = reaper.FindTempoTimeSigMarker(0,Pos)
Right = Find_TSM_At_Pos (reaper.TimeMap2_GetNextChangeTime( 0, Pos ))
if Left >= 0 then
if Pos <= ((GetTSM(Left).timepos + GetTSM(Right).timepos) / Denom(Left)) or Right <= Left then return Left else return Right end
else return -1 end
end
--------------------------------------------------------------------------------------------------------------------
if MsPos ~= -1 then
local TSM = {}
TSM[0] = GetTSM(Find_Clst_TSM(MsPos))
TSM[1] = GetTSM(TSM[0].num+1)
TSM[2] = GetTSM(TSM[0].num+2)
if TSM[0].lineartempo or TSM[1].lineartempo or TSM[2].lineartempo then
local test = (TSM[0].bpm+TSM[1].bpm+TSM[2].bpm) /3 - (TSM[2].QNpos-TSM[0].QNpos) / (TSM[2].timepos-TSM[0].timepos)
reaper.ShowConsoleMsg("("..TSM[0].bpm.." + "..TSM[1].bpm.." + "..TSM[2].bpm..") /3 - ("..TSM[2].QNpos.." - "..TSM[0].QNpos..") / ("..TSM[2].timepos.." - "..TSM[0].timepos..") = "..test.."\n\n" )
end
end