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.

187 lines
7.4KB

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