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.

116 lines
4.6KB

  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_ASYNCUPDATER_H_INCLUDED
  24. #define JUCE_ASYNCUPDATER_H_INCLUDED
  25. //==============================================================================
  26. /**
  27. Has a callback method that is triggered asynchronously.
  28. This object allows an asynchronous callback function to be triggered, for
  29. tasks such as coalescing multiple updates into a single callback later on.
  30. Basically, one or more calls to the triggerAsyncUpdate() will result in the
  31. message thread calling handleAsyncUpdate() as soon as it can.
  32. */
  33. class JUCE_API AsyncUpdater
  34. {
  35. public:
  36. //==============================================================================
  37. /** Creates an AsyncUpdater object. */
  38. AsyncUpdater();
  39. /** Destructor.
  40. If there are any pending callbacks when the object is deleted, these are lost.
  41. */
  42. virtual ~AsyncUpdater();
  43. //==============================================================================
  44. /** Causes the callback to be triggered at a later time.
  45. This method returns immediately, having made sure that a callback
  46. to the handleAsyncUpdate() method will occur as soon as possible.
  47. If an update callback is already pending but hasn't happened yet, calls
  48. to this method will be ignored.
  49. It's thread-safe to call this method from any number of threads without
  50. needing to worry about locking.
  51. */
  52. void triggerAsyncUpdate();
  53. /** This will stop any pending updates from happening.
  54. If called after triggerAsyncUpdate() and before the handleAsyncUpdate()
  55. callback happens, this will cancel the handleAsyncUpdate() callback.
  56. Note that this method simply cancels the next callback - if a callback is already
  57. in progress on a different thread, this won't block until the callback finishes, so
  58. there's no guarantee that the callback isn't still running when the method returns.
  59. */
  60. void cancelPendingUpdate() noexcept;
  61. /** If an update has been triggered and is pending, this will invoke it
  62. synchronously.
  63. Use this as a kind of "flush" operation - if an update is pending, the
  64. handleAsyncUpdate() method will be called immediately; if no update is
  65. pending, then nothing will be done.
  66. Because this may invoke the callback, this method must only be called on
  67. the main event thread.
  68. */
  69. void handleUpdateNowIfNeeded();
  70. /** Returns true if there's an update callback in the pipeline. */
  71. bool isUpdatePending() const noexcept;
  72. //==============================================================================
  73. /** Called back to do whatever your class needs to do.
  74. This method is called by the message thread at the next convenient time
  75. after the triggerAsyncUpdate() method has been called.
  76. */
  77. virtual void handleAsyncUpdate() = 0;
  78. private:
  79. //==============================================================================
  80. class AsyncUpdaterMessage;
  81. friend class ReferenceCountedObjectPtr<AsyncUpdaterMessage>;
  82. ReferenceCountedObjectPtr<AsyncUpdaterMessage> activeMessage;
  83. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AsyncUpdater)
  84. };
  85. #endif // JUCE_ASYNCUPDATER_H_INCLUDED