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

« back to all changes in this revision

Viewing changes to src/effects/Effect.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:
120
120
Effect::Effect()
121
121
{
122
122
   mWaveTracks = NULL;
 
123
   m_pOutputWaveTracks = NULL;
 
124
 
123
125
   // Can change effect flags later (this is the new way)
124
126
   // OR using the old way, over-ride GetEffectFlags().
125
127
   mFlags = BUILTIN_EFFECT | PROCESS_EFFECT | ADVANCED_EFFECT ;
138
140
      mWaveTracks = NULL;
139
141
   }
140
142
 
 
143
   if (m_pOutputWaveTracks) {
 
144
      delete m_pOutputWaveTracks;
 
145
      m_pOutputWaveTracks = NULL;
 
146
   }
 
147
 
141
148
   mFactory = factory;
142
149
   mProjectRate = projectRate;
143
150
   mParent = parent;
170
177
   End();
171
178
 
172
179
   delete mWaveTracks;
 
180
   if (m_pOutputWaveTracks != mWaveTracks) // If processing completed successfully, they should be the same.
 
181
      delete m_pOutputWaveTracks;
173
182
   mWaveTracks = NULL;
 
183
   m_pOutputWaveTracks = NULL;
174
184
 
175
185
   if (returnVal) {
176
186
      *t0 = mT0;
195
205
   return TotalProgress((whichGroup+frac)/mNumGroups);
196
206
}
197
207
 
 
208
//
 
209
// private methods
 
210
//
 
211
// Use these two methods to copy the input tracks to m_pOutputWaveTracks, if 
 
212
// doing the processing on them, and replacing the originals only on success (and not cancel).
 
213
void Effect::CopyInputWaveTracks()
 
214
{
 
215
   if (this->GetNumWaveTracks() <= 0)
 
216
      return;
 
217
 
 
218
   // Copy the mWaveTracks, to process the copies.
 
219
   TrackListIterator iterIn(mWaveTracks);
 
220
   WaveTrack* pInWaveTrack = (WaveTrack*)(iterIn.First());
 
221
   m_pOutputWaveTracks = new TrackList();
 
222
   WaveTrack* pOutWaveTrack = NULL;
 
223
   while (pInWaveTrack != NULL)
 
224
   {
 
225
      pOutWaveTrack = mFactory->DuplicateWaveTrack(*(WaveTrack*)pInWaveTrack);
 
226
      m_pOutputWaveTracks->Add(pOutWaveTrack);
 
227
      pInWaveTrack = (WaveTrack*)(iterIn.Next());
 
228
   }
 
229
}
 
230
 
 
231
 
 
232
// If bGoodResult, replace mWaveTracks tracks in mTracks with successfully processed 
 
233
// m_pOutputWaveTracks copies, get rid of old mWaveTracks, and set mWaveTracks to m_pOutputWaveTracks. 
 
234
// Else clear and delete m_pOutputWaveTracks copies.
 
235
void Effect::ReplaceProcessedWaveTracks(const bool bGoodResult)
 
236
{
 
237
   if (bGoodResult)
 
238
   {
 
239
      // Circular replacement of the input wave tracks with the processed m_pOutputWaveTracks tracks. 
 
240
      // But mWaveTracks is temporary, so replace in mTracks. More bookkeeping.
 
241
      TrackListIterator iterIn(mWaveTracks);
 
242
      WaveTrack* pInWaveTrack = (WaveTrack*)(iterIn.First());
 
243
 
 
244
      wxASSERT(m_pOutputWaveTracks != NULL); // Make sure we at least did the CopyInputWaveTracks().
 
245
      TrackListIterator iterOut(m_pOutputWaveTracks);
 
246
      WaveTrack* pOutWaveTrack = (WaveTrack*)(iterOut.First());
 
247
 
 
248
      TrackListIterator iterAllTracks(mTracks);
 
249
      Track* pFirstTrack = iterAllTracks.First();
 
250
      Track* pTrack = pFirstTrack;
 
251
      do
 
252
      {
 
253
         if (pTrack == pInWaveTrack)
 
254
         {
 
255
            // Replace pInWaveTrack with processed pOutWaveTrack, at end of list.
 
256
            mTracks->Add(pOutWaveTrack);
 
257
            delete pInWaveTrack;
 
258
            if (pTrack == pFirstTrack)
 
259
               pFirstTrack = pOutWaveTrack; // We replaced the first track, so update stop condition.
 
260
 
 
261
            pInWaveTrack = (WaveTrack*)(iterIn.Next());
 
262
            pOutWaveTrack = (WaveTrack*)(iterOut.Next());
 
263
         }
 
264
         else
 
265
            mTracks->Add(pTrack); // Add pTrack back to end of list.
 
266
 
 
267
         // Remove former pTrack from front of list and set pTrack to next.
 
268
         pTrack = iterAllTracks.RemoveCurrent(); 
 
269
      } while (pTrack != pFirstTrack);
 
270
 
 
271
      // Also need to clean up mWaveTracks, primarily because Preview uses it as the processed tracks. 
 
272
      delete mWaveTracks;
 
273
      mWaveTracks = m_pOutputWaveTracks;
 
274
   }
 
275
   else
 
276
   {
 
277
      // Processing failed or was cancelled so throw away the processed tracks.
 
278
      m_pOutputWaveTracks->Clear(true); // true => delete the tracks
 
279
   }
 
280
}
 
