COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 01-29-2017, 02:08 PM   #1
$h@d0 link
Human being with feelings
 
Join Date: Jan 2017
Posts: 9
Default Syncing to the tempo

is there anyway to have my plugin sync to the tempo of the project? I was wondering if there is a callback or something that tells my program when the project tempo changes or do I have to make my own separate thread and keep checking if the value has changed?
$h@d0 link is offline   Reply With Quote
Old 01-29-2017, 08:35 PM   #2
David S
Human being with feelings
 
Join Date: Jan 2017
Posts: 7
Default struct ITimeInfo

Hi,
I'm not an expert by any means, but hopefully this helps....
Utilize the structure ITimeInfo in ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames) to retrieve the current host tempo and compare it to a previous tempo stored in a variable. Then do whatever you want to accomplish with the new tempo.
In the private section of your main header:
Code:
double mOldTempo;
ITimeInfo mTimeInfo;
In the constructor of your Main .cpp file initialize mOldTempo with a value..
Code:
YourPlugin::YourPlugin(IPlugInstanceInfo instanceInfo)
    : IPLUG_CTOR(kNumParams, kNumPrograms, instanceInfo),
    mThis(1.0),
    mThat(2000.),
    mOldTempo(120.0),
    mSomethingelse(0)

{
  TRACE;//...........
In ProcessDoubleReplacing:
Code:
GetTime(&mTimeInfo);
  if (GetParam(kYourSwitch)->Bool() == true) //if you want to switch temposync on and off
  {
      if (mOldTempo != mTimeInfo.mTempo)//compare old tempo to current tempo
      {
          do something tempo related;
          mOldTempo = mTimeInfo.mTempo;
      }
  }
David S is offline   Reply With Quote
Old 01-29-2017, 11:53 PM   #3
$h@d0 link
Human being with feelings
 
Join Date: Jan 2017
Posts: 9
Default Thank you so much!

Deeply appreciated, I will try this and let you know if it works!
$h@d0 link is offline   Reply With Quote
Old 01-30-2017, 10:33 AM   #4
earlevel
Human being with feelings
 
Join Date: Dec 2015
Posts: 196
Default

I'm pretty sure there is no callback, but you can either poll on GUI idle (if it's a GUI thing), or in the audio thread (ProcessDoubleReplacing).

If you need only tempo, GetTempo() returns tempo as a double.
earlevel is offline   Reply With Quote
Old 01-30-2017, 07:22 PM   #5
$h@d0 link
Human being with feelings
 
Join Date: Jan 2017
Posts: 9
Default Worked!

It worked alright, works very well because ProcessDoubleReplacing is always being called and also at that point in execution you can get the tempo without it returning 0 like it does if you call it in your programs constructor.
$h@d0 link 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 09:33 AM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.