Loopp/src/timemanager.hxx

83 lines
2.1 KiB
C++
Raw Normal View History

2013-12-08 22:44:43 +01:00
/*
* Author: Harry van Haaren 2013
* harryhaaren@gmail.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LUPPP_TIME_H
#define LUPPP_TIME_H
#include <iostream>
#include <cstdio>
#include "buffers.hxx"
#include "eventhandler.hxx"
2013-07-31 11:55:48 +02:00
#include "observer/time.hxx"
using namespace std;
class TimeManager
{
public:
2013-08-15 22:05:19 +02:00
TimeManager();
2013-08-15 22:05:19 +02:00
int getFpb();
void setBpm(float bpm);
2013-12-01 20:01:58 +01:00
void setBpmZeroOne(float bpm);
2013-08-15 22:05:19 +02:00
void setFpb(float f);
2013-12-05 21:17:02 +01:00
/// add a component to be updated for time events
2013-08-15 22:05:19 +02:00
void registerObserver(TimeObserver* o);
2013-12-05 21:17:02 +01:00
/// call this when a tempo-tap occurs
2013-08-15 22:05:19 +02:00
void tap();
2013-12-05 21:17:02 +01:00
/// called to process buffers->nframes samples. If a beat is present, this
/// is handled gracefully, first calling process up to the beat, then doing
/// a beat() event on all TimeObservers, and processing the remaining samples
2013-08-15 22:05:19 +02:00
void process(Buffers* buffers);
/// returns the number of samples till beat if a beat exists in this process
/// Otherwise returns nframes
int getNframesToBeat();
private:
2013-09-17 14:11:11 +02:00
int samplerate;
2013-12-05 21:17:02 +01:00
/// number of frames per beat
float fpb;
2013-12-05 20:57:17 +01:00
2013-12-05 21:17:02 +01:00
/// holds the number of frames processed
2013-12-05 20:57:17 +01:00
long long totalFrameCounter;
/// counts down frames until the next beat
2013-12-05 20:57:17 +01:00
long beatFrameCountdown;
2013-12-05 21:17:02 +01:00
/// counts bars / beats processed
int barCounter;
int beatCounter;
/// tap tempo measurements
int frame;
int tapTempoPos;
int tapTempo[3];
2013-07-31 11:55:48 +02:00
std::vector<TimeObserver*> observers;
};
#endif // LUPPP_TIME_H