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.

133 lines
5.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_MULTITIMER_H_INCLUDED
  24. #define JUCE_MULTITIMER_H_INCLUDED
  25. //==============================================================================
  26. /**
  27. A type of timer class that can run multiple timers with different frequencies,
  28. all of which share a single callback.
  29. This class is very similar to the Timer class, but allows you run multiple
  30. separate timers, where each one has a unique ID number. The methods in this
  31. class are exactly equivalent to those in Timer, but with the addition of
  32. this ID number.
  33. To use it, you need to create a subclass of MultiTimer, implementing the
  34. timerCallback() method. Then you can start timers with startTimer(), and
  35. each time the callback is triggered, it passes in the ID of the timer that
  36. caused it.
  37. @see Timer
  38. */
  39. class JUCE_API MultiTimer
  40. {
  41. protected:
  42. //==============================================================================
  43. /** Creates a MultiTimer.
  44. When created, no timers are running, so use startTimer() to start things off.
  45. */
  46. MultiTimer() noexcept;
  47. /** Creates a copy of another timer.
  48. Note that this timer will not contain any running timers, even if the one you're
  49. copying from was running.
  50. */
  51. MultiTimer (const MultiTimer&) noexcept;
  52. public:
  53. //==============================================================================
  54. /** Destructor. */
  55. virtual ~MultiTimer();
  56. //==============================================================================
  57. /** The user-defined callback routine that actually gets called by each of the
  58. timers that are running.
  59. It's perfectly ok to call startTimer() or stopTimer() from within this
  60. callback to change the subsequent intervals.
  61. */
  62. virtual void timerCallback (int timerID) = 0;
  63. //==============================================================================
  64. /** Starts a timer and sets the length of interval required.
  65. If the timer is already started, this will reset it, so the
  66. time between calling this method and the next timer callback
  67. will not be less than the interval length passed in.
  68. @param timerID a unique Id number that identifies the timer to
  69. start. This is the id that will be passed back
  70. to the timerCallback() method when this timer is
  71. triggered
  72. @param intervalInMilliseconds the interval to use (any values less than 1 will be
  73. rounded up to 1)
  74. */
  75. void startTimer (int timerID, int intervalInMilliseconds) noexcept;
  76. /** Stops a timer.
  77. If a timer has been started with the given ID number, it will be cancelled.
  78. No more callbacks will be made for the specified timer after this method returns.
  79. If this is called from a different thread, any callbacks that may
  80. be currently executing may be allowed to finish before the method
  81. returns.
  82. */
  83. void stopTimer (int timerID) noexcept;
  84. //==============================================================================
  85. /** Checks whether a timer has been started for a specified ID.
  86. @returns true if a timer with the given ID is running.
  87. */
  88. bool isTimerRunning (int timerID) const noexcept;
  89. /** Returns the interval for a specified timer ID.
  90. @returns the timer's interval in milliseconds if it's running, or 0 if no
  91. timer was running for the ID number specified.
  92. */
  93. int getTimerInterval (int timerID) const noexcept;
  94. //==============================================================================
  95. private:
  96. SpinLock timerListLock;
  97. OwnedArray<Timer> timers;
  98. Timer* getCallback (int) const noexcept;
  99. MultiTimer& operator= (const MultiTimer&);
  100. };
  101. #endif // JUCE_MULTITIMER_H_INCLUDED