Audacity 3.2.0
Enumerations | Functions
TrackUtilities Namespace Reference

Enumerations

enum  MoveChoice { OnMoveUpID , OnMoveDownID , OnMoveTopID , OnMoveBottomID }
 

Functions

void DoRemoveTracks (AudacityProject &project)
 
void DoTrackMute (AudacityProject &project, Track *t, bool exclusive)
 
void DoTrackSolo (AudacityProject &project, Track *t, bool exclusive)
 
void DoRemoveTrack (AudacityProject &project, Track *toRemove)
 
void DoMoveTrack (AudacityProject &project, Track *target, MoveChoice choice)
 Move a track up, down, to top or to bottom. More...
 

Enumeration Type Documentation

◆ MoveChoice

Enumerator
OnMoveUpID 
OnMoveDownID 
OnMoveTopID 
OnMoveBottomID 

Definition at line 19 of file TrackUtilities.h.

Function Documentation

◆ DoMoveTrack()

AUDACITY_DLL_API void TrackUtilities::DoMoveTrack ( AudacityProject project,
Track target,
MoveChoice  choice 
)

Move a track up, down, to top or to bottom.

Definition at line 186 of file TrackUtilities.cpp.

188{
189 auto &tracks = TrackList::Get( project );
190
191 TranslatableString longDesc, shortDesc;
192
193 switch (choice)
194 {
195 case OnMoveTopID:
196 /* i18n-hint: Past tense of 'to move', as in 'moved audio track up'.*/
197 longDesc = XO("Moved '%s' to Top");
198 shortDesc = XO("Move Track to Top");
199
200 // TODO: write TrackList::Rotate to do this in one step and avoid emitting
201 // an event for each swap
202 while (tracks.CanMoveUp(target))
203 tracks.Move(target, true);
204
205 break;
206 case OnMoveBottomID:
207 /* i18n-hint: Past tense of 'to move', as in 'moved audio track up'.*/
208 longDesc = XO("Moved '%s' to Bottom");
209 shortDesc = XO("Move Track to Bottom");
210
211 // TODO: write TrackList::Rotate to do this in one step and avoid emitting
212 // an event for each swap
213 while (tracks.CanMoveDown(target))
214 tracks.Move(target, false);
215
216 break;
217 default:
218 bool bUp = (OnMoveUpID == choice);
219
220 tracks.Move(target, bUp);
221 longDesc =
222 /* i18n-hint: Past tense of 'to move', as in 'moved audio track up'.*/
223 bUp? XO("Moved '%s' Up")
224 : XO("Moved '%s' Down");
225 shortDesc =
226 /* i18n-hint: Past tense of 'to move', as in 'moved audio track up'.*/
227 bUp? XO("Move Track Up")
228 : XO("Move Track Down");
229
230 }
231
232 longDesc.Format(target->GetName());
233
234 ProjectHistory::Get( project ).PushState(longDesc, shortDesc);
235}
XO("Cut/Copy/Paste")
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
const wxString & GetName() const
Name is always the same for all channels of a group.
Definition: Track.cpp:68
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:385
Holds a msgid for the translation catalog; may also bind format arguments.
TranslatableString & Format(Args &&...args) &
Capture variadic format arguments (by copy) when there is no plural.

References TranslatableString::Format(), ProjectHistory::Get(), TrackList::Get(), Track::GetName(), OnMoveBottomID, OnMoveTopID, OnMoveUpID, ProjectHistory::PushState(), and XO().

Referenced by TrackMenuTable::OnMoveTrack(), anonymous_namespace{TrackMenus.cpp}::OnTrackMoveBottom(), anonymous_namespace{TrackMenus.cpp}::OnTrackMoveDown(), anonymous_namespace{TrackMenus.cpp}::OnTrackMoveTop(), and anonymous_namespace{TrackMenus.cpp}::OnTrackMoveUp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoRemoveTrack()

AUDACITY_DLL_API void TrackUtilities::DoRemoveTrack ( AudacityProject project,
Track toRemove 
)

Definition at line 151 of file TrackUtilities.cpp.

152{
153 auto &tracks = TrackList::Get( project );
154 auto &trackFocus = TrackFocus::Get( project );
155 auto &window = ProjectWindow::Get( project );
156
157 // If it was focused, then NEW focus is the next or, if
158 // unavailable, the previous track. (The NEW focus is set
159 // after the track has been removed.)
160 bool toRemoveWasFocused = trackFocus.Get() == toRemove;
161 Track* newFocus{};
162 if (toRemoveWasFocused) {
163 auto iterNext = tracks.FindLeader(toRemove), iterPrev = iterNext;
164 newFocus = *++iterNext;
165 if (!newFocus) {
166 newFocus = *--iterPrev;
167 }
168 }
169
170 wxString name = toRemove->GetName();
171
172 auto channels = TrackList::Channels(toRemove);
173 // Be careful to post-increment over positions that get erased!
174 auto &iter = channels.first;
175 while (iter != channels.end())
176 tracks.Remove( * iter++ );
177
178 if (toRemoveWasFocused)
179 trackFocus.Set( newFocus );
180
182 XO("Removed track '%s.'").Format( name ),
183 XO("Track Remove"));
184}
const TranslatableString name
Definition: Distortion.cpp:76
Abstract base class used in importing a file.
static ProjectWindow & Get(AudacityProject &project)
Track * Get()
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:162
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1417

References TrackList::Channels(), TrackFocus::Get(), ProjectHistory::Get(), TrackList::Get(), ProjectWindow::Get(), Track::GetName(), name, ProjectHistory::PushState(), and XO().

Referenced by CloseButtonHandle::CommitChanges(), and anonymous_namespace{TrackMenus.cpp}::OnTrackClose().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoRemoveTracks()

AUDACITY_DLL_API void TrackUtilities::DoRemoveTracks ( AudacityProject project)

Definition at line 21 of file TrackUtilities.cpp.

22{
23 auto &tracks = TrackList::Get( project );
24 auto &trackPanel = TrackPanel::Get( project );
25
26 std::vector<Track*> toRemove;
27 for (auto track : tracks.Selected())
28 toRemove.push_back(track);
29
30 // Capture the track preceding the first removed track
31 Track *f{};
32 if (!toRemove.empty()) {
33 auto found = tracks.Find(toRemove[0]);
34 f = *--found;
35 }
36
37 for (auto track : toRemove)
38 tracks.Remove(track);
39
40 if (!f)
41 // try to use the last track
42 f = *tracks.Any().rbegin();
43 if (f) {
44 // Try to use the first track after the removal
45 auto found = tracks.FindLeader(f);
46 auto t = *++found;
47 if (t)
48 f = t;
49 }
50
51 // If we actually have something left, then set focus and make sure it's seen
52 if (f) {
53 TrackFocus::Get(project).Set(f);
54 f->EnsureVisible();
55 }
56
57 ProjectHistory::Get( project )
58 .PushState(XO("Removed audio track(s)"), XO("Remove Track"));
59
60 trackPanel.UpdateViewIfNoTracks();
61}
Subclass * Find(const RegisteredFactory &key)
Get a (bare) pointer to an attachment, or null, down-cast it to Subclass *; will not create on demand...
Definition: ClientData.h:333
void EnsureVisible(bool modifyState=false)
Definition: Track.cpp:98
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:231

References Track::EnsureVisible(), ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >::Find(), TrackFocus::Get(), ProjectHistory::Get(), TrackList::Get(), TrackPanel::Get(), ProjectHistory::PushState(), and XO().

Referenced by anonymous_namespace{TrackMenus.cpp}::OnRemoveTracks(), and ProjectManager::ResetProjectToEmpty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoTrackMute()

AUDACITY_DLL_API void TrackUtilities::DoTrackMute ( AudacityProject project,
Track t,
bool  exclusive 
)

Definition at line 63 of file TrackUtilities.cpp.

64{
65 auto &tracks = TrackList::Get( project );
66
67 // Whatever t is, replace with lead channel
68 t = *tracks.FindLeader(t);
69
70 // "exclusive" mute means mute the chosen track and unmute all others.
71 if (exclusive) {
72 for (auto leader : tracks.Leaders<PlayableTrack>()) {
73 bool chosen = (t == leader);
74 leader->SetMute(chosen);
75 leader->SetSolo(false);
76 }
77 }
78 else {
79 // Normal click toggles this track.
80 auto pt = dynamic_cast<PlayableTrack *>( t );
81 if (!pt)
82 return;
83
84 bool wasMute = pt->GetMute();
85 pt->SetMute(!wasMute);
86
87 if (auto value = TracksBehaviorsSolo.ReadEnum();
88 value == SoloBehaviorSimple || value == SoloBehaviorNone)
89 {
90 // We also set a solo indicator if we have just one track / stereo pair playing.
91 // in a group of more than one playable tracks.
92 // otherwise clear solo on everything.
93
94 auto range = tracks.Leaders<PlayableTrack>();
95 auto nPlayableTracks = range.size();
96 auto nPlaying = (range - &PlayableTrack::GetMute).size();
97 for (auto track : range)
98 track->SetSolo((nPlaying == 1) &&
99 (nPlayableTracks > 1) && !track->GetMute());
100 }
101 }
102 ProjectHistory::Get( project ).ModifyState(true);
103
104 TrackFocus::Get( project ).UpdateAccessibility();
105}
EnumSetting< SoloBehavior > TracksBehaviorsSolo
@ SoloBehaviorSimple
Definition: PlayableTrack.h:70
@ SoloBehaviorNone
Definition: PlayableTrack.h:72
size_t size() const
How many attachment pointers are in the Site.
Definition: ClientData.h:251
AudioTrack subclass that can also be audibly replayed by the program.
Definition: PlayableTrack.h:40
bool GetMute() const
Definition: PlayableTrack.h:47
void ModifyState(bool bWantsAutoSave)

References TrackFocus::Get(), ProjectHistory::Get(), TrackList::Get(), PlayableTrack::GetMute(), ProjectHistory::ModifyState(), size, ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >::size(), SoloBehaviorNone, SoloBehaviorSimple, and TracksBehaviorsSolo.

Referenced by MuteButtonHandle::CommitChanges(), MixerTrackCluster::OnButton_Mute(), and anonymous_namespace{TrackMenus.cpp}::OnTrackMute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoTrackSolo()

AUDACITY_DLL_API void TrackUtilities::DoTrackSolo ( AudacityProject project,
Track t,
bool  exclusive 
)

Definition at line 107 of file TrackUtilities.cpp.

108{
109 auto &tracks = TrackList::Get( project );
110
111 // Whatever t is, replace with lead channel
112 t = *tracks.FindLeader(t);
113
114 const auto pt = dynamic_cast<PlayableTrack *>( t );
115 if (!pt)
116 return;
117 bool bWasSolo = pt->GetSolo();
118
119 bool simple = (TracksBehaviorsSolo.ReadEnum() == SoloBehaviorSimple);
120 bool bSoloMultiple = !simple ^ exclusive;
121
122 // Standard and Simple solo have opposite defaults:
123 // Standard - Behaves as individual buttons, shift=radio buttons
124 // Simple - Behaves as radio buttons, shift=individual
125 // In addition, Simple solo will mute/unmute tracks
126 // when in standard radio button mode.
127 if (bSoloMultiple)
128 pt->SetSolo(!bWasSolo);
129 else {
130 // Normal click solo this track only, mute everything else.
131 // OR unmute and unsolo everything.
132 for (auto leader : tracks.Leaders<PlayableTrack>()) {
133 bool chosen = (t == leader);
134 if (chosen) {
135 leader->SetSolo(!bWasSolo);
136 if (simple)
137 leader->SetMute(false);
138 }
139 else {
140 leader->SetSolo(false);
141 if (simple)
142 leader->SetMute(!bWasSolo);
143 }
144 }
145 }
146 ProjectHistory::Get( project ).ModifyState(true);
147
148 TrackFocus::Get( project ).UpdateAccessibility();
149}
bool GetSolo() const
Definition: PlayableTrack.h:48

References TrackFocus::Get(), ProjectHistory::Get(), TrackList::Get(), PlayableTrack::GetSolo(), ProjectHistory::ModifyState(), SoloBehaviorSimple, and TracksBehaviorsSolo.

Referenced by SoloButtonHandle::CommitChanges(), MixerTrackCluster::OnButton_Solo(), and anonymous_namespace{TrackMenus.cpp}::OnTrackSolo().

Here is the call graph for this function:
Here is the caller graph for this function: