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 ()
 
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 494 of file EditMenus.cpp.

Function Documentation

◆ CutCopyAvailableFlag()

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

Definition at line 1006 of file EditMenus.cpp.

1006 { static ReservedCommandFlag flag{
1007 [](const AudacityProject &project){
1008 auto range = TrackList::Get(project).Any<const LabelTrack>()
1009 + [&](const LabelTrack *pTrack){
1010 return LabelTrackView::Get( *pTrack ).IsTextSelected(
1011 // unhappy const_cast because track focus might be set
1012 const_cast<AudacityProject&>(project)
1013 );
1014 };
1015 if ( !range.empty() )
1016 return true;
1017
1018 if (
1020 &&
1022 )
1023 return true;
1024
1025 return false;
1026 },
1028}; 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:95
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 126 of file EditMenus.cpp.

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

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

109 {
110 auto result = TrackList::Create(nullptr);
111 for (auto track : src) {
112 const auto pTrack =
113 track->Copy(track->GetStartTime(), track->GetEndTime(), false);
114 pTrack->MoveTo(track->GetStartTime());
115 if (const auto waveTrack = dynamic_cast<WaveTrack*>(pTrack.get()))
117 result->Add(pTrack);
118 }
119 return result;
120}
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 1056 of file EditMenus.cpp.

1057{
1058 static const auto NotBusyTimeAndTracksFlags =
1060
1061 // The default shortcut key for Redo is different on different platforms.
1062 static constexpr auto redoKey =
1063#ifdef __WXMSW__
1064 wxT("Ctrl+Y")
1065#else
1066 wxT("Ctrl+Shift+Z")
1067#endif
1068 ;
1069
1070 // The default shortcut key for Preferences is different on different
1071 // platforms.
1072 static constexpr auto prefKey =
1073#ifdef __WXMAC__
1074 wxT("Ctrl+,")
1075#else
1076 wxT("Ctrl+P")
1077#endif
1078 ;
1079
1080 static auto menu = std::shared_ptr{
1081 Menu( wxT("Edit"), XXO("&Edit"),
1082 Section( "UndoRedo",
1083 Command( wxT("Undo"), XXO("&Undo"), OnUndo,
1084 AudioIONotBusyFlag() | UndoAvailableFlag(), wxT("Ctrl+Z") ),
1085
1086 Command( wxT("Redo"), XXO("&Redo"), OnRedo,
1087 AudioIONotBusyFlag() | RedoAvailableFlag(), redoKey ),
1088
1089 MenuCreator::Special( wxT("UndoItemsUpdateStep"),
1090 [](AudacityProject &project, wxMenu&) {
1091 // Change names in the CommandManager as a side-effect
1093 })
1094 ),
1095
1096 Section( "Basic",
1097 // Basic Edit commands
1098 /* i18n-hint: (verb)*/
1099 Command( wxT("Cut"), XXO("Cu&t"), OnCut,
1101 wxT("Ctrl+X") ),
1102 Command( wxT("Delete"), XXO("&Delete"), OnDelete,
1104 wxT("Ctrl+K") ),
1105 /* i18n-hint: (verb)*/
1106 Command( wxT("Copy"), XXO("&Copy"), OnCopy,
1107 AudioIONotBusyFlag() | CutCopyAvailableFlag(), wxT("Ctrl+C") ),
1108 /* i18n-hint: (verb)*/
1109 Command( wxT("Paste"), XXO("&Paste"), OnPaste,
1110 AudioIONotBusyFlag(), wxT("Ctrl+V") ),
1111 /* i18n-hint: (verb)*/
1112 Command( wxT("Duplicate"), XXO("Duplic&ate"), OnDuplicate,
1113 NotBusyTimeAndTracksFlags, wxT("Ctrl+D") ),
1114
1115 Section( "",
1116 Menu( wxT("RemoveSpecial"), XXO("R&emove Special"),
1117 Section( "",
1118 /* i18n-hint: (verb) Do a special kind of cut*/
1119 Command( wxT("SplitCut"), XXO("Spl&it Cut"), OnSplitCut,
1120 NotBusyTimeAndTracksFlags,
1121 Options{ wxT("Ctrl+Alt+X") } ),
1122 /* i18n-hint: (verb) Do a special kind of DELETE*/
1123 Command( wxT("SplitDelete"), XXO("Split D&elete"), OnSplitDelete,
1124 NotBusyTimeAndTracksFlags,
1125 Options{ wxT("Ctrl+Alt+K") } )
1126 ),
1127
1128 Section( "",
1129 /* i18n-hint: (verb)*/
1130 Command( wxT("Silence"), XXO("Silence Audi&o"), OnSilence,
1132 wxT("Ctrl+L") ),
1133 /* i18n-hint: (verb)*/
1134 Command( wxT("Trim"), XXO("Tri&m Audio"), OnTrim,
1136 Options{ wxT("Ctrl+T") } )
1137 )
1138 )
1139 )
1140 ),
1141
1142
1143 Section( "Other",
1145
1146 Menu( wxT("Clip"), XXO("Audi&o Clips"),
1147 Section( "",
1148 /* i18n-hint: (verb) It's an item on a menu. */
1149 Command( wxT("Split"), XXO("Sp&lit"), OnSplit,
1151 Options{ wxT("Ctrl+I") } ),
1152 Command( wxT("SplitNew"), XXO("Split Ne&w"), OnSplitNew,
1154 Options{ wxT("Ctrl+Alt+I") } )
1155 ),
1156
1157 Section( "",
1158 /* i18n-hint: (verb)*/
1159 Command( wxT("Join"), XXO("&Join"), OnJoin,
1160 JoinClipsAvailableFlag(), wxT("Ctrl+J") ),
1161 Command( wxT("Disjoin"), XXO("Detac&h at Silences"), OnDisjoin,
1162 NotBusyTimeAndTracksFlags, wxT("Ctrl+Alt+J") )
1163 )
1164 )
1165
1166 ),
1167
1168 // Note that on Mac, the Preferences menu item is specially handled in
1169 // CommandManager (assigned a special wxWidgets id) so that it does
1170 // not appear in the Edit menu but instead under Audacity, consistent with
1171 // MacOS conventions.
1172 Section( "Preferences",
1173 Command( wxT("Preferences"), XXO("Pre&ferences"), OnPreferences,
1174 AudioIONotBusyFlag(), prefKey )
1175 )
1176
1177 ) };
1178 return menu;
1179}
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:935
void OnRedo(const CommandContext &context)
Definition: EditMenus.cpp:209
void OnJoin(const CommandContext &context)
Definition: EditMenus.cpp:911
void OnDelete(const CommandContext &context)
Definition: EditMenus.cpp:330
void OnPaste(const CommandContext &context)
Definition: EditMenus.cpp:526
const ReservedCommandFlag & CutCopyAvailableFlag()
Definition: EditMenus.cpp:1006
void OnSplit(const CommandContext &context)
Definition: EditMenus.cpp:797
void OnSilence(const CommandContext &context)
Definition: EditMenus.cpp:753
const ReservedCommandFlag & JoinClipsAvailableFlag()
Definition: EditMenus.cpp:1031
void OnTrim(const CommandContext &context)
Definition: EditMenus.cpp:777
void OnSplitDelete(const CommandContext &context)
Definition: EditMenus.cpp:731
void OnCopy(const CommandContext &context)
Definition: EditMenus.cpp:355
void OnUndo(const CommandContext &context)
Definition: EditMenus.cpp:180
void OnSplitCut(const CommandContext &context)
Definition: EditMenus.cpp:697
void OnPreferences(const CommandContext &context)
Definition: EditMenus.cpp:950
void OnDuplicate(const CommandContext &context)
Definition: EditMenus.cpp:670
void OnSplitNew(const CommandContext &context)
Definition: EditMenus.cpp:862
void OnCut(const CommandContext &context)
Definition: EditMenus.cpp:237

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

102{
103 BlockArray::size_type result{};
104 for (const auto waveTrack : src.Any<const WaveTrack>())
105 result += WaveTrackUtilities::CountBlocks(*waveTrack);
106 return result;
107}
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 89 of file EditMenus.cpp.

90{
91 wxULongLong result{};
92 for (auto waveTrack : src.Any<const WaveTrack>()) {
93 const auto samplesCount =
95 result += samplesCount.as_long_long() *
96 SAMPLE_SIZE(waveTrack->GetSampleFormat());
97 }
98 return result;
99}
#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 1183 of file EditMenus.cpp.

1184{
1185 static const auto flags =
1187 static auto menu = std::shared_ptr{
1188 Menu( wxT("Edit"), XXO("&Edit"),
1189 Command( wxT("DeleteKey"), XXO("&Delete Key"), OnDelete,
1190 (flags | NoAutoSelect()),
1191 wxT("Backspace") ),
1192 Command( wxT("DeleteKey2"), XXO("Delete Key&2"), OnDelete,
1193 (flags | NoAutoSelect()),
1194 wxT("Delete") )
1195 ) };
1196 return menu;
1197}

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

498{
499 Correspondence result;
500 auto dstRange = dstTracks.Selected();
501 if (dstRange.size() == 1)
502 // Special rule when only one track is selected interprets the user's
503 // intent as pasting into that track and following ones
504 dstRange = dstTracks.Any().StartingWith(*dstRange.begin());
505 auto srcRange = srcTracks.Any();
506 while (!(dstRange.empty() || srcRange.empty())) {
507 auto &dst = **dstRange.begin();
508 auto &src = **srcRange.begin();
509 if (!FitsInto(src, dst)) {
510 // Skip selected track of inappropriate type and try again
511 ++dstRange.first;
512 continue;
513 }
514 result.emplace_back(&dst, &src);
515 ++srcRange.first;
516 ++dstRange.first;
517 }
518
519 if (!srcRange.empty())
520 // Could not fit all source tracks into the selected tracks
521 return {};
522 else
523 return result;
524}
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:483
std::vector< std::pair< Track *, const Track * > > Correspondence
Definition: EditMenus.cpp:494

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

400{
401 double sel0 = 0.0, sel1 = 0.0;
402
403#if 0
404 // Use the overriding selection if any was given in the context
405 if (auto *pRegion = context.temporarySelection.pSelectedRegion) {
406 auto &selectedRegion = *pRegion;
407 sel0 = selectedRegion.t0();
408 sel1 = selectedRegion.t1();
409 }
410 else
411#endif
412 {
413 auto &selectedRegion = ViewInfo::Get(context.project).selectedRegion;
414 sel0 = selectedRegion.t0();
415 sel1 = selectedRegion.t1();
416 }
417
418 return { sel0, sel1 };
419}
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 421 of file EditMenus.cpp.

422{
423 auto &project = context.project;
424 auto &window = GetProjectFrame(project);
426 const auto &clipboard = Clipboard::Get();
427 auto discardTrimmed = false;
428 if (&context.project != &*clipboard.Project().lock()) {
429 const auto waveClipCopyPolicy = TracksBehaviorsAudioTrackPastePolicy.Read();
430 if (waveClipCopyPolicy == wxT("Ask") &&
431 HasHiddenData(clipboard.GetTracks()))
432 {
433 AudioPasteDialog audioPasteDialog(
434 &window,
435 EstimateCopyBytesCount(clipboard.GetTracks(), tracks)
436 );
437 const auto result = audioPasteDialog.ShowModal();
438 if(result == wxID_CANCEL)
439 return {};
440 discardTrimmed =
442 }
443 else if(waveClipCopyPolicy == wxT("Discard"))
444 discardTrimmed = true;
445 }
446
447 std::shared_ptr<const TrackList> srcTracks;
448 if(discardTrimmed)
449 srcTracks = DuplicateDiscardTrimmed(clipboard.GetTracks());
450 else
451 srcTracks = clipboard.GetTracks().shared_from_this();
452
453 return srcTracks;
454}
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:89
std::shared_ptr< TrackList > DuplicateDiscardTrimmed(const TrackList &src)
Definition: EditMenus.cpp:109
bool HasHiddenData(const TrackList &trackList)
Definition: EditMenus.cpp:169

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

484{
485 if (!src.SameKindAs(dst))
486 return false;
487 // Mono can "fit" into stereo, by duplication of the channel
488 // Otherwise non-wave tracks always have just one "channel"
489 // Future: Fit stereo into mono too, using mix-down
490 return src.NChannels() <= dst.NChannels();
491}
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 169 of file EditMenus.cpp.

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

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

1031 { static ReservedCommandFlag flag {
1032 [](const AudacityProject &project)
1033 {
1035 return false;
1036
1037 const auto &viewInfo = ViewInfo::Get(project);
1038 if(viewInfo.selectedRegion.isPoint())
1039 return false;
1040
1041 const auto selectedTracks = TrackList::Get(project).Selected<const WaveTrack>();
1042 for (const auto track : selectedTracks)
1043 {
1044 const auto selectedClips =
1046 viewInfo.selectedRegion.t0(), viewInfo.selectedRegion.t1());
1047 if(selectedClips.size() > 1)
1048 return true;
1049 }
1050 return false;
1051 },
1053}; 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 456 of file EditMenus.cpp.

458{
459 auto &project = context.project;
461 auto &trackFactory = WaveTrackFactory::Get(project);
462 auto &pSampleBlockFactory = trackFactory.GetSampleBlockFactory();
463 return pSampleBlockFactory->Subscribe([
464 toCopy = EstimateCopiedBlocks(srcTracks, tracks),
465 nCopied = 0,
466 copyStartTime = std::chrono::system_clock::now(),
467 progressDialog = std::shared_ptr<BasicUI::ProgressDialog>()]
468 (const SampleBlockCreateMessage&) mutable {
469 using namespace std::chrono;
470 constexpr auto ProgressDialogShowDelay = milliseconds { 100 };
471 ++nCopied;
472 if(!progressDialog) {
473 if(duration_cast<milliseconds>(system_clock::now() - copyStartTime) >= ProgressDialogShowDelay)
474 progressDialog = BasicUI::MakeProgress(XO("Paste clip"), XO("Pasting clip contents, please wait"), 0);
475 }
476 else {
477 progressDialog->Poll(nCopied, toCopy);
478 }
479 });
480}
static WaveTrackFactory & Get(AudacityProject &project)
Definition: WaveTrack.cpp:3349
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:294
BlockArray::size_type EstimateCopiedBlocks(const TrackList &src, const TrackList &dst)
Definition: EditMenus.cpp:101

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

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

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

238{
239 auto &project = context.project;
240 auto &tracks = TrackList::Get( project );
241 auto &trackPanel = TrackPanel::Get( project );
242 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
244
245 // This doesn't handle cutting labels, it handles
246 // cutting the _text_ inside of labels, i.e. if you're
247 // in the middle of editing the label text and select "Cut".
248
249 for (auto lt : tracks.Selected<LabelTrack>()) {
250 auto &view = LabelTrackView::Get( *lt );
251 if (view.CutSelectedText( context.project )) {
252 trackPanel.Refresh(false);
253 return;
254 }
255 }
256
257 //Presumably, there might be not more than one track
258 //that expects text input
259 for (auto wt : tracks.Any<WaveTrack>()) {
260 auto& view = WaveChannelView::GetFirst(*wt);
261 if (view.CutSelectedText(context.project)) {
262 trackPanel.Refresh(false);
263 return;
264 }
265 }
266
267 auto &clipboard = Clipboard::Get();
268 clipboard.Clear();
269
270 auto pNewClipboard = TrackList::Create( nullptr );
271 auto &newClipboard = *pNewClipboard;
272
273 tracks.Selected().Visit(
274#if defined(USE_MIDI)
275 [&](NoteTrack &n) {
276 // Since portsmf has a built-in cut operator, we use that instead
277 auto dest = n.Cut(selectedRegion.t0(), selectedRegion.t1());
278 newClipboard.Add(dest);
279 },
280#endif
281 [&](Track &n) {
282 if (n.SupportsBasicEditing()) {
283 auto dest = n.Copy(selectedRegion.t0(), selectedRegion.t1());
284 newClipboard.Add(dest);
285 }
286 }
287 );
288
289 // Survived possibility of exceptions. Commit changes to the clipboard now.
290 clipboard.Assign(
291 std::move( newClipboard ),
292 selectedRegion.t0(),
293 selectedRegion.t1(),
294 project.shared_from_this()
295 );
296
297 // Proceed to change the project. If this throws, the project will be
298 // rolled back by the top level handler.
299
301#if defined(USE_MIDI)
302 [](NoteTrack&) {
303 //if NoteTrack, it was cut, so do not clear anything
304
305 // PRL: But what if it was sync lock selected only, not selected?
306 },
307#endif
308 [&](auto &&fallthrough){ return [&](WaveTrack &wt) {
309 if (gPrefs->Read(wxT("/GUI/EnableCutLines"), (long)0))
310 wt.ClearAndAddCutLine(selectedRegion.t0(), selectedRegion.t1());
311 else
312 fallthrough();
313 }; },
314 [&](Track &n) {
315 if (n.SupportsBasicEditing())
316 n.Clear(selectedRegion.t0(), selectedRegion.t1());
317 }
318 );
319
320 selectedRegion.collapseToT0();
321
323 .PushState(XO("Cut to the clipboard"), XO("Cut"));
324
325 // Bug 1663
326 //mRuler->ClearPlayRegion();
327 ruler.DrawOverlays( true );
328}
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:320
void Clear(double t0, double t1) override
Definition: NoteTrack.cpp:397
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
Create new tracks and don't modify this track.
Definition: NoteTrack.cpp:350
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(), 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 330 of file EditMenus.cpp.

331{
332 auto &project = context.project;
333 auto &tracks = TrackList::Get( project );
334 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
335
336 for (auto n : tracks) {
337 if (!n->SupportsBasicEditing())
338 continue;
340 n->Clear(selectedRegion.t0(), selectedRegion.t1());
341 }
342 }
343
344 double seconds = selectedRegion.duration();
345
346 selectedRegion.collapseToT0();
347
349 XO("Deleted %.2f seconds at t=%.2f")
350 .Format( seconds, selectedRegion.t0()),
351 XO("Delete"));
352}
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 935 of file EditMenus.cpp.

936{
937 auto &project = context.project;
939 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
940
941 for (auto wt : tracks.Selected<WaveTrack>())
942 wt->Disjoin(selectedRegion.t0(), selectedRegion.t1());
943
945 XO("Detached %.2f seconds at t=%.2f")
946 .Format(selectedRegion.duration(), selectedRegion.t0()),
947 XO("Detach"));
948}

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

671{
672 auto &project = context.project;
674 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
675
676 // This iteration is unusual because we add to the list inside the loop
677 auto range = tracks.Selected();
678 auto last = *range.rbegin();
679 for (auto n : range) {
680 if (!n->SupportsBasicEditing())
681 continue;
682
683 // Make copies not for clipboard but for direct addition to the project
684 auto dest = n->Copy(selectedRegion.t0(), selectedRegion.t1(), false);
685 dest->MoveTo(std::max(selectedRegion.t0(), n->GetStartTime()));
686 tracks.Add(dest);
687
688 // This break is really needed, else we loop infinitely
689 if (n == last)
690 break;
691 }
692
694 .PushState(XO("Duplicated"), XO("Duplicate"));
695}

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

912{
913 auto &project = context.project;
915 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
916 const auto selectedTracks = tracks.Selected<WaveTrack>();
918 [&](const ProgressReporter& reportProgress) {
919 using namespace BasicUI;
921 selectedTracks.begin(), selectedTracks.end(),
922 [&](WaveTrack* wt, const ProgressReporter& childProgress) {
923 wt->Join(
924 selectedRegion.t0(), selectedRegion.t1(), childProgress);
925 },
926 reportProgress);
927 });
928
930 XO("Joined %.2f seconds at t=%.2f")
931 .Format(selectedRegion.duration(), selectedRegion.t0()),
932 XO("Join"));
933}
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:331
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 526 of file EditMenus.cpp.

527{
528 auto &project = context.project;
529
530 // Handle text paste first.
531 if (DoPasteText(project))
532 return;
533
534 const auto &clipboard = Clipboard::Get();
535 if (clipboard.GetTracks().empty())
536 return;
537
538 const auto srcTracks = FindSourceTracks(context);
539 if (!srcTracks)
540 // user cancelled
541 return;
542
543 auto notificationScope = NotificationScope(context, *srcTracks);
544
546 // If nothing's selected, we just insert new tracks.
547 if (!tracks.Selected()) {
549 project, *srcTracks, clipboard.T0(), clipboard.T1());
550 return;
551 }
552
553 // Otherwise, paste into the selected tracks.
554 double t0, t1;
555 std::tie(t0, t1) = FindSelection(context);
556 auto newT1 = t0 + clipboard.Duration();
557 const auto isSyncLocked = SyncLockState::Get(project).IsSyncLocked();
558
559 Track *ff = nullptr;
560 bool bPastedSomething = false;
561
562 // Find tracks to paste in
563 auto correspondence = FindCorrespondence(tracks, *srcTracks);
564 if (correspondence.empty()) {
565 if (tracks.Selected().size() == 1)
567"The content you are trying to paste will span across more tracks than you "
568"currently have available. Add more tracks and try again.")
569 );
570 else
572"There are not enough tracks selected to accommodate your copied content. "
573"Select additional tracks and try again.")
574 );
575 return;
576 }
577 auto iPair = correspondence.begin();
578 const auto endPair = correspondence.cend();
579
580 // Outer loop by sync-lock groups
581 auto next = tracks.begin();
582 for (auto range = tracks.Any(); !range.empty();
583 // Skip to next sync lock group
584 range.first = next
585 ) {
586 if (iPair == endPair)
587 // Nothing more to paste
588 break;
589 auto group = SyncLock::Group(**range.first);
590 next = tracks.Find(*group.rbegin());
591 ++next;
592
593 if (!group.contains(iPair->first))
594 // Nothing to paste into this group
595 continue;
596
597 // Inner loop over the sync-lock group by tracks
598 for (auto member : group) {
599 if (iPair == endPair || member != iPair->first) {
600 if (isSyncLocked) {
601 // Track is not pasted into but must be adjusted
602 if (t1 != newT1 && t1 <= member->GetEndTime()) {
603 member->SyncLockAdjust(t1, newT1);
604 bPastedSomething = true;
605 }
606 }
607 }
608 else {
609 // Remember first pasted-into track, to focus it
610 if (!ff)
611 ff = member;
612 // Do the pasting!
613 const auto src = (iPair++)->second;
614 member->TypeSwitch(
615 [&](WaveTrack &wn){
616 bPastedSomething = true;
617 // For correct remapping of preserved split lines:
618 PasteTimeWarper warper{ t1, t0 + src->GetEndTime() };
619 const auto newClipOnPaste =
620 gPrefs->ReadBool(wxT("/GUI/PasteAsNewClips"), false);
621 // The new-clip-on-paste behavior means: not merging the
622 // clipboard data with data at the selection borders; not
623 // reproducing boundaries within the selected region in the
624 // new clip; preserving the data underneath by trimming
625 // (rather than deleting).
626 // The legacy behavior is the opposite.
627 const auto merge = newClipOnPaste ? false : true;
628 const auto preserveExistingBoundaries = newClipOnPaste ? false : true;
629 auto clearByTrimming = newClipOnPaste ? true : false;
630 wn.ClearAndPaste(
631 t0, t1, *static_cast<const WaveTrack*>(src),
632 preserveExistingBoundaries, merge, &warper,
633 clearByTrimming);
634 },
635 [&](LabelTrack &ln){
636 // Per Bug 293, users expect labels to move on a paste into
637 // a label track.
638 ln.Clear(t0, t1);
639
640 ln.ShiftLabelsOnInsert( clipboard.Duration(), t0 );
641
642 bPastedSomething |= ln.PasteOver(t0, *src);
643 },
644 [&](Track &t){
645 bPastedSomething = true;
646 t.Clear(t0, t1);
647 t.Paste(t0, *src);
648 }
649 );
650 }
651 }
652 }
653
654 // TODO: What if we clicked past the end of the track?
655
656 if (bPastedSomething) {
658 .setTimes( t0, t0 + clipboard.Duration() );
659
661 .PushState(XO("Pasted from the clipboard"), XO("Paste"));
662
663 if (ff) {
664 TrackFocus::Get(project).Set(ff);
666 }
667 }
668}
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 &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
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:1196
bool ReadBool(const wxString &key, bool defaultValue) const
std::shared_ptr< const TrackList > FindSourceTracks(const CommandContext &context)
Definition: EditMenus.cpp:421
Correspondence FindCorrespondence(TrackList &dstTracks, const TrackList &srcTracks)
Definition: EditMenus.cpp:496
void DoPasteNothingSelected(AudacityProject &project, const TrackList &src, double t0, double t1)
Definition: EditMenus.cpp:126
bool DoPasteText(AudacityProject &project)
Definition: EditMenus.cpp:45
auto NotificationScope(const CommandContext &context, const TrackList &srcTracks)
Definition: EditMenus.cpp:456
std::pair< double, double > FindSelection(const CommandContext &context)
Definition: EditMenus.cpp:399

References AudacityMessageBox(), WaveTrack::ClearAndPaste(), DoPasteNothingSelected(), DoPasteText(), FindCorrespondence(), FindSelection(), FindSourceTracks(), TrackFocus::Get(), Clipboard::Get(), ProjectHistory::Get(), ViewInfo::Get(), SyncLockState::Get(), TrackList::Get(), Viewport::Get(), gPrefs, SyncLock::Group(), SyncLockState::IsSyncLocked(), 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 950 of file EditMenus.cpp.

951{
952 auto &project = context.project;
953
954 GlobalPrefsDialog dialog(&GetProjectFrame(project) /* parent */, &project );
955
956 if (!dialog.ShowModal()) {
957 // Canceled
958 return;
959 }
960
961 // LL: Moved from PrefsDialog since wxWidgets on OSX can't deal with
962 // rebuilding the menus while the PrefsDialog is still in the modal
963 // state.
964 for (auto p : AllProjects{}) {
966// TODO: The comment below suggests this workaround is obsolete.
967#if defined(__WXGTK__)
968 // Workaround for:
969 //
970 // http://bugzilla.audacityteam.org/show_bug.cgi?id=458
971 //
972 // This workaround should be removed when Audacity updates to wxWidgets
973 // 3.x which has a fix.
974 auto &window = GetProjectFrame( *p );
975 wxRect r = window.GetRect();
976 window.SetSize(wxSize(1,1));
977 window.SetSize(r.GetSize());
978#endif
979 }
980}
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 209 of file EditMenus.cpp.

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

