JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_ThreadWithProgressWindow.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
30 const bool hasProgressBar,
31 const bool hasCancelButton,
32 const int cancellingTimeOutMs,
34 Component* componentToCentreAround)
35 : Thread ("ThreadWithProgressWindow"),
36 progress (0.0),
37 timeOutMsWhenCancelling (cancellingTimeOutMs),
38 wasCancelledByUser (false)
39{
40 alertWindow.reset (LookAndFeel::getDefaultLookAndFeel()
41 .createAlertWindow (title, {},
42 cancelButtonText.isEmpty() ? TRANS ("Cancel")
45 componentToCentreAround));
46
47 // if there are no buttons, we won't allow the user to interrupt the thread.
48 alertWindow->setEscapeKeyCancels (false);
49
51 alertWindow->addProgressBarComponent (progress);
52}
53
58
60{
62
64 startTimer (100);
65
66 {
67 const ScopedLock sl (messageLock);
68 alertWindow->setMessage (message);
69 }
70
71 alertWindow->enterModalState();
72}
73
75{
76 progress = newProgress;
77}
78
80{
81 const ScopedLock sl (messageLock);
82 message = newStatusMessage;
83}
84
85void ThreadWithProgressWindow::timerCallback()
86{
88
89 if (! (threadStillRunning && alertWindow->isCurrentlyModal (false)))
90 {
91 stopTimer();
92 stopThread (timeOutMsWhenCancelling);
93 alertWindow->exitModalState (1);
94 alertWindow->setVisible (false);
95
96 wasCancelledByUser = threadStillRunning;
98 return; // (this may be deleted now)
99 }
100
101 const ScopedLock sl (messageLock);
102 alertWindow->setMessage (message);
103}
104
106
107#if JUCE_MODAL_LOOPS_PERMITTED
108bool ThreadWithProgressWindow::runThread (Priority threadPriority)
109{
111
112 while (isTimerRunning())
113 MessageManager::getInstance()->runDispatchLoopUntil (5);
114
115 return ! wasCancelledByUser;
116}
117#endif
118
119} // namespace juce
The base class for all JUCE user-interface objects.
Automatically locks and unlocks a mutex object.
static LookAndFeel & getDefaultLookAndFeel() noexcept
Returns the current default look-and-feel for a component to use when it hasn't got one explicitly se...
static MessageManager * getInstance()
Returns the global instance of the MessageManager.
The JUCE String class!
Definition juce_String.h:53
bool isEmpty() const noexcept
Returns true if the string contains no characters.
void setStatusMessage(const String &newStatusMessage)
The thread can call this to change the message that's displayed in the dialog box.
void launchThread(Priority priority=Priority::normal)
Starts the thread and returns.
ThreadWithProgressWindow(const String &windowTitle, bool hasProgressBar, bool hasCancelButton, int timeOutMsWhenCancelling=10000, const String &cancelButtonText=String(), Component *componentToCentreAround=nullptr)
Creates the thread.
void setProgress(double newProgress)
The thread should call this periodically to update the position of the progress bar.
virtual void threadComplete(bool userPressedCancel)
This method is called (on the message thread) when the operation has finished.
Encapsulates a thread.
Definition juce_Thread.h:43
bool startThread()
Attempts to start a new thread with default ('Priority::normal') priority.
bool stopThread(int timeOutMilliseconds)
Attempts to stop the thread running.
Priority
The different runtime priorities of non-realtime threads.
Definition juce_Thread.h:54
bool isThreadRunning() const
Returns true if the thread is currently active.
void stopTimer() noexcept
Stops the timer.
bool isTimerRunning() const noexcept
Returns true if the timer is currently running.
Definition juce_Timer.h:111
void startTimer(int intervalInMilliseconds) noexcept
Starts the timer and sets the length of interval required.
#define TRANS(stringLiteral)
Uses the LocalisedStrings class to translate the given string literal.
#define JUCE_ASSERT_MESSAGE_THREAD
This macro is used to catch unsafe use of functions which expect to only be called on the message thr...
JUCE Namespace.
CriticalSection::ScopedLockType ScopedLock
Automatically locks and unlocks a CriticalSection object.
@ NoIcon
No icon will be shown on the dialog box.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88