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.

117 lines
4.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the Water library.
  4. Copyright (c) 2016 ROLI Ltd.
  5. Copyright (C) 2017 Filipe Coelho <falktx@falktx.com>
  6. Permission is granted to use this software under the terms of the ISC license
  7. http://www.isc.org/downloads/software-support-policy/isc-license/
  8. Permission to use, copy, modify, and/or distribute this software for any
  9. purpose with or without fee is hereby granted, provided that the above
  10. copyright notice and this permission notice appear in all copies.
  11. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  12. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  13. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  14. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  15. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  17. OF THIS SOFTWARE.
  18. ==============================================================================
  19. */
  20. #ifndef WATER_TIME_H_INCLUDED
  21. #define WATER_TIME_H_INCLUDED
  22. #include "../water.h"
  23. namespace water {
  24. //==============================================================================
  25. /**
  26. Holds an absolute date and time.
  27. Internally, the time is stored at millisecond precision.
  28. @see RelativeTime
  29. */
  30. class Time
  31. {
  32. public:
  33. //==============================================================================
  34. /** Creates a Time object.
  35. This default constructor creates a time of midnight Jan 1st 1970 UTC, (which is
  36. represented internally as 0ms).
  37. To create a time object representing the current time, use getCurrentTime().
  38. @see getCurrentTime
  39. */
  40. Time() noexcept;
  41. /** Creates a time based on a number of milliseconds.
  42. To create a time object set to the current time, use getCurrentTime().
  43. @param millisecondsSinceEpoch the number of milliseconds since the unix
  44. 'epoch' (midnight Jan 1st 1970 UTC).
  45. @see getCurrentTime, currentTimeMillis
  46. */
  47. explicit Time (int64 millisecondsSinceEpoch) noexcept;
  48. /** Creates a copy of another Time object. */
  49. Time (const Time& other) noexcept;
  50. /** Destructor. */
  51. ~Time() noexcept;
  52. /** Copies this time from another one. */
  53. Time& operator= (const Time& other) noexcept;
  54. //==============================================================================
  55. /** Returns a Time object that is set to the current system time.
  56. This may not be monotonic, as the system time can change at any moment.
  57. You should therefore not use this method for measuring time intervals.
  58. @see currentTimeMillis
  59. */
  60. static Time getCurrentTime() noexcept;
  61. //==============================================================================
  62. // Static methods for getting system timers directly..
  63. /** Returns the current system time.
  64. Returns the number of milliseconds since midnight Jan 1st 1970 UTC.
  65. Should be accurate to within a few millisecs, depending on platform,
  66. hardware, etc.
  67. */
  68. static int64 currentTimeMillis() noexcept;
  69. /** Returns the number of millisecs since a fixed event (usually system startup).
  70. This returns a monotonically increasing value which it unaffected by changes to the
  71. system clock. It should be accurate to within a few millisecs, depending on platform,
  72. hardware, etc.
  73. Being a 32-bit return value, it will of course wrap back to 0 after 2^32 seconds of
  74. uptime, so be careful to take that into account. If you need a 64-bit time, you can
  75. use currentTimeMillis() instead.
  76. */
  77. static uint32 getMillisecondCounter() noexcept;
  78. private:
  79. //==============================================================================
  80. int64 millisSinceEpoch;
  81. };
  82. }
  83. #endif // WATER_TIME_H_INCLUDED