Audacity 3.2.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
TimerProgressDialog Class Referencefinal

#include <ProgressDialog.h>

Inheritance diagram for TimerProgressDialog:
[legend]
Collaboration diagram for TimerProgressDialog:
[legend]

Public Member Functions

 TimerProgressDialog (const wxLongLong_t duration, const TranslatableString &title, const MessageTable &columns, int flags=pdlgDefaultFlags, const TranslatableString &sRemainingLabelText={})
 
ProgressResult UpdateProgress ()
 
- Public Member Functions inherited from ProgressDialog
 ProgressDialog ()
 Methods for ProgressDialog. More...
 
 ProgressDialog (const TranslatableString &title, const TranslatableString &message={}, int flags=pdlgDefaultFlags, const TranslatableString &sRemainingLabelText={})
 
virtual ~ProgressDialog ()
 
bool Create (const TranslatableString &title, const TranslatableString &message={}, int flags=pdlgDefaultFlags, const TranslatableString &sRemainingLabelText={})
 
void Reinit () override
 Reset the dialog state. More...
 
void SetDialogTitle (const TranslatableString &title) override
 Change the dialog's title. More...
 
ProgressResult Update (int value, const TranslatableString &message={})
 
ProgressResult Update (double current, const TranslatableString &message={})
 
ProgressResult Update (double current, double total, const TranslatableString &message={})
 
ProgressResult Update (wxULongLong_t current, wxULongLong_t total, const TranslatableString &message={})
 
ProgressResult Update (wxLongLong current, wxLongLong total, const TranslatableString &message={})
 
ProgressResult Update (wxLongLong_t current, wxLongLong_t total, const TranslatableString &message={})
 
ProgressResult Update (int current, int total, const TranslatableString &message={})
 
ProgressResult Poll (unsigned long long numerator, unsigned long long denominator, const TranslatableString &message={}) override
 Update the bar and poll for clicks. Call only on the main thread. More...
 
void SetMessage (const TranslatableString &message) override
 Change an existing dialog's message. More...
 
