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

Typedefs

using Correspondence = std::vector< std::pair< Track *, const Track * > >
 

Functions

bool DoPasteText (AudacityProject &project)
 
wxULongLong EstimateCopyBytesCount (const TrackList &src, const TrackList &dst)
 
BlockArray::size_type EstimateCopiedBlocks (const TrackList &src, const TrackList &dst)
 
std::shared_ptr< TrackListDuplicateDiscardTrimmed (const TrackList &src)
 
void DoPasteNothingSelected (AudacityProject &project, const TrackList &src, double t0, double t1)
 
bool HasHiddenData (const TrackList &trackList)
 
void OnUndo (const CommandContext &context)
 
void OnRedo (const CommandContext &context)
 
void OnCut (const CommandContext &context)
 
void OnDelete (const CommandContext &context)
 
void OnCopy (const CommandContext &context)
 
std::pair< double, double > FindSelection (const CommandContext &context)
 
std::shared_ptr< const TrackListFindSourceTracks (const CommandContext &context)
 
auto NotificationScope (const CommandContext &context, const TrackList &srcTracks)
 
bool FitsInto (const Track &src, const Track &dst)
 Whether the source track may be pasted into the destination track. More...
 
Correspondence FindCorrespondence (TrackList &dstTracks, const TrackList &srcTracks)
 
void OnPaste (const CommandContext &context)
 
void OnDuplicate (const CommandContext &context)
 
void OnSplitCut (const CommandContext &context)
 
void OnSplitDelete (const CommandContext &context)
 
void OnSilence (const CommandContext &context)
 
void OnTrim (const CommandContext &context)
 
void OnSplit (const CommandContext &context)
 
void OnSplitNew (const CommandContext &context)
 
void OnJoin (const CommandContext &context)
 
void OnDisjoin (const CommandContext &context)
 
void OnPreferences (const CommandContext &context)
 
const ReservedCommandFlagCutCopyAvailableFlag ()
 
BaseItemSharedPtr EditMenu ()
 
BaseItemSharedPtr ExtraEditMenu ()
 

Variables

AttachedItem sAttachment1
 
auto canSelectAll
 
auto selectAll
 
RegisteredMenuItemEnabler selectTracks
 
RegisteredMenuItemEnabler selectAnyTracks
 
RegisteredMenuItemEnabler selectWaveTracks
 
RegisteredMenuItemEnabler selectWaveTracks2
 
AttachedItem sAttachment2
 

Typedef Documentation

◆ Correspondence

using anonymous_namespace{EditMenus.cpp}::Correspondence = typedef std::vector<std::pair<Track*, const Track*> >

Definition at line 486 of file EditMenus.cpp.

Function Documentation

◆ CutCopyAvailableFlag()

const ReservedCommandFlag & anonymous_namespace{EditMenus.cpp}::CutCopyAvailableFlag ( )

Definition at line 998 of file EditMenus.cpp.

998 { static ReservedCommandFlag flag{
999 [](const AudacityProject &project){
1000 auto range = TrackList::Get(project).Any<const LabelTrack>()
1001 + [&](const LabelTrack *pTrack){
1002 return LabelTrackView::Get( *pTrack ).IsTextSelected(
1003 // unhappy const_cast because track focus might be set
1004 const_cast<AudacityProject&>(project)
1005 );
1006 };
1007 if ( !range.empty() )
1008 return true;
1009
1010 if (
1012 &&
1014 )
1015 return true;
1016
1017 return false;
1018 },
1020}; return flag; }
bool EditableTracksSelectedPred(const AudacityProject &project)
const CommandFlagOptions & cutCopyOptions()
bool TimeSelectedPred(const AudacityProject &project)
const auto project
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
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:87
static LabelTrackView & Get(LabelTrack &)
bool IsTextSelected(AudacityProject &project) const
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1091
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:354

References TrackList::Any(), cutCopyOptions(), EditableTracksSelectedPred(), flag, TrackList::Get(), LabelTrackView::Get(), LabelTrackView::IsTextSelected(), project, and TimeSelectedPred().

Referenced by EditMenu().

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

◆ DoPasteNothingSelected()

void anonymous_namespace{EditMenus.cpp}::DoPasteNothingSelected ( AudacityProject project,
const TrackList src,
double  t0,
double  t1 
)

Definition at line 122 of file EditMenus.cpp.

123{
124 auto &tracks = TrackList::Get( project );
125 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
126 auto &viewInfo = ViewInfo::Get( project );
127 auto &window = ProjectWindow::Get( project );
128
129 assert(tracks.Selected().empty());
130
131 Track* pFirstNewTrack = NULL;
132 for (auto pClip : src) {
133 auto pNewTrack = pClip->PasteInto(project, tracks);
134 if (!pFirstNewTrack)
135 pFirstNewTrack = pNewTrack.get();
136 pNewTrack->SetSelected(true);
137 }
138
139 // Select some pasted samples, which is probably impossible to get right
140 // with various project and track sample rates.
141 // So do it at the sample rate of the project
142 double projRate = ProjectRate::Get( project ).GetRate();
143 double quantT0 = QUANTIZED_TIME(t0, projRate);
144 double quantT1 = QUANTIZED_TIME(t1, projRate);
145 selectedRegion.setTimes(
146 0.0, // anywhere else and this should be
147 // half a sample earlier
148 quantT1 - quantT0);
149
151 .PushState(XO("Pasted from the clipboard"), XO("Paste"));
152
153 if (pFirstNewTrack) {
154 TrackFocus::Get(project).Set(pFirstNewTrack);
155 pFirstNewTrack->EnsureVisible();
156 }
157}
XO("Cut/Copy/Paste")
#define QUANTIZED_TIME(time, rate)
Definition: MemoryX.h:559
const auto tracks
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
double GetRate() const
Definition: ProjectRate.cpp:53
static ProjectWindow & Get(AudacityProject &project)
Track * Get()
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:123
void EnsureVisible(bool modifyState=false)
Definition: Track.cpp:86
virtual void SetSelected(bool s)
Definition: Track.cpp:75
virtual Holder PasteInto(AudacityProject &project, TrackList &list) const =0
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:219
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235

References Track::EnsureVisible(), TrackFocus::Get(), ProjectHistory::Get(), ProjectRate::Get(), ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), ProjectRate::GetRate(), Track::PasteInto(), project, ProjectHistory::PushState(), QUANTIZED_TIME, ViewInfo::selectedRegion, Track::SetSelected(), tracks, and XO().

Referenced by OnPaste().

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

◆ DoPasteText()

bool anonymous_namespace{EditMenus.cpp}::DoPasteText ( AudacityProject project)

Definition at line 41 of file EditMenus.cpp.

42{
43 auto &tracks = TrackList::Get( project );
44 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
45 auto &window = ProjectWindow::Get( project );
46
47 // Paste into the active label (if any)
48 for (auto pLabelTrack : tracks.Any<LabelTrack>()) {
49 // Does this track have an active label?
50 if (LabelTrackView::Get( *pLabelTrack ).GetTextEditIndex(project) != -1) {
51
52 // Yes, so try pasting into it
53 auto &view = LabelTrackView::Get( *pLabelTrack );
54 if (view.PasteSelectedText( project, selectedRegion.t0(),
55 selectedRegion.t1() ))
56 {
58 .PushState(XO("Pasted text from the clipboard"), XO("Paste"));
59
60 // Make sure caret is in view
61 int x;
62 if (view.CalcCursorX( project, &x )) {
63 window.ScrollIntoView(x);
64 }
65
66 return true;
67 }
68 }
69 }
70
71 //Presumably, there might be not more than one track
72 //that expects text input
73 for (auto wt : tracks.Any<WaveTrack>()) {
74 auto& view = WaveChannelView::Get(*wt);
75 if (view.PasteText(project)) {
76 auto &trackPanel = TrackPanel::Get(project);
77 trackPanel.Refresh(false);
78 return true;
79 }
80 }
81
82 return false;
83}
int GetTextEditIndex(AudacityProject &project) const
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:232
static WaveChannelView & Get(WaveChannel &channel)
A Track that contains audio waveform data.
Definition: WaveTrack.h:220

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), TrackPanel::Get(), LabelTrackView::Get(), WaveChannelView::Get(), LabelTrackView::GetTextEditIndex(), project, ProjectHistory::PushState(), ViewInfo::selectedRegion, tracks, and XO().

Referenced by OnPaste().

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

◆ DuplicateDiscardTrimmed()

std::shared_ptr< TrackList > anonymous_namespace{EditMenus.cpp}::DuplicateDiscardTrimmed ( const TrackList src)

Definition at line 104 of file EditMenus.cpp.

104 {
105 auto result = TrackList::Create(nullptr);
106 for (auto track : src) {
107 const auto copies =
108 track->Copy(track->GetStartTime(), track->GetEndTime(), false);
109 const auto pTrack = *copies->begin();
110 pTrack->MoveTo(track->GetStartTime());
111 if (const auto waveTrack = dynamic_cast<WaveTrack*>(pTrack))
112 waveTrack->DiscardTrimmed();
113 result->Append(std::move(*copies));
114 }
115 return result;
116}
static TrackListHolder Create(AudacityProject *pOwner)
Definition: Track.cpp:372

References TrackList::Create().

Referenced by FindSourceTracks().

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

◆ EditMenu()

BaseItemSharedPtr anonymous_namespace{EditMenus.cpp}::EditMenu ( )

Definition at line 1023 of file EditMenus.cpp.

1024{
1026
1027 static const auto NotBusyTimeAndTracksFlags =
1029
1030 // The default shortcut key for Redo is different on different platforms.
1031 static constexpr auto redoKey =
1032#ifdef __WXMSW__
1033 wxT("Ctrl+Y")
1034#else
1035 wxT("Ctrl+Shift+Z")
1036#endif
1037 ;
1038
1039 // The default shortcut key for Preferences is different on different
1040 // platforms.
1041 static constexpr auto prefKey =
1042#ifdef __WXMAC__
1043 wxT("Ctrl+,")
1044#else
1045 wxT("Ctrl+P")
1046#endif
1047 ;
1048
1049 static BaseItemSharedPtr menu{
1050 Menu( wxT("Edit"), XXO("&Edit"),
1051 Section( "UndoRedo",
1052 Command( wxT("Undo"), XXO("&Undo"), OnUndo,
1053 AudioIONotBusyFlag() | UndoAvailableFlag(), wxT("Ctrl+Z") ),
1054
1055 Command( wxT("Redo"), XXO("&Redo"), OnRedo,
1056 AudioIONotBusyFlag() | RedoAvailableFlag(), redoKey ),
1057
1058 Special( wxT("UndoItemsUpdateStep"),
1059 [](AudacityProject &project, wxMenu&) {
1060 // Change names in the CommandManager as a side-effect
1062 })
1063 ),
1064
1065 Section( "Basic",
1066 // Basic Edit commands
1067 /* i18n-hint: (verb)*/
1068 Command( wxT("Cut"), XXO("Cu&t"), OnCut,
1070 wxT("Ctrl+X") ),
1071 Command( wxT("Delete"), XXO("&Delete"), OnDelete,
1073 wxT("Ctrl+K") ),
1074 /* i18n-hint: (verb)*/
1075 Command( wxT("Copy"), XXO("&Copy"), OnCopy,
1076 AudioIONotBusyFlag() | CutCopyAvailableFlag(), wxT("Ctrl+C") ),
1077 /* i18n-hint: (verb)*/
1078 Command( wxT("Paste"), XXO("&Paste"), OnPaste,
1079 AudioIONotBusyFlag(), wxT("Ctrl+V") ),
1080 /* i18n-hint: (verb)*/
1081 Command( wxT("Duplicate"), XXO("Duplic&ate"), OnDuplicate,
1082 NotBusyTimeAndTracksFlags, wxT("Ctrl+D") ),
1083
1084 Section( "",
1085 Menu( wxT("RemoveSpecial"), XXO("R&emove Special"),
1086 Section( "",
1087 /* i18n-hint: (verb) Do a special kind of cut*/
1088 Command( wxT("SplitCut"), XXO("Spl&it Cut"), OnSplitCut,
1089 NotBusyTimeAndTracksFlags,
1090 Options{ wxT("Ctrl+Alt+X") } ),
1091 /* i18n-hint: (verb) Do a special kind of DELETE*/
1092 Command( wxT("SplitDelete"), XXO("Split D&elete"), OnSplitDelete,
1093 NotBusyTimeAndTracksFlags,
1094 Options{ wxT("Ctrl+Alt+K") } )
1095 ),
1096
1097 Section( "",
1098 /* i18n-hint: (verb)*/
1099 Command( wxT("Silence"), XXO("Silence Audi&o"), OnSilence,
1101 wxT("Ctrl+L") ),
1102 /* i18n-hint: (verb)*/
1103 Command( wxT("Trim"), XXO("Tri&m Audio"), OnTrim,
1105 Options{ wxT("Ctrl+T") } )
1106 )
1107 )
1108 )
1109 ),
1110
1111
1112 Section( "Other",
1114
1115 Menu( wxT("Clip"), XXO("Audi&o Clips"),
1116 Section( "",
1117 /* i18n-hint: (verb) It's an item on a menu. */
1118 Command( wxT("Split"), XXO("Sp&lit"), OnSplit,
1120 Options{ wxT("Ctrl+I") } ),
1121 Command( wxT("SplitNew"), XXO("Split Ne&w"), OnSplitNew,
1123 Options{ wxT("Ctrl+Alt+I") } )
1124 ),
1125
1126 Section( "",
1127 /* i18n-hint: (verb)*/
1128 Command( wxT("Join"), XXO("&Join"), OnJoin,
1129 NotBusyTimeAndTracksFlags, wxT("Ctrl+J") ),
1130 Command( wxT("Disjoin"), XXO("Detac&h at Silences"), OnDisjoin,
1131 NotBusyTimeAndTracksFlags, wxT("Ctrl+Alt+J") )
1132 )
1133 )
1134
1135 ),
1136
1137 // Note that on Mac, the Preferences menu item is specially handled in
1138 // CommandManager (assigned a special wxWidgets id) so that it does
1139 // not appear in the Edit menu but instead under Audacity, consistent with
1140 // MacOS conventions.
1141 Section( "Preferences",
1142 Command( wxT("Preferences"), XXO("Pre&ferences"), OnPreferences,
1143 AudioIONotBusyFlag(), prefKey )
1144 )
1145
1146 ) };
1147 return menu;
1148}
wxT("CloseDown"))
const ReservedCommandFlag & NoAutoSelect()
const ReservedCommandFlag & AudioIONotBusyFlag()
const ReservedCommandFlag & UndoAvailableFlag()
const ReservedCommandFlag & RedoAvailableFlag()
const ReservedCommandFlag & TimeSelectedFlag()
const ReservedCommandFlag & EditableTracksSelectedFlag()
const ReservedCommandFlag & WaveTracksSelectedFlag()
XXO("&Cut/Copy/Paste Toolbar")
static void ModifyUndoMenuItems(AudacityProject &project)
Definition: Menus.cpp:444
constexpr auto Special
constexpr auto Section
constexpr auto Menu
Items will appear in a main toolbar menu or in a sub-menu.
constexpr auto Command
std::shared_ptr< BaseItem > BaseItemSharedPtr
Definition: Registry.h:78
void OnDisjoin(const CommandContext &context)
Definition: EditMenus.cpp:923
void OnRedo(const CommandContext &context)
Definition: EditMenus.cpp:199
void OnJoin(const CommandContext &context)
Definition: EditMenus.cpp:907
void OnDelete(const CommandContext &context)
Definition: EditMenus.cpp:323
void OnPaste(const CommandContext &context)
Definition: EditMenus.cpp:518
const ReservedCommandFlag & CutCopyAvailableFlag()
Definition: EditMenus.cpp:998
void OnSplit(const CommandContext &context)
Definition: EditMenus.cpp:792
void OnSilence(const CommandContext &context)
Definition: EditMenus.cpp:736
void OnTrim(const CommandContext &context)
Definition: EditMenus.cpp:771
void OnSplitDelete(const CommandContext &context)
Definition: EditMenus.cpp:713
void OnCopy(const CommandContext &context)
Definition: EditMenus.cpp:349
void OnUndo(const CommandContext &context)
Definition: EditMenus.cpp:168
void OnSplitCut(const CommandContext &context)
Definition: EditMenus.cpp:678
void OnPreferences(const CommandContext &context)
Definition: EditMenus.cpp:939
void OnDuplicate(const CommandContext &context)
Definition: EditMenus.cpp:649
void OnSplitNew(const CommandContext &context)
Definition: EditMenus.cpp:857
void OnCut(const CommandContext &context)
Definition: EditMenus.cpp:229

