Audacity  2.2.2
GetProjectInfoCommand.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity - A Digital Audio Editor
4  Copyright 1999-2009 Audacity Team
5  License: wxwidgets
6 
7  Marty Goddard
8 
9 ******************************************************************//*******************************************************************/
18 
19 #include "GetProjectInfoCommand.h"
20 #include "../TrackPanel.h"
21 #include "../Project.h"
22 #include "../Track.h"
23 
25 {
26  return wxT("GetProjectInfo");
27 }
28 
30 {
31  auto infoTypeValidator = make_movable<OptionValidator>();
32  infoTypeValidator->AddOption(wxT("Name"));
33  infoTypeValidator->AddOption(wxT("NumberOfTracks"));
34  infoTypeValidator->AddOption(wxT("SelectedTracks"));
35  infoTypeValidator->AddOption(wxT("MuteTracks"));
36  infoTypeValidator->AddOption(wxT("SoloTracks"));
37  infoTypeValidator->AddOption(wxT("FocusedTrackID")); // returns the Track ID number of the track in focus
38 
39  signature.AddParameter(wxT("Type"), wxT("Name"), std::move(infoTypeValidator));
40 }
41 
42 CommandHolder GetProjectInfoCommandType::Create(std::unique_ptr<CommandOutputTarget> &&target)
43 {
44  return std::make_shared<GetProjectInfoCommand>(*this, std::move(target));
45 }
46 
47 
48 // *********************** Public Methods *******************
50 {
51  wxString mode = GetString(wxT("Type"));
52  TrackList *projTracks = context.GetProject()->GetTracks();
53 
54  if (mode.IsSameAs(wxT("Name")))
55  {
56  Status(context.GetProject()->GetFileName());
57  }
58  else if (mode.IsSameAs(wxT("FocusedTrackID")))
59  {
60  SendFocusedTrackIndex(context);
61  }
62  else if (mode.IsSameAs(wxT("NumberOfTracks")))
63  {
64  SendNumberOfTracks(context);
65  }
66  else if (mode.IsSameAs(wxT("SelectedTracks")))
67  {
69  }
70  else if (mode.IsSameAs(wxT("LinkedTracks")))
71  {
73  }
74  else if (mode.IsSameAs(wxT("SoloTracks")))
75  {
77  }
78  else if (mode.IsSameAs(wxT("MuteTracks")))
79  {
81  }
82  else
83  {
84  Error(wxT("Invalid info type!"));
85  return false;
86  }
87  return true;
88 }
89 
90 //********************* Private Methods *******************************
91 
93 {
94  int returnVal=0;
95 
96  TrackListIterator iter(context.GetProject()->GetTracks());
97  Track *t = iter.First();
98  while (t)
99  {
100  returnVal++;
101  t = iter.Next();
102  }
103  wxString trackNumStr;
104  trackNumStr << returnVal; // convert to a string to send over named pipe
105  Status(trackNumStr);
106  return returnVal;
107 }
108 
110 {
111  int returnVal=0;
112  int focusTrackIndex=0;
113  TrackPanel *panel = context.GetProject()->GetTrackPanel();
114  Track* focusedTrack = panel->GetFocusedTrack();
115 
116  TrackListIterator iter(context.GetProject()->GetTracks());
117  Track *t = iter.First();
118  while (t)
119  {
120  if(t == focusedTrack) // when we've found the focused track, we know the trackIndex
121  {
122  returnVal = focusTrackIndex;
123  break;
124  }
125  focusTrackIndex++;
126  t = iter.Next();
127  }
128  wxString trackIndexStr;
129  trackIndexStr << returnVal; // convert to a string to send over named pipe
130  Status(trackIndexStr);
131  return returnVal;
132 }
133 
134 
136  Getter functPtrToGetter)
137 {
138  wxString boolValueStr;
139  TrackListIterator iter(projTracks);
140  Track *trk = iter.First();
141  while (trk)
142  {
143  if( (this->*functPtrToGetter)(trk)) // Function Pointer to the desired parameter to Test
144  boolValueStr.Append(wxT("1"),1);
145  else
146  boolValueStr.Append(wxT("0"),1);
147  trk = iter.Next();
148  }
149  Status(boolValueStr);
150 }
151 
153 {
154  return track->GetSelected();
155 }
156 
157 bool GetProjectInfoCommand::testLinked(const Track * track) const
158 {
159  return track->GetLinked();
160 }
161 
162 bool GetProjectInfoCommand::testSolo(const Track * track) const
163 {
164  auto pt = dynamic_cast<const PlayableTrack *>(track);
165  return pt && pt->GetSolo();
166 }
167 
168 bool GetProjectInfoCommand::testMute(const Track * track) const
169 {
170  auto pt = dynamic_cast<const PlayableTrack *>(track);
171  return pt && pt->GetMute();
172 }
bool GetSolo() const
Definition: Track.h:376
A list of TrackListNode items.
Definition: Track.h:611
bool GetSelected() const
Definition: Track.h:268
std::shared_ptr< Command > CommandHolder
int SendNumberOfTracks(CommandExecutionContext context)
void AddParameter(const wxString &name, const wxVariant &dft, movable_ptr< Validator > &&valid)
wxString GetString(const wxString &paramName)
Definition: Command.cpp:165
bool GetLinked() const
Definition: Track.h:271
bool testSelected(const Track *track) const
Declarations of GetProjectInfoCommand and GetProjectInfoCommandType classes.
bool Apply(CommandExecutionContext context) override
bool testSolo(const Track *track) const
bool testMute(const Track *track) const
The TrackPanel class coordinates updates and operations on the main part of the screen which contains...
Definition: TrackPanel.h:245
CommandHolder Create(std::unique_ptr< CommandOutputTarget > &&target) override
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:94
void Status(const wxString &status) override
Definition: Command.cpp:179
virtual Track * First(TrackList *val=nullptr)
Definition: Track.cpp:414
bool testLinked(const Track *track) const
int SendFocusedTrackIndex(CommandExecutionContext context)
An AudioTrack that can be played and stopped.
Definition: Track.h:368
An iterator for a TrackList.
Definition: Track.h:394
void BuildSignature(CommandSignature &signature) override
Postcondition: signature is a 'signature' map containing parameter.
virtual Track * Next(bool skiplinked=false)
Definition: Track.cpp:456
Represents a context to which a command may be applied.
Definition: Command.h:50
Track * GetFocusedTrack()
TrackPanel * GetTrackPanel()
Definition: Project.h:289
bool GetMute() const
Definition: Track.h:375
TrackList * GetTracks()
Definition: Project.h:174
AudacityProject * GetProject() const
Definition: Command.h:60
void SendTracksInfo(TrackList *projTracks, Getter)
const wxString & GetFileName()
Definition: Project.h:284
Class that maps parameter names to default values and validators.
void Error(const wxString &message) override
Definition: Command.cpp:184