Audacity 3.2.0
Enumerations | Functions
TrackUtilities Namespace Reference

Enumerations

enum  MoveChoice { OnMoveUpID , OnMoveDownID , OnMoveTopID , OnMoveBottomID }
 

Functions

AUDACITY_DLL_API void DoMoveTrack (AudacityProject &project, Track &target, MoveChoice choice)
 Move a track up, down, to top or to bottom. More...
 
AUDACITY_DLL_API void DoTrackMute (AudacityProject &project, Track &track, bool exclusive)
 "exclusive" mute means mute the chosen track and unmute all others. More...
 
AUDACITY_DLL_API void DoTrackSolo (AudacityProject &project, Track &track, bool exclusive)
 
AUDACITY_DLL_API void DoRemoveTrack (AudacityProject &project, Track &toRemove)
 
AUDACITY_DLL_API void DoRemoveTracks (AudacityProject &)
 

Enumeration Type Documentation

◆ MoveChoice

Enumerator
OnMoveUpID 
OnMoveDownID 
OnMoveTopID 
OnMoveBottomID 

Definition at line 19 of file TrackUtilities.h.

Function Documentation

◆ DoMoveTrack()

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

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

Definition at line 175 of file TrackUtilities.cpp.

177{
178 auto &tracks = TrackList::Get( project );
179
180 TranslatableString longDesc, shortDesc;
181
182 switch (choice)
183 {
184 case OnMoveTopID:
185 /* i18n-hint: Past tense of 'to move', as in 'moved audio track up'.*/
186 longDesc = XO("Moved '%s' to Top");
187 shortDesc = XO("Move Track to Top");
188
189 // TODO: write TrackList::Rotate to do this in one step and avoid emitting
190 // an event for each swap
191 while (tracks.CanMoveUp(target))
192 tracks.Move(target, true);
193
194 break;
195 case OnMoveBottomID:
196 /* i18n-hint: Past tense of 'to move', as in 'moved audio track up'.*/
197 longDesc = XO("Moved '%s' to Bottom");
198 shortDesc = XO("Move Track to Bottom");
199
200 // TODO: write TrackList::Rotate to do this in one step and avoid emitting
201 // an event for each swap
202 while (tracks.CanMoveDown(target))
203 tracks.Move(target, false);
204
205 break;
206 default:
207 bool bUp = (OnMoveUpID == choice);
208
209 tracks.Move(target, bUp);
210 longDesc =
211 /* i18n-hint: Past tense of 'to move', as in 'moved audio track up'.*/
212 bUp? XO("Moved '%s' Up")
213 : XO("Moved '%s' Down");
214 shortDesc =
215 /* i18n-hint: Past tense of 'to move', as in 'moved audio track up'.*/
216 bUp? XO("Move Track Up")
217 : XO("Move Track Down");
218
219 }
220
221 longDesc.Format(target.GetName());
222
223 ProjectHistory::Get( project ).PushState(longDesc, shortDesc);
224}
XO("Cut/Copy/Paste")
const auto tracks
const auto project
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:64
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
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, project, ProjectHistory::PushState(), tracks, 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()

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

Definition at line 143 of file TrackUtilities.cpp.

144{
146 auto &trackFocus = TrackFocus::Get(project);
147
148 const auto iter = tracks.Find(&toRemove);
149
150 // If it was focused, then NEW focus is the next or, if
151 // unavailable, the previous track. (The NEW focus is set
152 // after the track has been removed.)
153 bool toRemoveWasFocused = trackFocus.Get() == *iter;
154 std::optional<decltype(iter)> newFocus{};
155 if (toRemoveWasFocused) {
156 auto iterNext = iter,
157 iterPrev = iter;
158 newFocus.emplace(++iterNext);
159 if (!**newFocus)
160 newFocus.emplace(--iterPrev);
161 }
162
163 wxString name = toRemove.GetName();
164
165 tracks.Remove(**iter);
166
167 if (toRemoveWasFocused)
168 trackFocus.Set(**newFocus);
169
171 XO("Removed track '%s'.").Format(name),
172 XO("Track Remove"));
173}
const TranslatableString name
Definition: Distortion.cpp:76
Abstract base class used in importing a file.
Track * Get()
Definition: TrackFocus.cpp:156

References TrackFocus::Get(), ProjectHistory::Get(), TrackList::Get(), Track::GetName(), name, project, ProjectHistory::PushState(), tracks, 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()

void TrackUtilities::DoRemoveTracks ( AudacityProject project)

Definition at line 19 of file TrackUtilities.cpp.

19 {
21 auto &trackPanel = TrackPanel::Get(project);
22
23 auto range = tracks.Selected();
24 using Iter = decltype(range.begin());
25
26 // Find the track preceding the first removed track
27 std::optional<Iter> focus;
28 if (!range.empty()) {
29 auto iter = tracks.Find(*range.begin());
30 // TrackIter allows decrement even of begin iterators
31 focus.emplace(--iter);
32 }
33
34 while (!range.empty())
35 tracks.Remove(**range.first++);
36
37 if (!(focus.has_value() && **focus))
38 // try to use the last track
39 focus.emplace(tracks.end().advance(-1));
40 assert(focus);
41 Track *f = **focus;
42 // Try to use the first track after the removal
43 // TrackIter allows increment even of end iterators
44 if (const auto nextF = * ++ *focus)
45 f = nextF;
46
47 // If we actually have something left, then set focus and make sure it's seen
48 if (f) {
51 }
52
54 .PushState(XO("Removed audio track(s)"), XO("Remove Track"));
55
56 trackPanel.UpdateViewIfNoTracks();
57}
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:234
void ShowTrack(const Track &track)
Definition: Viewport.cpp:456
static Viewport & Get(AudacityProject &project)
Definition: Viewport.cpp:33

References TrackFocus::Get(), ProjectHistory::Get(), TrackList::Get(), Viewport::Get(), TrackPanel::Get(), project, ProjectHistory::PushState(), Viewport::ShowTrack(), tracks, 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()

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

"exclusive" mute means mute the chosen track and unmute all others.

Definition at line 59 of file TrackUtilities.cpp.

61{
63
64 // "exclusive" mute means mute the chosen track and unmute all others.
65 if (exclusive) {
66 for (auto playable : tracks.Any<PlayableTrack>()) {
67 bool chosen = (&track == playable);
68 playable->SetMute(chosen);
69 playable->SetSolo(false);
70 }
71 }
72 else {
73 // Normal click toggles this track.
74 auto pt = dynamic_cast<PlayableTrack *>(&track);
75 if (!pt)
76 return;
77
78 bool wasMute = pt->GetMute();
79 pt->SetMute(!wasMute);
80
81 if (auto value = TracksBehaviorsSolo.ReadEnum();
82 value == SoloBehaviorSimple)
83 {
84 // We also set a solo indicator if we have just one track / stereo pair playing.
85 // in a group of more than one playable tracks.
86 // otherwise clear solo on everything.
87
88 auto range = tracks.Any<PlayableTrack>();
89 auto nPlayableTracks = range.size();
90 auto nPlaying = (range - &PlayableTrack::GetMute).size();
91 for (auto track : range)
92 track->SetSolo((nPlaying == 1) &&
93 (nPlayableTracks > 1) && !track->GetMute());
94 }
95 }
97
98 TrackFocus::Get( project ).UpdateAccessibility();
99}
EnumSetting< SoloBehavior > TracksBehaviorsSolo
@ SoloBehaviorSimple
Definition: PlayableTrack.h:70
size_t size() const
How many attachment pointers are in the Site.
Definition: ClientData.h:260
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(), project, ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >::size(), size, SoloBehaviorSimple, tracks, 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()

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

Type of solo (standard or simple) follows the set preference, unless exclusive == true, which causes the opposite behavior.

Definition at line 101 of file TrackUtilities.cpp.

103{
104 auto &tracks = TrackList::Get( project );
105
106 const auto pt = dynamic_cast<PlayableTrack *>(&track);
107 if (!pt)
108 return;
109 bool bWasSolo = pt->GetSolo();
110
111 bool simple = (TracksBehaviorsSolo.ReadEnum() == SoloBehaviorSimple);
112 bool bSoloMultiple = !simple ^ exclusive;
113
114 // Standard and Simple solo have opposite defaults:
115 // Standard - Behaves as individual buttons, shift=radio buttons
116 // Simple - Behaves as radio buttons, shift=individual
117 // In addition, Simple solo will mute/unmute tracks
118 // when in standard radio button mode.
119 if (bSoloMultiple)
120 pt->SetSolo(!bWasSolo);
121 else {
122 // Normal click solo this track only, mute everything else.
123 // OR unmute and unsolo everything.
124 for (auto playable : tracks.Any<PlayableTrack>()) {
125 bool chosen = (&track == playable);
126 if (chosen) {
127 playable->SetSolo(!bWasSolo);
128 if (simple)
129 playable->SetMute(false);
130 }
131 else {
132 playable->SetSolo(false);
133 if (simple)
134 playable->SetMute(!bWasSolo);
135 }
136 }
137 }
139
140 TrackFocus::Get( project ).UpdateAccessibility();
141}
bool GetSolo() const
Definition: PlayableTrack.h:48

References TrackFocus::Get(), ProjectHistory::Get(), TrackList::Get(), PlayableTrack::GetSolo(), ProjectHistory::ModifyState(), project, SoloBehaviorSimple, tracks, 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: