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 ClearClipboard ()
 
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 ()
 
const ReservedCommandFlagJoinClipsAvailableFlag ()
 
auto EditMenu ()
 
auto ExtraEditMenu ()
 

Variables

AttachedItem sAttachment1 { Indirect(EditMenu()) }
 
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 514 of file EditMenus.cpp.

Function Documentation

◆ ClearClipboard()

void anonymous_namespace{EditMenus.cpp}::ClearClipboard ( )

Definition at line 239 of file EditMenus.cpp.

240{
241 if (wxTheClipboard->Open())
242 {
243 // Clear the data from the clipboard, so that the next paste doesn't
244 // attempt to import whatever the user copied from the OS in a prior
245 // action.
246 const auto success = wxTheClipboard->SetData(safenew wxTextDataObject);
247 assert(success);
248 wxTheClipboard->Clear();
249 wxTheClipboard->Close();
250 }
251}
#define safenew
Definition: MemoryX.h:10

References safenew.

Referenced by OnCopy(), and OnCut().

Here is the caller graph for this function:

◆ CutCopyAvailableFlag()

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

Definition at line 1071 of file EditMenus.cpp.

1071 { static ReservedCommandFlag flag{
1072 [](const AudacityProject &project){
1073 auto range = TrackList::Get(project).Any<const LabelTrack>()
1074 + [&](const LabelTrack *pTrack){
1075 return LabelTrackView::Get( *pTrack ).IsTextSelected(
1076 // unhappy const_cast because track focus might be set
1077 const_cast<AudacityProject&>(project)
1078 );
1079 };
1080 if ( !range.empty() )
1081 return true;
1082
1083 if (
1085 &&
1087 )
1088 return true;
1089
1090 return false;
1091 },
1093}; return flag; }
bool EditableTracksSelectedPred(const AudacityProject &project)
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:98
static LabelTrackView & Get(LabelTrack &)
bool IsTextSelected(AudacityProject &project) const
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:950
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
CommandFlagOptions && DisableDefaultMessage() &&
Definition: CommandFlag.h:53

References TrackList::Any(), CommandFlagOptions::DisableDefaultMessage(), 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 128 of file EditMenus.cpp.

129{
130 auto &tracks = TrackList::Get( project );
131 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
132 auto &viewInfo = ViewInfo::Get( project );
133
134 assert(tracks.Selected().empty());
135
136 Track* pFirstNewTrack = NULL;
137 for (auto pClip : src) {
138 auto pNewTrack = pClip->PasteInto(project, tracks);
139 if (!pFirstNewTrack)
140 pFirstNewTrack = pNewTrack.get();
141 pNewTrack->SetSelected(true);
142 }
143
144 // Select some pasted samples, which is probably impossible to get right
145 // with various project and track sample rates.
146 // So do it at the sample rate of the project
147 const double projRate = ProjectRate::Get( project ).GetRate();
148 const double projTempo = ProjectTimeSignature::Get(project).GetTempo();
149 const double srcTempo =
150 pFirstNewTrack ? GetProjectTempo(*pFirstNewTrack).value_or(projTempo) :
151 projTempo;
152 // Apply adequate stretching to the selection. A selection of 10 seconds of
153 // audio in project A should become 5 seconds in project B if tempo in B is
154 // twice as fast.
155 const double quantT0 = QUANTIZED_TIME(t0 * srcTempo / projTempo, projRate);
156 const double quantT1 = QUANTIZED_TIME(t1 * srcTempo / projTempo, projRate);
157 selectedRegion.setTimes(
158 0.0, // anywhere else and this should be
159 // half a sample earlier
160 quantT1 - quantT0);
161
163 .PushState(XO("Pasted from the clipboard"), XO("Paste"));
164
165 if (pFirstNewTrack) {
166 TrackFocus::Get(project).Set(pFirstNewTrack);
167 Viewport::Get(project).ShowTrack(*pFirstNewTrack);
168 }
169}
XO("Cut/Copy/Paste")
#define QUANTIZED_TIME(time, rate)
Definition: MemoryX.h:336
const std::optional< double > & GetProjectTempo(const ChannelGroup &group)
Definition: TempoChange.cpp:48
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 ProjectTimeSignature & Get(AudacityProject &project)
Track * Get()
Definition: TrackFocus.cpp:156
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
virtual void SetSelected(bool s)
Definition: Track.cpp:83
virtual Holder PasteInto(AudacityProject &project, TrackList &list) const =0
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
void ShowTrack(const Track &track)
Definition: Viewport.cpp:460
static Viewport & Get(AudacityProject &project)
Definition: Viewport.cpp:33

References TrackFocus::Get(), ProjectTimeSignature::Get(), ProjectHistory::Get(), ProjectRate::Get(), ViewInfo::Get(), TrackList::Get(), Viewport::Get(), GetProjectTempo(), ProjectRate::GetRate(), ProjectTimeSignature::GetTempo(), Track::PasteInto(), project, ProjectHistory::PushState(), QUANTIZED_TIME, ViewInfo::selectedRegion, Track::SetSelected(), Viewport::ShowTrack(), 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 47 of file EditMenus.cpp.

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

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), Viewport::Get(), TrackPanel::Get(), LabelTrackView::Get(), WaveChannelView::GetFirst(), 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 111 of file EditMenus.cpp.

111 {
112 auto result = TrackList::Create(nullptr);
113 for (auto track : src) {
114 const auto pTrack =
115 track->Copy(track->GetStartTime(), track->GetEndTime(), false);
116 pTrack->MoveTo(track->GetStartTime());
117 if (const auto waveTrack = dynamic_cast<WaveTrack*>(pTrack.get()))
119 result->Add(pTrack);
120 }
121 return result;
122}
static TrackListHolder Create(AudacityProject *pOwner)
Definition: Track.cpp:330
WAVE_TRACK_API void DiscardTrimmed(WaveTrack &track)
Remove hidden audio from all clips.

References TrackList::Create(), and WaveTrackUtilities::DiscardTrimmed().

Referenced by FindSourceTracks().

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

◆ EditMenu()

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

Definition at line 1121 of file EditMenus.cpp.

