The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

174 lines
7.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. //==============================================================================
  19. /** A relative measure of time.
  20. The time is stored as a number of seconds, at double-precision floating
  21. point accuracy, and may be positive or negative.
  22. If you need an absolute time, (i.e. a date + time), see the Time class.
  23. */
  24. class JUCE_API RelativeTime
  25. {
  26. public:
  27. //==============================================================================
  28. /** Creates a RelativeTime.
  29. @param seconds the number of seconds, which may be +ve or -ve.
  30. @see milliseconds, minutes, hours, days, weeks
  31. */
  32. explicit RelativeTime (double seconds = 0.0) noexcept;
  33. /** Copies another relative time. */
  34. RelativeTime (const RelativeTime& other) noexcept;
  35. /** Copies another relative time. */
  36. RelativeTime& operator= (const RelativeTime& other) noexcept;
  37. /** Destructor. */
  38. ~RelativeTime() noexcept;
  39. //==============================================================================
  40. /** Creates a new RelativeTime object representing a number of milliseconds.
  41. @see seconds, minutes, hours, days, weeks
  42. */
  43. static RelativeTime milliseconds (int milliseconds) noexcept;
  44. /** Creates a new RelativeTime object representing a number of milliseconds.
  45. @see seconds, minutes, hours, days, weeks
  46. */
  47. static RelativeTime milliseconds (int64 milliseconds) noexcept;
  48. /** Creates a new RelativeTime object representing a number of seconds.
  49. @see milliseconds, minutes, hours, days, weeks
  50. */
  51. static RelativeTime seconds (double seconds) noexcept;
  52. /** Creates a new RelativeTime object representing a number of minutes.
  53. @see milliseconds, hours, days, weeks
  54. */
  55. static RelativeTime minutes (double numberOfMinutes) noexcept;
  56. /** Creates a new RelativeTime object representing a number of hours.
  57. @see milliseconds, minutes, days, weeks
  58. */
  59. static RelativeTime hours (double numberOfHours) noexcept;
  60. /** Creates a new RelativeTime object representing a number of days.
  61. @see milliseconds, minutes, hours, weeks
  62. */
  63. static RelativeTime days (double numberOfDays) noexcept;
  64. /** Creates a new RelativeTime object representing a number of weeks.
  65. @see milliseconds, minutes, hours, days
  66. */
  67. static RelativeTime weeks (double numberOfWeeks) noexcept;
  68. //==============================================================================
  69. /** Returns the number of milliseconds this time represents.
  70. @see milliseconds, inSeconds, inMinutes, inHours, inDays, inWeeks
  71. */
  72. int64 inMilliseconds() const noexcept;
  73. /** Returns the number of seconds this time represents.
  74. @see inMilliseconds, inMinutes, inHours, inDays, inWeeks
  75. */
  76. double inSeconds() const noexcept { return numSeconds; }
  77. /** Returns the number of minutes this time represents.
  78. @see inMilliseconds, inSeconds, inHours, inDays, inWeeks
  79. */
  80. double inMinutes() const noexcept;
  81. /** Returns the number of hours this time represents.
  82. @see inMilliseconds, inSeconds, inMinutes, inDays, inWeeks
  83. */
  84. double inHours() const noexcept;
  85. /** Returns the number of days this time represents.
  86. @see inMilliseconds, inSeconds, inMinutes, inHours, inWeeks
  87. */
  88. double inDays() const noexcept;
  89. /** Returns the number of weeks this time represents.
  90. @see inMilliseconds, inSeconds, inMinutes, inHours, inDays
  91. */
  92. double inWeeks() const noexcept;
  93. /** Returns a readable textual description of the time.
  94. The exact format of the string returned will depend on
  95. the magnitude of the time - e.g.
  96. "1 min 4 secs", "1 hr 45 mins", "2 weeks 5 days", "140 ms"
  97. so that only the two most significant units are printed.
  98. The returnValueForZeroTime value is the result that is returned if the
  99. length is zero. Depending on your application you might want to use this
  100. to return something more relevant like "empty" or "0 secs", etc.
  101. @see inMilliseconds, inSeconds, inMinutes, inHours, inDays, inWeeks
  102. */
  103. String getDescription (const String& returnValueForZeroTime = "0") const;
  104. //==============================================================================
  105. /** Adds another RelativeTime to this one. */
  106. RelativeTime operator+= (RelativeTime timeToAdd) noexcept;
  107. /** Subtracts another RelativeTime from this one. */
  108. RelativeTime operator-= (RelativeTime timeToSubtract) noexcept;
  109. /** Adds a number of seconds to this time. */
  110. RelativeTime operator+= (double secondsToAdd) noexcept;
  111. /** Subtracts a number of seconds from this time. */
  112. RelativeTime operator-= (double secondsToSubtract) noexcept;
  113. private:
  114. //==============================================================================
  115. double numSeconds;
  116. };
  117. //==============================================================================
  118. /** Compares two RelativeTimes. */
  119. JUCE_API bool JUCE_CALLTYPE operator== (RelativeTime t1, RelativeTime t2) noexcept;
  120. /** Compares two RelativeTimes. */
  121. JUCE_API bool JUCE_CALLTYPE operator!= (RelativeTime t1, RelativeTime t2) noexcept;
  122. /** Compares two RelativeTimes. */
  123. JUCE_API bool JUCE_CALLTYPE operator> (RelativeTime t1, RelativeTime t2) noexcept;
  124. /** Compares two RelativeTimes. */
  125. JUCE_API bool JUCE_CALLTYPE operator< (RelativeTime t1, RelativeTime t2) noexcept;
  126. /** Compares two RelativeTimes. */
  127. JUCE_API bool JUCE_CALLTYPE operator>= (RelativeTime t1, RelativeTime t2) noexcept;
  128. /** Compares two RelativeTimes. */
  129. JUCE_API bool JUCE_CALLTYPE operator<= (RelativeTime t1, RelativeTime t2) noexcept;
  130. //==============================================================================
  131. /** Adds two RelativeTimes together. */
  132. JUCE_API RelativeTime JUCE_CALLTYPE operator+ (RelativeTime t1, RelativeTime t2) noexcept;
  133. /** Subtracts two RelativeTimes. */
  134. JUCE_API RelativeTime JUCE_CALLTYPE operator- (RelativeTime t1, RelativeTime t2) noexcept;