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.

Time.h 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. namespace zyncarla {
  14. class AbsTime
  15. {
  16. public:
  17. AbsTime(const SYNTH_T &synth)
  18. :frames(0),
  19. s(synth){};
  20. void operator++(){++frames;};
  21. void operator++(int){frames++;};
  22. int64_t time() const {return frames;};
  23. float dt() const { return s.dt(); }
  24. float framesPerSec() const { return 1/s.dt();}
  25. int samplesPerFrame() const {return s.buffersize;}
  26. private:
  27. int64_t frames;
  28. const SYNTH_T &s;
  29. };
  30. //Marker for an event relative to some position of the absolute timer
  31. class RelTime
  32. {
  33. public:
  34. RelTime(const AbsTime &t_, float sec)
  35. :t(t_)
  36. {
  37. //Calculate time of event
  38. double deltaFrames = sec*t.framesPerSec();
  39. int64_t tmp = (int64_t)deltaFrames;
  40. frame = t.time() + tmp;
  41. sample = t.samplesPerFrame()*(deltaFrames-tmp);
  42. }
  43. bool inThisFrame() {return t.time() == frame;};
  44. bool inPast() {return t.time() > frame;}
  45. bool inFuture() {return t.time() < frame;}
  46. private:
  47. int64_t frame;
  48. int32_t sample;
  49. const AbsTime &t;
  50. };
  51. }