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.

179 lines
7.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_RELATIVETIME_JUCEHEADER__
  19. #define __JUCE_RELATIVETIME_JUCEHEADER__
  20. #include "../text/juce_String.h"
  21. //==============================================================================
  22. /** A relative measure of time.
  23. The time is stored as a number of seconds, at double-precision floating
  24. point accuracy, and may be positive or negative.
  25. If you need an absolute time, (i.e. a date + time), see the Time class.
  26. */
  27. class JUCE_API RelativeTime
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates a RelativeTime.
  32. @param seconds the number of seconds, which may be +ve or -ve.
  33. @see milliseconds, minutes, hours, days, weeks
  34. */
  35. explicit RelativeTime (double seconds = 0.0) noexcept;
  36. /** Copies another relative time. */
  37. RelativeTime (const RelativeTime& other) noexcept;
  38. /** Copies another relative time. */
  39. RelativeTime& operator= (const RelativeTime& other) noexcept;
  40. /** Destructor. */
  41. ~RelativeTime() noexcept;
  42. //==============================================================================
  43. /** Creates a new RelativeTime object representing a number of milliseconds.
  44. @see minutes, hours, days, weeks
  45. */
  46. static const RelativeTime milliseconds (int milliseconds) noexcept;
  47. /** Creates a new RelativeTime object representing a number of milliseconds.
  48. @see minutes, hours, days, weeks
  49. */
  50. static const RelativeTime milliseconds (int64 milliseconds) noexcept;
  51. /** Creates a new RelativeTime object representing a number of minutes.
  52. @see milliseconds, hours, days, weeks
  53. */
  54. static const RelativeTime minutes (double numberOfMinutes) noexcept;
  55. /** Creates a new RelativeTime object representing a number of hours.
  56. @see milliseconds, minutes, days, weeks
  57. */
  58. static const RelativeTime hours (double numberOfHours) noexcept;
  59. /** Creates a new RelativeTime object representing a number of days.
  60. @see milliseconds, minutes, hours, weeks
  61. */
  62. static const RelativeTime days (double numberOfDays) noexcept;
  63. /** Creates a new RelativeTime object representing a number of weeks.
  64. @see milliseconds, minutes, hours, days
  65. */
  66. static const RelativeTime weeks (double numberOfWeeks) noexcept;
  67. //==============================================================================
  68. /** Returns the number of milliseconds this time represents.
  69. @see milliseconds, inSeconds, inMinutes, inHours, inDays, inWeeks
  70. */
  71. int64 inMilliseconds() const noexcept;
  72. /** Returns the number of seconds this time represents.
  73. @see inMilliseconds, inMinutes, inHours, inDays, inWeeks
  74. */
  75. double inSeconds() const noexcept { return seconds; }
  76. /** Returns the number of minutes this time represents.
  77. @see inMilliseconds, inSeconds, inHours, inDays, inWeeks
  78. */
  79. double inMinutes() const noexcept;
  80. /** Returns the number of hours this time represents.
  81. @see inMilliseconds, inSeconds, inMinutes, inDays, inWeeks
  82. */
  83. double inHours() const noexcept;
  84. /** Returns the number of days this time represents.
  85. @see inMilliseconds, inSeconds, inMinutes, inHours, inWeeks
  86. */
  87. double inDays() const noexcept;
  88. /** Returns the number of weeks this time represents.
  89. @see inMilliseconds, inSeconds, inMinutes, inHours, inDays
  90. */
  91. double inWeeks() const noexcept;
  92. /** Returns a readable textual description of the time.
  93. The exact format of the string returned will depend on
  94. the magnitude of the time - e.g.
  95. "1 min 4 secs", "1 hr 45 mins", "2 weeks 5 days", "140 ms"
  96. so that only the two most significant units are printed.
  97. The returnValueForZeroTime value is the result that is returned if the
  98. length is zero. Depending on your application you might want to use this
  99. to return something more relevant like "empty" or "0 secs", etc.
  100. @see inMilliseconds, inSeconds, inMinutes, inHours, inDays, inWeeks
  101. */
  102. String getDescription (const String& returnValueForZeroTime = "0") const;
  103. //==============================================================================
  104. /** Adds another RelativeTime to this one. */
  105. const RelativeTime& operator+= (const RelativeTime& timeToAdd) noexcept;
  106. /** Subtracts another RelativeTime from this one. */
  107. const RelativeTime& operator-= (const RelativeTime& timeToSubtract) noexcept;
  108. /** Adds a number of seconds to this time. */
  109. const RelativeTime& operator+= (double secondsToAdd) noexcept;
  110. /** Subtracts a number of seconds from this time. */
  111. const RelativeTime& operator-= (double secondsToSubtract) noexcept;
  112. private:
  113. //==============================================================================
  114. double seconds;
  115. };
  116. //==============================================================================
  117. /** Compares two RelativeTimes. */
  118. bool operator== (const RelativeTime& t1, const RelativeTime& t2) noexcept;
  119. /** Compares two RelativeTimes. */
  120. bool operator!= (const RelativeTime& t1, const RelativeTime& t2) noexcept;
  121. /** Compares two RelativeTimes. */
  122. bool operator> (const RelativeTime& t1, const RelativeTime& t2) noexcept;
  123. /** Compares two RelativeTimes. */
  124. bool operator< (const RelativeTime& t1, const RelativeTime& t2) noexcept;
  125. /** Compares two RelativeTimes. */
  126. bool operator>= (const RelativeTime& t1, const RelativeTime& t2) noexcept;
  127. /** Compares two RelativeTimes. */
  128. bool operator<= (const RelativeTime& t1, const RelativeTime& t2) noexcept;
  129. //==============================================================================
  130. /** Adds two RelativeTimes together. */
  131. RelativeTime operator+ (const RelativeTime& t1, const RelativeTime& t2) noexcept;
  132. /** Subtracts two RelativeTimes. */
  133. RelativeTime operator- (const RelativeTime& t1, const RelativeTime& t2) noexcept;
  134. #endif // __JUCE_RELATIVETIME_JUCEHEADER__