~ubuntu-branches/ubuntu/gutsy/audacity/gutsy-backports

« back to all changes in this revision

Viewing changes to src/SmartRecordDialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-18 21:58:19 UTC
  • mfrom: (13.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080218215819-tmbcf1rx238r8gdv
Tags: 1.3.4-1.1ubuntu1~gutsy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
   ID_TIMETEXT_DURATION
44
44
};
45
45
 
46
 
const int kTimerInterval = 1000; // every 1000 ms -> 1 update per second   
 
46
const int kTimerInterval = 500; // every 500 ms => 2 updates per second   
47
47
 
48
48
double wxDateTime_to_AudacityTime(wxDateTime& dateTime)
49
49
{
68
68
: wxDialog(parent, -1, _("Audacity Timer Record"), wxDefaultPosition, 
69
69
           wxDefaultSize, wxDIALOG_MODAL | wxCAPTION | wxTHICK_FRAME)
70
70
{
71
 
   m_DateTime_Start = wxDateTime::Now(); 
 
71
   m_DateTime_Start = wxDateTime::UNow(); 
72
72
   m_TimeSpan_Duration = wxTimeSpan::Minutes(5); // default 5 minute duration
73
73
   m_DateTime_End = m_DateTime_Start + m_TimeSpan_Duration;
74
74
 
83
83
   ShuttleGui S(this, eIsCreating);
84
84
   this->PopulateOrExchange(S);
85
85
 
 
86
   // Set initial focus to "0" of "05m" in Duration TimeTextCtrl, instead of OK button (default).
 
87
   m_pTimeTextCtrl_Duration->SetFocus();
 
88
   m_pTimeTextCtrl_Duration->SetFieldFocus(4);
 
89
 
86
90
   m_timer.SetOwner(this, TIMER_ID);
87
 
   m_timer.Start(kTimerInterval);    // 1 second interval
 
91
   m_timer.Start(kTimerInterval); 
88
92
}
89
93
 
90
94
SmartRecordDialog::~SmartRecordDialog()
93
97
 
94
98
void SmartRecordDialog::OnTimer(wxTimerEvent& event)
95
99
{
96
 
   if (m_DateTime_Start < wxDateTime::Now()) {
97
 
      m_DateTime_Start = wxDateTime::Now();
 
100
   wxDateTime dateTime_UNow = wxDateTime::UNow();
 
101
   if (m_DateTime_Start < dateTime_UNow) {
 
102
      m_DateTime_Start = dateTime_UNow;
98
103
      m_pDatePickerCtrl_Start->SetValue(m_DateTime_Start);
99
104
      m_pTimeTextCtrl_Start->SetTimeValue(wxDateTime_to_AudacityTime(m_DateTime_Start));
 
105
      this->UpdateEnd(); // Keep Duration constant and update End for changed Start.
100
106
   }
101
 
 
102
 
   this->UpdateEnd(); // Keep Duration constant and update End for changed Start.
103
107
}
104
108
 
105
109
void SmartRecordDialog::OnDatePicker_Start(wxDateEvent& event)
117
121
   // had a future day, set hour of day less than now's, then changed day to today.
118
122
   wxTimerEvent dummyTimerEvent;
119
123
   this->OnTimer(dummyTimerEvent);
 
124
 
 
125
   // Always update End for changed Start, keeping Duration constant.
 
126
   // Note that OnTimer sometimes calls UpdateEnd, so sometimes this is redundant, 
 
127
   // but OnTimer doesn't need to always call UpdateEnd, but we must here.
 
128
   this->UpdateEnd(); 
120
129
}
121
130
 
122
131
void SmartRecordDialog::OnTimeText_Start(wxCommandEvent& event)
189
198
 
190
199
void SmartRecordDialog::OnOK(wxCommandEvent& event)
191
200
{
192
 
   m_timer.Stop();
 
201
   m_timer.Stop(); // Don't need to keep updating m_DateTime_Start to prevent backdating.
193
202
 
194
203
   this->TransferDataFromWindow();
195
204
 
196
205
   bool bDidCancel = false;
197
 
   if (m_DateTime_Start > wxDateTime::UNow()) bDidCancel = !this->WaitForStart(); 
 
206
   if (m_DateTime_Start > wxDateTime::UNow()) 
 
207
      bDidCancel = !this->WaitForStart(); 
198
208
 
199
 
   if (!bDidCancel) { // Record for specified time. 
200
 
      //v For now, just usual record mechanism.
 
209
   if (!bDidCancel)  
 
210
   {
 
211
      // Record for specified time.
201
212
        AudacityProject* pProject = GetActiveProject();
202
213
      pProject->OnRecord();
203
214
 
209
220
            wxString strNewMsg;
210
221
         */
211
222
      wxString strMsg = 
212
 
         _("Recording start: ") + m_DateTime_Start.Format() + 
213
 
         _("\n\nRecording end:   ") + m_DateTime_End.Format() + 
214
 
         _("          Duration: ") + m_TimeSpan_Duration.Format() + wxT("\n"); 
 
223
         _("Recording start") + (wxString)wxT(":  ")
 
224
                 + m_DateTime_Start.Format() + wxT("\n\n") + _("Recording end")
 
225
                 + wxT(":   ") + m_DateTime_End.Format() + wxT("\t\t")
 
226
                 + _("Duration") + wxT(": ") + m_TimeSpan_Duration.Format() + wxT("\n"); 
215
227
 
216
228
      pProject->ProgressShow(
217
229
               _("Audacity Smart Record Progress"), // const wxString& title,
218
230
               strMsg); // const wxString& message
219
231
 
 
232
      // Make sure that start and end time are updated, so we always get the full 
 
233
      // duration, even if there's some delay getting here.
 
234
      wxTimerEvent dummyTimerEvent;
 
235
      this->OnTimer(dummyTimerEvent);
 
236
 
 
237
      wxDateTime dateTime_UNow;
220
238
      wxTimeSpan done_TimeSpan;
221
239
      wxLongLong llProgValue;
222
240
      int nProgValue = 0;
223
241
      while (bIsRecording && !bDidCancel) {
224
242
         wxMilliSleep(kTimerInterval);
225
 
 
226
 
         done_TimeSpan = wxDateTime::Now() - m_DateTime_Start;
227
 
         // remaining_TimeSpan = m_DateTime_End - wxDateTime::Now();
 
243
         
 
244
         dateTime_UNow = wxDateTime::UNow();
 
245
         done_TimeSpan = dateTime_UNow - m_DateTime_Start;
 
246
         // remaining_TimeSpan = m_DateTime_End - dateTime_UNow;
228
247
 
229
248
         llProgValue = 
230
249
            (wxLongLong)((done_TimeSpan.GetSeconds() * (double)MAX_PROG) / 
233
252
 
234
253
         // strNewMsg = strMsg + _("\nDone: ") + done_TimeSpan.Format() + _("     Remaining: ") + remaining_TimeSpan.Format();
235
254
         bDidCancel = !pProject->ProgressUpdate(nProgValue); // , strNewMsg);
236
 
         bIsRecording = (wxDateTime::UNow() < m_DateTime_End);
 
255
         bIsRecording = (wxDateTime::UNow() <= m_DateTime_End);
237
256
      }
238
257
      pProject->OnStop();
239
258
      pProject->ProgressHide();
295
314
   }
296
315
   S.EndVerticalLay();
297
316
   
298
 
   GetSizer()->Add(CreateStdDialogButtonSizer(wxOK | wxCANCEL),
299
 
                   0,
300
 
                   wxCENTER | wxBOTTOM,
301
 
                   10);
 
317
   S.AddStandardButtons();
302
318
 
303
319
   Layout();
304
320
   Fit();
358
374
bool SmartRecordDialog::WaitForStart()
359
375
{
360
376
   AudacityProject* pProject = GetActiveProject();
361
 
   wxString strMsg = _("Waiting to start recording at ") + m_DateTime_Start.Format() + wxT(".\n"); 
 
377
   wxString strMsg;
 
378
   /* i18n-hint: A time specification like "Sunday 28th October 2007 15:16:17 GMT"
 
379
        * but hopefully translated by wxwidgets will be inserted into this */
 
380
   strMsg.Printf(_("Waiting to start recording at %s.\n"), m_DateTime_Start.Format()); 
362
381
   pProject->ProgressShow(_("Audacity Smart Record - Waiting for Start"),
363
382
                          strMsg);
364
 
   wxDateTime startWait_DateTime = wxDateTime::Now();
 
383
   wxDateTime startWait_DateTime = wxDateTime::UNow();
365
384
   wxTimeSpan waitDuration = m_DateTime_Start - startWait_DateTime;
366
385
 
367
386
   bool bDidCancel = false;
370
389
   wxLongLong llProgValue;
371
390
   int nProgValue = 0;
372
391
   while (!bDidCancel && !bIsRecording) {
373
 
      wxMilliSleep(kTimerInterval);
 
392
      wxMilliSleep(10);
374
393
 
375
 
      done_TimeSpan = wxDateTime::Now() - startWait_DateTime;
 
394
      done_TimeSpan = wxDateTime::UNow() - startWait_DateTime;
376
395
      llProgValue = 
377
396
         (wxLongLong)((done_TimeSpan.GetSeconds() * (double)MAX_PROG) / 
378
397
                        waitDuration.GetSeconds());