Audacity  2.2.2
GetTrackInfoCommand.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  Dan Horgan
8  Marty Goddard
9 ******************************************************************//*******************************************************************/
18 
19 #include "../Audacity.h"
20 #include "GetTrackInfoCommand.h"
21 #include "../TrackPanel.h"
22 #include "../Project.h"
23 #include "../WaveTrack.h"
24 
26 {
27  return wxT("GetTrackInfo");
28 }
29 
31 {
32  auto trackIndexValidator = make_movable<IntValidator>();
33  signature.AddParameter(wxT("TrackIndex"), 0, std::move(trackIndexValidator));
34 
35  auto infoTypeValidator = make_movable<OptionValidator>();
36  infoTypeValidator->AddOption(wxT("Name"));
37  infoTypeValidator->AddOption(wxT("StartTime"));
38  infoTypeValidator->AddOption(wxT("EndTime"));
39  infoTypeValidator->AddOption(wxT("Pan"));
40  infoTypeValidator->AddOption(wxT("Gain"));
41  infoTypeValidator->AddOption(wxT("Selected"));
42  infoTypeValidator->AddOption(wxT("Linked"));
43  infoTypeValidator->AddOption(wxT("Solo"));
44  infoTypeValidator->AddOption(wxT("Mute"));
45  infoTypeValidator->AddOption(wxT("Focused"));
46 
47  signature.AddParameter(wxT("Type"), wxT("Name"), std::move(infoTypeValidator));
48 }
49 
50 CommandHolder GetTrackInfoCommandType::Create(std::unique_ptr<CommandOutputTarget> &&target)
51 {
52  return std::make_shared<GetTrackInfoCommand>(*this, std::move(target));
53 }
54 
55 
56 
57 //******************* Private Member Functions ********************************
59 {
60  if(boolValue)
61  Status(wxT("1"));
62  else
63  Status(wxT("0"));
64 }
65 
66 
67 
68 
69 // ===================== Public Member Functions =================================
70 
72 {
73  wxString mode = GetString(wxT("Type"));
74 
75  long trackIndex = GetLong(wxT("TrackIndex"));
76 
77  // Get the track indicated by the TrackIndex parameter
78  // (Note: this ought to be somewhere else)
79  long i = 0;
80  TrackListIterator iter(context.GetProject()->GetTracks());
81  Track *t = iter.First();
82  while (t && i != trackIndex)
83  {
84  t = iter.Next();
85  ++i;
86  }
87  if (i != trackIndex || !t)
88  {
89  Error(wxT("TrackIndex was invalid."));
90  return false;
91  }
92 
93  // Now get the particular desired item about the track of interest
94  if (mode.IsSameAs(wxT("Name")))
95  {
96  Status(t->GetName());
97  }
98  else if (mode.IsSameAs(wxT("StartTime")))
99  {
100  Status(wxString::Format(wxT("%f"), t->GetStartTime()));
101  }
102  else if (mode.IsSameAs(wxT("EndTime")))
103  {
104  Status(wxString::Format(wxT("%.17g"), t->GetEndTime()));
105  }
106  else if (mode.IsSameAs(wxT("Pan")))
107  {
108  if(t->GetKind() == Track::Wave)
109  Status(wxString::Format(wxT("%f"), static_cast<WaveTrack*>(t)->GetPan()));
110  }
111  else if (mode.IsSameAs(wxT("Gain")))
112  {
113  if(t->GetKind() == Track::Wave)
114  Status(wxString::Format(wxT("%f"), static_cast<WaveTrack*>(t)->GetGain()));
115  }
116  else if (mode.IsSameAs(wxT("Focused")))
117  {
118  TrackPanel *panel = context.GetProject()->GetTrackPanel();
119  SendBooleanStatus(panel->GetFocusedTrack() == t);
120  }
121  else if (mode.IsSameAs(wxT("Selected")))
122  {
123  SendBooleanStatus(t->GetSelected());
124  }
125  else if (mode.IsSameAs(wxT("Linked")))
126  {
127  SendBooleanStatus(t->GetLinked());
128  }
129  else if (mode.IsSameAs(wxT("Solo")))
130  {
131  auto pt = dynamic_cast<const PlayableTrack *>(t);
132  if (pt)
133  SendBooleanStatus(pt->GetSolo());
134  else
135  SendBooleanStatus(false);
136  }
137  else if (mode.IsSameAs(wxT("Mute")))
138  {
139  auto pt = dynamic_cast<const PlayableTrack *>(t);
140  if (pt)
141  SendBooleanStatus(pt->GetMute());
142  else
143  SendBooleanStatus(false);
144  }
145  else
146  {
147  Error(wxT("Invalid info type!"));
148  return false;
149  }
150  return true;
151 }
bool Apply(CommandExecutionContext context) override
std::shared_ptr< Command > CommandHolder
void AddParameter(const wxString &name, const wxVariant &dft, movable_ptr< Validator > &&valid)
wxString GetString(const wxString &paramName)
Definition: Command.cpp:165
void SendBooleanStatus(bool BooleanValue)
wxString BuildName() override
CommandHolder Create(std::unique_ptr< CommandOutputTarget > &&target) override
long GetLong(const wxString &paramName)
Definition: Command.cpp:149
The TrackPanel class coordinates updates and operations on the main part of the screen which contains...
Definition: TrackPanel.h:245
void BuildSignature(CommandSignature &signature) override
Postcondition: signature is a 'signature' map containing parameter.
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
An AudioTrack that can be played and stopped.
Definition: Track.h:368
An iterator for a TrackList.
Definition: Track.h:394
Represents a context to which a command may be applied.
Definition: Command.h:50
Track * GetFocusedTrack()
TrackPanel * GetTrackPanel()
Definition: Project.h:289
TrackList * GetTracks()
Definition: Project.h:174
Declarations of GetTrackInfoCommand and GetTrackInfoCommandType classes.
AudacityProject * GetProject() const
Definition: Command.h:60
Class that maps parameter names to default values and validators.
void Error(const wxString &message) override
Definition: Command.cpp:184