Audacity  2.2.2
Public Member Functions | Protected Attributes | List of all members
ODWaveTrackTaskQueue Class Referencefinal

A class representing a modular task to be used with the On-Demand structures. More...

#include <ODWaveTrackTaskQueue.h>

Public Member Functions

 ODWaveTrackTaskQueue ()
 Constructs an ODWaveTrackTaskQueue. More...
 
virtual ~ODWaveTrackTaskQueue ()
 
void AddWaveTrack (WaveTrack *track)
 Adds a track to the associated list. More...
 
void RemoveWaveTrack (WaveTrack *track)
 
void DemandTrackUpdate (WaveTrack *track, double seconds)
 changes the tasks associated with this Waveform to process the task from a different point in the track More...
 
void ReplaceWaveTrack (WaveTrack *oldTrack, WaveTrack *newTrack)
 replaces all instances of a WaveTrack within this task with another. More...
 
void MakeWaveTrackIndependent (WaveTrack *track)
 
bool CanMergeWith (ODWaveTrackTaskQueue *otherQueue)
 returns whether or not this queue's task list and another's can merge together, as when we make two mono tracks stereo. More...
 
void MergeWaveTrack (WaveTrack *track)
 
bool ContainsWaveTrack (const WaveTrack *track)
 returns true if the argument is in the WaveTrack list. More...
 
WaveTrackGetWaveTrack (size_t x)
 
int GetNumWaveTracks ()
 returns the number of wavetracks in this queue. More...
 
void AddTask (std::unique_ptr< ODTask > &&mtask)
 Add a task to the queue. More...
 
bool IsEmpty ()
 
bool IsFrontTaskComplete ()
 
void RemoveFrontTask ()
 Removes and deletes the front task from the list. More...
 
ODTaskGetFrontTask ()
 Schedules the front task for immediate execution. More...
 
int GetNumTasks ()
 returns the number of ODTasks in this queue More...
 
ODTaskGetTask (size_t x)
 returns a ODTask at position x More...
 
void FillTipForWaveTrack (const WaveTrack *t, wxString &tip)
 fills in the status bar message for a given track More...
 

Protected Attributes

wxString mTipMsg
 
std::vector< WaveTrack * > mTracks
 the list of tracks associated with this queue. More...
 
ODLock mTracksMutex
 
std::vector< std::unique_ptr
< ODTask > > 
mTasks
 the list of tasks associated with the tracks. This class owns these tasks. More...
 
ODLock mTasksMutex
 

Detailed Description

A class representing a modular task to be used with the On-Demand structures.

watches over all to be done (not yet started and started but not finished) tasks associated with a WaveTrack.

Definition at line 32 of file ODWaveTrackTaskQueue.h.

Constructor & Destructor Documentation

ODWaveTrackTaskQueue::ODWaveTrackTaskQueue ( )

Constructs an ODWaveTrackTaskQueue.

Definition at line 24 of file ODWaveTrackTaskQueue.cpp.

25 {
26 }
ODWaveTrackTaskQueue::~ODWaveTrackTaskQueue ( )
virtual

Definition at line 28 of file ODWaveTrackTaskQueue.cpp.

References ODManager::Instance, mTasks, and ODManager::RemoveTaskIfInQueue().

29 {
30  //we need to DELETE all ODTasks. We will have to block or wait until block for the active ones.
31  for(unsigned int i=0;i<mTasks.size();i++)
32  {
33  mTasks[i]->TerminateAndBlock();//blocks if active.
34  //small chance we may have rea-added the task back into the queue from a diff thread. - so remove it if we have.
36  mTasks[i].reset();
37  }
38 
39 }
static ODManager *(* Instance)()
Definition: ODManager.h:49
void RemoveTaskIfInQueue(ODTask *task)
removes a task from the active task queue
Definition: ODManager.cpp:125
std::vector< std::unique_ptr< ODTask > > mTasks
the list of tasks associated with the tracks. This class owns these tasks.

Member Function Documentation

void ODWaveTrackTaskQueue::AddTask ( std::unique_ptr< ODTask > &&  mtask)

Add a task to the queue.

Definition at line 104 of file ODWaveTrackTaskQueue.cpp.

References ODTask::GetNumWaveTracks(), ODTask::GetWaveTrack(), mTasks, mTasksMutex, mTracks, and mTracksMutex.

Referenced by ODManager::AddNewTask().

105 {
106  ODTask *task = mtask.get();
107 
108  mTasksMutex.Lock();
109  mTasks.push_back(std::move(mtask));
110  mTasksMutex.Unlock();
111 
112  //take all of the tracks in the task.
113  mTracksMutex.Lock();
114  for(int i=0;i<task->GetNumWaveTracks();i++)
115  {
116  //task->GetWaveTrack(i) may return NULL, but we handle it by checking before using.
117  //The other worry that the WaveTrack returned and was deleted in the meantime is also
118  //handled since mQueuesMutex is locked one up in the stack from here,
119  //and WaveTrack deletion is bound to that.
120  mTracks.push_back(task->GetWaveTrack(i));
121  }
122 
123  mTracksMutex.Unlock();
124 
125 }
std::vector< WaveTrack * > mTracks
the list of tracks associated with this queue.
A class representing a modular task to be used with the On-Demand structures.
Definition: ODTask.h:39
virtual WaveTrack * GetWaveTrack(int i)
Definition: ODTask.cpp:261
virtual int GetNumWaveTracks()
Definition: ODTask.cpp:279
std::vector< std::unique_ptr< ODTask > > mTasks
the list of tasks associated with the tracks. This class owns these tasks.
void ODWaveTrackTaskQueue::AddWaveTrack ( WaveTrack track)

Adds a track to the associated list.

Definition at line 94 of file ODWaveTrackTaskQueue.cpp.

References mTracks, and mTracksMutex.

Referenced by MergeWaveTrack().

95 {
96 
97  mTracksMutex.Lock();
98  if(track)
99  mTracks.push_back(track);
100 
101  mTracksMutex.Unlock();
102 }
std::vector< WaveTrack * > mTracks
the list of tracks associated with this queue.
bool ODWaveTrackTaskQueue::CanMergeWith ( ODWaveTrackTaskQueue otherQueue)

returns whether or not this queue's task list and another's can merge together, as when we make two mono tracks stereo.

Definition at line 42 of file ODWaveTrackTaskQueue.cpp.

References GetNumTasks(), GetTask(), mTasks, and mTasksMutex.

Referenced by ODManager::MakeWaveTrackDependent().

43 {
44  //have to be very careful when dealing with two lists that need to be locked.
45  if(GetNumTasks()!=otherQueue->GetNumTasks())
46  return false;
47 
48  mTasksMutex.Lock();
49  for(unsigned int i=0;i<mTasks.size();i++)
50  {
51  if(!mTasks[i]->CanMergeWith(otherQueue->GetTask(i)))
52  {
53  mTasksMutex.Unlock();
54  return false;
55  }
56  }
57  mTasksMutex.Unlock();
58  return true;
59 }
int GetNumTasks()
returns the number of ODTasks in this queue
ODTask * GetTask(size_t x)
returns a ODTask at position x
std::vector< std::unique_ptr< ODTask > > mTasks
the list of tasks associated with the tracks. This class owns these tasks.
bool CanMergeWith(ODWaveTrackTaskQueue *otherQueue)
returns whether or not this queue's task list and another's can merge together, as when we make two m...
bool ODWaveTrackTaskQueue::ContainsWaveTrack ( const WaveTrack track)

returns true if the argument is in the WaveTrack list.

Definition at line 79 of file ODWaveTrackTaskQueue.cpp.

References mTracks, and mTracksMutex.

Referenced by FillTipForWaveTrack().

80 {
81  mTracksMutex.Lock();
82  for(unsigned int i=0;i<mTracks.size();i++)
83  {
84  if(mTracks[i]==track)
85  {
86  mTracksMutex.Unlock();
87  return true;
88  }
89  }
90  mTracksMutex.Unlock();
91  return false;
92 }
std::vector< WaveTrack * > mTracks
the list of tracks associated with this queue.
void ODWaveTrackTaskQueue::DemandTrackUpdate ( WaveTrack track,
double  seconds 
)

changes the tasks associated with this Waveform to process the task from a different point in the track

changes the tasks associated with this Waveform to process the task from a different point in the track

Parameters
trackthe track to update
secondsthe point in the track from which the tasks associated with track should begin processing from.

Definition at line 192 of file ODWaveTrackTaskQueue.cpp.

References mTasks, and mTracksMutex.