References AudioIONotBusyFlag(), MenuTable::Command, CutCopyAvailableFlag(), EditableTracksSelectedFlag(), MenuTable::Menu, MenuManager::ModifyUndoMenuItems(), NoAutoSelect(), OnCopy(), OnCut(), OnDelete(), OnDisjoin(), OnDuplicate(), OnJoin(), OnPaste(), OnPreferences(), OnRedo(), OnSilence(), OnSplit(), OnSplitCut(), OnSplitDelete(), OnSplitNew(), OnTrim(), OnUndo(), project, RedoAvailableFlag(), MenuTable::Section, MenuTable::Special, TimeSelectedFlag(), UndoAvailableFlag(), WaveTracksSelectedFlag(), wxT(), and XXO().

Here is the call graph for this function:

◆ EstimateCopiedBlocks()

BlockArray::size_type anonymous_namespace{EditMenus.cpp}::EstimateCopiedBlocks ( const TrackList src,
const TrackList dst 
)

Definition at line 96 of file EditMenus.cpp.

97{
98 BlockArray::size_type result{};
99 for (const auto waveTrack : src.Any<const WaveTrack>())
100 result += waveTrack->CountBlocks();
101 return result;
102}

References TrackList::Any().

Referenced by NotificationScope().

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

◆ EstimateCopyBytesCount()

wxULongLong anonymous_namespace{EditMenus.cpp}::EstimateCopyBytesCount ( const TrackList src,
const TrackList dst 
)

Definition at line 85 of file EditMenus.cpp.

86{
87 wxULongLong result{};
88 for (auto waveTrack : src.Any<const WaveTrack>()) {
89 const auto samplesCount = waveTrack->GetSequenceSamplesCount();
90 result += samplesCount.as_long_long() *
91 SAMPLE_SIZE(waveTrack->GetSampleFormat());
92 }
93 return result;
94}
#define SAMPLE_SIZE(SampleFormat)
Definition: SampleFormat.h:50

References TrackList::Any(), and SAMPLE_SIZE.

Referenced by FindSourceTracks().

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

◆ ExtraEditMenu()

BaseItemSharedPtr anonymous_namespace{EditMenus.cpp}::ExtraEditMenu ( )

Definition at line 1155 of file EditMenus.cpp.

1156{
1158 static const auto flags =
1160 static BaseItemSharedPtr menu{
1161 Menu( wxT("Edit"), XXO("&Edit"),
1162 Command( wxT("DeleteKey"), XXO("&Delete Key"), OnDelete,
1163 (flags | NoAutoSelect()),
1164 wxT("Backspace") ),
1165 Command( wxT("DeleteKey2"), XXO("Delete Key&2"), OnDelete,
1166 (flags | NoAutoSelect()),
1167 wxT("Delete") )
1168 ) };
1169 return menu;
1170}

References AudioIONotBusyFlag(), MenuTable::Command, EditableTracksSelectedFlag(), MenuTable::Menu, NoAutoSelect(), OnDelete(), TimeSelectedFlag(), wxT(), and XXO().

Here is the call graph for this function:

◆ FindCorrespondence()

Correspondence anonymous_namespace{EditMenus.cpp}::FindCorrespondence ( TrackList dstTracks,
const TrackList srcTracks 
)

Definition at line 488 of file EditMenus.cpp.

490{
491 Correspondence result;
492 auto dstRange = dstTracks.Selected();
493 if (dstRange.size() == 1)
494 // Special rule when only one track is selected interprets the user's
495 // intent as pasting into that track and following ones
496 dstRange = dstTracks.Any().StartingWith(*dstRange.begin());
497 auto srcRange = srcTracks.Any();
498 while (!(dstRange.empty() || srcRange.empty())) {
499 auto &dst = **dstRange.begin();
500 auto &src = **srcRange.begin();
501 if (!FitsInto(src, dst)) {
502 // Skip selected track of inappropriate type and try again
503 ++dstRange.first;
504 continue;
505 }
506 result.emplace_back(&dst, &src);
507 ++srcRange.first;
508 ++dstRange.first;
509 }
510
511 if (!srcRange.empty())
512 // Could not fit all source tracks into the selected tracks
513 return {};
514 else
515 return result;
516}
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:1108
bool FitsInto(const Track &src, const Track &dst)
Whether the source track may be pasted into the destination track.
Definition: EditMenus.cpp:475
std::vector< std::pair< Track *, const Track * > > Correspondence
Definition: EditMenus.cpp:486

References TrackList::Any(), FitsInto(), and TrackList::Selected().

Referenced by OnPaste().

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

◆ FindSelection()

std::pair< double, double > anonymous_namespace{EditMenus.cpp}::FindSelection ( const CommandContext context)

Definition at line 393 of file EditMenus.cpp.

394{
395 double sel0 = 0.0, sel1 = 0.0;
396
397#if 0
398 // Use the overriding selection if any was given in the context
399 if (auto *pRegion = context.temporarySelection.pSelectedRegion) {
400 auto &selectedRegion = *pRegion;
401 sel0 = selectedRegion.t0();
402 sel1 = selectedRegion.t1();
403 }
404 else
405#endif
406 {
407 auto &selectedRegion = ViewInfo::Get(context.project).selectedRegion;
408 sel0 = selectedRegion.t0();
409 sel1 = selectedRegion.t1();
410 }
411
412 return { sel0, sel1 };
413}
TemporarySelection temporarySelection
AudacityProject & project
double t0() const
Definition: ViewInfo.h:35
SelectedRegion * pSelectedRegion

References ViewInfo::Get(), CommandContext::project, TemporarySelection::pSelectedRegion, ViewInfo::selectedRegion, NotifyingSelectedRegion::t0(), and CommandContext::temporarySelection.

Referenced by OnPaste(), and OnSplit().

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

◆ FindSourceTracks()

std::shared_ptr< const TrackList > anonymous_namespace{EditMenus.cpp}::FindSourceTracks ( const CommandContext context)

Definition at line 415 of file EditMenus.cpp.

