Audacity  2.2.0
ODTask.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  ODTask.h
6 
7  Created by Michael Chinen (mchinen)
8  Audacity(R) is copyright (c) 1999-2008 Audacity Team.
9  License: GPL v2. See License.txt.
10 
11 ******************************************************************//*******************************************************************/
19 
20 
21 
22 
23 #ifndef __AUDACITY_ODTASK__
24 #define __AUDACITY_ODTASK__
25 
26 #include "ODTaskThread.h"
27 #include "../BlockFile.h"
28 #include "../Project.h"
29 
30 #include "../MemoryX.h"
31 #include <vector>
32 #include <wx/wx.h>
33 class WaveTrack;
34 
35 
36 DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_ODTASK_COMPLETE, -1)
37 
38 class ODTask /* not final */
40 {
41  public:
42  enum {
43  eODNone = 0x00000000,
44  eODFLAC = 0x00000001,
45  eODMP3 = 0x00000002,
46  eODFFMPEG = 0x00000004,
47  eODPCMSummary = 0x00001000,
48  eODOTHER = 0x10000000,
49  } ODTypeEnum;
50  // Constructor / Destructor
51 
53  ODTask();
54 
55  virtual ~ODTask(){};
56 
57  //clones everything except information about the tracks.
58  virtual movable_ptr<ODTask> Clone() const = 0;
59 
61  virtual unsigned int GetODType(){return eODNone;}
62 
63 
68  void DoSome(float amountWork=0.0);
69 
71  void DoAll();
72 
73  virtual float PercentComplete();
74 
75  virtual bool UsesCustomWorkUntilPercentage(){return false;}
76  virtual float ComputeNextWorkUntilPercentageComplete(){return 1.0;}
77 
81  virtual bool CanMergeWith(ODTask* otherTask){return strcmp(GetTaskName(),otherTask->GetTaskName())==0;}
82 
83  virtual void StopUsingWaveTrack(WaveTrack* track);
84 
87  virtual void ReplaceWaveTrack(WaveTrack* oldTrack,WaveTrack* newTrack);
88 
90  void AddWaveTrack(WaveTrack* track);
91  virtual int GetNumWaveTracks();
92  virtual WaveTrack* GetWaveTrack(int i);
93 
95  virtual void DemandTrackUpdate(WaveTrack* track, double seconds);
96 
97  bool IsComplete();
98 
99  void TerminateAndBlock();
101  virtual void Terminate(){}
102 
103  virtual const char* GetTaskName(){return "ODTask";}
104 
105  virtual sampleCount GetDemandSample() const;
106 
107  virtual void SetDemandSample(sampleCount sample);
108 
110  virtual void RecalculatePercentComplete();
111 
113  int GetTaskNumber(){return mTaskNumber;}
114 
115  void SetNeedsODUpdate();
116  bool GetNeedsODUpdate();
117  void ResetNeedsODUpdate();
118 
119  virtual const wxChar* GetTip()=0;
120 
122  virtual bool IsTaskAssociatedWithProject(AudacityProject* proj);
123 
124  bool IsRunning();
125 
126 
127  protected:
128 
130  virtual void CalculatePercentComplete() = 0;
131 
135  virtual void DoSomeInternal() = 0;
136 
138  virtual void Update(){}
139 
143  virtual void ODUpdate();
144 
145  void SetIsRunning(bool value);
146 
147 
148 
150  volatile float mPercentComplete;
152  volatile bool mDoingTask;
153  volatile bool mTaskStarted;
154  volatile bool mTerminate;
156  //for a function not a member var.
158 
159  std::vector<WaveTrack*> mWaveTracks;
161 
162  sampleCount mDemandSample;
164 
165  volatile bool mIsRunning;
167 
168 
169  private:
170 
171  volatile bool mNeedsODUpdate;
173 
174 
175 
176 };
177 
178 #endif
179 
virtual bool CanMergeWith(ODTask *otherTask)
Definition: ODTask.h:81
std::unique_ptr< T > movable_ptr
Definition: MemoryX.h:683
ODLock mTerminateMutex
Definition: ODTask.h:155
ODLock mDemandSampleMutex
Definition: ODTask.h:163
volatile bool mNeedsODUpdate
Definition: ODTask.h:171
ODLock mWaveTrackMutex
Definition: ODTask.h:160
virtual void Update()
virtual method called before DoSomeInternal is used from DoSome.
Definition: ODTask.h:138
volatile bool mIsRunning
Definition: ODTask.h:165
std::vector< WaveTrack * > mWaveTracks
Definition: ODTask.h:159
volatile float mPercentComplete
Definition: ODTask.h:150
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:161
A class representing a modular task to be used with the On-Demand structures.
Definition: ODTask.h:39
volatile bool mDoingTask
Definition: ODTask.h:152
sampleCount mDemandSample
Definition: ODTask.h:162
ODLock mNeedsODUpdateMutex
Definition: ODTask.h:172
A Track that contains audio waveform data.
Definition: WaveTrack.h:76
int GetTaskNumber()
returns the number of tasks created before this instance.
Definition: ODTask.h:113
virtual const char * GetTaskName()
Definition: ODTask.h:103
ODLock mBlockUntilTerminateMutex
Definition: ODTask.h:157
virtual float ComputeNextWorkUntilPercentageComplete()
Definition: ODTask.h:76
virtual ~ODTask()
Definition: ODTask.h:55
int mTaskNumber
Definition: ODTask.h:149
Definition: ODTaskThread.h:150
ODLock mPercentCompleteMutex
Definition: ODTask.h:151
volatile bool mTaskStarted
Definition: ODTask.h:153
virtual unsigned int GetODType()
Subclasses should override to return respective type.
Definition: ODTask.h:61
DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_OPEN_AUDIO_FILE,-1)
virtual void Terminate()
releases memory that the ODTask owns. Subclasses should override.
Definition: ODTask.h:101
ODLock mIsRunningMutex
Definition: ODTask.h:166
volatile bool mTerminate
Definition: ODTask.h:154
virtual bool UsesCustomWorkUntilPercentage()
Definition: ODTask.h:75