3#include "../Clipboard.h"
4#include "../CommonCommandFlags.h"
5#include "../LabelTrack.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 );
188 const auto tracksToEdit =
tracks.Any<
Track>() + [&](
const auto pTrack) {
190 (notLocked &&
dynamic_cast<const PlayableTrack*
>(pTrack) !=
nullptr);
194 tracksToEdit.begin(), tracksToEdit.end(),
199 BasicUI::SplitProgress(
200 regions.rbegin(), regions.rend(),
201 [&](const Region& region, const ProgressReporter& grandChild) {
202 action(*aTrack, region.start, region.end, grandChild);
216 action(track, t0, t1);
247 auto &newClipboard = *pNewClipboard;
254 const bool playable =
dynamic_cast<const PlayableTrack *
>(t) !=
nullptr;
258 for (
size_t i = regions.size(); i--;) {
259 const Region ®ion = regions.at(i);
260 if (
auto dest = action(*t, region.
start, region.
end)) {
266 if (i + 1 < regions.size())
268 regions.at(i + 1).start - region.
end);
275 merged->Paste(0.0, *dest);
281 if (i + 1 < regions.size() && merged)
282 merged->ShiftBy(regions.at(i + 1).start - region.
end);
285 newClipboard.Add(merged);
290 clipboard.Assign( std::move( newClipboard ),
291 regions.front().start, regions.back().end,
project.shared_from_this() );
322 gAudioIO->IsStreamActive(token)) {
323 double indicator = gAudioIO->GetStreamTime();
337 bool bPastedSomething =
false;
341 if (trackRange.empty())
369 view.AddLabel(selectedRegion);
370 if (view.PasteSelectedText( context.
project, selectedRegion.t0(),
371 selectedRegion.t1() ))
372 bPastedSomething =
true;
383 trackPanel.SetFocus();
386 if (bPastedSomething) {
388 XO(
"Pasted from the clipboard"),
XO(
"Paste Text to New Label"));
394 bool typeToCreateLabel;
395 gPrefs->
Read(
wxT(
"/GUI/TypeToCreateLabel"), &typeToCreateLabel,
false);
407 if (selectedRegion.isPoint())
412 auto copyfunc = [&](
Track &track,
double t0,
double t1) {
420 auto editfunc = [&](
Track &track,
double t0,
double t1) {
435 selectedRegion.collapseToT0();
440 XO(
"Cut labeled audio regions to clipboard"),
442 XO(
"Cut Labeled Audio"));
451 if (selectedRegion.isPoint())
454 auto editfunc = [&](
Track &track,
double t0,
double t1) {
459 selectedRegion.collapseToT0();
463 XO(
"Deleted labeled audio regions"),
465 XO(
"Delete Labeled Audio"));
474 if (selectedRegion.isPoint())
477 auto copyfunc = [&](
Track &track,
double t0,
double t1) {
484 result = t.Copy(t0, t1);
495 XO(
"Split Cut labeled audio regions to clipboard"),
497 XO(
"Split Cut Labeled Audio"));
506 if (selectedRegion.isPoint())
509 auto editfunc = [&](
Track &track,
double t0,
double t1) {
524 XO(
"Split Deleted labeled audio regions"),
527 XO(
"Split Delete Labeled Audio"));
536 if (selectedRegion.isPoint())
539 auto editfunc = [&](
Track &track,
double t0,
double t1) {
548 XO(
"Silenced labeled audio regions"),
550 XO(
"Silence Labeled Audio"));
559 if (selectedRegion.isPoint())
562 auto copyfunc = [&](
Track &track,
double t0,
double t1) {
570 .
PushState(
XO(
"Copied labeled audio regions to clipboard"),
572 XO(
"Copy Labeled Audio"));
581 if (selectedRegion.isPoint())
584 auto editfunc = [&](
Track &track,
double t0,
double t1) {
592 XO(
"Split labeled audio (points or regions)"),
594 XO(
"Split Labeled Audio"));
603 if (selectedRegion.isPoint())
608 [&](
WaveTrack& t) { t.
Join(t0, t1, std::move(reportProgress)); });
618 XO(
"Joined labeled audio (points or regions)"),
620 XO(
"Join Labeled Audio"));
629 if (selectedRegion.isPoint())
632 auto editfunc = [&](
Track &track,
double t0,
double t1) {
644 XO(
"Detached labeled audio regions"),
646 XO(
"Detach Labeled Audio"));
658 track->SetSelected(
true);
674 static const auto NotBusyLabelsAndWaveFlags =
680 static auto menus = std::shared_ptr{
693 XXO(
"Add Label at &Playback Position"),
701 Command(
wxT(
"PasteNewLabel"),
XXO(
"Paste Te&xt to New Label"),
708 XXO(
"&Typing Creates New Labels"),
736 Options{
wxT(
"Alt+Shift+K"),
XO(
"Label Split Delete") } )
745 NotBusyLabelsAndWaveFlags,
756 NotBusyLabelsAndWaveFlags,
770 { OrderingHint::Before,
wxT(
"EditMetaData") } }
776 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
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)
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.