Audacity 3.2.0
Typedefs | Functions | Variables
anonymous_namespace{LabelMenus.cpp} Namespace Reference

Namespace for functions for Edit Label submenu. More...

Typedefs

using EditFunction = std::function< void(Track &track, double, double)>
 
using EditFunctionWithProgress = std::function< void(Track &track, double, double, ProgressReporter)>
 
using EditDestFunction = std::function< Track::Holder(Track &, double, double)>
 

Functions

const ReservedCommandFlagLabelsSelectedFlag ()
 
int DoAddLabel (AudacityProject &project, const SelectedRegion &region, bool preserveFocus=false)
 
void GetRegionsByLabel (const TrackList &tracks, const SelectedRegion &selectedRegion, Regions &regions)
 
void EditByLabel (AudacityProject &project, TrackList &tracks, const SelectedRegion &selectedRegion, EditFunctionWithProgress action, ProgressReporter progress)
 
void EditByLabel (AudacityProject &project, TrackList &tracks, const SelectedRegion &selectedRegion, EditFunction action)
 
void EditClipboardByLabel (AudacityProject &project, TrackList &tracks, const SelectedRegion &selectedRegion, EditDestFunction action)
 
void OnEditLabels (const CommandContext &context)
 
void OnAddLabel (const CommandContext &context)
 
void OnAddLabelPlaying (const CommandContext &context)
 
void OnPasteNewLabel (const CommandContext &context)
 
void OnToggleTypeToCreateLabel (const CommandContext &WXUNUSED(context))
 
void OnCutLabels (const CommandContext &context)
 
void OnDeleteLabels (const CommandContext &context)
 
void OnSplitCutLabels (const CommandContext &context)
 
void OnSplitDeleteLabels (const CommandContext &context)
 
void OnSilenceLabels (const CommandContext &context)
 
void OnCopyLabels (const CommandContext &context)
 
void OnSplitLabels (const CommandContext &context)
 
void OnJoinLabels (const CommandContext &context)
 
void OnDisjoinLabels (const CommandContext &context)
 
void OnNewLabelTrack (const CommandContext &context)
 
auto LabelEditMenus ()
 

Variables

AttachedItem sAttachment1
 
AttachedItem sAttachment2
 

Detailed Description

Namespace for functions for Edit Label submenu.

Typedef Documentation

◆ EditDestFunction

using anonymous_namespace{LabelMenus.cpp}::EditDestFunction = typedef std::function<Track::Holder(Track &, double, double)>

Definition at line 221 of file LabelMenus.cpp.

◆ EditFunction

using anonymous_namespace{LabelMenus.cpp}::EditFunction = typedef std::function<void(Track& track, double, double)>

Definition at line 163 of file LabelMenus.cpp.

◆ EditFunctionWithProgress

using anonymous_namespace{LabelMenus.cpp}::EditFunctionWithProgress = typedef std::function<void(Track& track, double, double, ProgressReporter)>

Definition at line 164 of file LabelMenus.cpp.

Function Documentation

◆ DoAddLabel()

int anonymous_namespace{LabelMenus.cpp}::DoAddLabel ( AudacityProject project,
const SelectedRegion region,
bool  preserveFocus = false 
)

Definition at line 56 of file LabelMenus.cpp.

59{
60 auto &tracks = TrackList::Get( project );
61 auto &trackFocus = TrackFocus::Get( project );
62 auto &trackPanel = TrackPanel::Get( project );
63
64 wxString title; // of label
65
66 bool useDialog;
67 gPrefs->Read(wxT("/GUI/DialogForNameNewLabel"), &useDialog, false);
68 if (useDialog) {
70 project, region, wxEmptyString, title) == wxID_CANCEL)
71 return -1; // index
72 }
73
74 // If the focused track is a label track, use that
75 const auto pFocusedTrack = trackFocus.Get();
76
77 // Look for a label track at or after the focused track
78 auto begin = tracks.begin();
79 auto iter = pFocusedTrack
80 ? tracks.Find(pFocusedTrack)
81 : begin;
82 auto lt = * iter.Filter<LabelTrack>();
83
84 // If none found, start a NEW label track and use it
85 if (!lt)
87
88// LLL: Commented as it seemed a little forceful to remove users
89// selection when adding the label. This does not happen if
90// you select several tracks and the last one of those is a
91// label track...typing a label will not clear the selections.
92//
93// SelectNone();
94 lt->SetSelected(true);
95
96 int index;
97 if (useDialog) {
98 index = lt->AddLabel(region, title);
99 }
100 else {
101 int focusTrackNumber = -1;
102 if (pFocusedTrack && preserveFocus) {
103 // Must remember the track to re-focus after finishing a label edit.
104 // do NOT identify it by a pointer, which might dangle! Identify
105 // by position.
106 focusTrackNumber = std::distance(begin, iter);
107 }
108 index =
109 LabelTrackView::Get( *lt ).AddLabel(region, title, focusTrackNumber);
110 }
111
113 .PushState(XO("Added label"), XO("Label"));
114
115 if (!useDialog) {
116 TrackFocus::Get(project).Set(lt);
118 }
119 trackPanel.SetFocus();
120
121 return index;
122}
wxT("CloseDown"))
XO("Cut/Copy/Paste")
static const auto title
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
const auto tracks
const auto project
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:95
static LabelTrack * Create(TrackList &trackList, const wxString &name)
Create a new LabelTrack with specified name and append it to the trackList.
Definition: LabelTrack.cpp:95
static LabelTrackView & Get(LabelTrack &)
static int DialogForLabelName(AudacityProject &project, const SelectedRegion &region, const wxString &initialValue, wxString &value)
int AddLabel(const SelectedRegion &region, const wxString &title={}, int restoreFocus=-1)
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
Track * Get()
Definition: TrackFocus.cpp:156
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
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
virtual bool Read(const wxString &key, bool *value) const =0
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101

References LabelTrackView::AddLabel(), details::begin(), LabelTrack::Create(), LabelTrackView::DialogForLabelName(), TrackFocus::Get(), ProjectHistory::Get(), TrackList::Get(), Viewport::Get(), TrackPanel::Get(), LabelTrackView::Get(), gPrefs, project, ProjectHistory::PushState(), audacity::BasicSettings::Read(), Viewport::ShowTrack(), title, tracks, wxT(), and XO().

Referenced by OnAddLabel(), and OnAddLabelPlaying().

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

◆ EditByLabel() [1/2]

void anonymous_namespace{LabelMenus.cpp}::EditByLabel ( AudacityProject project,
TrackList tracks,
const SelectedRegion selectedRegion,
EditFunction  action 
)

Definition at line 209 of file LabelMenus.cpp.

212{
214 project, tracks, selectedRegion,
215 [&](Track& track, double t0, double t1, ProgressReporter) {
216 action(track, t0, t1);
217 },
218 nullptr);
219}
std::function< void(double)> ProgressReporter
Definition: Track.h:48
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
void EditByLabel(AudacityProject &project, TrackList &tracks, const SelectedRegion &selectedRegion, EditFunction action)
Definition: LabelMenus.cpp:209

References EditByLabel(), project, and tracks.

Referenced by EditByLabel(), OnCutLabels(), OnDeleteLabels(), OnDisjoinLabels(), OnJoinLabels(), OnSilenceLabels(), OnSplitDeleteLabels(), and OnSplitLabels().

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

◆ EditByLabel() [2/2]

void anonymous_namespace{LabelMenus.cpp}::EditByLabel ( AudacityProject project,
TrackList tracks,
const SelectedRegion selectedRegion,
EditFunctionWithProgress  action,
ProgressReporter  progress 
)

Definition at line 174 of file LabelMenus.cpp.

178{
179 Regions regions;
180
181 GetRegionsByLabel(tracks, selectedRegion, regions);
182 if (regions.empty())
183 return;
184
185 const bool notLocked = (!SyncLockState::Get(project).IsSyncLocked() &&
186 (tracks.Selected<PlayableTrack>()).empty());
187
188 const auto tracksToEdit = tracks.Any<Track>() + [&](const auto pTrack) {
189 return SyncLock::IsSyncLockSelected(*pTrack) ||
190 (notLocked && dynamic_cast<const PlayableTrack*>(pTrack) != nullptr);
191 };
192
194 tracksToEdit.begin(), tracksToEdit.end(),
195 [&](Track* aTrack, const ProgressReporter& child) {
196 // Apply action on tracks starting from labeled regions in the end.
197 // This is to correctly perform actions like 'Delete' which collapse
198 // the track area.
199 BasicUI::SplitProgress(
200 regions.rbegin(), regions.rend(),
201 [&](const Region& region, const ProgressReporter& grandChild) {
202 action(*aTrack, region.start, region.end, grandChild);
203 },
204 child);
205 },
206 progress);
207}
WaveTrack::Regions Regions
Definition: LabelMenus.cpp:26
AudioTrack subclass that can also be audibly replayed by the program.
Definition: PlayableTrack.h:40
static bool IsSyncLockSelected(const Track &track)
Definition: SyncLock.cpp:80
bool IsSyncLocked() const
Definition: SyncLock.cpp:44
static SyncLockState & Get(AudacityProject &project)
Definition: SyncLock.cpp:27
void SplitProgress(ItType first, ItType last, FnType action, ProgressReporter parent)
Helper for the update of a task's progress bar when this task is made of a range's subtasks.
Definition: BasicUI.h:331
void GetRegionsByLabel(const TrackList &tracks, const SelectedRegion &selectedRegion, Regions &regions)
Definition: LabelMenus.cpp:126

References SyncLockState::Get(), GetRegionsByLabel(), SyncLockState::IsSyncLocked(), SyncLock::IsSyncLockSelected(), project, BasicUI::SplitProgress(), and tracks.

Here is the call graph for this function:

◆ EditClipboardByLabel()

void anonymous_namespace{LabelMenus.cpp}::EditClipboardByLabel ( AudacityProject project,
TrackList tracks,
const SelectedRegion selectedRegion,
EditDestFunction  action 
)

Definition at line 230 of file LabelMenus.cpp.

233{
234 Regions regions;
235
236 GetRegionsByLabel(tracks, selectedRegion, regions);
237 if (regions.empty())
238 return;
239
240 const bool notLocked = (!SyncLockState::Get(project).IsSyncLocked() &&
241 (tracks.Selected<PlayableTrack>()).empty());
242
243 auto &clipboard = Clipboard::Get();
244 clipboard.Clear();
245
246 auto pNewClipboard = TrackList::Create(nullptr);
247 auto &newClipboard = *pNewClipboard;
248
249 //Apply action on wavetracks starting from
250 //labeled regions in the end. This is to correctly perform
251 //actions like 'Cut' which collapse the track area.
252
253 for (auto t : tracks) {
254 const bool playable = dynamic_cast<const PlayableTrack *>(t) != nullptr;
255 if (SyncLock::IsSyncLockSelected(*t) || (notLocked && playable)) {
256 // These tracks accumulate the needed clips, right to left:
257 Track::Holder merged;
258 for (size_t i = regions.size(); i--;) {
259 const Region &region = regions.at(i);
260 if (auto dest = action(*t, region.start, region.end)) {
261 if (!merged)
262 merged = dest;
263 else {
264 // Paste to the beginning; unless this is the first region,
265 // offset the track to account for time between the regions
266 if (i + 1 < regions.size())
267 merged->ShiftBy(
268 regions.at(i + 1).start - region.end);
269
270 // dest may have a placeholder clip at the end that is
271 // removed when pasting, which is okay because we proceed
272 // right to left. Any placeholder already in merged is kept.
273 // Only the rightmost placeholder is important in the final
274 // result.
275 merged->Paste(0.0, *dest);
276 }
277 }
278 else
279 // nothing copied but there is a 'region', so the 'region' must
280 // be a 'point label' so offset
281 if (i + 1 < regions.size() && merged)
282 merged->ShiftBy(regions.at(i + 1).start - region.end);
283 }
284 if (merged)
285 newClipboard.Add(merged);
286 }
287 }
288
289 // Survived possibility of exceptions. Commit changes to the clipboard now.
290 clipboard.Assign( std::move( newClipboard ),
291 regions.front().start, regions.back().end, project.shared_from_this() );
292}
static Clipboard & Get()
Definition: Clipboard.cpp:28
std::shared_ptr< Track > Holder
Definition: Track.h:202
static TrackListHolder Create(AudacityProject *pOwner)
Definition: Track.cpp:330
Structure to hold region of a wavetrack and a comparison function for sortability.
Definition: WaveTrack.h:217

References TrackList::Create(), WaveTrack::Region::end, Clipboard::Get(), SyncLockState::Get(), GetRegionsByLabel(), SyncLockState::IsSyncLocked(), SyncLock::IsSyncLockSelected(), project, WaveTrack::Region::start, and tracks.

Referenced by OnCopyLabels(), OnCutLabels(), and OnSplitCutLabels().

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

◆ GetRegionsByLabel()

void anonymous_namespace{LabelMenus.cpp}::GetRegionsByLabel ( const TrackList tracks,
const SelectedRegion selectedRegion,
Regions regions 
)

Definition at line 126 of file LabelMenus.cpp.

129{
130 //determine labeled regions
131 for (auto lt : tracks.Selected< const LabelTrack >()) {
132 for (int i = 0; i < lt->GetNumLabels(); i++)
133 {
134 const LabelStruct *ls = lt->GetLabel(i);
135 if (ls->selectedRegion.t0() >= selectedRegion.t0() &&
136 ls->selectedRegion.t1() <= selectedRegion.t1())
137 regions.push_back(Region(ls->getT0(), ls->getT1()));
138 }
139 }
140
141 //anything to do ?
142 if( regions.size() == 0 )
143 return;
144
145 //sort and remove unnecessary regions
146 std::sort(regions.begin(), regions.end());
147 unsigned int selected = 1;
148 while( selected < regions.size() )
149 {
150 const Region &cur = regions.at( selected );
151 Region &last = regions.at( selected - 1 );
152 if( cur.start < last.end )
153 {
154 if( cur.end > last.end )
155 last.end = cur.end;
156 regions.erase( regions.begin() + selected );
157 }
158 else
159 ++selected;
160 }
161}
WaveTrack::Region Region
Definition: LabelMenus.cpp:25
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:37
double getT1() const
Definition: LabelTrack.h:48
double getT0() const
Definition: LabelTrack.h:47
SelectedRegion selectedRegion
Definition: LabelTrack.h:77
double t1() const
double t0() const

References WaveTrack::Region::end, LabelStruct::getT0(), LabelStruct::getT1(), LabelStruct::selectedRegion, WaveTrack::Region::start, SelectedRegion::t0(), SelectedRegion::t1(), and tracks.

Referenced by EditByLabel(), and EditClipboardByLabel().

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

◆ LabelEditMenus()

auto anonymous_namespace{LabelMenus.cpp}::LabelEditMenus ( )

Definition at line 670 of file LabelMenus.cpp.

671{
672 using namespace MenuRegistry;
673
674 static const auto NotBusyLabelsAndWaveFlags =
677
678 // Returns TWO menus.
679
680 static auto menus = std::shared_ptr{
681 Items( wxT("LabelEditMenus"),
682
683 Menu( wxT("Labels"), XXO("&Labels"),
684 Section( "",
685 Command( wxT("EditLabels"), XXO("Label &Editor"), OnEditLabels,
687 ),
688
689 Section( "",
690 Command( wxT("AddLabel"), XXO("Add Label at &Selection"),
691 OnAddLabel, AlwaysEnabledFlag, wxT("Ctrl+B") ),
692 Command( wxT("AddLabelPlaying"),
693 XXO("Add Label at &Playback Position"),
695 #ifdef __WXMAC__
696 wxT("Ctrl+.")
697 #else
698 wxT("Ctrl+M")
699 #endif
700 ),
701 Command( wxT("PasteNewLabel"), XXO("Paste Te&xt to New Label"),
703 AudioIONotBusyFlag(), wxT("Ctrl+Alt+V") )
704 ),
705
706 Section( "",
707 Command( wxT("TypeToCreateLabel"),
708 XXO("&Typing Creates New Labels"),
710 Options{}.CheckTest(wxT("/GUI/TypeToCreateLabel"), false) )
711 )
712 ), // first menu
713
715
716 Menu( wxT("Labeled"), XXO("La&beled Audio"),
717 Section( "",
718 /* i18n-hint: (verb)*/
719 Command( wxT("CutLabels"), XXO("&Cut"), OnCutLabels,
722 Options{ wxT("Alt+X"), XO("Label Cut") } ),
723 Command( wxT("DeleteLabels"), XXO("&Delete"), OnDeleteLabels,
726 Options{ wxT("Alt+K"), XO("Label Delete") } )
727 ),
728
729 Section( "",
730 /* i18n-hint: (verb) A special way to cut out a piece of audio*/
731 Command( wxT("SplitCutLabels"), XXO("&Split Cut"),
732 OnSplitCutLabels, NotBusyLabelsAndWaveFlags,
733 Options{ wxT("Alt+Shift+X"), XO("Label Split Cut") } ),
734 Command( wxT("SplitDeleteLabels"), XXO("Sp&lit Delete"),
735 OnSplitDeleteLabels, NotBusyLabelsAndWaveFlags,
736 Options{ wxT("Alt+Shift+K"), XO("Label Split Delete") } )
737 ),
738
739 Section( "",
740 Command( wxT("SilenceLabels"), XXO("Silence &Audio"),
741 OnSilenceLabels, NotBusyLabelsAndWaveFlags,
742 Options{ wxT("Alt+L"), XO("Label Silence") } ),
743 /* i18n-hint: (verb)*/
744 Command( wxT("CopyLabels"), XXO("Co&py"), OnCopyLabels,
745 NotBusyLabelsAndWaveFlags,
746 Options{ wxT("Alt+Shift+C"), XO("Label Copy") } )
747 ),
748
749 Section( "",
750 /* i18n-hint: (verb)*/
751 Command( wxT("SplitLabels"), XXO("Spli&t"), OnSplitLabels,
753 Options{ wxT("Alt+I"), XO("Label Split") } ),
754 /* i18n-hint: (verb)*/
755 Command( wxT("JoinLabels"), XXO("&Join"), OnJoinLabels,
756 NotBusyLabelsAndWaveFlags,
757 Options{ wxT("Alt+J"), XO("Label Join") } ),
758 Command( wxT("DisjoinLabels"), XXO("Detac&h at Silences"),
759 OnDisjoinLabels, NotBusyLabelsAndWaveFlags,
760 wxT("Alt+Shift+J") )
761 )
762 ) // second menu
763
764 ) }; // two menus
765 return menus;
766}
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:34
const ReservedCommandFlag & AudioIOBusyFlag()
const ReservedCommandFlag & AudioIONotBusyFlag()
const ReservedCommandFlag & TimeSelectedFlag()
const ReservedCommandFlag & WaveTracksExistFlag()
XXO("&Cut/Copy/Paste Toolbar")
constexpr auto Section
Definition: MenuRegistry.h:436
constexpr auto Items
Definition: MenuRegistry.h:427
constexpr auto Command
Definition: MenuRegistry.h:456
constexpr auto Menu
Items will appear in a main toolbar menu or in a sub-menu.
Definition: MenuRegistry.h:445
void OnAddLabel(const CommandContext &context)
Definition: LabelMenus.cpp:307
void OnSplitDeleteLabels(const CommandContext &context)
Definition: LabelMenus.cpp:500
void OnSplitCutLabels(const CommandContext &context)
Definition: LabelMenus.cpp:468
void OnCopyLabels(const CommandContext &context)
Definition: LabelMenus.cpp:553
void OnSplitLabels(const CommandContext &context)
Definition: LabelMenus.cpp:575
void OnCutLabels(const CommandContext &context)
Definition: LabelMenus.cpp:401
void OnJoinLabels(const CommandContext &context)
Definition: LabelMenus.cpp:597
void OnPasteNewLabel(const CommandContext &context)
Definition: LabelMenus.cpp:330
void OnDeleteLabels(const CommandContext &context)
Definition: LabelMenus.cpp:445
void OnEditLabels(const CommandContext &context)
Definition: LabelMenus.cpp:301
const ReservedCommandFlag & LabelsSelectedFlag()
Definition: LabelMenus.cpp:32
void OnSilenceLabels(const CommandContext &context)
Definition: LabelMenus.cpp:530
void OnDisjoinLabels(const CommandContext &context)
Definition: LabelMenus.cpp:623
void OnAddLabelPlaying(const CommandContext &context)
Definition: LabelMenus.cpp:315
void OnToggleTypeToCreateLabel(const CommandContext &WXUNUSED(context))
Definition: LabelMenus.cpp:392
Options && CheckTest(const CheckFn &fn) &&
Definition: MenuRegistry.h:74

References AlwaysEnabledFlag, AudioIOBusyFlag(), AudioIONotBusyFlag(), MenuRegistry::Options::CheckTest(), MenuRegistry::Command, MenuRegistry::Items, LabelsSelectedFlag(), MenuRegistry::Menu, OnAddLabel(), OnAddLabelPlaying(), OnCopyLabels(), OnCutLabels(), OnDeleteLabels(), OnDisjoinLabels(), OnEditLabels(), OnJoinLabels(), OnPasteNewLabel(), OnSilenceLabels(), OnSplitCutLabels(), OnSplitDeleteLabels(), OnSplitLabels(), OnToggleTypeToCreateLabel(), MenuRegistry::Section, TimeSelectedFlag(), WaveTracksExistFlag(), wxT(), XO(), and XXO().

Here is the call graph for this function:

◆ LabelsSelectedFlag()

const ReservedCommandFlag & anonymous_namespace{LabelMenus.cpp}::LabelsSelectedFlag ( )

Definition at line 32 of file LabelMenus.cpp.

33 [](const AudacityProject &project){
34 // At least one label track selected, having at least one label
35 // completely within the time selection.
36 const auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
37 const auto &test = [&]( const LabelTrack *pTrack ){
38 const auto &labels = pTrack->GetLabels();
39 return std::any_of( labels.begin(), labels.end(),
40 [&](const LabelStruct &label){
41 return
42 label.getT0() >= selectedRegion.t0()
43 &&
44 label.getT1() <= selectedRegion.t1()
45 ;
46 }
47 );
48 };
49 auto range = TrackList::Get(project).Selected<const LabelTrack>()
50 + test;
51 return !range.empty();
52 }
53}; return flag; }
TranslatableString label
Definition: TagsEditor.cpp:165
static std::once_flag flag
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:967
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:215
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235

References flag, ViewInfo::Get(), TrackList::Get(), label, project, TrackList::Selected(), and ViewInfo::selectedRegion.

Referenced by LabelEditMenus().

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

◆ OnAddLabel()

void anonymous_namespace{LabelMenus.cpp}::OnAddLabel ( const CommandContext context)

Definition at line 307 of file LabelMenus.cpp.

308{
309 auto &project = context.project;
310 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
311
312 DoAddLabel(project, selectedRegion);
313}
AudacityProject & project
int DoAddLabel(AudacityProject &project, const SelectedRegion &region, bool preserveFocus=false)
Definition: LabelMenus.cpp:56

References DoAddLabel(), ViewInfo::Get(), CommandContext::project, project, and ViewInfo::selectedRegion.

Referenced by LabelEditMenus().

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

◆ OnAddLabelPlaying()

void anonymous_namespace{LabelMenus.cpp}::OnAddLabelPlaying ( const CommandContext context)

Definition at line 315 of file LabelMenus.cpp.

316{
317 auto &project = context.project;
319
320 auto gAudioIO = AudioIO::Get();
321 if (token > 0 &&
322 gAudioIO->IsStreamActive(token)) {
323 double indicator = gAudioIO->GetStreamTime();
324 DoAddLabel(project, SelectedRegion(indicator, indicator), true);
325 }
326}
static AudioIO * Get()
Definition: AudioIO.cpp:126
int GetAudioIOToken() const
static ProjectAudioIO & Get(AudacityProject &project)
Defines a selected portion of a project.

References DoAddLabel(), AudioIO::Get(), ProjectAudioIO::Get(), ProjectAudioIO::GetAudioIOToken(), CommandContext::project, and project.

Referenced by LabelEditMenus().

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

◆ OnCopyLabels()

void anonymous_namespace{LabelMenus.cpp}::OnCopyLabels ( const CommandContext context)

Definition at line 553 of file LabelMenus.cpp.

554{
555 auto &project = context.project;
557 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
558
559 if (selectedRegion.isPoint())
560 return;
561
562 auto copyfunc = [&](Track &track, double t0, double t1) {
563 Track::Holder result;
564 track.TypeSwitch( [&](WaveTrack &wt) { result = wt.Copy(t0, t1); } );
565 return result;
566 };
567 EditClipboardByLabel(project, tracks, selectedRegion, copyfunc);
568
570 .PushState(XO("Copied labeled audio regions to clipboard"),
571 /* i18n-hint: (verb)*/
572 XO("Copy Labeled Audio"));
573}
R TypeSwitch(const Functions &...functions)
Definition: Track.h:381
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
Create new tracks and don't modify this track.
Definition: WaveTrack.cpp:1073
void EditClipboardByLabel(AudacityProject &project, TrackList &tracks, const SelectedRegion &selectedRegion, EditDestFunction action)
Definition: LabelMenus.cpp:230

References WaveTrack::Copy(), EditClipboardByLabel(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), CommandContext::project, project, ProjectHistory::PushState(), ViewInfo::selectedRegion, tracks, Track::TypeSwitch(), and XO().

Referenced by LabelEditMenus().

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

◆ OnCutLabels()

void anonymous_namespace{LabelMenus.cpp}::OnCutLabels ( const CommandContext context)

Definition at line 401 of file LabelMenus.cpp.

402{
403 auto &project = context.project;
405 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
406
407 if (selectedRegion.isPoint())
408 return;
409
410 // Because of grouping the copy may need to operate on different tracks than
411 // the clear, so we do these actions separately.
412 auto copyfunc = [&](Track &track, double t0, double t1) {
413 Track::Holder result;
414 track.TypeSwitch( [&](WaveTrack &wt) { result = wt.Copy(t0, t1); } );
415 return result;
416 };
417 EditClipboardByLabel(project, tracks, selectedRegion, copyfunc);
418
419 bool enableCutlines = gPrefs->ReadBool(wxT( "/GUI/EnableCutLines"), false);
420 auto editfunc = [&](Track &track, double t0, double t1) {
421 track.TypeSwitch(
422 [&](WaveTrack &t) {
423 if (enableCutlines)
424 t.ClearAndAddCutLine(t0, t1);
425 else
426 t.Clear(t0, t1);
427 },
428 [&](Track &t) {
429 t.Clear(t0, t1);
430 }
431 );
432 };
433 EditByLabel(project, tracks, selectedRegion, editfunc);
434
435 selectedRegion.collapseToT0();
436
438 /* i18n-hint: (verb) past tense. Audacity has just cut the labeled audio
439 regions.*/
440 XO("Cut labeled audio regions to clipboard"),
441 /* i18n-hint: (verb)*/
442 XO("Cut Labeled Audio"));
443}
void ClearAndAddCutLine(double t0, double t1)
Definition: WaveTrack.cpp:1144
void Clear(double t0, double t1) override
Definition: WaveTrack.cpp:1138
bool ReadBool(const wxString &key, bool defaultValue) const

References WaveTrack::Clear(), WaveTrack::ClearAndAddCutLine(), WaveTrack::Copy(), EditByLabel(), EditClipboardByLabel(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), gPrefs, CommandContext::project, project, ProjectHistory::PushState(), audacity::BasicSettings::ReadBool(), ViewInfo::selectedRegion, tracks, Track::TypeSwitch(), wxT(), and XO().

Referenced by LabelEditMenus().

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

◆ OnDeleteLabels()

void anonymous_namespace{LabelMenus.cpp}::OnDeleteLabels ( const CommandContext context)

Definition at line 445 of file LabelMenus.cpp.

446{
447 auto &project = context.project;
449 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
450
451 if (selectedRegion.isPoint())
452 return;
453
454 auto editfunc = [&](Track &track, double t0, double t1) {
455 track.TypeSwitch( [&](Track &t) { t.Clear(t0, t1); } );
456 };
457 EditByLabel(project, tracks, selectedRegion, editfunc);
458
459 selectedRegion.collapseToT0();
460
462 /* i18n-hint: (verb) Audacity has just deleted the labeled audio regions*/
463 XO("Deleted labeled audio regions"),
464 /* i18n-hint: (verb)*/
465 XO("Delete Labeled Audio"));
466}
virtual void Clear(double t0, double t1)=0

References Track::Clear(), EditByLabel(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), CommandContext::project, project, ProjectHistory::PushState(), ViewInfo::selectedRegion, tracks, Track::TypeSwitch(), and XO().

Referenced by LabelEditMenus().

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

◆ OnDisjoinLabels()

void anonymous_namespace{LabelMenus.cpp}::OnDisjoinLabels ( const CommandContext context)

Definition at line 623 of file LabelMenus.cpp.

624{
625 auto &project = context.project;
627 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
628
629 if (selectedRegion.isPoint())
630 return;
631
632 auto editfunc = [&](Track &track, double t0, double t1) {
633 track.TypeSwitch( [&](WaveTrack &t) {
634 wxBusyCursor busy;
635 t.Disjoin(t0, t1);
636 } );
637 };
638 EditByLabel(project, tracks, selectedRegion, editfunc);
639
641 /* i18n-hint: (verb) Audacity has just detached the labeled audio regions.
642 This message appears in history and tells you about something
643 Audacity has done.*/
644 XO("Detached labeled audio regions"),
645 /* i18n-hint: (verb)*/
646 XO("Detach Labeled Audio"));
647}
void Disjoin(double t0, double t1)
Definition: WaveTrack.cpp:2040

References WaveTrack::Disjoin(), EditByLabel(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), CommandContext::project, project, ProjectHistory::PushState(), ViewInfo::selectedRegion, tracks, Track::TypeSwitch(), and XO().

Referenced by LabelEditMenus().

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

◆ OnEditLabels()

void anonymous_namespace{LabelMenus.cpp}::OnEditLabels ( const CommandContext context)

Definition at line 301 of file LabelMenus.cpp.

302{
303 auto &project = context.project;
305}
static void DoEditLabels(AudacityProject &project, LabelTrack *lt=nullptr, int index=-1)

References LabelTrackView::DoEditLabels(), CommandContext::project, and project.

Referenced by LabelEditMenus().

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

◆ OnJoinLabels()

void anonymous_namespace{LabelMenus.cpp}::OnJoinLabels ( const CommandContext context)

Definition at line 597 of file LabelMenus.cpp.

598{
599 auto &project = context.project;
601 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
602
603 if (selectedRegion.isPoint())
604 return;
605
606 auto editfunc = [&](Track& track, double t0, double t1, ProgressReporter reportProgress) {
607 track.TypeSwitch(
608 [&](WaveTrack& t) { t.Join(t0, t1, std::move(reportProgress)); });
609 };
611 [&](ProgressReporter progress) {
612 EditByLabel(project, tracks, selectedRegion, editfunc, progress);
613 });
614
616 /* i18n-hint: (verb) Audacity has just joined the labeled audio (points or
617 regions) */
618 XO("Joined labeled audio (points or regions)"),
619 /* i18n-hint: (verb) */
620 XO("Join Labeled Audio"));
621}
void Join(double t0, double t1, const ProgressReporter &reportProgress)
Definition: WaveTrack.cpp:2127
WAVE_TRACK_API void WithClipRenderingProgress(std::function< void(const ProgressReporter &)> action, TranslatableString title=defaultStretchRenderingTitle)

References EditByLabel(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), WaveTrack::Join(), CommandContext::project, project, ProjectHistory::PushState(), ViewInfo::selectedRegion, tracks, Track::TypeSwitch(), TimeStretching::WithClipRenderingProgress(), and XO().

Referenced by LabelEditMenus().

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

◆ OnNewLabelTrack()

void anonymous_namespace{LabelMenus.cpp}::OnNewLabelTrack ( const CommandContext context)

Definition at line 649 of file LabelMenus.cpp.

650{
651 auto &project = context.project;
652 auto &tracks = TrackList::Get( project );
653
654 auto track = LabelTrack::Create(tracks);
655
657
658 track->SetSelected(true);
659
661 .PushState(XO("Created new label track"), XO("New Track"));
662
663 TrackFocus::Get(project).Set(track);
665}
void SelectNone(AudacityProject &project)

References LabelTrack::Create(), TrackFocus::Get(), ProjectHistory::Get(), TrackList::Get(), Viewport::Get(), CommandContext::project, project, ProjectHistory::PushState(), SelectUtilities::SelectNone(), Viewport::ShowTrack(), tracks, and XO().

Here is the call graph for this function:

◆ OnPasteNewLabel()

void anonymous_namespace{LabelMenus.cpp}::OnPasteNewLabel ( const CommandContext context)

Definition at line 330 of file LabelMenus.cpp.

331{
332 auto &project = context.project;
333 auto &tracks = TrackList::Get( project );
334 auto &trackPanel = TrackPanel::Get( project );
335 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
336
337 bool bPastedSomething = false;
338
339 {
340 auto trackRange = tracks.Selected<const LabelTrack>();
341 if (trackRange.empty())
342 {
343 // If there are no selected label tracks, try to choose the first label
344 // track after some other selected track
345 Track *t = *tracks.Selected().begin()
346 .Filter(&Track::Any)
347 .Filter<LabelTrack>();
348
349 // If no match found, add one
350 if (!t)
352
353 // Select this track so the loop picks it up
354 t->SetSelected(true);
355 }
356 }
357
358 LabelTrack *plt = NULL; // the previous track
359 for ( auto lt : tracks.Selected<LabelTrack>() )
360 {
361 // Unselect the last label, so we'll have just one active label when
362 // we're done
363 if (plt)
365
366 // Add a NEW label, paste into it
367 // Paul L: copy whatever defines the selected region, not just times
368 auto &view = LabelTrackView::Get( *lt );
369 view.AddLabel(selectedRegion);
370 if (view.PasteSelectedText( context.project, selectedRegion.t0(),
371 selectedRegion.t1() ))
372 bPastedSomething = true;
373
374 // Set previous track
375 plt = lt;
376 }
377
378 // plt should point to the last label track pasted to -- ensure it's visible
379 // and set focus
380 if (plt) {
381 TrackFocus::Get(project).Set(plt);
383 trackPanel.SetFocus();
384 }
385
386 if (bPastedSomething) {
388 XO("Pasted from the clipboard"), XO("Paste Text to New Label"));
389 }
390}
virtual void SetSelected(bool s)
Definition: Track.cpp:83
bool Any() const
Definition: Track.cpp:255

References Track::Any(), LabelTrack::Create(), TrackFocus::Get(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), Viewport::Get(), TrackPanel::Get(), LabelTrackView::Get(), CommandContext::project, project, ProjectHistory::PushState(), LabelTrackView::ResetTextSelection(), ViewInfo::selectedRegion, Track::SetSelected(), Viewport::ShowTrack(), tracks, and XO().

Referenced by LabelEditMenus().

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

◆ OnSilenceLabels()

void anonymous_namespace{LabelMenus.cpp}::OnSilenceLabels ( const CommandContext context)

Definition at line 530 of file LabelMenus.cpp.

531{
532 auto &project = context.project;
534 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
535
536 if (selectedRegion.isPoint())
537 return;
538
539 auto editfunc = [&](Track &track, double t0, double t1) {
540 // TODO use progress-bar utilities pending in
541 // https://github.com/audacity/audacity/pull/5043
542 track.TypeSwitch([&](WaveTrack& t) { t.Silence(t0, t1, {}); });
543 };
544 EditByLabel(project, tracks, selectedRegion, editfunc);
545
547 /* i18n-hint: (verb)*/
548 XO("Silenced labeled audio regions"),
549 /* i18n-hint: (verb)*/
550 XO("Silence Labeled Audio"));
551}
void Silence(double t0, double t1, ProgressReporter reportProgress) override
Definition: WaveTrack.cpp:1979

References EditByLabel(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), CommandContext::project, project, ProjectHistory::PushState(), ViewInfo::selectedRegion, WaveTrack::Silence(), tracks, Track::TypeSwitch(), and XO().

Referenced by LabelEditMenus().

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

◆ OnSplitCutLabels()

void anonymous_namespace{LabelMenus.cpp}::OnSplitCutLabels ( const CommandContext context)

Definition at line 468 of file LabelMenus.cpp.

469{
470 auto &project = context.project;
472 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
473
474 if (selectedRegion.isPoint())
475 return;
476
477 auto copyfunc = [&](Track &track, double t0, double t1) {
478 Track::Holder result;
479 track.TypeSwitch(
480 [&](WaveTrack &wt) {
481 result = wt.SplitCut(t0, t1);
482 },
483 [&](Track &t) {
484 result = t.Copy(t0, t1);
485 t.Silence(t0, t1);
486 }
487 );
488 return result;
489 };
490 EditClipboardByLabel(project, tracks, selectedRegion, copyfunc);
491
493 /* i18n-hint: (verb) Audacity has just split cut the labeled audio
494 regions*/
495 XO("Split Cut labeled audio regions to clipboard"),
496 /* i18n-hint: (verb) Do a special kind of cut on the labels*/
497 XO("Split Cut Labeled Audio"));
498}
Holder SplitCut(double t0, double t1)
Definition: WaveTrack.cpp:943

References EditClipboardByLabel(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), CommandContext::project, project, ProjectHistory::PushState(), ViewInfo::selectedRegion, WaveTrack::SplitCut(), tracks, Track::TypeSwitch(), and XO().

Referenced by LabelEditMenus().

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

◆ OnSplitDeleteLabels()

void anonymous_namespace{LabelMenus.cpp}::OnSplitDeleteLabels ( const CommandContext context)

Definition at line 500 of file LabelMenus.cpp.

501{
502 auto &project = context.project;
504 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
505
506 if (selectedRegion.isPoint())
507 return;
508
509 auto editfunc = [&](Track &track, double t0, double t1) {
510 track.TypeSwitch(
511 [&](WaveTrack &t) {
512 t.SplitDelete(t0, t1);
513 },
514 [&](Track &t) {
515 t.Silence(t0, t1);
516 }
517 );
518 };
519 EditByLabel(project, tracks, selectedRegion, editfunc);
520
522 /* i18n-hint: (verb) Audacity has just done a special kind of DELETE on
523 the labeled audio regions */
524 XO("Split Deleted labeled audio regions"),
525 /* i18n-hint: (verb) Do a special kind of DELETE on labeled audio
526 regions */
527 XO("Split Delete Labeled Audio"));
528}
void SplitDelete(double t0, double t1)
Definition: WaveTrack.cpp:1503

References EditByLabel(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), CommandContext::project, project, ProjectHistory::PushState(), ViewInfo::selectedRegion, WaveTrack::Silence(), WaveTrack::SplitDelete(), tracks, Track::TypeSwitch(), and XO().

Referenced by LabelEditMenus().

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

◆ OnSplitLabels()

void anonymous_namespace{LabelMenus.cpp}::OnSplitLabels ( const CommandContext context)

Definition at line 575 of file LabelMenus.cpp.

576{
577 auto &project = context.project;
579 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
580
581 if (selectedRegion.isPoint())
582 return;
583
584 auto editfunc = [&](Track &track, double t0, double t1) {
585 track.TypeSwitch( [&](WaveTrack &t) { t.Split(t0, t1); } );
586 };
587 EditByLabel(project, tracks, selectedRegion, editfunc);
588
590 /* i18n-hint: (verb) past tense. Audacity has just split the labeled
591 audio (a point or a region)*/
592 XO("Split labeled audio (points or regions)"),
593 /* i18n-hint: (verb)*/
594 XO("Split Labeled Audio"));
595}
void Split(double t0, double t1)
Definition: WaveTrack.cpp:3130

References EditByLabel(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), CommandContext::project, project, ProjectHistory::PushState(), ViewInfo::selectedRegion, WaveTrack::Split(), tracks, Track::TypeSwitch(), and XO().

Referenced by LabelEditMenus().

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

◆ OnToggleTypeToCreateLabel()

void anonymous_namespace{LabelMenus.cpp}::OnToggleTypeToCreateLabel ( const CommandContext WXUNUSEDcontext)

Definition at line 392 of file LabelMenus.cpp.

393{
394 bool typeToCreateLabel;
395 gPrefs->Read(wxT("/GUI/TypeToCreateLabel"), &typeToCreateLabel, false);
396 gPrefs->Write(wxT("/GUI/TypeToCreateLabel"), !typeToCreateLabel);
397 gPrefs->Flush();
399}
static void ModifyAllProjectToolbarMenus()
virtual bool Flush() noexcept=0
virtual bool Write(const wxString &key, bool value)=0

References audacity::BasicSettings::Flush(), gPrefs, ToolManager::ModifyAllProjectToolbarMenus(), audacity::BasicSettings::Read(), audacity::BasicSettings::Write(), and wxT().

Referenced by LabelEditMenus().

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

Variable Documentation

◆ sAttachment1

AttachedItem anonymous_namespace{LabelMenus.cpp}::sAttachment1
Initial value:
{ wxT("Edit/Other"),
{ OrderingHint::Before, wxT("EditMetaData") } }
}
std::unique_ptr< detail::IndirectItem< Item > > Indirect(const std::shared_ptr< Item > &ptr)
A convenience function.
Definition: Registry.h:175

Definition at line 768 of file LabelMenus.cpp.

◆ sAttachment2

AttachedItem anonymous_namespace{LabelMenus.cpp}::sAttachment2
Initial value:
{
Command( wxT("NewLabelTrack"), XXO("&Label Track"),
wxT("Tracks/Add/Add")
}
void OnNewLabelTrack(const CommandContext &context)
Definition: LabelMenus.cpp:649

Definition at line 773 of file LabelMenus.cpp.