281
 
198
282
void Effect::CountWaveTracks()
199
283
{
200
284
   mNumTracks = 0;
311
395
 
312
396
   WaveTrackArray playbackTracks;
313
397
   WaveTrackArray recordingTracks;
 
398
   // Probably not the same tracks post-processing, so can't rely on previous values of mixLeft & mixRight.
 
399
   TrackListIterator iter(mWaveTracks); 
 
400
   mixLeft = (WaveTrack*)(iter.First());
 
401
   mixRight = (WaveTrack*)(iter.Next());
314
402
   playbackTracks.Add(mixLeft);
315
403
   if (mixRight)
316
404
      playbackTracks.Add(mixRight);
317
405
 
318
 
 
319
406
   // Start audio playing
320
407
 
321
408
   int token =
346
433
                   _("Error"), wxOK | wxICON_EXCLAMATION, mParent);
347
434
   }
348
435
 
 
436
   if (mWaveTracks == m_pOutputWaveTracks) // typical case, but depends on descendant implementation
 
437
      m_pOutputWaveTracks = NULL; 
 
438
   mWaveTracks->Clear(true); // true => delete the tracks
349
439
   delete mWaveTracks;
350
 
   delete mixLeft;
351
 
   if (mixRight)
352
 
      delete mixRight;
353
440
 
354
441
   mWaveTracks = saveWaveTracks;
355
442
}
372
459
   {
373
460
      PopulateOrExchange(S);
374
461
 
375
 
      S.SetBorder(5);
376
 
      S.StartHorizontalLay(wxALIGN_BOTTOM | wxALIGN_CENTER, false);
 
462
      long buttons = eOkButton;
 
463
 
 
464
      if (mType == PROCESS_EFFECT || mType == INSERT_EFFECT)
377
465
      {
 
466
         buttons |= eCancelButton;
378
467
         if (mType == PROCESS_EFFECT)
379
468
         {
380
 
            S.StartHorizontalLay(wxALIGN_LEFT, false);
381
 
            {
382
 
               S.Id(ID_EFFECT_PREVIEW).AddButton(_("Pre&view"));
383
 
            }
384
 
            S.EndHorizontalLay();
385
 
 
386
 
            S.SetBorder(10);
387
 
            S.StartHorizontalLay(wxALIGN_LEFT, false);
388
 
            {
389
 
               // Everyone needs a little space sometime
390
 
            }
391
 
            S.EndHorizontalLay();
392
 
            S.SetBorder(5);
393
 
         }
394
 
 
395
 
         S.StartHorizontalLay(wxALIGN_CENTER, false);
396
 
         {
397
 
#if defined(__WXGTK20__) || defined(__WXMAC__)
398
 
            S.Id(wxID_CANCEL)
399
 
             .AddButton(_("&Cancel"))
400
 
             ->Show( mType == PROCESS_EFFECT || mType == INSERT_EFFECT);
401
 
            S.Id(wxID_OK).AddButton(_("&OK"))->SetDefault();
402
 
#else
403
 
            S.Id(wxID_OK).AddButton(_("&OK"))->SetDefault();
404
 
            S.Id(wxID_CANCEL)
405
 
             .AddButton(_("&Cancel"))
406
 
             ->Show( mType == PROCESS_EFFECT || mType == INSERT_EFFECT);
407
 
#endif
 
469
            buttons |= ePreviewButton;
408
470
         }
409
471
      }
410
 
      S.EndHorizontalLay();
 
472
      S.AddStandardButtons(buttons);
411
473
   }
412
474
   S.EndVerticalLay();
413
 
   GetSizer()->AddSpacer(5);
 
475
 
414
476
   Layout();
415
477
   Fit();
416
478
   SetMinSize(GetSize());
427
489
 
428
490
bool EffectDialog::TransferDataToWindow()
429
491
{
 
492
   ShuttleGui S(this, eIsSettingToDialog);
 
493
   PopulateOrExchange(S);
 
494
 
430
495
   return true;
431
496
}
432
497
 
433
498
bool EffectDialog::TransferDataFromWindow()
434
499
{
 
500
   ShuttleGui S(this, eIsGettingFromDialog);
 
501
   PopulateOrExchange(S);
 
502
 
435
503
   return true;
436
504
}
437
505