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.

103 lines
3.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  18. const bool hasProgressBar,
  19. const bool hasCancelButton,
  20. const int timeOutMsWhenCancelling_,
  21. const String& cancelButtonText,
  22. Component* componentToCentreAround)
  23. : Thread ("Juce Progress Window"),
  24. progress (0.0),
  25. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  26. {
  27. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  28. .createAlertWindow (title, String(),
  29. cancelButtonText.isEmpty() ? TRANS("Cancel")
  30. : cancelButtonText,
  31. String(), String(),
  32. AlertWindow::NoIcon, hasCancelButton ? 1 : 0,
  33. componentToCentreAround);
  34. // if there are no buttons, we won't allow the user to interrupt the thread.
  35. alertWindow->setEscapeKeyCancels (false);
  36. if (hasProgressBar)
  37. alertWindow->addProgressBarComponent (progress);
  38. }
  39. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  40. {
  41. stopThread (timeOutMsWhenCancelling);
  42. }
  43. #if JUCE_MODAL_LOOPS_PERMITTED
  44. bool ThreadWithProgressWindow::runThread (const int priority)
  45. {
  46. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  47. startThread (priority);
  48. startTimer (100);
  49. {
  50. const ScopedLock sl (messageLock);
  51. alertWindow->setMessage (message);
  52. }
  53. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  54. stopThread (timeOutMsWhenCancelling);
  55. alertWindow->setVisible (false);
  56. return finishedNaturally;
  57. }
  58. #endif
  59. void ThreadWithProgressWindow::setProgress (const double newProgress)
  60. {
  61. progress = newProgress;
  62. }
  63. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  64. {
  65. const ScopedLock sl (messageLock);
  66. message = newStatusMessage;
  67. }
  68. void ThreadWithProgressWindow::timerCallback()
  69. {
  70. if (! isThreadRunning())
  71. {
  72. // thread has finished normally..
  73. alertWindow->exitModalState (1);
  74. alertWindow->setVisible (false);
  75. }
  76. else
  77. {
  78. const ScopedLock sl (messageLock);
  79. alertWindow->setMessage (message);
  80. }
  81. }