754{
755 auto &project = context.project;
757 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
758
759 const auto selectedWaveTracks = tracks.Selected<WaveTrack>();
761 [&](const ProgressReporter& parent) {
763 selectedWaveTracks.begin(), selectedWaveTracks.end(),
764 [&](WaveTrack* n, const ProgressReporter& child) {
765 n->Silence(selectedRegion.t0(), selectedRegion.t1(), child);
766 },
767 parent);
768 });
769
771 XO("Silenced selected tracks for %.2f seconds at %.2f")
772 .Format(selectedRegion.duration(), selectedRegion.t0()),
773 /* i18n-hint: verb */
774 XC("Silence", "command"));
775}
#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 797 of file EditMenus.cpp.

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

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

698{
699 auto &project = context.project;
701 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
702
703 auto &clipboard = Clipboard::Get();
704 clipboard.Clear();
705
706 auto pNewClipboard = TrackList::Create(nullptr);
707 auto &newClipboard = *pNewClipboard;
708
709 tracks.Selected().Visit(
710 [&](WaveTrack &n) {
711 auto track = n.SplitCut(selectedRegion.t0(), selectedRegion.t1());
712 newClipboard.Add(track);
713 },
714 [&](Track &n) {
715 if (n.SupportsBasicEditing()) {
716 auto dest = n.Copy(selectedRegion.t0(), selectedRegion.t1());
717 n.Silence(selectedRegion.t0(), selectedRegion.t1());
718 newClipboard.Add(dest);
719 }
720 }
721 );
722
723 // Survived possibility of exceptions. Commit changes to the clipboard now.
724 clipboard.Assign(std::move(newClipboard),
725 selectedRegion.t0(), selectedRegion.t1(), project.shared_from_this());
726
728 .PushState(XO("Split-cut to the clipboard"), XO("Split Cut"));
729}
void Silence(double t0, double t1, ProgressReporter reportProgress) override
Definition: WaveTrack.cpp:1979
Holder SplitCut(double t0, double t1)
Definition: WaveTrack.cpp:943
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
Create new tracks and don't modify this track.
Definition: WaveTrack.cpp:1073

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

732{
733 auto &project = context.project;
735 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
736
737 tracks.Selected().Visit(
738 [&](WaveTrack &wt) {
739 wt.SplitDelete(selectedRegion.t0(), selectedRegion.t1());
740 },
741 [&](Track &n) {
742 if (n.SupportsBasicEditing())
743 n.Silence(selectedRegion.t0(), selectedRegion.t1());
744 }
745 );
746
748 XO("Split-deleted %.2f seconds at t=%.2f")
749 .Format(selectedRegion.duration(), selectedRegion.t0()),
750 XO("Split Delete"));
751}
void SplitDelete(double t0, double t1)
Definition: WaveTrack.cpp:1503

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

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

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

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

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

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

◆ sAttachment1

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

Definition at line 1181 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 1237 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 1201 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 1215 of file EditMenus.cpp.

◆ selectTracks

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

Definition at line 1207 of file EditMenus.cpp.

◆ selectWaveTracks

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

Definition at line 1222 of file EditMenus.cpp.

◆ selectWaveTracks2

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

Definition at line 1230 of file EditMenus.cpp.