Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.5KB

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