193 {
194  if(track)
195  {
196  mTracksMutex.Lock();
197  for(unsigned int i=0;i<mTasks.size();i++)
198  {
199  mTasks[i]->DemandTrackUpdate(track,seconds);
200  }
201 
202  mTracksMutex.Unlock();
203  }
204 }
std::vector< std::unique_ptr< ODTask > > mTasks
the list of tasks associated with the tracks. This class owns these tasks.
void ODWaveTrackTaskQueue::FillTipForWaveTrack ( const WaveTrack t,
wxString &  tip 
)

fills in the status bar message for a given track

Definition at line 329 of file ODWaveTrackTaskQueue.cpp.

References _(), ContainsWaveTrack(), GetFrontTask(), GetNumTasks(), and mTipMsg.

330 {
331  if(ContainsWaveTrack(t) && GetNumTasks())
332  {
333 
334  // if(GetNumTasks()==1)
335  mTipMsg.Printf(_("%s %2.0f%% complete. Click to change task focal point."), GetFrontTask()->GetTip(), GetFrontTask()->PercentComplete()*100.0 );
336  // else
337  // msg.Printf(_("%s %d additional tasks remaining."), GetFrontTask()->GetTip(), GetNumTasks());
338 
339  tip = mTipMsg;
340 
341  }
342 }
ODTask * GetFrontTask()
Schedules the front task for immediate execution.
bool ContainsWaveTrack(const WaveTrack *track)
returns true if the argument is in the WaveTrack list.
int GetNumTasks()
returns the number of ODTasks in this queue
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
ODTask * ODWaveTrackTaskQueue::GetFrontTask ( )

Schedules the front task for immediate execution.

gets the front task for immediate execution

Definition at line 316 of file ODWaveTrackTaskQueue.cpp.

References mTasks, and mTasksMutex.

Referenced by FillTipForWaveTrack(), and ODManager::UpdateQueues().

317 {
318  mTasksMutex.Lock();
319  if(mTasks.size())
320  {
321  mTasksMutex.Unlock();
322  return mTasks[0].get();
323  }
324  mTasksMutex.Unlock();
325  return NULL;
326 }
std::vector< std::unique_ptr< ODTask > > mTasks
the list of tasks associated with the tracks. This class owns these tasks.
int ODWaveTrackTaskQueue::GetNumTasks ( )

returns the number of ODTasks in this queue

Definition at line 247 of file ODWaveTrackTaskQueue.cpp.

References mTasks, and mTasksMutex.

Referenced by CanMergeWith(), and FillTipForWaveTrack().

248 {
249  int ret = 0;
250  mTasksMutex.Lock();
251  ret=mTasks.size();
252  mTasksMutex.Unlock();
253  return ret;
254 }
std::vector< std::unique_ptr< ODTask > > mTasks
the list of tasks associated with the tracks. This class owns these tasks.
int ODWaveTrackTaskQueue::GetNumWaveTracks ( )

returns the number of wavetracks in this queue.

Definition at line 237 of file ODWaveTrackTaskQueue.cpp.

References mTracks, and mTracksMutex.

238 {
239  int ret = 0;
240  mTracksMutex.Lock();
241  ret=mTracks.size();
242  mTracksMutex.Unlock();
243  return ret;
244 }
std::vector< WaveTrack * > mTracks
the list of tracks associated with this queue.
ODTask * ODWaveTrackTaskQueue::GetTask ( size_t  x)

returns a ODTask at position x

Definition at line 257 of file ODWaveTrackTaskQueue.cpp.

References mTasks, and mTasksMutex.

Referenced by CanMergeWith().

258 {
259  ODTask* ret = NULL;
260  mTasksMutex.Lock();
261  if (x < mTasks.size())
262  ret = mTasks[x].get();
263  mTasksMutex.Unlock();
264  return ret;
265 }
A class representing a modular task to be used with the On-Demand structures.
Definition: ODTask.h:39
std::vector< std::unique_ptr< ODTask > > mTasks
the list of tasks associated with the tracks. This class owns these tasks.
WaveTrack * ODWaveTrackTaskQueue::GetWaveTrack ( size_t  x)

Definition at line 226 of file ODWaveTrackTaskQueue.cpp.

References mTracks, and mTracksMutex.

227 {
228  WaveTrack* ret = NULL;
229  mTracksMutex.Lock();
230  if (x < mTracks.size())
231  ret = mTracks[x];
232  mTracksMutex.Unlock();
233  return ret;
234 }
std::vector< WaveTrack * > mTracks
the list of tracks associated with this queue.
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
bool ODWaveTrackTaskQueue::IsEmpty ( )

Definition at line 270 of file ODWaveTrackTaskQueue.cpp.

References mTasks, mTasksMutex, mTracks, and mTracksMutex.

271 {
272  bool isEmpty;
273  mTracksMutex.Lock();
274  isEmpty = mTracks.size()<=0;
275  mTracksMutex.Unlock();
276 
277  mTasksMutex.Lock();
278  isEmpty = isEmpty || mTasks.size()<=0;
279  mTasksMutex.Unlock();
280 
281  return isEmpty;
282 }
std::vector< WaveTrack * > mTracks
the list of tracks associated with this queue.
std::vector< std::unique_ptr< ODTask > > mTasks
the list of tasks associated with the tracks. This class owns these tasks.
bool ODWaveTrackTaskQueue::IsFrontTaskComplete ( )

Definition at line 285 of file ODWaveTrackTaskQueue.cpp.

References mTasks, and mTasksMutex.

286 {
287  mTasksMutex.Lock();
288  if(mTasks.size())
289  {
290  //there is a chance the task got updated and now has more to do, (like when it is joined with a NEW track)
291  //check.
292  mTasks[0]->RecalculatePercentComplete();
293  bool ret;
294  ret = mTasks[0]->IsComplete();
295  mTasksMutex.Unlock();
296 
297  return ret;
298  }
299  mTasksMutex.Unlock();
300  return false;
301 }
std::vector< std::unique_ptr< ODTask > > mTasks
the list of tasks associated with the tracks. This class owns these tasks.
void ODWaveTrackTaskQueue::MakeWaveTrackIndependent ( WaveTrack track)

Definition at line 149 of file ODWaveTrackTaskQueue.cpp.

References ODManager::AddNewTask(), ODManager::Instance, mTasks, mTasksMutex, mTracks, mTracksMutex, and RemoveWaveTrack().

Referenced by ODManager::MakeWaveTrackIndependent().

150 {
151 
152  mTracksMutex.Lock();
153  if(mTracks.size()<2)
154  {
155  //if there is only one track, it is already independent.
156  mTracksMutex.Unlock();
157  return;
158  }
159 
160  for(unsigned int i=0;i<mTracks.size();i++)
161  {
162  if(mTracks[i]==track)
163  {
164  mTracksMutex.Unlock();//release the lock, since RemoveWaveTrack is a public threadsafe method.
166 
167  //clone the items in order and add them to the ODManager.
168  mTasksMutex.Lock();
169  for(unsigned int j=0;j<mTasks.size();j++)
170  {
171  auto task = mTasks[j]->Clone();
172  task->AddWaveTrack(track);
173  //AddNewTask requires us to relinquish this lock. However, it is safe because ODManager::MakeWaveTrackIndependent
174  //has already locked the m_queuesMutex.
175  mTasksMutex.Unlock();
176  //AddNewTask locks the m_queuesMutex which is already locked by ODManager::MakeWaveTrackIndependent,
177  //so we pass a boolean flag telling it not to lock again.
178  ODManager::Instance()->AddNewTask(std::move(task), false);
179  mTasksMutex.Lock();
180  }
181  mTasksMutex.Unlock();
182  mTracksMutex.Lock();
183  break;
184  }
185  }
186  mTracksMutex.Unlock();
187 }
static ODManager *(* Instance)()
Definition: ODManager.h:49
void AddNewTask(std::unique_ptr< ODTask > &&mtask, bool lockMutex=true)
Adds a wavetrack, creates a queue member.
Definition: ODManager.cpp:145
std::vector< WaveTrack * > mTracks
the list of tracks associated with this queue.
void RemoveWaveTrack(WaveTrack *track)
std::vector< std::unique_ptr< ODTask > > mTasks
the list of tasks associated with the tracks. This class owns these tasks.
void ODWaveTrackTaskQueue::MergeWaveTrack ( WaveTrack track)

add track to the masterTrack's queue - this will allow future ODScheduling to affect them together. sets the NeedODUpdateFlag since we don't want the head task to finish without haven't dealt with the depednent

Parameters
trackthe track to bring into the tasks AND tracklist for this queue

Definition at line 65 of file ODWaveTrackTaskQueue.cpp.

References AddWaveTrack(), mTasks, and mTasksMutex.

Referenced by ODManager::MakeWaveTrackDependent().

