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 1712 of file ProgressDialog.cpp.

1717: ProgressDialog(title, columns, flags, sRemainingLabelText)
1718{
1719 mDuration = duration;
1720}
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.

1460{
1461 return Update((int)(current * 1000), message);
1462}
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.

1540{
1541 if (total != 0)
1542 {
1543 return Update((int)(current * 1000.0 / total), message);
1544 }
1545 else
1546 {
1547 return Update(1000, message);
1548 }
1549}

◆ Update() [3/7]

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

Definition at line 102 of file ProgressDialog.cpp.

1517{
1518 if (total != 0)
1519 {
1520 return Update((int)(current * ((double)(1000.0 / total))), message);
1521 }
1522 else
1523 {
1524 return Update(1000, message);
1525 }
1526}

◆ Update() [4/7]

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

Definition at line 96 of file ProgressDialog.cpp.

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

1485{
1486 if (total.GetValue() != 0)
1487 {
1488 return Update((int)(current.GetValue() * 1000ll / total.GetValue()), message);
1489 }
1490 else
1491 {
1492 return Update(1000, message);
1493 }
1494}

◆ Update() [6/7]

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

Definition at line 101 of file ProgressDialog.cpp.

1501{
1502 if (total != 0)
1503 {
1504 return Update((int)(current * 1000ll / total), message);
1505 }
1506 else
1507 {
1508 return Update(1000, message);
1509 }
1510}

◆ Update() [7/7]

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

Definition at line 99 of file ProgressDialog.cpp.

1469{
1470 if (total != 0)
1471 {
1472 return Update((int)(current * 1000 / total), message);
1473 }
1474 else
1475 {
1476 return Update(1000, message);
1477 }
1478}

◆ UpdateProgress()

ProgressResult TimerProgressDialog::UpdateProgress ( )

Definition at line 1722 of file ProgressDialog.cpp.

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

References BasicUI::Cancelled, ProgressDialog::m_bShowElapsedTime, ProgressDialog::mCancel, mDuration, ProgressDialog::mElapsed, ProgressDialog::mGauge, ProgressDialog::mIsTransparent, ProgressDialog::mLastUpdate, ProgressDialog::mLastValue, ProgressDialog::mRemaining, ProgressDialog::mStartTime, ProgressDialog::mStop, BasicUI::Stopped, 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: