3#include "../Clipboard.h"
4#include "../CommonCommandFlags.h"
11#include "../SelectUtilities.h"
14#include "../TrackPanel.h"
20#include "../tracks/labeltrack/ui/LabelTrackView.h"
37 const auto &test = [&](
const LabelTrack *pTrack ){
38 const auto &labels = pTrack->GetLabels();
39 return std::any_of( labels.begin(), labels.end(),
42 label.getT0() >= selectedRegion.t0()
44 label.getT1() <= selectedRegion.t1()
51 return !range.empty();
58 bool preserveFocus =
false)
67 gPrefs->
Read(
wxT(
"/GUI/DialogForNameNewLabel"), &useDialog,
false);
75 const auto pFocusedTrack = trackFocus.Get();
79 auto iter = pFocusedTrack
80 ?
tracks.Find(pFocusedTrack)
94 lt->SetSelected(
true);
98 index = lt->AddLabel(region,
title);
101 int focusTrackNumber = -1;
102 if (pFocusedTrack && preserveFocus) {
106 focusTrackNumber = std::distance(
begin, iter);
119 trackPanel.SetFocus();
132 for (
int i = 0; i < lt->GetNumLabels(); i++)
142 if( regions.size() == 0 )
146 std::sort(regions.begin(), regions.end());
147 unsigned int selected = 1;
148 while( selected < regions.size() )
150 const Region &cur = regions.at( selected );
151 Region &last = regions.at( selected - 1 );
156 regions.erase( regions.begin() + selected );
169 return [syncLocked, playableTrackSelected](
const auto pTrack) {
183 return playableTrackSelected ? pTrack->IsSelected() :
true;
212 tracksToEdit.begin(), tracksToEdit.end(),
217 BasicUI::SplitProgress(
218 regions.rbegin(), regions.rend(),
219 [&](const Region& region, const ProgressReporter& grandChild) {
220 action(*aTrack, region.start, region.end, grandChild);
234 action(track, t0, t1);
264 auto &newClipboard = *pNewClipboard;
270 for (
auto t : tracksToEdit) {
273 for (
size_t i = regions.size(); i--;) {
274 const Region ®ion = regions.at(i);
275 if (
auto dest = action(*t, region.
start, region.
end)) {
281 if (i + 1 < regions.size())
283 regions.at(i + 1).start - region.
end);
290 merged->ShiftBy(dest->GetEndTime());
297 merged->Paste(0.0, *dest);
303 if (i + 1 < regions.size() && merged)
304 merged->ShiftBy(regions.at(i + 1).start - region.
end);
307 newClipboard.Add(merged);
311 clipboard.Assign( std::move( newClipboard ),
312 regions.front().start, regions.back().end,
project.shared_from_this() );
343 gAudioIO->IsStreamActive(token)) {
344 double indicator = gAudioIO->GetStreamTime();
358 bool bPastedSomething =
false;
362 if (trackRange.empty())
390 view.AddLabel(selectedRegion);
391 if (view.PasteSelectedText( context.
project, selectedRegion.t0(),
392 selectedRegion.t1() ))
393 bPastedSomething =
true;
404 trackPanel.SetFocus();
407 if (bPastedSomething) {
409 XO(
"Pasted from the clipboard"),
XO(
"Paste Text to New Label"));
415 bool typeToCreateLabel;
416 gPrefs->
Read(
wxT(
"/GUI/TypeToCreateLabel"), &typeToCreateLabel,
false);
428 if (selectedRegion.isPoint())
433 auto copyfunc = [&](
Track &track,
double t0,
double t1) {
441 auto editfunc = [&](
Track &track,
double t0,
double t1) {
456 selectedRegion.collapseToT0();
461 XO(
"Cut labeled audio regions to clipboard"),
463 XO(
"Cut Labeled Audio"));
472 if (selectedRegion.isPoint())
475 auto editfunc = [&](
Track &track,
double t0,
double t1) {
480 selectedRegion.collapseToT0();
484 XO(
"Deleted labeled audio regions"),
486 XO(
"Delete Labeled Audio"));
495 if (selectedRegion.isPoint())
498 auto copyfunc = [&](
Track &track,
double t0,
double t1) {
505 result = t.Copy(t0, t1);
514 XO(
"Cut labeled audio regions to clipboard and leave gap"),
515 XO(
"Cut labeled audio and leave gap"));
524 if (selectedRegion.isPoint())
527 auto editfunc = [&](
Track &track,
double t0,
double t1) {
542 XO(
"Split Deleted labeled audio regions"),
545 XO(
"Split Delete Labeled Audio"));
554 if (selectedRegion.isPoint())
557 auto editfunc = [&](
Track &track,
double t0,
double t1) {
566 XO(
"Silenced labeled audio regions"),
568 XO(
"Silence Labeled Audio"));
577 if (selectedRegion.isPoint())
580 auto copyfunc = [&](
Track &track,
double t0,
double t1) {
588 .
PushState(
XO(
"Copied labeled audio regions to clipboard"),
590 XO(
"Copy Labeled Audio"));
599 if (selectedRegion.isPoint())
602 auto editfunc = [&](
Track &track,
double t0,
double t1) {
610 XO(
"Split labeled audio (points or regions)"),
612 XO(
"Split Labeled Audio"));
621 if (selectedRegion.isPoint())
629 const auto sampleTime = 1.0 / t.
GetRate();
630 t.
Join(t0 - sampleTime, t1 + sampleTime, std::move(reportProgress));
641 XO(
"Joined labeled audio (points or regions)"),
643 XO(
"Join Labeled Audio"));
652 if (selectedRegion.isPoint())
655 auto editfunc = [&](
Track &track,
double t0,
double t1) {
667 XO(
"Detached labeled audio regions"),
669 XO(
"Detach Labeled Audio"));
681 track->SetSelected(
true);
697 static const auto NotBusyLabelsAndWaveFlags =
703 static auto menus = std::shared_ptr{
716 XXO(
"Add Label at &Playback Position"),
724 Command(
wxT(
"PasteNewLabel"),
XXO(
"Paste Te&xt to New Label"),
731 XXO(
"&Typing Creates New Labels"),
756 Options{
wxT(
"Alt+Shift+X"),
XO(
"Cut by labels and leave gap") } ),
757 Command(
wxT(
"SplitDeleteLabels"),
XXO(
"De&lete and leave gap"),
759 Options{
wxT(
"Alt+Shift+K"),
XO(
"Delete by labels and leave gap") } )
768 NotBusyLabelsAndWaveFlags,
779 NotBusyLabelsAndWaveFlags,
793 { OrderingHint::Before,
wxT(
"EditMetaData") } }
799 wxT(
"Tracks/Add/Add")
Toolkit-neutral facade for basic user interface services.
AttachedItem sAttachment1
AttachedItem sAttachment2
constexpr CommandFlag AlwaysEnabledFlag
const ReservedCommandFlag & AudioIOBusyFlag()
const ReservedCommandFlag & AudioIONotBusyFlag()
const ReservedCommandFlag & TimeSelectedFlag()
const ReservedCommandFlag & WaveTracksExistFlag()
XXO("&Cut/Copy/Paste Toolbar")
audacity::BasicSettings * gPrefs
std::function< void(double)> ProgressReporter
bool GetEditClipsCanMove()
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
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)
Generates classes whose instances register items at construction.
Defines a selected portion of a project.
static bool IsSyncLockSelected(const Track &track)
bool IsSyncLocked() const
static SyncLockState & Get(AudacityProject &project)
Abstract base class for an object holding data associated with points on a time axis.
virtual void SetSelected(bool s)
R TypeSwitch(const Functions &...functions)
virtual void Clear(double t0, double t1)=0
std::shared_ptr< Track > Holder
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
static TrackListHolder Create(AudacityProject *pOwner)
static TrackList & Get(AudacityProject &project)
auto Selected() -> TrackIterRange< TrackType >
static TrackPanel & Get(AudacityProject &project)
NotifyingSelectedRegion selectedRegion
static ViewInfo & Get(AudacityProject &project)
void ShowTrack(const Track &track)
static Viewport & Get(AudacityProject &project)
A Track that contains audio waveform data.
void SplitDelete(double t0, double t1)
std::vector< Region > Regions
void Silence(double t0, double t1, ProgressReporter reportProgress) override
void Join(double t0, double t1, const ProgressReporter &reportProgress)
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)
Holder SplitCut(double t0, double t1)
double GetRate() const override
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
Create new tracks and don't modify this track.
virtual bool Flush() noexcept=0
virtual bool Write(const wxString &key, bool value)=0
bool ReadBool(const wxString &key, bool defaultValue) const
virtual bool Read(const wxString &key, bool *value) const =0
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.
std::unique_ptr< detail::IndirectItem< Item > > Indirect(const std::shared_ptr< Item > &ptr)
A convenience function.
void SelectNone(AudacityProject &project)
WAVE_TRACK_API void WithClipRenderingProgress(std::function< void(const ProgressReporter &)> action, TranslatableString title=defaultStretchRenderingTitle)
const char * begin(const char *str) noexcept
Structure to hold region of a wavetrack and a comparison function for sortability.