1122{
1123 static const auto NotBusyTimeAndTracksFlags =
1125
1126 // The default shortcut key for Redo is different on different platforms.
1127 static constexpr auto redoKey =
1128#ifdef __WXMSW__
1129 wxT("Ctrl+Y")
1130#else
1131 wxT("Ctrl+Shift+Z")
1132#endif
1133 ;
1134
1135 // The default shortcut key for Preferences is different on different
1136 // platforms.
1137 static constexpr auto prefKey =
1138#ifdef __WXMAC__
1139 wxT("Ctrl+,")
1140#else
1141 wxT("Ctrl+P")
1142#endif
1143 ;
1144
1145 static auto menu = std::shared_ptr{
1146 Menu( wxT("Edit"), XXO("&Edit"),
1147 Section( "UndoRedo",
1148 Command( wxT("Undo"), XXO("&Undo"), OnUndo,
1149 AudioIONotBusyFlag() | UndoAvailableFlag(), wxT("Ctrl+Z") ),
1150
1151 Command( wxT("Redo"), XXO("&Redo"), OnRedo,
1152 AudioIONotBusyFlag() | RedoAvailableFlag(), redoKey ),
1153
1154 MenuCreator::Special( wxT("UndoItemsUpdateStep"),
1155 [](AudacityProject &project, wxMenu&) {
1156 // Change names in the CommandManager as a side-effect
1158 })
1159 ),
1160
1161 Section( "Basic",
1162 // Basic Edit commands
1163 /* i18n-hint: (verb)*/
1164 Command( wxT("Cut"), XXO("Cu&t"), OnCut,
1166 wxT("Ctrl+X") ),
1167 Command( wxT("Delete"), XXO("&Delete"), OnDelete,
1169 wxT("Ctrl+K") ),
1170 /* i18n-hint: (verb)*/
1171 Command( wxT("Copy"), XXO("&Copy"), OnCopy,
1172 AudioIONotBusyFlag() | CutCopyAvailableFlag(), wxT("Ctrl+C") ),
1173 /* i18n-hint: (verb)*/
1174 Command( wxT("Paste"), XXO("&Paste"), OnPaste,
1175 AudioIONotBusyFlag(), wxT("Ctrl+V") ),
1176 /* i18n-hint: (verb)*/
1177 Command( wxT("Duplicate"), XXO("Duplic&ate"), OnDuplicate,
1178 NotBusyTimeAndTracksFlags, wxT("Ctrl+D") ),
1179
1180 Section( "",
1181 Menu( wxT("RemoveSpecial"), XXO("R&emove Special"),
1182 Section( "",
1183 /* i18n-hint: (verb) Do a special kind of cut*/
1184 Command( wxT("SplitCut"), XXO("&Cut and leave gap"), OnSplitCut,
1185 NotBusyTimeAndTracksFlags,
1186 Options{ wxT("Ctrl+Alt+X") } ),
1187 /* i18n-hint: (verb) Do a special kind of DELETE*/
1188 Command( wxT("SplitDelete"), XXO("&Delete and leave gap"), OnSplitDelete,
1189 NotBusyTimeAndTracksFlags,
1190 Options{ wxT("Ctrl+Alt+K") } )
1191 ),
1192
1193 Section( "",
1194 /* i18n-hint: (verb)*/
1195 Command( wxT("Silence"), XXO("Silence Audi&o"), OnSilence,
1197 wxT("Ctrl+L") ),
1198 /* i18n-hint: (verb)*/
1199 Command( wxT("Trim"), XXO("Tri&m Audio"), OnTrim,
1201 Options{ wxT("Ctrl+T") } )
1202 )
1203 )
1204 )
1205 ),
1206
1207
1208 Section( "Other",
1210
1211 Menu( wxT("Clip"), XXO("Audi&o Clips"),
1212 Section( "",
1213 /* i18n-hint: (verb) It's an item on a menu. */
1214 Command( wxT("Split"), XXO("Sp&lit"), OnSplit,
1216 Options{ wxT("Ctrl+I") } ),
1217 Command( wxT("SplitNew"), XXO("Split Ne&w"), OnSplitNew,
1219 Options{ wxT("Ctrl+Alt+I") } )
1220 ),
1221
1222 Section( "",
1223 /* i18n-hint: (verb)*/
1224 Command( wxT("Join"), XXO("&Join"), OnJoin,
1225 JoinClipsAvailableFlag(), wxT("Ctrl+J") ),
1226 Command( wxT("Disjoin"), XXO("Detac&h at Silences"), OnDisjoin,
1227 NotBusyTimeAndTracksFlags, wxT("Ctrl+Alt+J") )
1228 )
1229 )
1230
1231 ),
1232
1233 // Note that on Mac, the Preferences menu item is specially handled in
1234 // CommandManager (assigned a special wxWidgets id) so that it does
1235 // not appear in the Edit menu but instead under Audacity, consistent with
1236 // MacOS conventions.
1237 Section( "Preferences",
1238 Command( wxT("Preferences"), XXO("Pre&ferences"), OnPreferences,
1239 AudioIONotBusyFlag(), prefKey )
1240 )
1241
1242 ) };
1243 return menu;
1244}
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 CommandManager & Get(AudacityProject &project)
static constexpr auto Special
Definition: MenuCreator.h:36
constexpr auto Section
Definition: MenuRegistry.h:436
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 OnDisjoin(const CommandContext &context)
Definition: EditMenus.cpp:1000
void OnRedo(const CommandContext &context)
Definition: EditMenus.cpp:211
void OnJoin(const CommandContext &context)
Definition: EditMenus.cpp:976
void OnDelete(const CommandContext &context)
Definition: EditMenus.cpp:348
void OnPaste(const CommandContext &context)
Definition: EditMenus.cpp:546
const ReservedCommandFlag & CutCopyAvailableFlag()
Definition: EditMenus.cpp:1071
void OnSplit(const CommandContext &context)
Definition: EditMenus.cpp:862
void OnSilence(const CommandContext &context)
Definition: EditMenus.cpp:818
const ReservedCommandFlag & JoinClipsAvailableFlag()
Definition: EditMenus.cpp:1096
void OnTrim(const CommandContext &context)
Definition: EditMenus.cpp:842
void OnSplitDelete(const CommandContext &context)
Definition: EditMenus.cpp:796
void OnCopy(const CommandContext &context)
Definition: EditMenus.cpp:373
void OnUndo(const CommandContext &context)
Definition: EditMenus.cpp:182
void OnSplitCut(const CommandContext &context)
Definition: EditMenus.cpp:762
void OnPreferences(const CommandContext &context)
Definition: EditMenus.cpp:1015
void OnDuplicate(const CommandContext &context)
Definition: EditMenus.cpp:735
void OnSplitNew(const CommandContext &context)
Definition: EditMenus.cpp:927
void OnCut(const CommandContext &context)
Definition: EditMenus.cpp:253

References AudioIONotBusyFlag(), MenuRegistry::Command, CutCopyAvailableFlag(), EditableTracksSelectedFlag(), CommandManager::Get(), JoinClipsAvailableFlag(), MenuRegistry::Menu, CommandManager::ModifyUndoMenuItems(), NoAutoSelect(), OnCopy(), OnCut(), OnDelete(), OnDisjoin(), OnDuplicate(), OnJoin(), OnPaste(), OnPreferences(), OnRedo(), OnSilence(), OnSplit(), OnSplitCut(), OnSplitDelete(), OnSplitNew(), OnTrim(), OnUndo(), project, RedoAvailableFlag(), MenuRegistry::Section, MenuCreator::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 103 of file EditMenus.cpp.

104{
105 BlockArray::size_type result{};
106 for (const auto waveTrack : src.Any<const WaveTrack>())
107 result += WaveTrackUtilities::CountBlocks(*waveTrack);
108 return result;
109}
WAVE_TRACK_API size_t CountBlocks(const WaveTrack &track)

References TrackList::Any(), and WaveTrackUtilities::CountBlocks().

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 91 of file EditMenus.cpp.

92{
93 wxULongLong result{};
94 for (auto waveTrack : src.Any<const WaveTrack>()) {
95 const auto samplesCount =
97 result += samplesCount.as_long_long() *
98 SAMPLE_SIZE(waveTrack->GetSampleFormat());
99 }
100 return result;
101}
#define SAMPLE_SIZE(SampleFormat)
Definition: SampleFormat.h:52
WAVE_TRACK_API sampleCount GetSequenceSamplesCount(const WaveTrack &track)

References TrackList::Any(), WaveTrackUtilities::GetSequenceSamplesCount(), and SAMPLE_SIZE.

Referenced by FindSourceTracks().

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

◆ ExtraEditMenu()

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

Definition at line 1248 of file EditMenus.cpp.

1249{
1250 static const auto flags =
1252 static auto menu = std::shared_ptr{
1253 Menu( wxT("Edit"), XXO("&Edit"),
1254 Command( wxT("DeleteKey"), XXO("&Delete Key"), OnDelete,
1255 (flags | NoAutoSelect()),
1256 wxT("Backspace") ),
1257 Command( wxT("DeleteKey2"), XXO("Delete Key&2"), OnDelete,
1258 (flags | NoAutoSelect()),
1259 wxT("Delete") )
1260 ) };
1261 return menu;
1262}

References AudioIONotBusyFlag(), MenuRegistry::Command, EditableTracksSelectedFlag(), MenuRegistry::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 516 of file EditMenus.cpp.

518{
519 Correspondence result;
520 auto dstRange = dstTracks.Selected();
521 if (dstRange.size() == 1)
522 // Special rule when only one track is selected interprets the user's
523 // intent as pasting into that track and following ones
524 dstRange = dstTracks.Any().StartingWith(*dstRange.begin());
525 auto srcRange = srcTracks.Any();
526 while (!(dstRange.empty() || srcRange.empty())) {
527 auto &dst = **dstRange.begin();
528 auto &src = **srcRange.begin();
529 if (!FitsInto(src, dst)) {
530 // Skip selected track of inappropriate type and try again
531 ++dstRange.first;
532 continue;
533 }
534 result.emplace_back(&dst, &src);
535 ++srcRange.first;
536 ++dstRange.first;
537 }
538
539 if (!srcRange.empty())
540 // Could not fit all source tracks into the selected tracks
541 return {};
542 else
543 return result;
544}
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:967
bool FitsInto(const Track &src, const Track &dst)
Whether the source track may be pasted into the destination track.
Definition: EditMenus.cpp:503
std::vector< std::pair< Track *, const Track * > > Correspondence
Definition: EditMenus.cpp:514

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 419 of file EditMenus.cpp.

420{
421 double sel0 = 0.0, sel1 = 0.0;
422
423#if 0
424 // Use the overriding selection if any was given in the context
425 if (auto *pRegion = context.temporarySelection.pSelectedRegion) {
426 auto &selectedRegion = *pRegion;
427 sel0 = selectedRegion.t0();
428 sel1 = selectedRegion.t1();
429 }
430 else
431#endif
432 {
433 auto &selectedRegion = ViewInfo::Get(context.project).selectedRegion;
434 sel0 = selectedRegion.t0();
435 sel1 = selectedRegion.t1();
436 }
437
438 return { sel0, sel1 };
439}
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 441 of file EditMenus.cpp.

442{
443 auto &project = context.project;
444 auto &window = GetProjectFrame(project);
446 const auto &clipboard = Clipboard::Get();
447 auto discardTrimmed = false;
448 if (&context.project != &*clipboard.Project().lock()) {
449 const auto waveClipCopyPolicy = TracksBehaviorsAudioTrackPastePolicy.Read();
450 if (waveClipCopyPolicy == wxT("Ask") &&
451 HasHiddenData(clipboard.GetTracks()))
452 {
453 AudioPasteDialog audioPasteDialog(
454 &window,
455 EstimateCopyBytesCount(clipboard.GetTracks(), tracks)
456 );
457 const auto result = audioPasteDialog.ShowModal();
458 if(result == wxID_CANCEL)
459 return {};
460 discardTrimmed =
462 }
463 else if(waveClipCopyPolicy == wxT("Discard"))
464 discardTrimmed = true;
465 }
466
467 std::shared_ptr<const TrackList> srcTracks;
468 if(discardTrimmed)
469 srcTracks = DuplicateDiscardTrimmed(clipboard.GetTracks());
470 else
471 srcTracks = clipboard.GetTracks().shared_from_this();
472
473 return srcTracks;
474}
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 ...
ChoiceSetting TracksBehaviorsAudioTrackPastePolicy
wxString Read() const
Definition: Prefs.cpp:388
static Clipboard & Get()
Definition: Clipboard.cpp:28
wxULongLong EstimateCopyBytesCount(const TrackList &src, const TrackList &dst)
Definition: EditMenus.cpp:91
std::shared_ptr< TrackList > DuplicateDiscardTrimmed(const TrackList &src)
Definition: EditMenus.cpp:111
bool HasHiddenData(const TrackList &trackList)
Definition: EditMenus.cpp:171

References AudioPasteDialog::DISCARD, DuplicateDiscardTrimmed(), EstimateCopyBytesCount(), Clipboard::Get(), TrackList::Get(), GetProjectFrame(), HasHiddenData(), CommandContext::project, 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 503 of file EditMenus.cpp.

504{
505 if (!src.SameKindAs(dst))
506 return false;
507 // Mono can "fit" into stereo, by duplication of the channel
508 // Otherwise non-wave tracks always have just one "channel"
509 // Future: Fit stereo into mono too, using mix-down
510 return src.NChannels() <= dst.NChannels();
511}
virtual size_t NChannels() const =0
Report the number of channels.
bool SameKindAs(const Track &track) const
Definition: Track.h:373