416{
417 auto &project = context.project;
418 auto &window = ProjectWindow::Get(project);
420 const auto &clipboard = Clipboard::Get();
421 auto discardTrimmed = false;
422 if (&context.project != &*clipboard.Project().lock()) {
423 const auto waveClipCopyPolicy = TracksBehaviorsAudioTrackPastePolicy.Read();
424 if(waveClipCopyPolicy == wxT("Ask") && HasHiddenData(clipboard.GetTracks())) {
425 AudioPasteDialog audioPasteDialog(
426 &window,
427 EstimateCopyBytesCount(clipboard.GetTracks(), tracks)
428 );
429 const auto result = audioPasteDialog.ShowModal();
430 if(result == wxID_CANCEL)
431 return {};
432 discardTrimmed =
434 }
435 else if(waveClipCopyPolicy == wxT("Discard"))
436 discardTrimmed = true;
437 }
438
439 std::shared_ptr<const TrackList> srcTracks;
440 if(discardTrimmed)
441 srcTracks = DuplicateDiscardTrimmed(clipboard.GetTracks());
442 else
443 srcTracks = clipboard.GetTracks().shared_from_this();
444
445 return srcTracks;
446}
ChoiceSetting TracksBehaviorsAudioTrackPastePolicy
wxString Read() const
Definition: Prefs.cpp:369
static Clipboard & Get()
Definition: Clipboard.cpp:28
wxULongLong EstimateCopyBytesCount(const TrackList &src, const TrackList &dst)
Definition: EditMenus.cpp:85
std::shared_ptr< TrackList > DuplicateDiscardTrimmed(const TrackList &src)
Definition: EditMenus.cpp:104
bool HasHiddenData(const TrackList &trackList)
Definition: EditMenus.cpp:159

References AudioPasteDialog::DISCARD, DuplicateDiscardTrimmed(), EstimateCopyBytesCount(), Clipboard::Get(), TrackList::Get(), ProjectWindow::Get(), HasHiddenData(), project, CommandContext::project, ChoiceSetting::Read(), tracks, TracksBehaviorsAudioTrackPastePolicy, and wxT().

Referenced by OnPaste().

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

◆ FitsInto()

bool anonymous_namespace{EditMenus.cpp}::FitsInto ( const Track src,
const Track dst 
)

Whether the source track may be pasted into the destination track.

Definition at line 475 of file EditMenus.cpp.

476{
477 if (!src.SameKindAs(dst))
478 return false;
479 // Mono can "fit" into stereo, by duplication of the channel
480 // Otherwise non-wave tracks always have just one "channel"
481 // Future: Fit stereo into mono too, using mix-down
482 return TrackList::NChannels(src) <= TrackList::NChannels(dst);
483}
bool SameKindAs(const Track &track) const
Definition: Track.h:419
size_t NChannels() const
Definition: Track.cpp:977

References TrackList::NChannels(), and Track::SameKindAs().

Referenced by FindCorrespondence().

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

◆ HasHiddenData()

bool anonymous_namespace{EditMenus.cpp}::HasHiddenData ( const TrackList trackList)

Definition at line 159 of file EditMenus.cpp.

160{
161 const auto range = trackList.Any<const WaveTrack>();
162 return std::any_of(range.begin(), range.end(),
163 [](const WaveTrack *pTrack){ return pTrack->HasHiddenData(); });
164}

References TrackList::Any().

Referenced by FindSourceTracks().

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

◆ NotificationScope()

auto anonymous_namespace{EditMenus.cpp}::NotificationScope ( const CommandContext context,
const TrackList srcTracks 
)

Definition at line 448 of file EditMenus.cpp.

450{
451 auto &project = context.project;
453 auto &trackFactory = WaveTrackFactory::Get(project);
454 auto &pSampleBlockFactory = trackFactory.GetSampleBlockFactory();
455 return pSampleBlockFactory->Subscribe([
456 toCopy = EstimateCopiedBlocks(srcTracks, tracks),
457 nCopied = 0,
458 copyStartTime = std::chrono::system_clock::now(),
459 progressDialog = std::shared_ptr<BasicUI::ProgressDialog>()]
460 (const SampleBlockCreateMessage&) mutable {
461 using namespace std::chrono;
462 constexpr auto ProgressDialogShowDelay = milliseconds { 100 };
463 ++nCopied;
464 if(!progressDialog) {
465 if(duration_cast<milliseconds>(system_clock::now() - copyStartTime) >= ProgressDialogShowDelay)
466 progressDialog = BasicUI::MakeProgress(XO("Paste clip"), XO("Pasting clip contents, please wait"), 0);
467 }
468 else {
469 progressDialog->Poll(nCopied, toCopy);
470 }
471 });
472}
static WaveTrackFactory & Get(AudacityProject &project)
Definition: WaveTrack.cpp:4079
std::unique_ptr< ProgressDialog > MakeProgress(const TranslatableString &title, const TranslatableString &message, unsigned flags=(ProgressShowStop|ProgressShowCancel), const TranslatableString &remainingLabelText={})
Create and display a progress dialog.
Definition: BasicUI.h:289
BlockArray::size_type EstimateCopiedBlocks(const TrackList &src, const TrackList &dst)
Definition: EditMenus.cpp:96

References EstimateCopiedBlocks(), TrackList::Get(), WaveTrackFactory::Get(), BasicUI::MakeProgress(), project, CommandContext::project, tracks, and XO().

Referenced by OnPaste().

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

◆ OnCopy()

void anonymous_namespace{EditMenus.cpp}::OnCopy ( const CommandContext context)

Definition at line 349 of file EditMenus.cpp.

350{
351 auto &project = context.project;
352 auto &tracks = TrackList::Get( project );
353 auto &trackPanel = TrackPanel::Get( project );
354 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
355
356 for (auto lt : tracks.Selected<LabelTrack>()) {
357 auto &view = LabelTrackView::Get( *lt );
358 if (view.CopySelectedText( context.project )) {
359 //trackPanel.Refresh(false);
360 return;
361 }
362 }
363 //Presumably, there might be not more than one track
364 //that expects text input
365 for (auto wt : tracks.Any<WaveTrack>()) {
366 auto& view = WaveChannelView::Get(*wt);
367 if (view.CopySelectedText(context.project)) {
368 return;
369 }
370 }
371
372 auto &clipboard = Clipboard::Get();
373 clipboard.Clear();
374
375 auto pNewClipboard = TrackList::Create( nullptr );
376 auto &newClipboard = *pNewClipboard;
377
378 for (auto n : tracks.Selected()) {
379 if (n->SupportsBasicEditing()) {
380 auto dest = n->Copy(selectedRegion.t0(), selectedRegion.t1());
381 newClipboard.Append(std::move(*dest));
382 }
383 }
384
385 // Survived possibility of exceptions. Commit changes to the clipboard now.
386 clipboard.Assign( std::move( newClipboard ),
387 selectedRegion.t0(), selectedRegion.t1(), project.shared_from_this() );
388
389 //Make sure the menus/toolbar states get updated
390 trackPanel.Refresh(false);
391}

References TrackList::Create(), Clipboard::Get(), ViewInfo::Get(), TrackList::Get(), TrackPanel::Get(), LabelTrackView::Get(), WaveChannelView::Get(), project, CommandContext::project, ViewInfo::selectedRegion, and tracks.

Referenced by EditMenu().

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

◆ OnCut()

void anonymous_namespace{EditMenus.cpp}::OnCut ( const CommandContext context)

Definition at line 229 of file EditMenus.cpp.

230{
231 auto &project = context.project;
232 auto &tracks = TrackList::Get( project );
233 auto &trackPanel = TrackPanel::Get( project );
234 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
236 auto &window = ProjectWindow::Get( project );
237
238 // This doesn't handle cutting labels, it handles
239 // cutting the _text_ inside of labels, i.e. if you're
240 // in the middle of editing the label text and select "Cut".
241
242 for (auto lt : tracks.Selected<LabelTrack>()) {
243 auto &view = LabelTrackView::Get( *lt );
244 if (view.CutSelectedText( context.project )) {
245 trackPanel.Refresh(false);
246 return;
247 }
248 }
249
250 //Presumably, there might be not more than one track
251 //that expects text input
252 for (auto wt : tracks.Any<WaveTrack>()) {
253 auto& view = WaveChannelView::Get(*wt);
254 if (view.CutSelectedText(context.project)) {
255 trackPanel.Refresh(false);
256 return;
257 }
258 }
259
260 auto &clipboard = Clipboard::Get();
261 clipboard.Clear();
262
263 auto pNewClipboard = TrackList::Create( nullptr );
264 auto &newClipboard = *pNewClipboard;
265
266 tracks.Selected().Visit(
267#if defined(USE_MIDI)
268 [&](NoteTrack &n) {
269 // Since portsmf has a built-in cut operator, we use that instead
270 auto dest = n.Cut(selectedRegion.t0(), selectedRegion.t1());
271 newClipboard.Append(std::move(*dest));
272 },
273#endif
274 [&](Track &n) {
275 if (n.SupportsBasicEditing()) {
276 auto dest = n.Copy(selectedRegion.t0(), selectedRegion.t1());
277 newClipboard.Append(std::move(*dest));
278 }
279 }
280 );
281
282 // Survived possibility of exceptions. Commit changes to the clipboard now.
283 clipboard.Assign(
284 std::move( newClipboard ),
285 selectedRegion.t0(),
286 selectedRegion.t1(),
287 project.shared_from_this()
288 );
289
290 // Proceed to change the project. If this throws, the project will be
291 // rolled back by the top level handler.
292
294#if defined(USE_MIDI)
295 [](NoteTrack&) {
296 //if NoteTrack, it was cut, so do not clear anything
297
298 // PRL: But what if it was sync lock selected only, not selected?
299 },
300#endif
301 [&](auto &&fallthrough){ return [&](WaveTrack &wt) {
302 if (gPrefs->Read(wxT("/GUI/EnableCutLines"), (long)0))
303 wt.ClearAndAddCutLine(selectedRegion.t0(), selectedRegion.t1());
304 else
305 fallthrough();
306 }; },
307 [&](Track &n) {
308 if (n.SupportsBasicEditing())
309 n.Clear(selectedRegion.t0(), selectedRegion.t1());
310 }
311 );
312
313 selectedRegion.collapseToT0();
314
316 .PushState(XO("Cut to the clipboard"), XO("Cut"));
317
318 // Bug 1663
319 //mRuler->ClearPlayRegion();
320 ruler.DrawOverlays( true );
321}
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
static AdornedRulerPanel & Get(AudacityProject &project)
A Track that is used for Midi notes. (Somewhat old code).
Definition: NoteTrack.h:65
TrackListHolder Cut(double t0, double t1) override
Create tracks and modify this track.
Definition: NoteTrack.cpp:452
TrackListHolder Copy(double t0, double t1, bool forClipboard=true) const override
Create new tracks and don't modify this track.
Definition: NoteTrack.cpp:483
void Clear(double t0, double t1) override
Definition: NoteTrack.cpp:530
static bool IsSelectedOrSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:112
virtual bool SupportsBasicEditing() const
Whether this track type implements cut-copy-paste; by default, true.
Definition: Track.cpp:1230
virtual bool Read(const wxString &key, bool *value) const =0
void Visit(Visitor &visitor, BaseItem *pTopItem, const GroupItemBase *pRegistry)
Definition: Registry.cpp:739

References NoteTrack::Clear(), NoteTrack::Copy(), TrackList::Create(), NoteTrack::Cut(), Clipboard::Get(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), AdornedRulerPanel::Get(), ProjectWindow::Get(), TrackPanel::Get(), LabelTrackView::Get(), WaveChannelView::Get(), gPrefs, SyncLock::IsSelectedOrSyncLockSelected(), project, CommandContext::project, ProjectHistory::PushState(), audacity::BasicSettings::Read(), anonymous_namespace{TimeTrackVRulerControls.cpp}::ruler(), ViewInfo::selectedRegion, Track::SupportsBasicEditing(), tracks, Registry::Visit(), wxT(), and XO().

Referenced by EditMenu().

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

◆ OnDelete()

void anonymous_namespace{EditMenus.cpp}::OnDelete ( const CommandContext context)

Definition at line 323 of file EditMenus.cpp.

324{
325 auto &project = context.project;
326 auto &tracks = TrackList::Get( project );
327 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
328 auto &window = ProjectWindow::Get( project );
329
330 for (auto n : tracks) {
331 if (!n->SupportsBasicEditing())
332 continue;
334 n->Clear(selectedRegion.t0(), selectedRegion.t1());
335 }
336 }
337
338 double seconds = selectedRegion.duration();
339
340 selectedRegion.collapseToT0();
341
343 XO("Deleted %.2f seconds at t=%.2f")
344 .Format( seconds, selectedRegion.t0()),
345 XO("Delete"));
346}
Abstract base class used in importing a file.

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), SyncLock::IsSelectedOrSyncLockSelected(), project, CommandContext::project, ProjectHistory::PushState(), ViewInfo::selectedRegion, tracks, and XO().

Referenced by EditMenu(), and ExtraEditMenu().

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

◆ OnDisjoin()

void anonymous_namespace{EditMenus.cpp}::OnDisjoin ( const CommandContext context)

Definition at line 923 of file EditMenus.cpp.

924{
925 auto &project = context.project;
927 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
928 auto &window = ProjectWindow::Get(project);
929
930 for (auto wt : tracks.Selected<WaveTrack>())
931 wt->Disjoin(selectedRegion.t0(), selectedRegion.t1());
932
934 XO("Detached %.2f seconds at t=%.2f")
935 .Format(selectedRegion.duration(), selectedRegion.t0()),
936 XO("Detach"));
937}

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), project, CommandContext::project, ProjectHistory::PushState(), ViewInfo::selectedRegion, tracks, and XO().

Referenced by EditMenu().

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

◆ OnDuplicate()

void anonymous_namespace{EditMenus.cpp}::OnDuplicate ( const CommandContext context)

Definition at line 649 of file EditMenus.cpp.

650{
651 auto &project = context.project;
653 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
654 auto &window = ProjectWindow::Get(project);
655
656 // This iteration is unusual because we add to the list inside the loop
657 auto range = tracks.Selected();
658 auto last = *range.rbegin();
659 for (auto n : range) {
660 if (!n->SupportsBasicEditing())
661 continue;
662
663 // Make copies not for clipboard but for direct addition to the project
664 auto dest = n->Copy(selectedRegion.t0(), selectedRegion.t1(), false);
665 (*dest->begin())
666 ->MoveTo(std::max(selectedRegion.t0(), n->GetStartTime()));
667 tracks.Append(std::move(*dest));
668
669 // This break is really needed, else we loop infinitely
670 if (n == last)
671 break;
672 }
673
675 .PushState(XO("Duplicated"), XO("Duplicate"));
676}

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), project, CommandContext::project, ProjectHistory::PushState(), ViewInfo::selectedRegion, tracks, and XO().

Referenced by EditMenu().

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

◆ OnJoin()

void anonymous_namespace{EditMenus.cpp}::OnJoin ( const CommandContext context)

Definition at line 907 of file EditMenus.cpp.

908{
909 auto &project = context.project;
911 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
912 auto &window = ProjectWindow::Get(project);
913
914 for (auto wt : tracks.Selected<WaveTrack>())
915 wt->Join(selectedRegion.t0(), selectedRegion.t1());
916
918 XO("Joined %.2f seconds at t=%.2f")
919 .Format(selectedRegion.duration(), selectedRegion.t0()),
920 XO("Join"));
921}

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), project, CommandContext::project, ProjectHistory::PushState(), ViewInfo::selectedRegion, tracks, and XO().

Referenced by EditMenu().

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

◆ OnPaste()

void anonymous_namespace{EditMenus.cpp}::OnPaste ( const CommandContext context)

Definition at line 518 of file EditMenus.cpp.

519{
520 auto &project = context.project;
521
522 // Handle text paste first.
523 if (DoPasteText(project))
524 return;
525
526 const auto &clipboard = Clipboard::Get();
527 if (clipboard.GetTracks().empty())
528 return;
529
530 const auto srcTracks = FindSourceTracks(context);
531 if (!srcTracks)
532 // user cancelled
533 return;
534
535 auto notificationScope = NotificationScope(context, *srcTracks);
536
538 // If nothing's selected, we just insert new tracks.
539 if (!tracks.Selected()) {
541 project, *srcTracks, clipboard.T0(), clipboard.T1());
542 return;
543 }
544
545 // Otherwise, paste into the selected tracks.
546 double t0, t1;
547 std::tie(t0, t1) = FindSelection(context);
548 auto newT1 = t0 + clipboard.Duration();
549 const auto isSyncLocked = SyncLockState::Get(project).IsSyncLocked();
550
551 Track *ff = nullptr;
552 bool bPastedSomething = false;
553
554 // Find tracks to paste in
555 auto correspondence = FindCorrespondence(tracks, *srcTracks);
556 if (correspondence.empty()) {
557 if (tracks.Selected().size() == 1)
559"The content you are trying to paste will span across more tracks than you "
560"currently have available. Add more tracks and try again.")
561 );
562 else
564"There are not enough tracks selected to accommodate your copied content. "
565"Select additional tracks and try again.")
566 );
567 return;
568 }
569 auto iPair = correspondence.begin();
570 const auto endPair = correspondence.cend();
571
572 // Outer loop by sync-lock groups
573 auto next = tracks.begin();
574 for (auto range = tracks.Any(); !range.empty();
575 // Skip to next sync lock group
576 range.first = next
577 ) {
578 if (iPair == endPair)
579 // Nothing more to paste
580 break;
581 auto group = SyncLock::Group(*range.first);
582 next = tracks.Find(*group.rbegin());
583 ++next;
584
585 if (!group.contains(iPair->first))
586 // Nothing to paste into this group
587 continue;
588
589 // Inner loop over the group by tracks (not channels)
590 for (auto leader : group) {
591 if (iPair == endPair || leader != iPair->first) {
592 if (isSyncLocked) {
593 // Track is not pasted into but must be adjusted
594 if (t1 != newT1 && t1 <= leader->GetEndTime()) {
595 leader->SyncLockAdjust(t1, newT1);
596 bPastedSomething = true;
597 }
598 }
599 }
600 else {
601 // Remember first pasted-into track, to focus it
602 if (!ff)
603 ff = leader;
604 // Do the pasting!
605 const auto src = (iPair++)->second;
606 leader->TypeSwitch(
607 [&](WaveTrack &wn){
608 bPastedSomething = true;
609 // For correct remapping of preserved split lines:
610 PasteTimeWarper warper{ t1, t0 + src->GetEndTime() };
611 wn.ClearAndPaste(t0, t1,
612 *static_cast<const WaveTrack*>(src), true, true, &warper);
613 },
614 [&](LabelTrack &ln){
615 // Per Bug 293, users expect labels to move on a paste into
616 // a label track.
617 ln.Clear(t0, t1);
618
619 ln.ShiftLabelsOnInsert( clipboard.Duration(), t0 );
620
621 bPastedSomething |= ln.PasteOver(t0, *src);
622 },
623 [&](Track &t){
624 bPastedSomething = true;
625 t.Clear(t0, t1);
626 t.Paste(t0, *src);
627 }
628 );
629 }
630 }
631 }
632
633 // TODO: What if we clicked past the end of the track?
634
635 if (bPastedSomething) {
637 .setTimes( t0, t0 + clipboard.Duration() );
638
640 .PushState(XO("Pasted from the clipboard"), XO("Paste"));
641
642 if (ff) {
643 TrackFocus::Get(project).Set(ff);
644 ff->EnsureVisible();
645 }
646 }
647}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
bool setTimes(double t0, double t1)
Definition: ViewInfo.cpp:51
Unit slope but with either a jump (pasting more) or a flat interval (pasting less)
Definition: TimeWarper.h:181
static TrackIterRange< Track > Group(Track *pTrack)
Definition: SyncLock.cpp:161
bool IsSyncLocked() const
Definition: SyncLock.cpp:43
static SyncLockState & Get(AudacityProject &project)
Definition: SyncLock.cpp:26
R TypeSwitch(const Functions &...functions)
Definition: Track.h:427
void ClearAndPaste(double t0, double t1, const WaveTrack &src, bool preserve=true, bool merge=true, const TimeWarper *effectWarper=nullptr)
Definition: WaveTrack.cpp:1277
std::shared_ptr< const TrackList > FindSourceTracks(const CommandContext &context)
Definition: EditMenus.cpp:415
Correspondence FindCorrespondence(TrackList &dstTracks, const TrackList &srcTracks)
Definition: EditMenus.cpp:488
void DoPasteNothingSelected(AudacityProject &project, const TrackList &src, double t0, double t1)
Definition: EditMenus.cpp:122
bool DoPasteText(AudacityProject &project)
Definition: EditMenus.cpp:41
auto NotificationScope(const CommandContext &context, const TrackList &srcTracks)
Definition: EditMenus.cpp:448
std::pair< double, double > FindSelection(const CommandContext &context)
Definition: EditMenus.cpp:393

References AudacityMessageBox(), WaveTrack::ClearAndPaste(), DoPasteNothingSelected(), DoPasteText(), Track::EnsureVisible(), FindCorrespondence(), FindSelection(), FindSourceTracks(), Clipboard::Get(), TrackFocus::Get(), ProjectHistory::Get(), ViewInfo::Get(), SyncLockState::Get(), TrackList::Get(), SyncLock::Group(), SyncLockState::IsSyncLocked(), NotificationScope(), project, CommandContext::project, ProjectHistory::PushState(), ViewInfo::selectedRegion, NotifyingSelectedRegion::setTimes(), tracks, Track::TypeSwitch(), and XO().

Referenced by EditMenu().

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

◆ OnPreferences()

void anonymous_namespace{EditMenus.cpp}::OnPreferences ( const CommandContext context)

Definition at line 939 of file EditMenus.cpp.

940{
941 auto &project = context.project;
942
943 GlobalPrefsDialog dialog(&GetProjectFrame( project ) /* parent */, &project );
944
945 if( VetoDialogHook::Call( &dialog ) )
946 return;
947
948 if (!dialog.ShowModal()) {
949 // Canceled
950 return;
951 }
952
953 // LL: Moved from PrefsDialog since wxWidgets on OSX can't deal with
954 // rebuilding the menus while the PrefsDialog is still in the modal
955 // state.
956 for (auto p : AllProjects{}) {
958// TODO: The comment below suggests this workaround is obsolete.
959#if defined(__WXGTK__)
960 // Workaround for:
961 //
962 // http://bugzilla.audacityteam.org/show_bug.cgi?id=458
963 //
964 // This workaround should be removed when Audacity updates to wxWidgets
965 // 3.x which has a fix.
966 auto &window = GetProjectFrame( *p );
967 wxRect r = window.GetRect();
968 window.SetSize(wxSize(1,1));
969 window.SetSize(r.GetSize());
970#endif
971 }
972}
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
static result_type Call(Arguments &&...arguments)
Null check of the installed function is done for you.
void RebuildMenuBar(AudacityProject &project)
Definition: Menus.cpp:486
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:69

References GlobalHook< VetoDialogHook, bool(wxDialog *) >::Call(), MenuManager::Get(), GetProjectFrame(), project, CommandContext::project, MenuCreator::RebuildMenuBar(), and PrefsDialog::ShowModal().

Referenced by EditMenu().

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

◆ OnRedo()

void anonymous_namespace{EditMenus.cpp}::OnRedo ( const CommandContext context)

Definition at line 199 of file EditMenus.cpp.

200{
201 auto &project = context.project;
202 auto &tracks = TrackList::Get( project );
203 auto &trackPanel = TrackPanel::Get( project );
204 auto &undoManager = UndoManager::Get( project );
205 auto &window = ProjectWindow::Get( project );
206
207 if (!ProjectHistory::Get( project ).RedoAvailable()) {
208 AudacityMessageBox( XO("Nothing to redo") );
209 return;
210 }
211 // Can't redo whilst dragging
212 if (trackPanel.IsMouseCaptured()) {
213 return;
214 }
215
216 undoManager.Redo(
217 [&]( const UndoStackElem &elem ){
219
220 auto t = *tracks.Selected().begin();
221 if (!t)
222 t = *tracks.begin();
223 TrackFocus::Get(project).Set(t);
224 if (t) {
225 t->EnsureVisible();
226 }
227}
void PopState(const UndoState &state, bool doAutosave=true)
static UndoManager & Get(AudacityProject &project)
Definition: UndoManager.cpp:71
Holds one item with description and time range for the UndoManager.
Definition: UndoManager.h:117
UndoState state
Definition: UndoManager.h:128

References AudacityMessageBox(), Track::EnsureVisible(), TrackFocus::Get(), ProjectHistory::Get(), UndoManager::Get(), TrackList::Get(), ProjectWindow::Get(), TrackPanel::Get(), ProjectHistory::PopState(), project, CommandContext::project, UndoStackElem::state, tracks, and XO().

Referenced by EditMenu().

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

◆ OnSilence()

void anonymous_namespace{EditMenus.cpp}::OnSilence ( const CommandContext context)

Definition at line 736 of file EditMenus.cpp.

737{
738 auto &project = context.project;
740 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
741
742 using namespace BasicUI;
743 const auto selectedWaveTracks = tracks.Selected<WaveTrack>();
744 // TODO replace this with utilities pending in
745 // https://github.com/audacity/audacity/pull/5043
746 auto progress = MakeProgress(
747 XO("Pre-processing"), XO("Rendering Time-Stretched Audio"),
749 const auto numTracks = selectedWaveTracks.size();
750 auto count = 0;
751 auto reportProgress = [&](double progressFraction) {
752 const auto overallProgress = (count + progressFraction) / numTracks;
753 if (
754 progress->Poll(overallProgress * 1000, 1000) !=
756 throw UserException{};
757 };
758 for (auto n : selectedWaveTracks)
759 {
760 n->Silence(selectedRegion.t0(), selectedRegion.t1(), reportProgress);
761 ++count;
762 }
763
765 XO("Silenced selected tracks for %.2f seconds at %.2f")
766 .Format(selectedRegion.duration(), selectedRegion.t0()),
767 /* i18n-hint: verb */
768 XC("Silence", "command"));
769}
#define XC(s, c)
Definition: Internat.h:37
Can be thrown when user cancels operations, as with a progress dialog. Delayed handler does nothing.
Definition: UserException.h:17
@ ProgressShowCancel
Definition: BasicUI.h:141

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), BasicUI::MakeProgress(), BasicUI::ProgressShowCancel, project, CommandContext::project, ProjectHistory::PushState(), ViewInfo::selectedRegion, BasicUI::Success, tracks, XC, and XO().

Referenced by EditMenu().

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

◆ OnSplit()

void anonymous_namespace{EditMenus.cpp}::OnSplit ( const CommandContext context)

Definition at line 792 of file EditMenus.cpp.

793{
794 auto &project = context.project;
796 auto [sel0, sel1] = FindSelection(context);
797 if (auto *pTrack = *tracks.Find(context.temporarySelection.pTrack)) {
798 if (auto pWaveTrack = dynamic_cast<WaveTrack*>(pTrack))
799 pWaveTrack->Split(sel0, sel1);
800 else
801 // Did nothing, don't push history
802 return;
803 }
804 else
805 for (auto wt : tracks.Selected<WaveTrack>())
806 wt->Split(sel0, sel1);
807
808 ProjectHistory::Get( project ).PushState(XO("Split"), XO("Split"));
809#if 0
810//ANSWER-ME: Do we need to keep this commented out OnSplit() code?
811// This whole section no longer used...
812 /*
813 * Previous (pre-multiclip) implementation of "Split" command
814 * This does work only when a range is selected!
815 *
816 TrackListIterator iter(tracks);
817
818 Track *n = iter.First();
819 Track *dest;
820
821 TrackList newTracks;
822
823 while (n) {
824 if (n->GetSelected()) {
825 double sel0 = selectedRegion.t0();
826 double sel1 = selectedRegion.t1();
827
828 dest = n->Copy(sel0, sel1);
829 dest->Init(*n);
830 dest->MoveTo(std::max(sel0, n->GetOffset()));
831
832 if (sel1 >= n->GetEndTime())
833 n->Clear(sel0, sel1);
834 else if (sel0 <= n->GetOffset()) {
835 n->Clear(sel0, sel1);
836 n->MoveTo(sel1);
837 } else
838 n->Silence(sel0, sel1);
839
840 newTracks.Add(dest);
841 }
842 n = iter.Next();
843 }
844
845 TrackListIterator nIter(&newTracks);
846 n = nIter.First();
847 while (n) {
848 tracks->Add(n);
849 n = nIter.Next();
850 }
851
852 PushState(XO("Split"), XO("Split"));
853 */
854#endif
855}

References FindSelection(), ProjectHistory::Get(), TrackList::Get(), project, CommandContext::project, TemporarySelection::pTrack, ProjectHistory::PushState(), CommandContext::temporarySelection, tracks, and XO().

Referenced by EditMenu().

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

◆ OnSplitCut()

void anonymous_namespace{EditMenus.cpp}::OnSplitCut ( const CommandContext context)

Definition at line 678 of file EditMenus.cpp.

679{
680 auto &project = context.project;
682 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
683 auto &window = ProjectWindow::Get(project);
684
685 auto &clipboard = Clipboard::Get();
686 clipboard.Clear();
687
688 auto pNewClipboard = TrackList::Create(nullptr);
689 auto &newClipboard = *pNewClipboard;
690
691 tracks.Selected().Visit(
692 [&](WaveTrack &n) {
693 auto tracks = n.SplitCut(selectedRegion.t0(), selectedRegion.t1());
694 newClipboard.Append(std::move(*tracks));
695 },
696 [&](Track &n) {
697 if (n.SupportsBasicEditing()) {
698 auto dest = n.Copy(selectedRegion.t0(), selectedRegion.t1());
699 n.Silence(selectedRegion.t0(), selectedRegion.t1());
700 newClipboard.Append(std::move(*dest));
701 }
702 }
703 );
704
705 // Survived possibility of exceptions. Commit changes to the clipboard now.
706 clipboard.Assign(std::move(newClipboard),
707 selectedRegion.t0(), selectedRegion.t1(), project.shared_from_this());
708
710 .PushState(XO("Split-cut to the clipboard"), XO("Split Cut"));
711}
void Silence(double t0, double t1, ProgressReporter reportProgress) override
Definition: WaveTrack.cpp:2116
TrackListHolder Copy(double t0, double t1, bool forClipboard=true) const override
Create new tracks and don't modify this track.
Definition: WaveTrack.cpp:1147
TrackListHolder SplitCut(double t0, double t1)
Definition: WaveTrack.cpp:1055

References WaveTrack::Copy(), TrackList::Create(), Clipboard::Get(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), project, CommandContext::project, ProjectHistory::PushState(), ViewInfo::selectedRegion, WaveTrack::Silence(), WaveTrack::SplitCut(), Track::SupportsBasicEditing(), tracks, and XO().

Referenced by EditMenu().

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

◆ OnSplitDelete()

void anonymous_namespace{EditMenus.cpp}::OnSplitDelete ( const CommandContext context)

Definition at line 713 of file EditMenus.cpp.

714{
715 auto &project = context.project;
717 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
718 auto &window = ProjectWindow::Get(project);
719
720 tracks.Selected().Visit(
721 [&](WaveTrack &wt) {
722 wt.SplitDelete(selectedRegion.t0(), selectedRegion.t1());
723 },
724 [&](Track &n) {
725 if (n.SupportsBasicEditing())
726 n.Silence(selectedRegion.t0(), selectedRegion.t1());
727 }
728 );
729
731 XO("Split-deleted %.2f seconds at t=%.2f")
732 .Format(selectedRegion.duration(), selectedRegion.t0()),
733 XO("Split Delete"));
734}
void SplitDelete(double t0, double t1)
Definition: WaveTrack.cpp:1579

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), project, CommandContext::project, ProjectHistory::PushState(), ViewInfo::selectedRegion, WaveTrack::SplitDelete(), tracks, and XO().

Referenced by EditMenu().

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

◆ OnSplitNew()

void anonymous_namespace{EditMenus.cpp}::OnSplitNew ( const CommandContext context)

Definition at line 857 of file EditMenus.cpp.

858{
859 auto &project = context.project;
861 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
862 auto &window = ProjectWindow::Get(project);
863
864 // This iteration is unusual because we add to the list inside the loop
865 auto range = tracks.Selected();
866 auto last = *range.rbegin();
867 for (auto track : range) {
868 track->TypeSwitch(
869 [&](WaveTrack &wt) {
870 // Clips must be aligned to sample positions or the NEW clip will
871 // not fit in the gap where it came from
872 const double newt0 = wt.SnapToSample(selectedRegion.t0());
873 const double newt1 = wt.SnapToSample(selectedRegion.t1());
874 // Fix issue 2846 by calling copy with forClipboard = false.
875 // This avoids creating the blank placeholder clips
876 const auto dest = wt.Copy(newt0, newt1, false);
877 if (dest) {
878 // The copy function normally puts the clip at time 0
879 // This offset lines it up with the original track's timing
880 (*dest->begin())->MoveTo(newt0);
881 tracks.Append(std::move(*dest));
882 }
883 wt.SplitDelete(newt0, newt1);
884 }
885#if 0
886 ,
887 // LL: For now, just skip all non-wave tracks since the other do not
888 // yet support proper splitting.
889 [&](Track &n) {
890 dest = n.Cut(viewInfo.selectedRegion.t0(),
891 viewInfo.selectedRegion.t1());
892 if (dest) {
893 dest->MoveTo(std::max(0, n.GetOffset()));
894 tracks.Add(dest);
895 }
896 }
897#endif
898 );
899 if (track == last)
900 break;
901 }
902
904 .PushState(XO("Split to new track"), XO("Split New"));
905}
double SnapToSample(double t) const

References WaveTrack::Copy(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), project, CommandContext::project, ProjectHistory::PushState(), ViewInfo::selectedRegion, WideSampleSequence::SnapToSample(), WaveTrack::SplitDelete(), tracks, and XO().

Referenced by EditMenu().

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

◆ OnTrim()

void anonymous_namespace{EditMenus.cpp}::OnTrim ( const CommandContext context)

Definition at line 771 of file EditMenus.cpp.

772{
773 auto &project = context.project;
774 auto &tracks = TrackList::Get( project );
775 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
776 auto &window = ProjectWindow::Get( project );
777
778 if (selectedRegion.isPoint())
779 return;
780
781 tracks.Selected().Visit( [&](WaveTrack &wt) {
782 //Hide the section before the left selector
783 wt.Trim(selectedRegion.t0(), selectedRegion.t1());
784 } );
785
787 XO("Trim selected audio tracks from %.2f seconds to %.2f seconds")
788 .Format( selectedRegion.t0(), selectedRegion.t1() ),
789 XO("Trim Audio"));
790}
void Trim(double t0, double t1)
Definition: WaveTrack.cpp:1070

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), project, CommandContext::project, ProjectHistory::PushState(), ViewInfo::selectedRegion, tracks, WaveTrack::Trim(), and XO().

Referenced by EditMenu().

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

◆ OnUndo()

void anonymous_namespace{EditMenus.cpp}::OnUndo ( const CommandContext context)

Definition at line 168 of file EditMenus.cpp.

169{
170 auto &project = context.project;
171 auto &tracks = TrackList::Get( project );
172 auto &trackPanel = TrackPanel::Get( project );
173 auto &undoManager = UndoManager::Get( project );
174 auto &window = ProjectWindow::Get( project );
175
176 if (!ProjectHistory::Get( project ).UndoAvailable()) {
177 AudacityMessageBox( XO("Nothing to undo") );
178 return;
179 }
180
181 // can't undo while dragging
182 if (trackPanel.IsMouseCaptured()) {
183 return;
184 }
185
186 undoManager.Undo(
187 [&]( const UndoStackElem &elem ){
189
190 auto t = *tracks.Selected().begin();
191 if (!t)
192 t = *tracks.begin();
193 TrackFocus::Get(project).Set(t);
194 if (t) {
195 t->EnsureVisible();
196 }
197}

References AudacityMessageBox(), Track::EnsureVisible(), TrackFocus::Get(), ProjectHistory::Get(), UndoManager::Get(), TrackList::Get(), ProjectWindow::Get(), TrackPanel::Get(), ProjectHistory::PopState(), project, CommandContext::project, UndoStackElem::state, tracks, and XO().

Referenced by EditMenu().

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

Variable Documentation

◆ canSelectAll

auto anonymous_namespace{EditMenus.cpp}::canSelectAll
Initial value:
= [](const AudacityProject &project){
int mWhatIfNoSelection
Definition: Menus.h:124

Definition at line 1172 of file EditMenus.cpp.

◆ sAttachment1

AttachedItem anonymous_namespace{EditMenus.cpp}::sAttachment1
Initial value:
{
wxT(""),
}
std::unique_ptr< detail::IndirectItem< Item > > Indirect(const std::shared_ptr< Item > &ptr)
A convenience function.
Definition: Registry.h:113

Definition at line 1150 of file EditMenus.cpp.

◆ sAttachment2

AttachedItem anonymous_namespace{EditMenus.cpp}::sAttachment2
Initial value:
{
wxT("Optional/Extra/Part1"),
}
BaseItemSharedPtr ExtraEditMenu()
Definition: EditMenus.cpp:1155

Definition at line 1210 of file EditMenus.cpp.

◆ selectAll

auto anonymous_namespace{EditMenus.cpp}::selectAll
Initial value:
= []( AudacityProject &project, CommandFlag flagsRqd ){
(flagsRqd & NoAutoSelect()).none() )
}
std::bitset< NCommandFlags > CommandFlag
Definition: CommandFlag.h:30
@ none
Definition: Dither.h:20
void DoSelectAllAudio(AudacityProject &project)

Definition at line 1174 of file EditMenus.cpp.

◆ selectAnyTracks

RegisteredMenuItemEnabler anonymous_namespace{EditMenus.cpp}::selectAnyTracks
Initial value:
{{
[]{ return TracksExistFlag(); },
[]{ return AnyTracksSelectedFlag(); },
}}
const ReservedCommandFlag & AnyTracksSelectedFlag()
const ReservedCommandFlag & TracksExistFlag()

Definition at line 1188 of file EditMenus.cpp.

◆ selectTracks

RegisteredMenuItemEnabler anonymous_namespace{EditMenus.cpp}::selectTracks
Initial value:
{{
[]{ return TracksExistFlag(); },
[]{ return EditableTracksSelectedFlag(); },
}}

Definition at line 1180 of file EditMenus.cpp.

◆ selectWaveTracks

RegisteredMenuItemEnabler anonymous_namespace{EditMenus.cpp}::selectWaveTracks
Initial value:
{{
[]{ return WaveTracksExistFlag(); },
}}
const ReservedCommandFlag & WaveTracksExistFlag()

Definition at line 1195 of file EditMenus.cpp.

◆ selectWaveTracks2

RegisteredMenuItemEnabler anonymous_namespace{EditMenus.cpp}::selectWaveTracks2
Initial value:
{{
[]{ return WaveTracksExistFlag(); },
}}
const ReservedCommandFlag & NoiseReductionTimeSelectedFlag()

Definition at line 1203 of file EditMenus.cpp.