- Public Member Functions inherited from wxDialogWrapper
 wxDialogWrapper ()
 
 wxDialogWrapper (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
bool Create (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
void SetTitle (const TranslatableString &title)
 
void SetLabel (const TranslatableString &title)
 
void SetName (const TranslatableString &title)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxDialog >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 
virtual ~ProgressDialog ()
 
virtual ProgressResult Poll (unsigned long long numerator, unsigned long long denominator, const TranslatableString &message={})=0
 Update the bar and poll for clicks. Call only on the main thread. More...
 
virtual void SetMessage (const TranslatableString &message)=0
 Change an existing dialog's message. More...
 
virtual void SetDialogTitle (const TranslatableString &title)=0
 Change the dialog's title. More...
 
virtual void Reinit ()=0
 Reset the dialog state. More...
 

Protected Member Functions

ProgressResult Update (int value, const TranslatableString &message={})
 
ProgressResult Update (double current, const TranslatableString &message={})
 
ProgressResult Update (double current, double total, const TranslatableString &message={})
 
ProgressResult Update (wxULongLong_t current, wxULongLong_t total, const TranslatableString &message={})
 
ProgressResult Update (wxLongLong current, wxLongLong total, const TranslatableString &message={})
 
ProgressResult Update (wxLongLong_t current, wxLongLong_t total, const TranslatableString &message={})
 
ProgressResult Update (int current, int total, const TranslatableString &message={})
 
- Protected Member Functions inherited from ProgressDialog
 ProgressDialog (const TranslatableString &title, const MessageTable &columns, int flags=pdlgDefaultFlags, const TranslatableString &sRemainingLabelText={})
 
bool Create (const TranslatableString &title, const MessageTable &columns, int flags=pdlgDefaultFlags, const TranslatableString &sRemainingLabelText={})
 

Protected Attributes

wxLongLong_t mDuration
 
- Protected Attributes inherited from ProgressDialog
wxWindowRef mHadFocus
 
wxStaticText * mElapsed
 
wxStaticText * mRemaining
 
wxGauge * mGauge
 
wxLongLong_t mStartTime
 
wxLongLong_t mLastUpdate
 
wxLongLong_t mYieldTimer
 
wxLongLong_t mElapsedTime {}
 
int mLastValue
 
bool mCancel
 
bool mStop
 
bool mIsTransparent
 
bool m_bShowElapsedTime = true
 
bool m_bConfirmAction = false
 

Additional Inherited Members

- Public Types inherited from ProgressDialog
using MessageColumn = std::vector< TranslatableString >
 
using MessageTable = std::vector< MessageColumn >
 

Detailed Description

Definition at line 165 of file ProgressDialog.h.

Constructor & Destructor Documentation

◆ TimerProgressDialog()

TimerProgressDialog::TimerProgressDialog ( const wxLongLong_t  duration,
const TranslatableString title,
const MessageTable columns,
int  flags = pdlgDefaultFlags,
const TranslatableString sRemainingLabelText = {} 
)

Definition at line 1701 of file ProgressDialog.cpp.

1706: ProgressDialog(title, columns, flags, sRemainingLabelText)
1707{
1708 mDuration = duration;
1709}
static const auto title
ProgressDialog()
Methods for ProgressDialog.
wxLongLong_t mDuration

References mDuration.

Member Function Documentation

◆ Update() [1/7]

ProgressResult ProgressDialog::Update ( double  current,
const TranslatableString message = {} 
)
protected

Definition at line 97 of file ProgressDialog.cpp.

1455{
1456 return Update((int)(current * 1000), message);
1457}
ProgressResult Update(int value, const TranslatableString &message={})

◆ Update() [2/7]

ProgressResult ProgressDialog::Update ( double  current,
double  total,
const TranslatableString message = {} 
)
protected

Definition at line 98 of file ProgressDialog.cpp.

1535{
1536 if (total != 0)
1537 {
1538 return Update((int)(current * 1000.0 / total), message);
1539 }
1540 else
1541 {
1542 return Update(1000, message);
1543 }
1544}

◆ Update() [3/7]

ProgressResult ProgressDialog::Update ( int  current,
int  total,
const TranslatableString message = {} 
)
protected

Definition at line 102 of file ProgressDialog.cpp.

1512{
1513 if (total != 0)
1514 {
1515 return Update((int)(current * ((double)(1000.0 / total))), message);
1516 }
1517 else
1518 {
1519 return Update(1000, message);
1520 }
1521}

◆ Update() [4/7]

ProgressResult ProgressDialog::Update ( int  value,
const TranslatableString message = {} 
)
protected

Definition at line 96 of file ProgressDialog.cpp.

1351{
1352 using namespace std::chrono;
1353 auto updatePollTime = finally([this, pollStart = high_resolution_clock::now()] {
1354 mTotalPollTime += high_resolution_clock::now() - pollStart;
1355 });
1356
1357 mPollsCount++;
1358
1359 if (mCancel)
1360 {
1361 // for compatibility with old Update, that returned false on cancel
1363 }
1364 else if (mStop)
1365 {
1366 return ProgressResult::Stopped;
1367 }
1368
1369 wxLongLong_t now = wxGetUTCTimeMillis().GetValue();
1370 mElapsedTime = now - mStartTime;
1371
1372 if (mElapsedTime < 500)
1373 {
1375 }
1376
1377 if (mIsTransparent)
1378 {
1379 SetTransparent(255);
1380 mIsTransparent = false;
1381 }
1382
1383 if (value <= 0)
1384 {
1385 value = 1;
1386 }
1387
1388 if (value > 1000)
1389 {
1390 value = 1000;
1391 }
1392
1393 wxLongLong_t estimate = mElapsedTime * 1000ll / value;
1394 wxLongLong_t remains = (estimate + mStartTime) - now;
1395
1396 SetMessage(message);
1397
1398 if (value != mLastValue)
1399 {
1400 mGauge->SetValue(value);
1401 mGauge->Update();
1402 mLastValue = value;
1403 }
1404
1405 // Only update if a full second has passed or track progress is complete
1406 if ((now - mLastUpdate > 1000) || (value == 1000))
1407 {
1408 if (m_bShowElapsedTime) {
1409 wxTimeSpan tsElapsed(0, 0, 0, mElapsedTime);
1410 mElapsed->SetLabel(tsElapsed.Format(wxT("%H:%M:%S")));
1411 mElapsed->SetName(mElapsed->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1412 mElapsed->Update();
1413 }
1414
1415 wxTimeSpan tsRemains(0, 0, 0, remains);
1416 mRemaining->SetLabel(tsRemains.Format(wxT("%H:%M:%S")));
1417 mRemaining->SetName(mRemaining->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1418 mRemaining->Update();
1419
1420 mLastUpdate = now;
1421 }
1422
1423 wxDialogWrapper::Update();
1424
1425 // Copied from wx 3.0.2 generic progress dialog
1426 //
1427 // we have to yield because not only we want to update the display but
1428 // also to process the clicks on the cancel and skip buttons
1429 // NOTE: using YieldFor() this call shouldn't give re-entrancy problems
1430 // for event handlers not interested to UI/user-input events.
1431 //
1432 // LL: Added timer category to prevent extreme delays when processing effects
1433 // (and probably other things). I do not yet know why this happens and
1434 // I'm not too keen on having timer events processed here, but you do
1435 // what you have to do.
1436
1437 // Nyquist effects call Update on every callback, but YieldFor is
1438 // quite slow on Linux / Mac, so don't call too frequently. (bug 1575)
1439 if ((now - mYieldTimer > 50) || (value == 1000)) {
1440 const auto yieldStart = high_resolution_clock::now();
1441 mYieldsCount++;
1442 wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI | wxEVT_CATEGORY_USER_INPUT | wxEVT_CATEGORY_TIMER);
1443 mTotalYieldTime += high_resolution_clock::now() - yieldStart;
1444 mYieldTimer = now;
1445 }
1446
1448}
wxT("CloseDown"))
wxStaticText * mElapsed
wxGauge * mGauge
std::chrono::nanoseconds mTotalPollTime
wxStaticText * mRemaining
wxLongLong_t mElapsedTime
wxLongLong_t mStartTime
wxLongLong_t mLastUpdate
wxLongLong_t mYieldTimer
std::chrono::nanoseconds mTotalYieldTime
unsigned mPollsCount
unsigned mYieldsCount
void SetMessage(const TranslatableString &message) override
Change an existing dialog's message.

◆ Update() [5/7]

ProgressResult ProgressDialog::Update ( wxLongLong  current,
wxLongLong  total,
const TranslatableString message = {} 
)
protected

Definition at line 100 of file ProgressDialog.cpp.

1480{
1481 if (total.GetValue() != 0)
1482 {
1483 return Update((int)(current.GetValue() * 1000ll / total.GetValue()), message);
1484 }
1485 else
1486 {
1487 return Update(1000, message);
1488 }
1489}

◆ Update() [6/7]

ProgressResult ProgressDialog::Update ( wxLongLong_t  current,
wxLongLong_t  total,
const TranslatableString message = {} 
)
protected

Definition at line 101 of file ProgressDialog.cpp.

1496{
1497 if (total != 0)
1498 {
1499 return Update((int)(current * 1000ll / total), message);
1500 }
1501 else
1502 {
1503 return Update(1000, message);
1504 }
1505}

◆ Update() [7/7]

ProgressResult ProgressDialog::Update ( wxULongLong_t  current,
wxULongLong_t  total,
const TranslatableString message = {} 
)
protected

Definition at line 99 of file ProgressDialog.cpp.

1464{
1465 if (total != 0)
1466 {
1467 return Update((int)(current * 1000 / total), message);
1468 }
1469 else
1470 {
1471 return Update(1000, message);
1472 }
1473}

◆ UpdateProgress()

ProgressResult TimerProgressDialog::UpdateProgress ( )

Definition at line 1711 of file ProgressDialog.cpp.

1712{
1713 if (mCancel)
1714 {
1715 // for compatibility with old Update, that returned false on cancel
1717 }
1718 else if (mStop)
1719 {
1720 return ProgressResult::Stopped;
1721 }
1722
1723 wxLongLong_t now = wxGetUTCTimeMillis().GetValue();
1724 wxLongLong_t elapsed = now - mStartTime;
1725
1726 if (elapsed < 500)
1727 {
1729 }
1730
1731 if (mIsTransparent)
1732 {
1733 SetTransparent(255);
1734 mIsTransparent = false;
1735 }
1736
1737 wxLongLong_t remains = mStartTime + mDuration - now;
1738
1739 int nGaugeValue = (1000 * elapsed) / mDuration; // range = [0,1000]
1740 // Running in TimerRecordDialog::RunWaitDialog(), for some unknown reason,
1741 // nGaugeValue here is often a little over 1000.
1742 // From testing, it's never shown bigger than 1009, but
1743 // give it a little extra, to 1010.
1744 // wxASSERT((nGaugeValue >= 0) && (nGaugeValue <= 1000)); // This ought to work.
1745 // wxASSERT((nGaugeValue >= 0) && (nGaugeValue <= 1010));
1746 //
1747 // stf. Update was being called after wxMilliSleep(<ms>), which could be up to <ms>
1748 // beyond the completion time. My guess is that the microsleep in RunWaitDialog was originally 10 ms
1749 // (same as other uses of Update) but was updated to kTimerInterval = 50 ms, thus triggering
1750 // the Assert (Bug 1367). By calling Update() before sleeping then I think nGaugeValue <= 1000 should work.
1751 wxASSERT((nGaugeValue >= 0) && (nGaugeValue <= 1000));
1752
1753 if (nGaugeValue != mLastValue)
1754 {
1755 mGauge->SetValue(nGaugeValue);
1756 mGauge->Update();
1757 mLastValue = nGaugeValue;
1758 }
1759
1760 // Only update if a full second has passed.
1761 if (now - mLastUpdate > 1000)
1762 {
1763 // Bug 1952:
1764 // wxTimeSpan will assert on ridiculously large values.
1765 // We silently wrap the displayed range at one day.
1766 // You'll only see the remaining hours, mins and secs.
1767 // With a + sign, if the time was wrapped.
1768 const wxLongLong_t wrapTime = 24 * 60 * 60 * 1000;
1769 if (m_bShowElapsedTime) {
1770 wxTimeSpan tsElapsed(0, 0, 0, elapsed % wrapTime);
1771 mElapsed->SetLabel(tsElapsed.Format(wxT("%H:%M:%S")) + ((elapsed >= wrapTime) ? " +":""));
1772 mElapsed->Update();
1773 }
1774
1775 wxTimeSpan tsRemains(0, 0, 0, remains % wrapTime);
1776 mRemaining->SetLabel(tsRemains.Format(wxT("%H:%M:%S")) + ((remains >= wrapTime) ? " +":""));
1777 mRemaining->Update();
1778
1779 mLastUpdate = now;
1780 }
1781
1782 // Copied from wx 3.0.2 generic progress dialog
1783 //
1784 // we have to yield because not only we want to update the display but
1785 // also to process the clicks on the cancel and skip buttons
1786 // NOTE: using YieldFor() this call shouldn't give re-entrancy problems
1787 // for event handlers not interested to UI/user-input events.
1788 //
1789 // LL: Added timer category to prevent extreme delays when processing effects
1790 // (and probably other things). I do not yet know why this happens and
1791 // I'm not too keen on having timer events processed here, but you do
1792 // what you have to do.
1793 // JKC: Added thread category, since blocking a thread message could cause things
1794 // to gum up.
1795 // See http://trac.wxwidgets.org/ticket/14027 for discussion of why
1796 // YieldFor is flaky.
1797 // Conclusion... use wxEVT_CATEGORY_ALL since with the list below, we
1798 // are pretty much there already.
1799 // wxEVT_CATEGORY_UI |
1800 // wxEVT_CATEGORY_USER_INPUT |
1801 // wxEVT_CATEGORY_TIMER |
1802 // wxEVT_CATEGORY_THREAD
1803
1804 wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_ALL );
1805 // JKC: Yielding twice, because e.g. a timer can build up a lot of events, and we
1806 // really want to make sure they are worked through.
1807 wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_ALL );
1808
1809 // MY: Added this after the YieldFor to check we haven't changed the outcome based on buttons pressed...
1810 auto iReturn = ProgressResult::Success;
1811 if (mCancel)
1812 {
1813 iReturn = ProgressResult::Cancelled;
1814 }
1815 else if (mStop)
1816 {
1817 iReturn = ProgressResult::Stopped;
1818 }
1819 return iReturn;
1820}

References RefreshCode::Cancelled, ProgressDialog::m_bShowElapsedTime, ProgressDialog::mCancel, mDuration, ProgressDialog::mElapsed, ProgressDialog::mGauge, ProgressDialog::mIsTransparent, ProgressDialog::mLastUpdate, ProgressDialog::mLastValue, ProgressDialog::mRemaining, ProgressDialog::mStartTime, ProgressDialog::mStop, BasicUI::Success, and wxT().

Referenced by TimerRecordDialog::PreActionDelay(), TimerRecordDialog::RunWaitDialog(), and TimerRecordDialog::WaitForStart().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mDuration

wxLongLong_t TimerProgressDialog::mDuration
protected

Definition at line 179 of file ProgressDialog.h.

Referenced by TimerProgressDialog(), and UpdateProgress().


The documentation for this class was generated from the following files: