2#include "../Clipboard.h"
3#include "../CommonCommandFlags.h"
4#include "../LabelTrack.h"
9#include "../ProjectWindow.h"
10#include "../SelectUtilities.h"
12#include "../TrackPanelAx.h"
13#include "../TrackPanel.h"
16#include "../commands/CommandContext.h"
17#include "../commands/CommandManager.h"
18#include "../tracks/labeltrack/ui/LabelTrackView.h"
33 const auto &test = [&](
const LabelTrack *pTrack ){
34 const auto &labels = pTrack->GetLabels();
35 return std::any_of( labels.begin(), labels.end(),
38 label.getT0() >= selectedRegion.t0()
40 label.getT1() <= selectedRegion.t1()
47 return !range.empty();
54 bool preserveFocus =
false)
63 gPrefs->Read(
wxT(
"/GUI/DialogForNameNewLabel"), &useDialog,
false);
66 project, region, wxEmptyString,
title) == wxID_CANCEL)
71 const auto pFocusedTrack = trackFocus.Get();
74 auto iter = pFocusedTrack
75 ? tracks.Find(pFocusedTrack)
76 : tracks.Any().begin();
89 lt->SetSelected(
true);
93 index = lt->AddLabel(region,
title);
96 int focusTrackNumber = -1;
97 if (pFocusedTrack && preserveFocus) {
101 focusTrackNumber = pFocusedTrack->GetIndex();
114 trackPanel.SetFocus();
127 for (
int i = 0; i < lt->GetNumLabels(); i++)
137 if( regions.size() == 0 )
141 std::sort(regions.begin(), regions.end());
142 unsigned int selected = 1;
143 while( selected < regions.size() )
145 const Region &cur = regions.at( selected );
146 Region &last = regions.at( selected - 1 );
151 regions.erase( regions.begin() + selected );
173 if( regions.size() == 0 )
182 for (
auto t : tracks.
Any())
184 const bool playable =
dynamic_cast<const PlayableTrack *
>(t) !=
nullptr;
188 for (
int i = (
int)regions.size() - 1; i >= 0; i--)
190 const Region ®ion = regions.at(i);
191 action(t, region.
start, region.
end);
212 if( regions.size() == 0 )
222 auto &newClipboard = *pNewClipboard;
228 for(
auto t : tracks.
Any())
230 const bool playable =
dynamic_cast<const PlayableTrack *
>(t) !=
nullptr;
236 for(
int i = (
int)regions.size() - 1; i >= 0; i-- )
238 const Region ®ion = regions.at(i);
239 auto dest = action(t, region.
start, region.
end );
249 if (i < (
int)regions.size() - 1)
251 regions.at(i + 1).start - region.
end);
258 merged->Paste( 0.0 , dest.get() );
264 if (i < (
int)regions.size() - 1)
267 regions.at(i + 1).start - region.
end);
270 newClipboard.Add( merged );
275 clipboard.Assign( std::move( newClipboard ),
276 regions.front().start, regions.back().end, project.shared_from_this() );
288 auto &project = context.
project;
294 auto &project = context.
project;
302 auto &project = context.
project;
307 gAudioIO->IsStreamActive(token)) {
308 double indicator = gAudioIO->GetStreamTime();
317 auto &project = context.
project;
322 bool bPastedSomething =
false;
325 auto trackRange = tracks.Selected<
const LabelTrack >();
326 if (trackRange.empty())
330 Track *t = *tracks.Selected().begin()
344 for (
auto lt : tracks.Selected<
LabelTrack >() )
354 view.AddLabel(selectedRegion);
355 if (view.PasteSelectedText( context.
project, selectedRegion.t0(),
356 selectedRegion.t1() ))
357 bPastedSomething =
true;
368 trackPanel.SetFocus();
371 if (bPastedSomething) {
373 XO(
"Pasted from the clipboard"),
XO(
"Paste Text to New Label"));
379 bool typeToCreateLabel;
380 gPrefs->Read(
wxT(
"/GUI/TypeToCreateLabel"), &typeToCreateLabel,
false);
381 gPrefs->Write(
wxT(
"/GUI/TypeToCreateLabel"), !typeToCreateLabel);
388 auto &project = context.
project;
392 if( selectedRegion.isPoint() )
397 auto copyfunc = [&](
Track *track,
double t0,
double t1)
410 bool enableCutlines =
gPrefs->ReadBool(
wxT(
"/GUI/EnableCutLines"),
false);
411 auto editfunc = [&](
Track *track,
double t0,
double t1)
431 EditByLabel(project, tracks, selectedRegion, editfunc);
433 selectedRegion.collapseToT0();
438 XO(
"Cut labeled audio regions to clipboard" ),
440 XO(
"Cut Labeled Audio" ) );
445 auto &project = context.
project;
449 if( selectedRegion.isPoint() )
452 auto editfunc = [&](
Track *track,
double t0,
double t1)
454 track->
Clear(t0, t1);
456 EditByLabel(project, tracks, selectedRegion, editfunc);
458 selectedRegion.collapseToT0();
462 XO(
"Deleted labeled audio regions" ),
464 XO(
"Delete Labeled Audio" ) );
469 auto &project = context.
project;
473 if( selectedRegion.isPoint() )
476 auto copyfunc = [&](
Track *track,
double t0,
double t1)
486 dest = t->
Copy(t0, t1);
497 XO(
"Split Cut labeled audio regions to clipboard" ),
499 XO(
"Split Cut Labeled Audio" ) );
504 auto &project = context.
project;
508 if( selectedRegion.isPoint() )
511 auto editfunc = [&](
Track *track,
double t0,
double t1)
524 EditByLabel(project, tracks, selectedRegion, editfunc);
529 XO(
"Split Deleted labeled audio regions" ),
532 XO(
"Split Delete Labeled Audio" ) );
537 auto &project = context.
project;
541 if( selectedRegion.isPoint() )
544 auto editfunc = [&](
Track *track,
double t0,
double t1)
553 EditByLabel(project, tracks, selectedRegion, editfunc);
557 XO(
"Silenced labeled audio regions" ),
559 XO(
"Silence Labeled Audio" ) );
564 auto &project = context.
project;
568 if( selectedRegion.isPoint() )
571 auto copyfunc = [&](
Track *track,
double t0,
double t1)
585 XO(
"Copy Labeled Audio" ) );
590 auto &project = context.
project;
594 if( selectedRegion.isPoint() )
597 auto editfunc = [&](
Track *track,
double t0,
double t1)
606 EditByLabel(project, tracks, selectedRegion, editfunc);
611 XO(
"Split labeled audio (points or regions)" ),
613 XO(
"Split Labeled Audio" ) );
618 auto &project = context.
project;
622 if( selectedRegion.isPoint() )
625 auto editfunc = [&](
Track *track,
double t0,
double t1)
634 EditByLabel(project, tracks, selectedRegion, editfunc);
639 XO(
"Joined labeled audio (points or regions)" ),
641 XO(
"Join Labeled Audio" ) );
646 auto &project = context.
project;
650 if( selectedRegion.isPoint() )
653 auto editfunc = [&](
Track *track,
double t0,
double t1)
663 EditByLabel(project, tracks, selectedRegion, editfunc);
669 XO(
"Detached labeled audio regions" ),
671 XO(
"Detach Labeled Audio" ) );
676 auto &project = context.
project;
683 track->SetSelected(
true);
700 static const auto NotBusyLabelsAndWaveFlags =
719 XXO(
"Add Label at &Playback Position"),
727 Command(
wxT(
"PasteNewLabel"),
XXO(
"Paste Te&xt to New Label"),
734 XXO(
"&Type to Create a Label (on/off)"),
762 Options{
wxT(
"Alt+Shift+K"),
XO(
"Label Split Delete") } )
771 NotBusyLabelsAndWaveFlags,
782 NotBusyLabelsAndWaveFlags,
796 { OrderingHint::Before,
wxT(
"EditMetaData") } },
AttachedItem sAttachment1
AttachedItem sAttachment2
constexpr CommandFlag AlwaysEnabledFlag
const ReservedCommandFlag & AudioIOBusyFlag()
const ReservedCommandFlag & AudioIONotBusyFlag()
const ReservedCommandFlag & TimeSelectedFlag()
const ReservedCommandFlag & WaveTracksExistFlag()
XXO("&Cut/Copy/Paste Toolbar")
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
A LabelStruct holds information for ONE label in a LabelTrack.
SelectedRegion selectedRegion
A LabelTrack is a Track that holds labels (LabelStruct).
static LabelTrack * Create(TrackList &trackList, const wxString &name)
Create a new LabelTrack with specified name and append it to the trackList.
void ResetTextSelection()
static LabelTrackView & Get(LabelTrack &)
static int DialogForLabelName(AudacityProject &project, const SelectedRegion ®ion, const wxString &initialValue, wxString &value)
int AddLabel(const SelectedRegion ®ion, const wxString &title={}, int restoreFocus=-1)
static void DoEditLabels(AudacityProject &project, LabelTrack *lt=nullptr, int index=-1)
AudioTrack subclass that can also be audibly replayed by the program.
int GetAudioIOToken() const
static ProjectAudioIO & Get(AudacityProject &project)
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
Defines a selected portion of a project.
static bool IsSyncLockSelected(const Track *pTrack)
bool IsSyncLocked() const
static SyncLockState & Get(AudacityProject &project)
Abstract base class for an object holding data associated with points on a time axis.
void EnsureVisible(bool modifyState=false)
virtual void SetSelected(bool s)
virtual void Clear(double WXUNUSED(t0), double WXUNUSED(t1))=0
static void FinishCopy(const Track *n, Track *dest)
R TypeSwitch(const Functions &...functions)
Use this function rather than testing track type explicitly and making down-casts.
std::shared_ptr< Track > Holder
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
static std::shared_ptr< TrackList > Create(AudacityProject *pOwner)
auto Any() -> TrackIterRange< TrackType >
static TrackList & Get(AudacityProject &project)
auto Selected() -> TrackIterRange< TrackType >
static TrackPanel & Get(AudacityProject &project)
NotifyingSelectedRegion selectedRegion
static ViewInfo & Get(AudacityProject &project)
A Track that contains audio waveform data.
void SplitDelete(double t0, double t1)
std::vector< Region > Regions
void Join(double t0, double t1)
void Silence(double t0, double t1) override
void ClearAndAddCutLine(double t0, double t1)
void Clear(double t0, double t1) override
void Split(double t0, double t1)
void Disjoin(double t0, double t1)
Track::Holder CopyNonconst(double t0, double t1)
Track::Holder SplitCut(double t0, double t1)
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
std::shared_ptr< BaseItem > BaseItemSharedPtr
void SelectNone(AudacityProject &project)
CommandManager::Options Options
Options && CheckTest(const CheckFn &fn) &&
Structure to hold region of a wavetrack and a comparison function for sortability.