References ChannelGroup::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 171 of file EditMenus.cpp.

172{
173 const auto range = trackList.Any<const WaveTrack>();
174 return std::any_of(range.begin(), range.end(),
175 [](const WaveTrack *pTrack){
176 return WaveTrackUtilities::HasHiddenData(*pTrack);
177 });
178}

References TrackList::Any().

Referenced by FindSourceTracks().

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

◆ JoinClipsAvailableFlag()

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

Definition at line 1096 of file EditMenus.cpp.

1096 { static ReservedCommandFlag flag {
1097 [](const AudacityProject &project)
1098 {
1100 return false;
1101
1102 const auto &viewInfo = ViewInfo::Get(project);
1103 if(viewInfo.selectedRegion.isPoint())
1104 return false;
1105
1106 const auto selectedTracks = TrackList::Get(project).Selected<const WaveTrack>();
1107 for (const auto track : selectedTracks)
1108 {
1109 const auto selectedClips =
1111 viewInfo.selectedRegion.t0(), viewInfo.selectedRegion.t1());
1112 if(selectedClips.size() > 1)
1113 return true;
1114 }
1115 return false;
1116 },
1118}; return flag; }
bool AudioIOBusyPred(const AudacityProject &project)
WAVE_TRACK_API WaveTrack::IntervalConstHolders GetClipsIntersecting(const WaveTrack &track, double t0, double t1)

References AudioIOBusyPred(), CommandFlagOptions::DisableDefaultMessage(), flag, ViewInfo::Get(), TrackList::Get(), WaveTrackUtilities::GetClipsIntersecting(), project, and TrackList::Selected().

Referenced by EditMenu().

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 476 of file EditMenus.cpp.

478{
479 auto &project = context.project;
481 auto &trackFactory = WaveTrackFactory::Get(project);
482 auto &pSampleBlockFactory = trackFactory.GetSampleBlockFactory();
483 return pSampleBlockFactory->Subscribe([
484 toCopy = EstimateCopiedBlocks(srcTracks, tracks),
485 nCopied = 0,
486 copyStartTime = std::chrono::system_clock::now(),
487 progressDialog = std::shared_ptr<BasicUI::ProgressDialog>()]
488 (const SampleBlockCreateMessage&) mutable {
489 using namespace std::chrono;
490 constexpr auto ProgressDialogShowDelay = milliseconds { 100 };
491 ++nCopied;
492 if(!progressDialog) {
493 if(duration_cast<milliseconds>(system_clock::now() - copyStartTime) >= ProgressDialogShowDelay)
494 progressDialog = BasicUI::MakeProgress(XO("Paste clip"), XO("Pasting clip contents, please wait"), 0);
495 }
496 else {
497 progressDialog->Poll(nCopied, toCopy);
498 }
499 });
500}
static WaveTrackFactory & Get(AudacityProject &project)
Definition: WaveTrack.cpp:3376
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:302
BlockArray::size_type EstimateCopiedBlocks(const TrackList &src, const TrackList &dst)
Definition: EditMenus.cpp:103

References EstimateCopiedBlocks(), TrackList::Get(), WaveTrackFactory::Get(), BasicUI::MakeProgress(), CommandContext::project, 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 373 of file EditMenus.cpp.

374{
376
377 auto &project = context.project;
378 auto &tracks = TrackList::Get( project );
379 auto &trackPanel = TrackPanel::Get( project );
380 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
381
382 for (auto lt : tracks.Selected<LabelTrack>()) {
383 auto &view = LabelTrackView::Get( *lt );
384 if (view.CopySelectedText( context.project )) {
385 //trackPanel.Refresh(false);
386 return;
387 }
388 }
389 //Presumably, there might be not more than one track
390 //that expects text input
391 for (auto wt : tracks.Any<WaveTrack>()) {
392 auto& view = WaveChannelView::GetFirst(*wt);
393 if (view.CopySelectedText(context.project)) {
394 return;
395 }
396 }
397
398 auto &clipboard = Clipboard::Get();
399 clipboard.Clear();
400
401 auto pNewClipboard = TrackList::Create( nullptr );
402 auto &newClipboard = *pNewClipboard;
403
404 for (auto n : tracks.Selected()) {
405 if (n->SupportsBasicEditing()) {
406 auto dest = n->Copy(selectedRegion.t0(), selectedRegion.t1());
407 newClipboard.Add(dest);
408 }
409 }
410
411 // Survived possibility of exceptions. Commit changes to the clipboard now.
412 clipboard.Assign( std::move( newClipboard ),
413 selectedRegion.t0(), selectedRegion.t1(), project.shared_from_this() );
414
415 //Make sure the menus/toolbar states get updated
416 trackPanel.Refresh(false);
417}

References ClearClipboard(), TrackList::Create(), Clipboard::Get(), ViewInfo::Get(), TrackList::Get(), TrackPanel::Get(), LabelTrackView::Get(), WaveChannelView::GetFirst(), CommandContext::project, 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 253 of file EditMenus.cpp.

254{
256
257 auto &project = context.project;
258 auto &tracks = TrackList::Get( project );
259 auto &trackPanel = TrackPanel::Get( project );
260 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
262
263 // This doesn't handle cutting labels, it handles
264 // cutting the _text_ inside of labels, i.e. if you're
265 // in the middle of editing the label text and select "Cut".
266
267 for (auto lt : tracks.Selected<LabelTrack>()) {
268 auto &view = LabelTrackView::Get( *lt );
269 if (view.CutSelectedText( context.project )) {
270 trackPanel.Refresh(false);
271 return;
272 }
273 }
274
275 //Presumably, there might be not more than one track
276 //that expects text input
277 for (auto wt : tracks.Any<WaveTrack>()) {
278 auto& view = WaveChannelView::GetFirst(*wt);
279 if (view.CutSelectedText(context.project)) {
280 trackPanel.Refresh(false);
281 return;
282 }
283 }
284
285 auto &clipboard = Clipboard::Get();
286 clipboard.Clear();
287
288 auto pNewClipboard = TrackList::Create( nullptr );
289 auto &newClipboard = *pNewClipboard;
290
291 tracks.Selected().Visit(
292#if defined(USE_MIDI)
293 [&](NoteTrack &n) {
294 // Since portsmf has a built-in cut operator, we use that instead
295 auto dest = n.Cut(selectedRegion.t0(), selectedRegion.t1());
296 newClipboard.Add(dest);
297 },
298#endif
299 [&](Track &n) {
300 if (n.SupportsBasicEditing()) {
301 auto dest = n.Copy(selectedRegion.t0(), selectedRegion.t1());
302 newClipboard.Add(dest);
303 }
304 }
305 );
306
307 // Survived possibility of exceptions. Commit changes to the clipboard now.
308 clipboard.Assign(
309 std::move( newClipboard ),
310 selectedRegion.t0(),
311 selectedRegion.t1(),
312 project.shared_from_this()
313 );
314
315 // Proceed to change the project. If this throws, the project will be
316 // rolled back by the top level handler.
317
319#if defined(USE_MIDI)
320 [](NoteTrack&) {
321 //if NoteTrack, it was cut, so do not clear anything
322
323 // PRL: But what if it was sync lock selected only, not selected?
324 },
325#endif
326 [&](auto &&fallthrough){ return [&](WaveTrack &wt) {
327 if (gPrefs->Read(wxT("/GUI/EnableCutLines"), (long)0))
328 wt.ClearAndAddCutLine(selectedRegion.t0(), selectedRegion.t1());
329 else
330 fallthrough();
331 }; },
332 [&](Track &n) {
333 if (n.SupportsBasicEditing())
334 n.Clear(selectedRegion.t0(), selectedRegion.t1());
335 }
336 );
337
338 selectedRegion.collapseToT0();
339
341 .PushState(XO("Cut to the clipboard"), XO("Cut"));
342
343 // Bug 1663
344 //mRuler->ClearPlayRegion();
345 ruler.DrawOverlays( true );
346}
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:78
Track::Holder Cut(double t0, double t1) override
Create tracks and modify this track.
Definition: NoteTrack.cpp:326
void Clear(double t0, double t1) override
Definition: NoteTrack.cpp:403
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
Create new tracks and don't modify this track.
Definition: NoteTrack.cpp:356
static bool IsSelectedOrSyncLockSelectedP(const Track *pTrack)
Definition: SyncLock.h:61
virtual bool SupportsBasicEditing() const
Whether this track type implements cut-copy-paste; by default, true.
Definition: Track.cpp:797
virtual bool Read(const wxString &key, bool *value) const =0
MENUS_API void Visit(Visitor< Traits > &visitor, AudacityProject &project)

References NoteTrack::Clear(), ClearClipboard(), NoteTrack::Copy(), TrackList::Create(), NoteTrack::Cut(), Clipboard::Get(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), AdornedRulerPanel::Get(), TrackPanel::Get(), LabelTrackView::Get(), WaveChannelView::GetFirst(), gPrefs, SyncLock::IsSelectedOrSyncLockSelectedP(), CommandContext::project, project, ProjectHistory::PushState(), audacity::BasicSettings::Read(), anonymous_namespace{TimeTrackVRulerControls.cpp}::ruler(), ViewInfo::selectedRegion, Track::SupportsBasicEditing(), tracks, MenuRegistry::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 348 of file EditMenus.cpp.

349{
350 auto &project = context.project;
351 auto &tracks = TrackList::Get( project );
352 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
353
354 for (auto n : tracks) {
355 if (!n->SupportsBasicEditing())
356 continue;
358 n->Clear(selectedRegion.t0(), selectedRegion.t1());
359 }
360 }
361
362 double seconds = selectedRegion.duration();
363
364 selectedRegion.collapseToT0();
365
367 XO("Deleted %.2f seconds at t=%.2f")
368 .Format( seconds, selectedRegion.t0()),
369 XO("Delete"));
370}
Abstract base class used in importing a file.
double duration() const
Definition: ViewInfo.h:41
static bool IsSelectedOrSyncLockSelected(const Track &track)
Definition: SyncLock.cpp:104

References NotifyingSelectedRegion::duration(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), SyncLock::IsSelectedOrSyncLockSelected(), CommandContext::project, 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 1000 of file EditMenus.cpp.

1001{
1002 auto &project = context.project;
1003 auto &tracks = TrackList::Get(project);
1004 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
1005
1006 for (auto wt : tracks.Selected<WaveTrack>())
1007 wt->Disjoin(selectedRegion.t0(), selectedRegion.t1());
1008
1010 XO("Detached %.2f seconds at t=%.2f")
1011 .Format(selectedRegion.duration(), selectedRegion.t0()),
1012 XO("Detach"));
1013}

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), CommandContext::project, 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 735 of file EditMenus.cpp.

736{
737 auto &project = context.project;
739 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
740
741 // This iteration is unusual because we add to the list inside the loop
742 auto range = tracks.Selected();
743 auto last = *range.rbegin();
744 for (auto n : range) {
745 if (!n->SupportsBasicEditing())
746 continue;
747
748 // Make copies not for clipboard but for direct addition to the project
749 auto dest = n->Copy(selectedRegion.t0(), selectedRegion.t1(), false);
750 dest->MoveTo(std::max(selectedRegion.t0(), n->GetStartTime()));
751 tracks.Add(dest);
752
753 // This break is really needed, else we loop infinitely
754 if (n == last)
755 break;
756 }
757
759 .PushState(XO("Duplicated"), XO("Duplicate"));
760}

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), CommandContext::project, 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 976 of file EditMenus.cpp.

977{
978 auto &project = context.project;
980 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
981 const auto selectedTracks = tracks.Selected<WaveTrack>();
983 [&](const ProgressReporter& reportProgress) {
984 using namespace BasicUI;
986 selectedTracks.begin(), selectedTracks.end(),
987 [&](WaveTrack* wt, const ProgressReporter& childProgress) {
988 wt->Join(
989 selectedRegion.t0(), selectedRegion.t1(), childProgress);
990 },
991 reportProgress);
992 });
993
995 XO("Joined %.2f seconds at t=%.2f")
996 .Format(selectedRegion.duration(), selectedRegion.t0()),
997 XO("Join"));
998}
std::function< void(double)> ProgressReporter
Definition: BasicUI.h:25
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:339
WAVE_TRACK_API void WithClipRenderingProgress(std::function< void(const ProgressReporter &)> action, TranslatableString title=defaultStretchRenderingTitle)

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), CommandContext::project, project, ProjectHistory::PushState(), ViewInfo::selectedRegion, BasicUI::SplitProgress(), tracks, TimeStretching::WithClipRenderingProgress(), 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 546 of file EditMenus.cpp.

547{
548 if (wxTheClipboard->IsSupported(wxDF_FILENAME) && wxTheClipboard->Open())
549 {
550 wxFileDataObject data;
551 const auto hadData = wxTheClipboard->GetData(data);
552 wxTheClipboard->Close();
553 if (hadData)
554 {
555 ProjectFileManager::Get(context.project).Import(data.GetFilenames());
556 return;
557 }
558 }
559
560 auto &project = context.project;
561
562 // Handle text paste first.
563 if (DoPasteText(project))
564 return;
565
566 const auto &clipboard = Clipboard::Get();
567 if (clipboard.GetTracks().empty())
568 return;
569
570 const auto srcTracks = FindSourceTracks(context);
571 if (!srcTracks)
572 // user cancelled
573 return;
574
575 auto notificationScope = NotificationScope(context, *srcTracks);
576
578 // If nothing's selected, we just insert new tracks.
579 if (!tracks.Selected()) {
581 project, *srcTracks, clipboard.T0(), clipboard.T1());
582 return;
583 }
584
585 // Otherwise, paste into the selected tracks.
586 double t0, t1;
587 std::tie(t0, t1) = FindSelection(context);
588 auto newT1 = t0 + clipboard.Duration();
589 const auto isSyncLocked = SyncLockState::Get(project).IsSyncLocked();
590
591 Track *ff = nullptr;
592 bool bPastedSomething = false;
593
594 // Find tracks to paste in
595 auto correspondence = FindCorrespondence(tracks, *srcTracks);
596 if (correspondence.empty()) {
597 if (tracks.Selected().size() == 1)
599"The content you are trying to paste will span across more tracks than you "
600"currently have available. Add more tracks and try again.")
601 );
602 else
604"There are not enough tracks selected to accommodate your copied content. "
605"Select additional tracks and try again.")
606 );
607 return;
608 }
609 auto iPair = correspondence.begin();
610 const auto endPair = correspondence.cend();
611
612 // Outer loop by sync-lock groups
613 auto next = tracks.begin();
614 for (auto range = tracks.Any(); !range.empty();
615 // Skip to next sync lock group
616 range.first = next
617 ) {
618 if (iPair == endPair)
619 // Nothing more to paste
620 break;
621 auto group = SyncLock::Group(**range.first);
622 next = tracks.Find(*group.rbegin());
623 ++next;
624
625 if (!group.contains(iPair->first))
626 // Nothing to paste into this group
627 continue;
628
629 // Inner loop over the sync-lock group by tracks
630 for (auto member : group) {
631 if (iPair == endPair || member != iPair->first) {
632 if (isSyncLocked) {
633 // Track is not pasted into but must be adjusted
634 if (t1 != newT1 && t1 <= member->GetEndTime()) {
635 member->SyncLockAdjust(t1, newT1);
636 bPastedSomething = true;
637 }
638 }
639 }
640 else {
641 // Remember first pasted-into track, to focus it
642 if (!ff)
643 ff = member;
644 // Do the pasting!
645 const auto src = (iPair++)->second;
646 member->TypeSwitch(
647 [&](WaveTrack &wn){
648 bPastedSomething = true;
649 // For correct remapping of preserved split lines:
650 PasteTimeWarper warper{ t1, t0 + src->GetEndTime() };
651 const auto newClipOnPaste =
652 gPrefs->ReadBool(wxT("/GUI/PasteAsNewClips"), false);
653 // The new-clip-on-paste behavior means: not merging the
654 // clipboard data with data at the selection borders; not
655 // reproducing boundaries within the selected region in the
656 // new clip; preserving the data underneath by trimming
657 // (rather than deleting).
658 // The legacy behavior is the opposite.
659 const auto merge = newClipOnPaste ? false : true;
660 const auto preserveExistingBoundaries = newClipOnPaste ? false : true;
661 auto clearByTrimming = newClipOnPaste ? true : false;
662 if(src->NChannels() == 1 && wn.NChannels() == 2)
663 {
664 // When the source is mono, may paste its only channel
665 // repeatedly into a stereo track
666 const auto pastedTrack = std::static_pointer_cast<WaveTrack>(src->Duplicate());
667 pastedTrack->MonoToStereo();
668 wn.ClearAndPaste(
669 t0, t1, *pastedTrack,
670 preserveExistingBoundaries, merge, &warper,
671 clearByTrimming);
672 }
673 else
674 {
675 wn.ClearAndPaste(
676 t0, t1, *static_cast<const WaveTrack*>(src),
677 preserveExistingBoundaries, merge, &warper,
678 clearByTrimming);
679 }
680 },
681 [&](LabelTrack &ln){
682 // Per Bug 293, users expect labels to move on a paste into
683 // a label track.
684 ln.Clear(t0, t1);
685
686 ln.ShiftLabelsOnInsert( clipboard.Duration(), t0 );
687
688 bPastedSomething |= ln.PasteOver(t0, *src);
689 },
690 [&](Track &t){
691 bPastedSomething = true;
692 t.Clear(t0, t1);
693 t.Paste(t0, *src);
694 }
695 );
696 }
697 }
698 }
699
700 // TODO: What if we clicked past the end of the track?
701
702 if (bPastedSomething) {
703
704 if(!isSyncLocked && GetEditClipsCanMove())
705 {
706 //Special case when pasting without sync lock and
707 //"...move other clips" option is
708 //Also shift all intervals in all other selected tracks that
709 //starts after t0
710 const auto offset = srcTracks->GetEndTime() - (t1 - t0);
711 for(auto track : tracks.Selected<Track>())
712 {
713 const auto it = std::find_if(correspondence.begin(), correspondence.end(),
714 [=](auto& p) { return p.first == track; });
715 if(it != correspondence.end())
716 continue;
717
718 track->ShiftBy(t0, offset);
719 }
720 }
721
723 .setTimes( t0, t0 + clipboard.Duration() );
724
726 .PushState(XO("Pasted from the clipboard"), XO("Paste"));
727
728 if (ff) {
729 TrackFocus::Get(project).Set(ff);
731 }
732 }
733}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
bool GetEditClipsCanMove()
Definition: WaveTrack.cpp:3408
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
bool Import(const FilePath &fileName, bool addToHistory=true)
static ProjectFileManager & Get(AudacityProject &project)
static TrackIterRange< Track > Group(Track &track)
Definition: SyncLock.cpp:150
bool IsSyncLocked() const
Definition: SyncLock.cpp:44
static SyncLockState & Get(AudacityProject &project)
Definition: SyncLock.cpp:27
R TypeSwitch(const Functions &...functions)
Definition: Track.h:381
size_t NChannels() const override
A constant property.
Definition: WaveTrack.cpp:530
void ClearAndPaste(double t0, double t1, const WaveTrack &src, bool preserve=true, bool merge=true, const TimeWarper *effectWarper=nullptr, bool clearByTrimming=false)
Definition: WaveTrack.cpp:1219
bool ReadBool(const wxString &key, bool defaultValue) const
std::shared_ptr< const TrackList > FindSourceTracks(const CommandContext &context)
Definition: EditMenus.cpp:441
Correspondence FindCorrespondence(TrackList &dstTracks, const TrackList &srcTracks)
Definition: EditMenus.cpp:516
void DoPasteNothingSelected(AudacityProject &project, const TrackList &src, double t0, double t1)
Definition: EditMenus.cpp:128
bool DoPasteText(AudacityProject &project)
Definition: EditMenus.cpp:47
auto NotificationScope(const CommandContext &context, const TrackList &srcTracks)
Definition: EditMenus.cpp:476
std::pair< double, double > FindSelection(const CommandContext &context)
Definition: EditMenus.cpp:419

