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.

185 lines
7.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  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. namespace juce
  18. {
  19. //==============================================================================
  20. /** A relative measure of time.
  21. The time is stored as a number of seconds, at double-precision floating
  22. point accuracy, and may be positive or negative.
  23. If you need an absolute time, (i.e. a date + time), see the Time class.
  24. @tags{Core}
  25. */
  26. class JUCE_API RelativeTime
  27. {
  28. public:
  29. //==============================================================================
  30. /** Creates a RelativeTime.
  31. @param seconds the number of seconds, which may be +ve or -ve.
  32. @see milliseconds, minutes, hours, days, weeks
  33. */
  34. explicit RelativeTime (double seconds = 0.0) noexcept;
  35. /** Copies another relative time. */
  36. RelativeTime (const RelativeTime& other) noexcept;
  37. /** Copies another relative time. */
  38. RelativeTime& operator= (const RelativeTime& other) noexcept;
  39. /** Destructor. */
  40. ~RelativeTime() noexcept;
  41. //==============================================================================
  42. /** Creates a new RelativeTime object representing a number of milliseconds.
  43. @see seconds, minutes, hours, days, weeks
  44. */
  45. static RelativeTime milliseconds (int milliseconds) noexcept;
  46. /** Creates a new RelativeTime object representing a number of milliseconds.
  47. @see seconds, minutes, hours, days, weeks
  48. */
  49. static RelativeTime milliseconds (int64 milliseconds) noexcept;
  50. /** Creates a new RelativeTime object representing a number of seconds.
  51. @see milliseconds, minutes, hours, days, weeks
  52. */
  53. static RelativeTime seconds (double seconds) noexcept;
  54. /** Creates a new RelativeTime object representing a number of minutes.
  55. @see milliseconds, hours, days, weeks
  56. */
  57. static RelativeTime minutes (double numberOfMinutes) noexcept;
  58. /** Creates a new RelativeTime object representing a number of hours.
  59. @see milliseconds, minutes, days, weeks
  60. */
  61. static RelativeTime hours (double numberOfHours) noexcept;
  62. /** Creates a new RelativeTime object representing a number of days.
  63. @see milliseconds, minutes, hours, weeks
  64. */
  65. static RelativeTime days (double numberOfDays) noexcept;
  66. /** Creates a new RelativeTime object representing a number of weeks.
  67. @see milliseconds, minutes, hours, days
  68. */
  69. static RelativeTime weeks (double numberOfWeeks) noexcept;
  70. //==============================================================================
  71. /** Returns the number of milliseconds this time represents.
  72. @see milliseconds, inSeconds, inMinutes, inHours, inDays, inWeeks
  73. */
  74. int64 inMilliseconds() const noexcept;
  75. /** Returns the number of seconds this time represents.
  76. @see inMilliseconds, inMinutes, inHours, inDays, inWeeks
  77. */
  78. double inSeconds() const noexcept { return numSeconds; }
  79. /** Returns the number of minutes this time represents.
  80. @see inMilliseconds, inSeconds, inHours, inDays, inWeeks
  81. */
  82. double inMinutes() const noexcept;
  83. /** Returns the number of hours this time represents.
  84. @see inMilliseconds, inSeconds, inMinutes, inDays, inWeeks
  85. */
  86. double inHours() const noexcept;
  87. /** Returns the number of days this time represents.
  88. @see inMilliseconds, inSeconds, inMinutes, inHours, inWeeks
  89. */
  90. double inDays() const noexcept;
  91. /** Returns the number of weeks this time represents.
  92. @see inMilliseconds, inSeconds, inMinutes, inHours, inDays
  93. */
  94. double inWeeks() const noexcept;
  95. /** Returns a readable textual description of the time.
  96. The exact format of the string returned will depend on
  97. the magnitude of the time - e.g.
  98. "1 min 4 secs", "1 hr 45 mins", "2 weeks 5 days", "140 ms"
  99. so that only the two most significant units are printed.
  100. The returnValueForZeroTime value is the result that is returned if the
  101. length is zero. Depending on your application you might want to use this
  102. to return something more relevant like "empty" or "0 secs", etc.
  103. @see inMilliseconds, inSeconds, inMinutes, inHours, inDays, inWeeks
  104. */
  105. String getDescription (const String& returnValueForZeroTime = "0") const;
  106. //==============================================================================
  107. /** This returns a string that roughly describes how long ago this time was, which
  108. can be handy for showing ages of files, etc.
  109. This will only attempt to be accurate to within the nearest order of magnitude
  110. so returns strings such as "5 years", "2 weeks", "< 1 minute", "< 1 sec" etc.
  111. */
  112. String getApproximateDescription() const;
  113. //==============================================================================
  114. /** Adds another RelativeTime to this one. */
  115. RelativeTime operator+= (RelativeTime timeToAdd) noexcept;
  116. /** Subtracts another RelativeTime from this one. */
  117. RelativeTime operator-= (RelativeTime timeToSubtract) noexcept;
  118. /** Adds a number of seconds to this time. */
  119. RelativeTime operator+= (double secondsToAdd) noexcept;
  120. /** Subtracts a number of seconds from this time. */
  121. RelativeTime operator-= (double secondsToSubtract) noexcept;
  122. private:
  123. //==============================================================================
  124. double numSeconds;
  125. };
  126. //==============================================================================
  127. /** Compares two RelativeTimes. */
  128. JUCE_API bool JUCE_CALLTYPE operator== (RelativeTime t1, RelativeTime t2) noexcept;
  129. /** Compares two RelativeTimes. */
  130. JUCE_API bool JUCE_CALLTYPE operator!= (RelativeTime t1, RelativeTime t2) noexcept;
  131. /** Compares two RelativeTimes. */
  132. JUCE_API bool JUCE_CALLTYPE operator> (RelativeTime t1, RelativeTime t2) noexcept;
  133. /** Compares two RelativeTimes. */
  134. JUCE_API bool JUCE_CALLTYPE operator< (RelativeTime t1, RelativeTime t2) noexcept;
  135. /** Compares two RelativeTimes. */
  136. JUCE_API bool JUCE_CALLTYPE operator>= (RelativeTime t1, RelativeTime t2) noexcept;
  137. /** Compares two RelativeTimes. */
  138. JUCE_API bool JUCE_CALLTYPE operator<= (RelativeTime t1, RelativeTime t2) noexcept;
  139. //==============================================================================
  140. /** Adds two RelativeTimes together. */
  141. JUCE_API RelativeTime JUCE_CALLTYPE operator+ (RelativeTime t1, RelativeTime t2) noexcept;
  142. /** Subtracts two RelativeTimes. */
  143. JUCE_API RelativeTime JUCE_CALLTYPE operator- (RelativeTime t1, RelativeTime t2) noexcept;
  144. } // namespace juce