Fixup: fftwf_real, elliminate more doubles
[zynaddsubfx-code.git] / src / Misc / Time.h
blob2c636e41013bc164a10713f5cab5dc5f94ba2c66
1 /*
2 ZynAddSubFX - a software synthesizer
4 Time.h - Frame Tracker
5 Copyright (C) 2016 Mark McCurry
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 #pragma once
13 #include <stdint.h>
14 #include "../globals.h"
16 namespace zyn {
18 class AbsTime
20 public:
21 AbsTime(const SYNTH_T &synth)
22 :frames(0),
23 s(synth){};
24 void operator++(){++frames;};
25 void operator++(int){frames++;};
26 int64_t time() const {return frames;};
27 unsigned int tempo;
28 float dt() const { return s.dt(); }
29 float framesPerSec() const { return 1/s.dt();}
30 int samplesPerFrame() const {return s.buffersize;}
31 private:
32 int64_t frames;
33 const SYNTH_T &s;
37 //Marker for an event relative to some position of the absolute timer
38 class RelTime
40 public:
41 RelTime(const AbsTime &t_, float sec)
42 :t(t_)
44 //Calculate time of event
45 float deltaFrames = sec*t.framesPerSec();
46 int64_t tmp = (int64_t)deltaFrames;
47 frame = t.time() + tmp;
48 sample = (int32_t)(t.samplesPerFrame()*(deltaFrames-tmp));
50 bool inThisFrame() {return t.time() == frame;};
51 bool inPast() {return t.time() > frame;}
52 bool inFuture() {return t.time() < frame;}
53 private:
54 int64_t frame;
55 int32_t sample;
56 const AbsTime &t;