Page 1 of 1

Get tempo over time

Posted: Sun Dec 29, 2019 5:50 pm
by abject39
Happy Holidays! I have been struggling to get the hosts tempo over time. My goal is to get the tempo and use it as a variable anywhere in my script. The issue is once the function is ran it gets the tempo only at that exact moment. If an end-user changes the tempo later the script isn't aware of the tempo change. I want to be able to continually tell the script to get the tempo. So far I've tried several things but none have worked. Anyone knows how I can enhance the following scipt?

Code: Select all

T1 = getTempo()
I've tried scripts such as the one below but nothing has worked.

Code: Select all

defineParameter("TempoDetect", nil, 0, 0, 10, 1) --Fast loop for sun gradient

function calcModulation()
  local freq = 100
  local rate = getSamplingRate() / 32
  local TempoDetect = TempoDetect + freq / rate
  
  if TempoDetect >= 10 then
      TempoDetect = TempoDetect - 10
      return getTempo(T1)
  end
end
Anyone know what I am doing incorrectly? No matter what I have tried I either end up with nil value for T1 or I end up only being able to get the tempo once.

Re: Get tempo over time

Posted: Sun Dec 29, 2019 11:48 pm
by misohoza
Hi Chris,

Is it for an animation?

Something like this could probably work:

Code: Select all

defineParameter("TempoDetect", nil, 0, 0, 10, 1) --Fast loop for sun gradient
assert(getTempo() ~= -1) --Check if host provides tempo information

local rate = getSamplingRate() / 32
local phase = 0

function calcModulation()
  if isPlaying() then
    _, phase = math.modf(getBeatTime())
  else
    local freq = getTempo() / 60
    phase = phase + freq / rate
  end

  if phase >= 1 then
    phase = phase - 1
  end

  TempoDetect = 10 * phase

end

Re: Get tempo over time

Posted: Wed Jan 01, 2020 5:13 pm
by abject39
Ooops! That comment was just an old comment I forgot to delete lol.

No it isn't for an animation. I am getting the tempo and then putting it into a table of note times as a synchronized option. So basically the user can choose to adjust the time in increments of milliseconds or synchronize to note values. When they choose to synchronize to note values I want to get the tempo and convert and calculate the note time value from the tempo. The issue I had is that if the tempo changes then the values in the table are not longer accurate. This is why I want the tempo to occasionally check the tempo to ensure accuracy. Your example doesn't seem to work for me either. I'll send you a PM.