References AudacityMessageBox(), WaveTrack::ClearAndPaste(), DoPasteNothingSelected(), DoPasteText(), FindCorrespondence(), FindSelection(), FindSourceTracks(), TrackFocus::Get(), Clipboard::Get(), ProjectHistory::Get(), ViewInfo::Get(), SyncLockState::Get(), TrackList::Get(), Viewport::Get(), ProjectFileManager::Get(), GetEditClipsCanMove(), gPrefs, SyncLock::Group(), ProjectFileManager::Import(), SyncLockState::IsSyncLocked(), WaveTrack::NChannels(), NotificationScope(), CommandContext::project, project, ProjectHistory::PushState(), audacity::BasicSettings::ReadBool(), ViewInfo::selectedRegion, NotifyingSelectedRegion::setTimes(), Viewport::ShowTrack(), tracks, Track::TypeSwitch(), wxT(), 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 1015 of file EditMenus.cpp.

1016{
1017 auto &project = context.project;
1018
1019 GlobalPrefsDialog dialog(&GetProjectFrame(project) /* parent */, &project );
1020
1021 if (!dialog.ShowModal()) {
1022 // Canceled
1023 return;
1024 }
1025
1026 // LL: Moved from PrefsDialog since wxWidgets on OSX can't deal with
1027 // rebuilding the menus while the PrefsDialog is still in the modal
1028 // state.
1029 for (auto p : AllProjects{}) {
1031// TODO: The comment below suggests this workaround is obsolete.
1032#if defined(__WXGTK__)
1033 // Workaround for:
1034 //
1035 // http://bugzilla.audacityteam.org/show_bug.cgi?id=458
1036 //
1037 // This workaround should be removed when Audacity updates to wxWidgets
1038 // 3.x which has a fix.
1039 auto &window = GetProjectFrame( *p );
1040 wxRect r = window.GetRect();
1041 window.SetSize(wxSize(1,1));
1042 window.SetSize(r.GetSize());
1043#endif
1044 }
1045}
void RebuildMenuBar()
static MenuCreator & Get(AudacityProject &project)
Definition: MenuCreator.cpp:91

References MenuCreator::Get(), GetProjectFrame(), CommandContext::project, 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 211 of file EditMenus.cpp.

212{
213 auto &project = context.project;
214 auto &tracks = TrackList::Get( project );
215 auto &trackPanel = TrackPanel::Get( project );
216 auto &undoManager = UndoManager::Get( project );
217
218 if (!ProjectHistory::Get( project ).RedoAvailable()) {
219 AudacityMessageBox( XO("Nothing to redo") );
220 return;
221 }
222 // Can't redo whilst dragging
223 if (trackPanel.IsMouseCaptured()) {
224 return;
225 }
226
227 undoManager.Redo(
228 [&]( const UndoStackElem &elem ){
230
231 auto t = *tracks.Selected().begin();
232 if (!t)
233 t = *tracks.begin();
234 TrackFocus::Get(project).Set(t);
235 if (t)
237}
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(), TrackFocus::Get(), ProjectHistory::Get(), UndoManager::Get(), TrackList::Get(), Viewport::Get(), TrackPanel::Get(), ProjectHistory::PopState(), CommandContext::project, project, Viewport::ShowTrack(), 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 818 of file EditMenus.cpp.

819{
820 auto &project = context.project;
822 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
823
824 const auto selectedWaveTracks = tracks.Selected<WaveTrack>();
826 [&](const ProgressReporter& parent) {
828 selectedWaveTracks.begin(), selectedWaveTracks.end(),
829 [&](WaveTrack* n, const ProgressReporter& child) {
830 n->Silence(selectedRegion.t0(), selectedRegion.t1(), child);
831 },
832 parent);
833 });
834
836 XO("Silenced selected tracks for %.2f seconds at %.2f")
837 .Format(selectedRegion.duration(), selectedRegion.t0()),
838 /* i18n-hint: verb */
839 XC("Silence", "command"));
840}
#define XC(s, c)
Definition: Internat.h:37

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), CommandContext::project, project, ProjectHistory::PushState(), ViewInfo::selectedRegion, BasicUI::SplitProgress(), tracks, TimeStretching::WithClipRenderingProgress(), 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 862 of file EditMenus.cpp.

863{
864 auto &project = context.project;
866 auto [sel0, sel1] = FindSelection(context);
867 if (auto *pTrack = context.temporarySelection.pTrack) {
868 if (auto pWaveTrack = dynamic_cast<WaveTrack*>(pTrack))
869 pWaveTrack->Split(sel0, sel1);
870 else
871 // Did nothing, don't push history
872 return;
873 }
874 else
875 for (auto wt : tracks.Selected<WaveTrack>())
876 wt->Split(sel0, sel1);
877
878 ProjectHistory::Get( project ).PushState(XO("Split"), XO("Split"));
879#if 0
880//ANSWER-ME: Do we need to keep this commented out OnSplit() code?
881// This whole section no longer used...
882 /*
883 * Previous (pre-multiclip) implementation of "Split" command
884 * This does work only when a range is selected!
885 *
886 TrackListIterator iter(tracks);
887
888 Track *n = iter.First();
889 Track *dest;
890
891 TrackList newTracks;
892
893 while (n) {
894 if (n->GetSelected()) {
895 double sel0 = selectedRegion.t0();
896 double sel1 = selectedRegion.t1();
897
898 dest = n->Copy(sel0, sel1);
899 dest->Init(*n);
900 dest->MoveTo(std::max(sel0, n->GetOffset()));
901
902 if (sel1 >= n->GetEndTime())
903 n->Clear(sel0, sel1);
904 else if (sel0 <= n->GetOffset()) {
905 n->Clear(sel0, sel1);
906 n->MoveTo(sel1);
907 } else
908 n->Silence(sel0, sel1);
909
910 newTracks.Add(dest);
911 }
912 n = iter.Next();
913 }
914
915 TrackListIterator nIter(&newTracks);
916 n = nIter.First();
917 while (n) {
918 tracks->Add(n);
919 n = nIter.Next();
920 }
921
922 PushState(XO("Split"), XO("Split"));
923 */
924#endif
925}

References FindSelection(), ProjectHistory::Get(), TrackList::Get(), CommandContext::project, 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 762 of file EditMenus.cpp.

763{
764 auto &project = context.project;
766 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
767
768 auto &clipboard = Clipboard::Get();
769 clipboard.Clear();
770
771 auto pNewClipboard = TrackList::Create(nullptr);
772 auto &newClipboard = *pNewClipboard;
773
774 tracks.Selected().Visit(
775 [&](WaveTrack &n) {
776 auto track = n.SplitCut(selectedRegion.t0(), selectedRegion.t1());
777 newClipboard.Add(track);
778 },
779 [&](Track &n) {
780 if (n.SupportsBasicEditing()) {
781 auto dest = n.Copy(selectedRegion.t0(), selectedRegion.t1());
782 n.Silence(selectedRegion.t0(), selectedRegion.t1());
783 newClipboard.Add(dest);
784 }
785 }
786 );
787
788 // Survived possibility of exceptions. Commit changes to the clipboard now.
789 clipboard.Assign(std::move(newClipboard),
790 selectedRegion.t0(), selectedRegion.t1(), project.shared_from_this());
791
793 .PushState(XO("Cut to clipboard and leave gap"), XO("Cut and leave gap"));
794}
void Silence(double t0, double t1, ProgressReporter reportProgress) override
Definition: WaveTrack.cpp:2000
Holder SplitCut(double t0, double t1)
Definition: WaveTrack.cpp:966
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
Create new tracks and don't modify this track.
Definition: WaveTrack.cpp:1097

References WaveTrack::Copy(), TrackList::Create(), Clipboard::Get(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), CommandContext::project, 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 796 of file EditMenus.cpp.

797{
798 auto &project = context.project;
800 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
801
802 tracks.Selected().Visit(
803 [&](WaveTrack &wt) {
804 wt.SplitDelete(selectedRegion.t0(), selectedRegion.t1());
805 },
806 [&](Track &n) {
807 if (n.SupportsBasicEditing())
808 n.Silence(selectedRegion.t0(), selectedRegion.t1());
809 }
810 );
811
813 XO("Split-deleted %.2f seconds at t=%.2f")
814 .Format(selectedRegion.duration(), selectedRegion.t0()),
815 XO("Split Delete"));
816}
void SplitDelete(double t0, double t1)
Definition: WaveTrack.cpp:1526

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), CommandContext::project, 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 927 of file EditMenus.cpp.

928{
929 auto &project = context.project;
931 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
932
933 // This iteration is unusual because we add to the list inside the loop
934 auto range = tracks.Selected();
935 auto last = *range.rbegin();
936 for (auto track : range) {
937 track->TypeSwitch(
938 [&](WaveTrack &wt) {
939 // Clips must be aligned to sample positions or the NEW clip will
940 // not fit in the gap where it came from
941 const double newt0 = wt.SnapToSample(selectedRegion.t0());
942 const double newt1 = wt.SnapToSample(selectedRegion.t1());
943 // Fix issue 2846 by calling copy with forClipboard = false.
944 // This avoids creating the blank placeholder clips
945 const auto dest = wt.Copy(newt0, newt1, false);
946 if (dest) {
947 // The copy function normally puts the clip at time 0
948 // This offset lines it up with the original track's timing
949 dest->MoveTo(newt0);
950 tracks.Add(dest);
951 }
952 wt.SplitDelete(newt0, newt1);
953 }
954#if 0
955 ,
956 // LL: For now, just skip all non-wave tracks since the other do not
957 // yet support proper splitting.
958 [&](Track &n) {
959 dest = n.Cut(viewInfo.selectedRegion.t0(),
960 viewInfo.selectedRegion.t1());
961 if (dest) {
962 dest->MoveTo(std::max(0, n.GetOffset()));
963 tracks.Add(dest);
964 }
965 }
966#endif
967 );
968 if (track == last)
969 break;
970 }
971
973 .PushState(XO("Split to new track"), XO("Split New"));
974}
double SnapToSample(double t) const

References WaveTrack::Copy(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), CommandContext::project, 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 842 of file EditMenus.cpp.

843{
844 auto &project = context.project;
845 auto &tracks = TrackList::Get( project );
846 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
847
848 if (selectedRegion.isPoint())
849 return;
850
851 tracks.Selected().Visit( [&](WaveTrack &wt) {
852 //Hide the section before the left selector
853 wt.Trim(selectedRegion.t0(), selectedRegion.t1());
854 } );
855
857 XO("Trim selected audio tracks from %.2f seconds to %.2f seconds")
858 .Format( selectedRegion.t0(), selectedRegion.t1() ),
859 XO("Trim Audio"));
860}
void Trim(double t0, double t1)
Definition: WaveTrack.cpp:980

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), CommandContext::project, 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 182 of file EditMenus.cpp.

183{
184 auto &project = context.project;
185 auto &tracks = TrackList::Get( project );
186 auto &trackPanel = TrackPanel::Get( project );
187 auto &undoManager = UndoManager::Get( project );
188
189 if (!ProjectHistory::Get( project ).UndoAvailable()) {
190 AudacityMessageBox( XO("Nothing to undo") );
191 return;
192 }
193
194 // can't undo while dragging
195 if (trackPanel.IsMouseCaptured()) {
196 return;
197 }
198
199 undoManager.Undo(
200 [&]( const UndoStackElem &elem ){
202
203 auto t = *tracks.Selected().begin();
204 if (!t)
205 t = *tracks.begin();
206 TrackFocus::Get(project).Set(t);
207 if (t)
209}

References AudacityMessageBox(), TrackFocus::Get(), ProjectHistory::Get(), UndoManager::Get(), TrackList::Get(), Viewport::Get(), TrackPanel::Get(), ProjectHistory::PopState(), CommandContext::project, project, Viewport::ShowTrack(), 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:

Definition at line 1264 of file EditMenus.cpp.

◆ sAttachment1

AttachedItem anonymous_namespace{EditMenus.cpp}::sAttachment1 { Indirect(EditMenu()) }

Definition at line 1246 of file EditMenus.cpp.

◆ sAttachment2

AttachedItem anonymous_namespace{EditMenus.cpp}::sAttachment2
Initial value:
wxT("Optional/Extra/Part1")
}
std::unique_ptr< detail::IndirectItem< Item > > Indirect(const std::shared_ptr< Item > &ptr)
A convenience function.
Definition: Registry.h:175

Definition at line 1302 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 1266 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 1280 of file EditMenus.cpp.

◆ selectTracks

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

Definition at line 1272 of file EditMenus.cpp.

◆ selectWaveTracks

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

Definition at line 1287 of file EditMenus.cpp.

◆ selectWaveTracks2

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

Definition at line 1295 of file EditMenus.cpp.