66 {
67  AddWaveTrack(track);
68  mTasksMutex.Lock();
69  for(unsigned int i=0;i<mTasks.size();i++)
70  {
71  mTasks[i]->AddWaveTrack(track);
72  mTasks[i]->SetNeedsODUpdate();
73  }
74  mTasksMutex.Unlock();
75 
76 }
void AddWaveTrack(WaveTrack *track)
Adds a track to the associated list.
std::vector< std::unique_ptr< ODTask > > mTasks
the list of tasks associated with the tracks. This class owns these tasks.
void ODWaveTrackTaskQueue::RemoveFrontTask ( )

Removes and deletes the front task from the list.

Definition at line 304 of file ODWaveTrackTaskQueue.cpp.

References mTasks, and mTasksMutex.

305 {
306  mTasksMutex.Lock();
307  if(mTasks.size())
308  {
309  //wait for the task to stop running.
310  mTasks.erase(mTasks.begin());
311  }
312  mTasksMutex.Unlock();
313 }
std::vector< std::unique_ptr< ODTask > > mTasks
the list of tasks associated with the tracks. This class owns these tasks.
void ODWaveTrackTaskQueue::RemoveWaveTrack ( WaveTrack track)

Removes a track from the list. Also notifies mTasks to stop using references to the instance in a thread-safe manner (may block)

Definition at line 129 of file ODWaveTrackTaskQueue.cpp.

References mTasks, mTasksMutex, mTracks, and mTracksMutex.

Referenced by MakeWaveTrackIndependent().

130 {
131  if(track)
132  {
133 
134  mTasksMutex.Lock();
135  for(unsigned int i=0;i<mTasks.size();i++)
136  mTasks[i]->StopUsingWaveTrack(track);
137  mTasksMutex.Unlock();
138 
139  mTracksMutex.Lock();
140  for(unsigned int i=0;i<mTracks.size();i++)
141  if(mTracks[i]==track)
142  mTracks.erase(mTracks.begin()+i--);//decrement i after the removal.
143 
144  mTracksMutex.Unlock();
145  }
146 }
std::vector< WaveTrack * > mTracks
the list of tracks associated with this queue.
std::vector< std::unique_ptr< ODTask > > mTasks
the list of tasks associated with the tracks. This class owns these tasks.
void ODWaveTrackTaskQueue::ReplaceWaveTrack ( WaveTrack oldTrack,
WaveTrack newTrack 
)

replaces all instances of a WaveTrack within this task with another.

Definition at line 208 of file ODWaveTrackTaskQueue.cpp.

References mTasks, mTasksMutex, mTracks, and mTracksMutex.

209 {
210  if(oldTrack)
211  {
212  mTasksMutex.Lock();
213  for(unsigned int i=0;i<mTasks.size();i++)
214  mTasks[i]->ReplaceWaveTrack(oldTrack,newTrack);
215  mTasksMutex.Unlock();
216 
217  mTracksMutex.Lock();
218  for(unsigned int i=0;i<mTracks.size();i++)
219  if(mTracks[i]==oldTrack)
220  mTracks[i]=newTrack;
221  mTracksMutex.Unlock();
222  }
223 }
std::vector< WaveTrack * > mTracks
the list of tracks associated with this queue.
std::vector< std::unique_ptr< ODTask > > mTasks
the list of tasks associated with the tracks. This class owns these tasks.
void ReplaceWaveTrack(WaveTrack *oldTrack, WaveTrack *newTrack)
replaces all instances of a WaveTrack within this task with another.

Member Data Documentation

std::vector<std::unique_ptr<ODTask> > ODWaveTrackTaskQueue::mTasks
protected
ODLock ODWaveTrackTaskQueue::mTasksMutex
protected
wxString ODWaveTrackTaskQueue::mTipMsg
protected

Definition at line 101 of file ODWaveTrackTaskQueue.h.

Referenced by FillTipForWaveTrack().

std::vector<WaveTrack*> ODWaveTrackTaskQueue::mTracks
protected

the list of tracks associated with this queue.

Definition at line 105 of file ODWaveTrackTaskQueue.h.

Referenced by AddTask(), AddWaveTrack(), ContainsWaveTrack(), GetNumWaveTracks(), GetWaveTrack(), IsEmpty(), MakeWaveTrackIndependent(), RemoveWaveTrack(), and ReplaceWaveTrack().

ODLock ODWaveTrackTaskQueue::mTracksMutex
protected

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