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

Functions

void FinishCopy (const Track *n, const Track::Holder &dest, TrackList &list)
 
bool DoPasteText (AudacityProject &project)
 
void ForEachCopiedWaveTrack (const TrackList &src, const TrackList &dst, const std::function< void(const WaveTrack &waveTrack)> &f)
 
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)
 
void OnPaste (const CommandContext &context)
 
void OnDuplicate (const CommandContext &context)
 
void OnSplitCut (const CommandContext &context)
 
void OnSplitDelete (const CommandContext &context)
 
void OnSilence (const CommandContext &context)
 
void OnTrim (const CommandContext &context)
 
void OnSplit (const CommandContext &context)
 
void OnSplitNew (const CommandContext &context)
 
void OnJoin (const CommandContext &context)
 
void OnDisjoin (const CommandContext &context)
 
void OnPreferences (const CommandContext &context)
 
const ReservedCommandFlagCutCopyAvailableFlag ()
 
BaseItemSharedPtr EditMenu ()
 
BaseItemSharedPtr ExtraEditMenu ()
 

Variables

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

Function Documentation

◆ CutCopyAvailableFlag()

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

Definition at line 1192 of file EditMenus.cpp.

1192 { static ReservedCommandFlag flag{
1193 [](const AudacityProject &project){
1194 auto range = TrackList::Get( project ).Any<const LabelTrack>()
1195 + [&](const LabelTrack *pTrack){
1196 return LabelTrackView::Get( *pTrack ).IsTextSelected(
1197 // unhappy const_cast because track focus might be set
1198 const_cast<AudacityProject&>(project)
1199 );
1200 };
1201 if ( !range.empty() )
1202 return true;
1203
1204 if (
1205 TimeSelectedPred( project )
1206 &&
1208 )
1209 return true;
1210
1211 return false;
1212 },
1214}; return flag; }
bool EditableTracksSelectedPred(const AudacityProject &project)
const CommandFlagOptions & cutCopyOptions()
bool TimeSelectedPred(const AudacityProject &project)
static std::once_flag flag
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:87
static LabelTrackView & Get(LabelTrack &)
bool IsTextSelected(AudacityProject &project) const
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1440
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:487

References TrackList::Any(), cutCopyOptions(), EditableTracksSelectedPred(), flag, TrackList::Get(), LabelTrackView::Get(), LabelTrackView::IsTextSelected(), 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 202 of file EditMenus.cpp.

203{
204 auto &tracks = TrackList::Get( project );
205 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
206 auto &viewInfo = ViewInfo::Get( project );
207 auto &window = ProjectWindow::Get( project );
208
209 assert(!tracks.Selected());
210
211 Track* pFirstNewTrack = NULL;
212 for (auto pClip : src) {
213 auto pNewTrack = pClip->PasteInto( project );
214 bool newTrack = (pNewTrack.use_count() == 1);
215 wxASSERT(pClip);
216
217 if (!pFirstNewTrack)
218 pFirstNewTrack = pNewTrack.get();
219
220 pNewTrack->SetSelected(true);
221 if (newTrack)
222 FinishCopy(pClip, pNewTrack, tracks);
223 else
224 Track::FinishCopy(pClip, pNewTrack.get());
225 }
226
227 // Select some pasted samples, which is probably impossible to get right
228 // with various project and track sample rates.
229 // So do it at the sample rate of the project
230 double projRate = ProjectRate::Get( project ).GetRate();
231 double quantT0 = QUANTIZED_TIME(t0, projRate);
232 double quantT1 = QUANTIZED_TIME(t1, projRate);
233 selectedRegion.setTimes(
234 0.0, // anywhere else and this should be
235 // half a sample earlier
236 quantT1 - quantT0);
237
238 ProjectHistory::Get( project )
239 .PushState(XO("Pasted from the clipboard"), XO("Paste"));
240
241 if (pFirstNewTrack) {
242 TrackFocus::Get(project).Set(pFirstNewTrack);
243 pFirstNewTrack->EnsureVisible();
244 }
245}
XO("Cut/Copy/Paste")
#define QUANTIZED_TIME(time, rate)
Definition: MemoryX.h:558
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
double GetRate() const
Definition: ProjectRate.cpp:53
static ProjectWindow & Get(AudacityProject &project)
Track * Get()
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:226
void EnsureVisible(bool modifyState=false)
Definition: Track.cpp:98
virtual void SetSelected(bool s)
Definition: Track.cpp:88
virtual Holder PasteInto(AudacityProject &) const =0
Find or create the destination track for a paste, maybe in a different project.
static void FinishCopy(const Track *n, Track *dest)
Definition: Track.cpp:415
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:219
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
void FinishCopy(const Track *n, const Track::Holder &dest, TrackList &list)
Definition: EditMenus.cpp:38

References Track::EnsureVisible(), FinishCopy(), Track::FinishCopy(), TrackFocus::Get(), ProjectHistory::Get(), ProjectRate::Get(), ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), ProjectRate::GetRate(), Track::PasteInto(), ProjectHistory::PushState(), QUANTIZED_TIME, ViewInfo::selectedRegion, Track::SetSelected(), 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 &window = ProjectWindow::Get( project );
52
53 for (auto pLabelTrack : tracks.Any<LabelTrack>())
54 {
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 {
63 ProjectHistory::Get( project )
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 window.ScrollIntoView(x);
70 }
71
72 return true;
73 }
74 }
75 }
76 return false;
77}
int GetTextEditIndex(AudacityProject &project) const

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), LabelTrackView::Get(), LabelTrackView::GetTextEditIndex(), ProjectHistory::PushState(), ViewInfo::selectedRegion, 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 167 of file EditMenus.cpp.

167 {
168 auto result = TrackList::Create(nullptr);
169 for(auto track : src)
170 {
171 auto trackCopy = track->Copy(track->GetStartTime(), track->GetEndTime(), false);
172 trackCopy->Init(*track);
173 trackCopy->SetOffset(track->GetOffset());
174
175 if(auto waveTrack = dynamic_cast<WaveTrack*>(trackCopy.get()))
176 {
177 for(auto clip : waveTrack->GetClips())
178 {
179 if(clip->GetTrimLeft() != 0)
180 {
181 auto t0 = clip->GetPlayStartTime();
182 clip->SetTrimLeft(0);
183 clip->ClearLeft(t0);
184 }
185 if(clip->GetTrimRight() != 0)
186 {
187 auto t1 = clip->GetPlayEndTime();
188 clip->SetTrimRight(0);
189 clip->ClearRight(t1);
190 }
191 }
192 }
193 result->Add(trackCopy);
194 }
195 return result;
196}
static std::shared_ptr< TrackList > Create(AudacityProject *pOwner)
Definition: Track.cpp:503
A Track that contains audio waveform data.
Definition: WaveTrack.h:51

References TrackList::Create().

Referenced by OnPaste().

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

◆ EditMenu()

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

Definition at line 1217 of file EditMenus.cpp.

1218{
1220
1221 static const auto NotBusyTimeAndTracksFlags =
1223
1224 // The default shortcut key for Redo is different on different platforms.
1225 static constexpr auto redoKey =
1226#ifdef __WXMSW__
1227 wxT("Ctrl+Y")
1228#else
1229 wxT("Ctrl+Shift+Z")
1230#endif
1231 ;
1232
1233 // The default shortcut key for Preferences is different on different
1234 // platforms.
1235 static constexpr auto prefKey =
1236#ifdef __WXMAC__
1237 wxT("Ctrl+,")
1238#else
1239 wxT("Ctrl+P")
1240#endif
1241 ;
1242
1243 static BaseItemSharedPtr menu{
1244 Menu( wxT("Edit"), XXO("&Edit"),
1245 Section( "UndoRedo",
1246 Command( wxT("Undo"), XXO("&Undo"), OnUndo,
1247 AudioIONotBusyFlag() | UndoAvailableFlag(), wxT("Ctrl+Z") ),
1248
1249 Command( wxT("Redo"), XXO("&Redo"), OnRedo,
1250 AudioIONotBusyFlag() | RedoAvailableFlag(), redoKey ),
1251
1252 Special( wxT("UndoItemsUpdateStep"),
1253 [](AudacityProject &project, wxMenu&) {
1254 // Change names in the CommandManager as a side-effect
1256 })
1257 ),
1258
1259 Section( "Basic",
1260 // Basic Edit commands
1261 /* i18n-hint: (verb)*/
1262 Command( wxT("Cut"), XXO("Cu&t"), OnCut,
1264 wxT("Ctrl+X") ),
1265 Command( wxT("Delete"), XXO("&Delete"), OnDelete,
1267 wxT("Ctrl+K") ),
1268 /* i18n-hint: (verb)*/
1269 Command( wxT("Copy"), XXO("&Copy"), OnCopy,
1270 AudioIONotBusyFlag() | CutCopyAvailableFlag(), wxT("Ctrl+C") ),
1271 /* i18n-hint: (verb)*/
1272 Command( wxT("Paste"), XXO("&Paste"), OnPaste,
1273 AudioIONotBusyFlag(), wxT("Ctrl+V") ),
1274 /* i18n-hint: (verb)*/
1275 Command( wxT("Duplicate"), XXO("Duplic&ate"), OnDuplicate,
1276 NotBusyTimeAndTracksFlags, wxT("Ctrl+D") ),
1277
1278 Section( "",
1279 Menu( wxT("RemoveSpecial"), XXO("R&emove Special"),
1280 Section( "",
1281 /* i18n-hint: (verb) Do a special kind of cut*/
1282 Command( wxT("SplitCut"), XXO("Spl&it Cut"), OnSplitCut,
1283 NotBusyTimeAndTracksFlags,
1284 Options{ wxT("Ctrl+Alt+X") } ),
1285 /* i18n-hint: (verb) Do a special kind of DELETE*/
1286 Command( wxT("SplitDelete"), XXO("Split D&elete"), OnSplitDelete,
1287 NotBusyTimeAndTracksFlags,
1288 Options{ wxT("Ctrl+Alt+K") } )
1289 ),
1290
1291 Section( "",
1292 /* i18n-hint: (verb)*/
1293 Command( wxT("Silence"), XXO("Silence Audi&o"), OnSilence,
1295 wxT("Ctrl+L") ),
1296 /* i18n-hint: (verb)*/
1297 Command( wxT("Trim"), XXO("Tri&m Audio"), OnTrim,
1299 Options{ wxT("Ctrl+T") } )
1300 )
1301 )
1302 )
1303 ),
1304
1305
1306 Section( "Other",
1308
1309 Menu( wxT("Clip"), XXO("Audi&o Clips"),
1310 Section( "",
1311 /* i18n-hint: (verb) It's an item on a menu. */
1312 Command( wxT("Split"), XXO("Sp&lit"), OnSplit,
1314 Options{ wxT("Ctrl+I") } ),
1315 Command( wxT("SplitNew"), XXO("Split Ne&w"), OnSplitNew,
1317 Options{ wxT("Ctrl+Alt+I") } )
1318 ),
1319
1320 Section( "",
1321 /* i18n-hint: (verb)*/
1322 Command( wxT("Join"), XXO("&Join"), OnJoin,
1323 NotBusyTimeAndTracksFlags, wxT("Ctrl+J") ),
1324 Command( wxT("Disjoin"), XXO("Detac&h at Silences"), OnDisjoin,
1325 NotBusyTimeAndTracksFlags, wxT("Ctrl+Alt+J") )
1326 )
1327 )
1328
1329 ),
1330
1331 // Note that on Mac, the Preferences menu item is specially handled in
1332 // CommandManager (assigned a special wxWidgets id) so that it does
1333 // not appear in the Edit menu but instead under Audacity, consistent with
1334 // MacOS conventions.
1335 Section( "Preferences",
1336 Command( wxT("Preferences"), XXO("Pre&ferences"), OnPreferences,
1337 AudioIONotBusyFlag(), prefKey )
1338 )
1339
1340 ) };
1341 return menu;
1342}
wxT("CloseDown"))
const ReservedCommandFlag & NoAutoSelect()
const ReservedCommandFlag & AudioIONotBusyFlag()
const ReservedCommandFlag & UndoAvailableFlag()
const ReservedCommandFlag & RedoAvailableFlag()
const ReservedCommandFlag & TimeSelectedFlag()
const ReservedCommandFlag & EditableTracksSelectedFlag()
const ReservedCommandFlag & WaveTracksSelectedFlag()
XXO("&Cut/Copy/Paste Toolbar")
static void ModifyUndoMenuItems(AudacityProject &project)
Definition: Menus.cpp:451
std::unique_ptr< MenuItem > Menu(const Identifier &internalName, const TranslatableString &title, Args &&... args)
std::unique_ptr< MenuPart > Section(const Identifier &internalName, Args &&... args)
std::unique_ptr< CommandItem > Command(const CommandID &name, const TranslatableString &label_in, void(Handler::*pmf)(const CommandContext &), CommandFlag flags, const CommandManager::Options &options={}, CommandHandlerFinder finder=FinderScope::DefaultFinder())
std::unique_ptr< SpecialItem > Special(const Identifier &name, const SpecialItem::Appender &fn)
std::shared_ptr< BaseItem > BaseItemSharedPtr
Definition: Registry.h:72
void OnDisjoin(const CommandContext &context)
Definition: EditMenus.cpp:1116
void OnRedo(const CommandContext &context)
Definition: EditMenus.cpp:297
void OnJoin(const CommandContext &context)
Definition: EditMenus.cpp:1099
void OnDelete(const CommandContext &context)
Definition: EditMenus.cpp:426
void OnPaste(const CommandContext &context)
Definition: EditMenus.cpp:519
const ReservedCommandFlag & CutCopyAvailableFlag()
Definition: EditMenus.cpp:1192
void OnSplit(const CommandContext &context)
Definition: EditMenus.cpp:976
void OnSilence(const CommandContext &context)
Definition: EditMenus.cpp:936
void OnTrim(const CommandContext &context)
Definition: EditMenus.cpp:952
void OnSplitDelete(const CommandContext &context)
Definition: EditMenus.cpp:911
void OnCopy(const CommandContext &context)
Definition: EditMenus.cpp:452
void OnUndo(const CommandContext &context)
Definition: EditMenus.cpp:266
void OnSplitCut(const CommandContext &context)
Definition: EditMenus.cpp:868
void OnPreferences(const CommandContext &context)
Definition: EditMenus.cpp:1133
void OnDuplicate(const CommandContext &context)
Definition: EditMenus.cpp:838
void OnSplitNew(const CommandContext &context)
Definition: EditMenus.cpp:1045
void OnCut(const CommandContext &context)
Definition: EditMenus.cpp:327

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

Here is the call graph for this function:

◆ EstimateCopiedBlocks()

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

Definition at line 157 of file EditMenus.cpp.

158{
159 BlockArray::size_type result{};
160 ForEachCopiedWaveTrack(src, dst, [&](const WaveTrack& waveTrack) {
161 for(auto& clip : waveTrack.GetClips())
162 result += clip->GetSequenceBlockArray()->size();
163 });
164 return result;
165}
WaveClipHolders & GetClips()
Definition: WaveTrack.h:322
void ForEachCopiedWaveTrack(const TrackList &src, const TrackList &dst, const std::function< void(const WaveTrack &waveTrack)> &f)
Definition: EditMenus.cpp:91

References ForEachCopiedWaveTrack(), WaveTrack::GetClips(), and TrackList::size().

Referenced by OnPaste().

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

146{
147 wxULongLong result{};
148 ForEachCopiedWaveTrack(src, dst, [&](const WaveTrack& waveTrack) {
149 sampleCount samplesCount = 0;
150 for(auto& clip : waveTrack.GetClips())
151 samplesCount += clip->GetSequenceSamplesCount();
152 result += samplesCount.as_long_long() * SAMPLE_SIZE(waveTrack.GetSampleFormat());
153 });
154 return result;
155}
#define SAMPLE_SIZE(SampleFormat)
Definition: SampleFormat.h:50
sampleFormat GetSampleFormat() const override
Definition: WaveTrack.h:151
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
long long as_long_long() const
Definition: SampleCount.h:48

References sampleCount::as_long_long(), ForEachCopiedWaveTrack(), WaveTrack::GetClips(), WaveTrack::GetSampleFormat(), and SAMPLE_SIZE.

Referenced by OnPaste().

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

◆ ExtraEditMenu()

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

Definition at line 1349 of file EditMenus.cpp.

1350{
1352 static const auto flags =
1354 static BaseItemSharedPtr menu{
1355 Menu( wxT("Edit"), XXO("&Edit"),
1356 Command( wxT("DeleteKey"), XXO("&Delete Key"), OnDelete,
1357 (flags | NoAutoSelect()),
1358 wxT("Backspace") ),
1359 Command( wxT("DeleteKey2"), XXO("Delete Key&2"), OnDelete,
1360 (flags | NoAutoSelect()),
1361 wxT("Delete") )
1362 ) };
1363 return menu;
1364}

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

Here is the call graph for this function:

◆ FindSelection()

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

Definition at line 497 of file EditMenus.cpp.

498{
499 double sel0 = 0.0, sel1 = 0.0;
500
501#if 0
502 // Use the overriding selection if any was given in the context
503 if (auto *pRegion = context.temporarySelection.pSelectedRegion) {
504 auto &selectedRegion = *pRegion;
505 sel0 = selectedRegion.t0();
506 sel1 = selectedRegion.t1();
507 }
508 else
509#endif
510 {
511 auto &selectedRegion = ViewInfo::Get(context.project).selectedRegion;
512 sel0 = selectedRegion.t0();
513 sel1 = selectedRegion.t1();
514 }
515
516 return { sel0, sel1 };
517}
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:

◆ FinishCopy()

void anonymous_namespace{EditMenus.cpp}::FinishCopy ( const Track n,
const Track::Holder dest,
TrackList list 
)

Definition at line 37 of file EditMenus.cpp.

39{
40 Track::FinishCopy( n, dest.get() );
41 if (dest)
42 list.Add( dest );
43}
TrackKind * Add(const std::shared_ptr< TrackKind > &t)
Definition: Track.h:1567

References TrackList::Add(), and Track::FinishCopy().

Referenced by DoPasteNothingSelected(), OnCopy(), OnCut(), OnSplitCut(), and OnSplitNew().

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

◆ ForEachCopiedWaveTrack()

void anonymous_namespace{EditMenus.cpp}::ForEachCopiedWaveTrack ( const TrackList src,
const TrackList dst,
const std::function< void(const WaveTrack &waveTrack)> &  f 
)

Definition at line 91 of file EditMenus.cpp.

94{
95 if(dst.Selected().empty())
96 {
97 for(auto waveTrack : src.Any<const WaveTrack>())
98 f(*waveTrack);
99 }
100 else
101 {
102 const auto srcTrackRange = src.Any<const WaveTrack>();
103 const auto dstTrackRange = dst.Any<const WaveTrack>();
104 auto srcTrack = srcTrackRange.begin();
105 auto dstTrack = dstTrackRange.begin();
106 auto lastCopiedTrack = srcTrack;
107 while(dstTrack != dstTrackRange.end() && srcTrack != srcTrackRange.end())
108 {
109 if(!(*dstTrack)->GetSelected())
110 {
111 ++dstTrack;
112 continue;
113 }
114
115 auto srcChannelCount = TrackList::Channels(*srcTrack).size();
116 auto dstChannelCount = TrackList::Channels(*dstTrack).size();
117
118 while(srcChannelCount > 0 && dstChannelCount > 0)
119 {
120 f(**srcTrack);
121
122 lastCopiedTrack = srcTrack;
123 ++srcTrack;
124 ++dstTrack;
125 --srcChannelCount;
126 --dstChannelCount;
127 }
128
129 while(dstChannelCount > 0)
130 {
131 f(**lastCopiedTrack);
132 ++dstTrack;
133 --dstChannelCount;
134 }
135 }
136 while(dstTrack != dstTrackRange.end())
137 {
138 if((*dstTrack)->GetSelected())
139 f(**lastCopiedTrack);
140 ++dstTrack;
141 }
142 }
143}
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:1457
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1544

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

Referenced by EstimateCopiedBlocks(), and EstimateCopyBytesCount().

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

248{
249 for(auto waveTrack : trackList.Any<const WaveTrack>())
250 {
251 for(auto& clip : waveTrack->GetClips())
252 {
253 if(clip->GetTrimLeft() != 0 || clip->GetTrimRight() != 0)
254 return true;
255 }
256 }
257 return false;
258}

References TrackList::Any().

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

453{
454 auto &project = context.project;
455 auto &tracks = TrackList::Get( project );
456 auto &trackPanel = TrackPanel::Get( project );
457 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
458
459 for (auto lt : tracks.Selected< LabelTrack >()) {
460 auto &view = LabelTrackView::Get( *lt );
461 if (view.CopySelectedText( context.project )) {
462 //trackPanel.Refresh(false);
463 return;
464 }
465 }
466 //Presumably, there might be not more than one track
467 //that expects text input
468 for (auto wt : tracks.Any<WaveTrack>()) {
469 auto& view = WaveTrackView::Get(*wt);
470 if (view.CopySelectedText(context.project)) {
471 return;
472 }
473 }
474
475 auto &clipboard = Clipboard::Get();
476 clipboard.Clear();
477
478 auto pNewClipboard = TrackList::Create( nullptr );
479 auto &newClipboard = *pNewClipboard;
480
481 for (auto n : tracks.Selected()) {
482 if (n->SupportsBasicEditing()) {
483 auto dest = n->Copy(selectedRegion.t0(),
484 selectedRegion.t1());
485 FinishCopy(n, dest, newClipboard);
486 }
487 }
488
489 // Survived possibility of exceptions. Commit changes to the clipboard now.
490 clipboard.Assign( std::move( newClipboard ),
491 selectedRegion.t0(), selectedRegion.t1(), project.shared_from_this() );
492
493 //Make sure the menus/toolbar states get updated
494 trackPanel.Refresh(false);
495}
static Clipboard & Get()
Definition: Clipboard.cpp:28
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:231
static WaveTrackView & Get(WaveTrack &track)

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

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

328{
329 auto &project = context.project;
330 auto &tracks = TrackList::Get( project );
331 auto &trackPanel = TrackPanel::Get( project );
332 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
333 auto &ruler = AdornedRulerPanel::Get( project );
334 auto &window = ProjectWindow::Get( project );
335
336 // This doesn't handle cutting labels, it handles
337 // cutting the _text_ inside of labels, i.e. if you're
338 // in the middle of editing the label text and select "Cut".
339
340 for (auto lt : tracks.Selected< LabelTrack >()) {
341 auto &view = LabelTrackView::Get( *lt );
342 if (view.CutSelectedText( context.project )) {
343 trackPanel.Refresh(false);
344 return;
345 }
346 }
347
348 //Presumably, there might be not more than one track
349 //that expects text input
350 for (auto wt : tracks.Any<WaveTrack>()) {
351 auto& view = WaveTrackView::Get(*wt);
352 if (view.CutSelectedText(context.project)) {
353 trackPanel.Refresh(false);
354 return;
355 }
356 }
357
358 auto &clipboard = Clipboard::Get();
359 clipboard.Clear();
360
361 auto pNewClipboard = TrackList::Create( nullptr );
362 auto &newClipboard = *pNewClipboard;
363
364 tracks.Selected().Visit(
365#if defined(USE_MIDI)
366 [&](NoteTrack *n) {
367 // Since portsmf has a built-in cut operator, we use that instead
368 auto dest = n->Cut(selectedRegion.t0(),
369 selectedRegion.t1());
370 FinishCopy(n, dest, newClipboard);
371 },
372#endif
373 [&](Track *n) {
374 if (n->SupportsBasicEditing()) {
375 auto dest = n->Copy(selectedRegion.t0(),
376 selectedRegion.t1());
377 FinishCopy(n, dest, newClipboard);
378 }
379 }
380 );
381
382 // Survived possibility of exceptions. Commit changes to the clipboard now.
383 clipboard.Assign(
384 std::move( newClipboard ),
385 selectedRegion.t0(),
386 selectedRegion.t1(),
387 project.shared_from_this()
388 );
389
390 // Proceed to change the project. If this throws, the project will be
391 // rolled back by the top level handler.
392
394#if defined(USE_MIDI)
395 [](NoteTrack*) {
396 //if NoteTrack, it was cut, so do not clear anything
397
398 // PRL: But what if it was sync lock selected only, not selected?
399 },
400#endif
401 [&](WaveTrack *wt, const Track::Fallthrough &fallthrough) {
402 if (gPrefs->Read(wxT("/GUI/EnableCutLines"), (long)0)) {
404 selectedRegion.t0(),
405 selectedRegion.t1());
406 }
407 else
408 fallthrough();
409 },
410 [&](Track *n) {
411 if (n->SupportsBasicEditing())
412 n->Clear(selectedRegion.t0(), selectedRegion.t1());
413 }
414 );
415
416 selectedRegion.collapseToT0();
417
418 ProjectHistory::Get( project )
419 .PushState(XO("Cut to the clipboard"), XO("Cut"));
420
421 // Bug 1663
422 //mRuler->ClearPlayRegion();
423 ruler.DrawOverlays( true );
424}
auto Visit(Visitor &&vis, Variant &&var)
Mimic some of std::visit, for the case of one visitor only.
Definition: MemoryX.h:628
FileConfig * gPrefs
Definition: Prefs.cpp:70
static AdornedRulerPanel & Get(AudacityProject &project)
A Track that is used for Midi notes. (Somewhat old code).
Definition: NoteTrack.h:63
Track::Holder Cut(double t0, double t1) override
Definition: NoteTrack.cpp:443
void Clear(double t0, double t1) override
Definition: NoteTrack.cpp:520
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
Definition: NoteTrack.cpp:473
static bool IsSelectedOrSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:112
virtual bool SupportsBasicEditing() const
Whether this track type implements cut-copy-paste; by default, true.
Definition: Track.cpp:1259
Continuation<> Fallthrough
Type of arguments passed as optional second parameter to TypeSwitch<void>() cases.
Definition: Track.h:542
void ClearAndAddCutLine(double t0, double t1)
Definition: WaveTrack.cpp:658

References NoteTrack::Clear(), WaveTrack::ClearAndAddCutLine(), NoteTrack::Copy(), TrackList::Create(), NoteTrack::Cut(), FinishCopy(), Clipboard::Get(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), AdornedRulerPanel::Get(), ProjectWindow::Get(), TrackPanel::Get(), LabelTrackView::Get(), WaveTrackView::Get(), gPrefs, SyncLock::IsSelectedOrSyncLockSelected(), CommandContext::project, ProjectHistory::PushState(), anonymous_namespace{TimeTrackVRulerControls.cpp}::ruler(), ViewInfo::selectedRegion, Track::SupportsBasicEditing(), 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 426 of file EditMenus.cpp.

427{
428 auto &project = context.project;
429 auto &tracks = TrackList::Get( project );
430 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
431 auto &window = ProjectWindow::Get( project );
432
433 for (auto n : tracks.Any()) {
434 if (!n->SupportsBasicEditing())
435 continue;
437 n->Clear(selectedRegion.t0(), selectedRegion.t1());
438 }
439 }
440
441 double seconds = selectedRegion.duration();
442
443 selectedRegion.collapseToT0();
444
446 XO("Deleted %.2f seconds at t=%.2f")
447 .Format( seconds, selectedRegion.t0()),
448 XO("Delete"));
449}
Abstract base class used in importing a file.

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), SyncLock::IsSelectedOrSyncLockSelected(), CommandContext::project, ProjectHistory::PushState(), ViewInfo::selectedRegion, 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 1116 of file EditMenus.cpp.

1117{
1118 auto &project = context.project;
1119 auto &tracks = TrackList::Get( project );
1120 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
1121 auto &window = ProjectWindow::Get( project );
1122
1123 for (auto wt : tracks.Selected< WaveTrack >())
1124 wt->Disjoin(selectedRegion.t0(),
1125 selectedRegion.t1());
1126
1127 ProjectHistory::Get( project ).PushState(
1128 XO("Detached %.2f seconds at t=%.2f")
1129 .Format( selectedRegion.duration(), selectedRegion.t0() ),
1130 XO("Detach"));
1131}

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

839{
840 auto &project = context.project;
841 auto &tracks = TrackList::Get( project );
842 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
843 auto &window = ProjectWindow::Get( project );
844
845 // This iteration is unusual because we add to the list inside the loop
846 auto range = tracks.Selected();
847 auto last = *range.rbegin();
848 for (auto n : range) {
849 if (!n->SupportsBasicEditing())
850 continue;
851
852 // Make copies not for clipboard but for direct addition to the project
853 auto dest = n->Copy(selectedRegion.t0(),
854 selectedRegion.t1(), false);
855 dest->Init(*n);
856 dest->SetOffset(wxMax(selectedRegion.t0(), n->GetOffset()));
857 tracks.Add( dest );
858
859 // This break is really needed, else we loop infinitely
860 if (n == last)
861 break;
862 }
863
864 ProjectHistory::Get( project )
865 .PushState(XO("Duplicated"), XO("Duplicate"));
866}

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

1100{
1101 auto &project = context.project;
1102 auto &tracks = TrackList::Get( project );
1103 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
1104 auto &window = ProjectWindow::Get( project );
1105
1106 for (auto wt : tracks.Selected< WaveTrack >())
1107 wt->Join(selectedRegion.t0(),
1108 selectedRegion.t1());
1109
1110 ProjectHistory::Get( project ).PushState(
1111 XO("Joined %.2f seconds at t=%.2f")
1112 .Format( selectedRegion.duration(), selectedRegion.t0() ),
1113 XO("Join"));
1114}

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

520{
521 auto &project = context.project;
522 auto &tracks = TrackList::Get( project );
523 auto& trackPanel = TrackPanel::Get(project);
524 auto &trackFactory = WaveTrackFactory::Get( project );
525 auto &pSampleBlockFactory = trackFactory.GetSampleBlockFactory();
526 auto &window = ProjectWindow::Get( project );
527
528 auto isSyncLocked = SyncLockState::Get(project).IsSyncLocked();
529
530 // Handle text paste (into active label) first.
531 if (DoPasteText(project))
532 return;
533
534 //Presumably, there might be not more than one track
535 //that expects text input
536 for (auto wt : tracks.Any<WaveTrack>()) {
537 auto& view = WaveTrackView::Get(*wt);
538 if (view.PasteText(context.project)) {
539 trackPanel.Refresh(false);
540 return;
541 }
542 }
543
544 const auto &clipboard = Clipboard::Get();
545 if (clipboard.GetTracks().empty())
546 return;
547
548 auto discardTrimmed = false;
549 if(&context.project != &*clipboard.Project().lock())
550 {
551 const auto waveClipCopyPolicy = TracksBehaviorsAudioTrackPastePolicy.Read();
552 if(waveClipCopyPolicy == wxT("Ask") && HasHiddenData(clipboard.GetTracks())) {
553 AudioPasteDialog audioPasteDialog(
554 &window,
555 EstimateCopyBytesCount(clipboard.GetTracks(), tracks)
556 );
557 const auto result = audioPasteDialog.ShowModal();
558 if(result == wxID_CANCEL)
559 return;
560 discardTrimmed =
562 }
563 else if(waveClipCopyPolicy == wxT("Discard"))
564 discardTrimmed = true;
565 }
566
567 std::shared_ptr<const TrackList> srcTracks;
568 if(discardTrimmed)
569 srcTracks = DuplicateDiscardTrimmed(clipboard.GetTracks());
570 else
571 srcTracks = clipboard.GetTracks().shared_from_this();
572
573 auto scopedSubscription = pSampleBlockFactory->Subscribe([
574 toCopy = EstimateCopiedBlocks(*srcTracks, tracks),
575 nCopied = 0,
576 copyStartTime = std::chrono::system_clock::now(),
577 progressDialog = std::shared_ptr<BasicUI::ProgressDialog>()]
578 (const SampleBlockCreateMessage&) mutable {
579 using namespace std::chrono;
580 constexpr auto ProgressDialogShowDelay = milliseconds { 100 };
581 ++nCopied;
582 if(!progressDialog) {
583 if(duration_cast<milliseconds>(system_clock::now() - copyStartTime) >= ProgressDialogShowDelay)
584 progressDialog = BasicUI::MakeProgress(XO("Paste clip"), XO("Pasting clip contents, please wait"), 0);
585 }
586 else {
587 progressDialog->Poll(nCopied, toCopy);
588 }
589 });
590
591 // If nothing's selected, we just insert NEW tracks.
592 if(!tracks.Selected())
593 {
594 DoPasteNothingSelected(project, *srcTracks, clipboard.T0(), clipboard.T1());
595 return;
596 }
597
598 // Otherwise, paste into the selected tracks.
599 double t0, t1;
600 std::tie(t0, t1) = FindSelection(context);
601
602 auto pN = tracks.Any().begin();
603
604 Track *ff = NULL;
605 const Track *lastClipBeforeMismatch = NULL;
606 const Track *mismatchedClip = NULL;
607 const Track *prevClip = NULL;
608
609 bool bAdvanceClipboard = true;
610 bool bPastedSomething = false;
611
612 auto pasteWaveTrack = [&](WaveTrack *dst, const Track *src){
613 bPastedSomething = true;
614 // For correct remapping of preserved split lines:
615 PasteTimeWarper warper{ t1, t0 + src->GetEndTime() };
616 dst->ClearAndPaste(t0, t1, src, true, true, &warper);
617 };
618
619 auto clipTrackRange = srcTracks->Any();
620 auto pC = clipTrackRange.begin();
621 size_t nnChannels=0, ncChannels=0;
622 while (*pN && *pC) {
623 auto n = *pN;
624 auto c = *pC;
625 if (n->GetSelected()) {
626 bAdvanceClipboard = true;
627 if (mismatchedClip)
628 c = mismatchedClip;
629 if (!c->SameKindAs(*n)) {
630 if (!mismatchedClip) {
631 lastClipBeforeMismatch = prevClip;
632 mismatchedClip = c;
633 }
634 bAdvanceClipboard = false;
635 c = lastClipBeforeMismatch;
636
637
638 // If the types still don't match...
639 while (c && !c->SameKindAs(*n)) {
640 prevClip = c;
641 c = * ++ pC;
642 }
643 }
644
645 // Handle case where the first track in clipboard
646 // is of different type than the first selected track
647 if (!c) {
648 c = mismatchedClip;
649 while (n && (!c->SameKindAs(*n) || !n->GetSelected()))
650 {
651 // Must perform sync-lock adjustment before incrementing n
653 auto newT1 = t0 + clipboard.Duration();
654 if (t1 != newT1 && t1 <= n->GetEndTime()) {
655 n->SyncLockAdjust(t1, newT1);
656 bPastedSomething = true;
657 }
658 }
659 n = * ++ pN;
660 }
661 if (!n)
662 c = NULL;
663 }
664
665 // The last possible case for cross-type pastes: triggered when we try
666 // to paste 1+ tracks from one type into 1+ tracks of another type. If
667 // there's a mix of types, this shouldn't run.
668 if (!c)
669 // Throw, so that any previous changes to the project in this loop
670 // are discarded.
673 XO("Pasting one type of track into another is not allowed."),
674 XO("Warning"),
675 "Error:_Copying_or_Pasting"
676 };
677
678 // We should need this check only each time we visit the leading
679 // channel
680 if ( n->IsLeader() ) {
681 wxASSERT( c->IsLeader() ); // the iteration logic should ensure this
682
683 auto cChannels = TrackList::Channels(c);
684 ncChannels = cChannels.size();
685 auto nChannels = TrackList::Channels(n);
686 nnChannels = nChannels.size();
687
688 // When trying to copy from stereo to mono track, show error and
689 // exit
690 // TODO: Automatically offer user to mix down to mono (unfortunately
691 // this is not easy to implement
692 if (ncChannels > nnChannels)
693 {
694 if (ncChannels > 2) {
695 // TODO: more-than-two-channels-message
696 // Re-word the error message
697 }
698 // else
699
700 // Throw, so that any previous changes to the project in this
701 // loop are discarded.
704 XO("Copying stereo audio into a mono track is not allowed."),
705 XO("Warning"),
706 "Error:_Copying_or_Pasting"
707 };
708 }
709 }
710
711 if (!ff)
712 ff = n;
713
714 wxASSERT( n && c && n->SameKindAs(*c) );
715 n->TypeSwitch(
716 [&](WaveTrack *wn){
717 pasteWaveTrack(wn, static_cast<const WaveTrack *>(c));
718 },
719 [&](LabelTrack *ln){
720 // Per Bug 293, users expect labels to move on a paste into
721 // a label track.
722 ln->Clear(t0, t1);
723
724 ln->ShiftLabelsOnInsert( clipboard.Duration(), t0 );
725
726 bPastedSomething |= ln->PasteOver(t0, c);
727 },
728 [&](Track *){
729 bPastedSomething = true;
730 n->Clear(t0, t1);
731 n->Paste(t0, c);
732 }
733 );
734
735 --nnChannels;
736 --ncChannels;
737
738 // When copying from mono to stereo track, paste the wave form
739 // to both channels
740 // TODO: more-than-two-channels
741 // This will replicate the last pasted channel as many times as needed
742 while (nnChannels > 0 && ncChannels == 0)
743 {
744 n = * ++ pN;
745 --nnChannels;
746
747 n->TypeSwitch(
748 [&](WaveTrack *wn){
749 pasteWaveTrack(wn, c);
750 },
751 [&](Track *){
752 n->Clear(t0, t1);
753 bPastedSomething = true;
754 n->Paste(t0, c);
755 }
756 );
757 }
758
759 if (bAdvanceClipboard) {
760 prevClip = c;
761 c = * ++ pC;
762 }
763 } // if (n->GetSelected())
765 {
766 auto newT1 = t0 + clipboard.Duration();
767 if (t1 != newT1 && t1 <= n->GetEndTime()) {
768 n->SyncLockAdjust(t1, newT1);
769 bPastedSomething = true;
770 }
771 }
772 ++pN;
773 }
774
775 // This block handles the cases where our clipboard is smaller
776 // than the amount of selected destination tracks. We take the
777 // last wave track, and paste that one into the remaining
778 // selected tracks.
779 if ( *pN && ! *pC )
780 {
781 const auto wc =
782 *srcTracks->Any< const WaveTrack >().rbegin();
783
784 tracks.Any().StartingWith(*pN).Visit(
785 [&](WaveTrack *wt, const Track::Fallthrough &fallthrough) {
786 if (!wt->GetSelected())
787 return fallthrough();
788
789 if (wc) {
790 pasteWaveTrack(wt, wc);
791 }
792 else {
793 auto tmp = wt->EmptyCopy( pSampleBlockFactory );
794 tmp->InsertSilence( 0.0,
795 // MJS: Is this correct?
796 clipboard.Duration() );
797 tmp->Flush();
798
799 pasteWaveTrack(wt, tmp.get());
800 }
801 },
802 [&](LabelTrack *lt, const Track::Fallthrough &fallthrough) {
804 return fallthrough();
805
806 lt->Clear(t0, t1);
807
808 // As above, only shift labels if sync-lock is on.
809 if (isSyncLocked)
811 clipboard.Duration(), t0);
812 },
813 [&](Track *n) {
815 n->SyncLockAdjust(t1, t0 + clipboard.Duration() );
816 }
817 );
818 }
819
820 // TODO: What if we clicked past the end of the track?
821
822 if (bPastedSomething)
823 {
825 .setTimes( t0, t0 + clipboard.Duration() );
826
827 ProjectHistory::Get( project )
828 .PushState(XO("Pasted from the clipboard"), XO("Paste"));
829
830 if (ff) {
831 TrackFocus::Get(project).Set(ff);
832 ff->EnsureVisible();
833 ff->LinkConsistencyFix();
834 }
835 }
836}
@ BadUserAction
Indicates that the user performed an action that is not allowed.
ChoiceSetting TracksBehaviorsAudioTrackPastePolicy
wxString Read() const
Definition: Prefs.cpp:354
void ShiftLabelsOnInsert(double length, double pt)
Definition: LabelTrack.cpp:226
void Clear(double t0, double t1) override
Definition: LabelTrack.cpp:177
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
A MessageBoxException that shows a given, unvarying string.
static bool IsSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:82
bool IsSyncLocked() const
Definition: SyncLock.cpp:43
static SyncLockState & Get(AudacityProject &project)
Definition: SyncLock.cpp:26
virtual void SyncLockAdjust(double oldT1, double newT1)
Definition: Track.cpp:286
virtual bool LinkConsistencyFix(bool doFix=true, bool completeList=true)
Check consistency of channel groups, and maybe fix it.
Definition: Track.cpp:425
static WaveTrackFactory & Get(AudacityProject &project)
Definition: WaveTrack.cpp:2536
void ClearAndPaste(double t0, double t1, const Track *src, bool preserve=true, bool merge=true, const TimeWarper *effectWarper=NULL)
Definition: WaveTrack.cpp:710
std::unique_ptr< ProgressDialog > MakeProgress(const TranslatableString &title, const TranslatableString &message, unsigned flags=(ProgressShowStop|ProgressShowCancel), const TranslatableString &remainingLabelText={})
Create and display a progress dialog.
Definition: BasicUI.h:289
wxULongLong EstimateCopyBytesCount(const TrackList &src, const TrackList &dst)
Definition: EditMenus.cpp:145
BlockArray::size_type EstimateCopiedBlocks(const TrackList &src, const TrackList &dst)
Definition: EditMenus.cpp:157
void DoPasteNothingSelected(AudacityProject &project, const TrackList &src, double t0, double t1)
Definition: EditMenus.cpp:202
bool DoPasteText(AudacityProject &project)
Definition: EditMenus.cpp:47
std::shared_ptr< TrackList > DuplicateDiscardTrimmed(const TrackList &src)
Definition: EditMenus.cpp:167
std::pair< double, double > FindSelection(const CommandContext &context)
Definition: EditMenus.cpp:497
bool HasHiddenData(const TrackList &trackList)
Definition: EditMenus.cpp:247

References BadUserAction, TrackList::Channels(), LabelTrack::Clear(), WaveTrack::ClearAndPaste(), AudioPasteDialog::DISCARD, DoPasteNothingSelected(), DoPasteText(), DuplicateDiscardTrimmed(), EstimateCopiedBlocks(), EstimateCopyBytesCount(), FindSelection(), Clipboard::Get(), SyncLockState::Get(), TrackList::Get(), WaveTrackFactory::Get(), ProjectWindow::Get(), TrackPanel::Get(), WaveTrackView::Get(), HasHiddenData(), SyncLock::IsSelectedOrSyncLockSelected(), SyncLockState::IsSyncLocked(), SyncLock::IsSyncLockSelected(), BasicUI::MakeProgress(), CommandContext::project, ChoiceSetting::Read(), LabelTrack::ShiftLabelsOnInsert(), Track::SyncLockAdjust(), TracksBehaviorsAudioTrackPastePolicy, 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 1133 of file EditMenus.cpp.

1134{
1135 auto &project = context.project;
1136
1137 GlobalPrefsDialog dialog(&GetProjectFrame( project ) /* parent */, &project );
1138
1139 if( VetoDialogHook::Call( &dialog ) )
1140 return;
1141
1142 if (!dialog.ShowModal()) {
1143 // Canceled
1144 return;
1145 }
1146
1147 // LL: Moved from PrefsDialog since wxWidgets on OSX can't deal with
1148 // rebuilding the menus while the PrefsDialog is still in the modal
1149 // state.
1150 for (auto p : AllProjects{}) {
1152// TODO: The comment below suggests this workaround is obsolete.
1153#if defined(__WXGTK__)
1154 // Workaround for:
1155 //
1156 // http://bugzilla.audacityteam.org/show_bug.cgi?id=458
1157 //
1158 // This workaround should be removed when Audacity updates to wxWidgets
1159 // 3.x which has a fix.
1160 auto &window = GetProjectFrame( *p );
1161 wxRect r = window.GetRect();
1162 window.SetSize(wxSize(1,1));
1163 window.SetSize(r.GetSize());
1164#endif
1165 }
1166}
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
static result_type Call(Arguments &&...arguments)
Null check of the installed function is done for you.
void RebuildMenuBar(AudacityProject &project)
Definition: Menus.cpp:493
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:69

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

Referenced by EditMenu().

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

◆ OnRedo()

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

Definition at line 297 of file EditMenus.cpp.

298{
299 auto &project = context.project;
300 auto &tracks = TrackList::Get( project );
301 auto &trackPanel = TrackPanel::Get( project );
302 auto &undoManager = UndoManager::Get( project );
303 auto &window = ProjectWindow::Get( project );
304
305 if (!ProjectHistory::Get( project ).RedoAvailable()) {
306 AudacityMessageBox( XO("Nothing to redo") );
307 return;
308 }
309 // Can't redo whilst dragging
310 if (trackPanel.IsMouseCaptured()) {
311 return;
312 }
313
314 undoManager.Redo(
315 [&]( const UndoStackElem &elem ){
316 ProjectHistory::Get( project ).PopState( elem.state ); } );
317
318 auto t = *tracks.Selected().begin();
319 if (!t)
320 t = *tracks.Any().begin();
321 TrackFocus::Get(project).Set(t);
322 if (t) {
323 t->EnsureVisible();
324 }
325}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
void PopState(const UndoState &state, bool doAutosave=true)
static UndoManager & Get(AudacityProject &project)
Definition: UndoManager.cpp:71
Holds one item with description and time range for the UndoManager.
Definition: UndoManager.h:117
UndoState state
Definition: UndoManager.h:128

References AudacityMessageBox(), Track::EnsureVisible(), TrackFocus::Get(), ProjectHistory::Get(), UndoManager::Get(), TrackList::Get(), ProjectWindow::Get(), TrackPanel::Get(), ProjectHistory::PopState(), CommandContext::project, UndoStackElem::state, 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 936 of file EditMenus.cpp.

937{
938 auto &project = context.project;
939 auto &tracks = TrackList::Get( project );
940 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
941
942 for ( auto n : tracks.Selected< WaveTrack >() )
943 n->Silence(selectedRegion.t0(), selectedRegion.t1());
944
946 XO("Silenced selected tracks for %.2f seconds at %.2f")
947 .Format( selectedRegion.duration(), selectedRegion.t0() ),
948 /* i18n-hint: verb */
949 XC("Silence", "command"));
950}
#define XC(s, c)
Definition: Internat.h:37

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

977{
978 auto &project = context.project;
979 auto &tracks = TrackList::Get( project );
980
981 auto [sel0, sel1] = FindSelection(context);
982
983 if (auto *pTrack = context.temporarySelection.pTrack) {
984 if (auto pWaveTrack = dynamic_cast<WaveTrack*>(pTrack))
985 for (auto pChannel : TrackList::Channels(pWaveTrack))
986 pChannel->Split( sel0, sel1 );
987 else
988 // Did nothing, don't push history
989 return;
990 }
991 else {
992 for (auto wt : tracks.Selected< WaveTrack >())
993 wt->Split( sel0, sel1 );
994 }
995
996 ProjectHistory::Get( project ).PushState(XO("Split"), XO("Split"));
997#if 0
998//ANSWER-ME: Do we need to keep this commented out OnSplit() code?
999// This whole section no longer used...
1000 /*
1001 * Previous (pre-multiclip) implementation of "Split" command
1002 * This does work only when a range is selected!
1003 *
1004 TrackListIterator iter(tracks);
1005
1006 Track *n = iter.First();
1007 Track *dest;
1008
1009 TrackList newTracks;
1010
1011 while (n) {
1012 if (n->GetSelected()) {
1013 double sel0 = selectedRegion.t0();
1014 double sel1 = selectedRegion.t1();
1015
1016 dest = n->Copy(sel0, sel1);
1017 dest->Init(*n);
1018 dest->SetOffset(wxMax(sel0, n->GetOffset()));
1019
1020 if (sel1 >= n->GetEndTime())
1021 n->Clear(sel0, sel1);
1022 else if (sel0 <= n->GetOffset()) {
1023 n->Clear(sel0, sel1);
1024 n->SetOffset(sel1);
1025 } else
1026 n->Silence(sel0, sel1);
1027
1028 newTracks.Add(dest);
1029 }
1030 n = iter.Next();
1031 }
1032
1033 TrackListIterator nIter(&newTracks);
1034 n = nIter.First();
1035 while (n) {
1036 tracks->Add(n);
1037 n = nIter.Next();
1038 }
1039
1040 PushState(XO("Split"), XO("Split"));
1041 */
1042#endif
1043}

References TrackList::Channels(), FindSelection(), ProjectHistory::Get(), TrackList::Get(), CommandContext::project, TemporarySelection::pTrack, ProjectHistory::PushState(), CommandContext::temporarySelection, 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 868 of file EditMenus.cpp.

869{
870 auto &project = context.project;
871 auto &tracks = TrackList::Get( project );
872 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
873 auto &window = ProjectWindow::Get( project );
874
875 auto &clipboard = Clipboard::Get();
876 clipboard.Clear();
877
878 auto pNewClipboard = TrackList::Create( nullptr );
879 auto &newClipboard = *pNewClipboard;
880
881 Track::Holder dest;
882
883 tracks.Selected().Visit(
884 [&](WaveTrack *n) {
885 dest = n->SplitCut(
886 selectedRegion.t0(),
887 selectedRegion.t1());
888 if (dest)
889 FinishCopy(n, dest, newClipboard);
890 },
891 [&](Track *n) {
892 if (n->SupportsBasicEditing()) {
893 dest = n->Copy(selectedRegion.t0(),
894 selectedRegion.t1());
895 n->Silence(selectedRegion.t0(),
896 selectedRegion.t1());
897 if (dest)
898 FinishCopy(n, dest, newClipboard);
899 }
900 }
901 );
902
903 // Survived possibility of exceptions. Commit changes to the clipboard now.
904 clipboard.Assign( std::move( newClipboard ),
905 selectedRegion.t0(), selectedRegion.t1(), project.shared_from_this() );
906
907 ProjectHistory::Get( project )
908 .PushState(XO("Split-cut to the clipboard"), XO("Split Cut"));
909}
std::shared_ptr< Track > Holder
Definition: Track.h:369
void Silence(double t0, double t1) override
Definition: WaveTrack.cpp:1376
Track::Holder SplitCut(double t0, double t1)
Definition: WaveTrack.cpp:509
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
Definition: WaveTrack.cpp:585

References WaveTrack::Copy(), TrackList::Create(), FinishCopy(), Clipboard::Get(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), CommandContext::project, ProjectHistory::PushState(), ViewInfo::selectedRegion, WaveTrack::Silence(), WaveTrack::SplitCut(), Track::SupportsBasicEditing(), 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 911 of file EditMenus.cpp.

912{
913 auto &project = context.project;
914 auto &tracks = TrackList::Get( project );
915 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
916 auto &window = ProjectWindow::Get( project );
917
918 tracks.Selected().Visit(
919 [&](WaveTrack *wt) {
920 wt->SplitDelete(selectedRegion.t0(),
921 selectedRegion.t1());
922 },
923 [&](Track *n) {
924 if (n->SupportsBasicEditing())
925 n->Silence(selectedRegion.t0(),
926 selectedRegion.t1());
927 }
928 );
929
931 XO("Split-deleted %.2f seconds at t=%.2f")
932 .Format( selectedRegion.duration(), selectedRegion.t0() ),
933 XO("Split Delete"));
934}
void SplitDelete(double t0, double t1)
Definition: WaveTrack.cpp:970

References ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), CommandContext::project, ProjectHistory::PushState(), ViewInfo::selectedRegion, WaveTrack::SplitDelete(), 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 1045 of file EditMenus.cpp.

1046{
1047 auto &project = context.project;
1048 auto &tracks = TrackList::Get( project );
1049 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
1050 auto &window = ProjectWindow::Get( project );
1051
1052 Track::Holder dest;
1053
1054 // This iteration is unusual because we add to the list inside the loop
1055 auto range = tracks.Selected();
1056 auto last = *range.rbegin();
1057 for (auto track : range) {
1058 track->TypeSwitch(
1059 [&](WaveTrack *wt) {
1060 // Clips must be aligned to sample positions or the NEW clip will
1061 // not fit in the gap where it came from
1062 double newt0 = wt->LongSamplesToTime(wt->TimeToLongSamples(
1063 selectedRegion.t0()));
1064 double newt1 = wt->LongSamplesToTime(wt->TimeToLongSamples(
1065 selectedRegion.t1()));
1066 // Fix issue 2846 by calling copy with forClipboard = false.
1067 // This avoids creating the blank placeholder clips
1068 dest = wt->Copy(newt0, newt1, false);
1069 wt->SplitDelete(newt0, newt1);
1070 if (dest) {
1071 // The copy function normally puts the clip at time 0
1072 // This offset lines it up with the original track's timing
1073 dest->Offset(newt0);
1074 FinishCopy(wt, dest, tracks);
1075 }
1076 }
1077#if 0
1078 ,
1079 // LL: For now, just skip all non-wave tracks since the other do not
1080 // yet support proper splitting.
1081 [&](Track *n) {
1082 dest = n->Cut(viewInfo.selectedRegion.t0(),
1083 viewInfo.selectedRegion.t1());
1084 if (dest) {
1085 dest->SetOffset(wxMax(0, n->GetOffset()));
1086 FinishCopy(n, dest, *tracks);
1087 }
1088 }
1089#endif
1090 );
1091 if (track == last)
1092 break;
1093 }
1094
1095 ProjectHistory::Get( project )
1096 .PushState(XO("Split to new track"), XO("Split New"));
1097}
double LongSamplesToTime(sampleCount pos) const
Convert correctly between a number of samples and an (absolute) time in seconds.
Definition: SampleTrack.cpp:48
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: SampleTrack.cpp:43

References WaveTrack::Copy(), FinishCopy(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), SampleTrack::LongSamplesToTime(), CommandContext::project, ProjectHistory::PushState(), ViewInfo::selectedRegion, WaveTrack::SplitDelete(), SampleTrack::TimeToLongSamples(), 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 952 of file EditMenus.cpp.

953{
954 auto &project = context.project;
955 auto &tracks = TrackList::Get( project );
956 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
957 auto &window = ProjectWindow::Get( project );
958
959 if (selectedRegion.isPoint())
960 return;
961
962 tracks.Selected().Visit(
963 [&](WaveTrack *wt) {
964 //Hide the section before the left selector
965 wt->Trim(selectedRegion.t0(),
966 selectedRegion.t1());
967 }
968 );
969
971 XO("Trim selected audio tracks from %.2f seconds to %.2f seconds")
972 .Format( selectedRegion.t0(), selectedRegion.t1() ),
973 XO("Trim Audio"));
974}
void Trim(double t0, double t1)
Definition: WaveTrack.cpp:542

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

267{
268 auto &project = context.project;
269 auto &tracks = TrackList::Get( project );
270 auto &trackPanel = TrackPanel::Get( project );
271 auto &undoManager = UndoManager::Get( project );
272 auto &window = ProjectWindow::Get( project );
273
274 if (!ProjectHistory::Get( project ).UndoAvailable()) {
275 AudacityMessageBox( XO("Nothing to undo") );
276 return;
277 }
278
279 // can't undo while dragging
280 if (trackPanel.IsMouseCaptured()) {
281 return;
282 }
283
284 undoManager.Undo(
285 [&]( const UndoStackElem &elem ){
286 ProjectHistory::Get( project ).PopState( elem.state ); } );
287
288 auto t = *tracks.Selected().begin();
289 if (!t)
290 t = *tracks.Any().begin();
291 TrackFocus::Get(project).Set(t);
292 if (t) {
293 t->EnsureVisible();
294 }
295}

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

Referenced by EditMenu().

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

Variable Documentation

◆ canSelectAll

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

Definition at line 1366 of file EditMenus.cpp.

◆ sAttachment1

AttachedItem anonymous_namespace{EditMenus.cpp}::sAttachment1
Initial value:

Definition at line 1344 of file EditMenus.cpp.

◆ sAttachment2

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

Definition at line 1404 of file EditMenus.cpp.

◆ selectAll

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

Definition at line 1368 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 1382 of file EditMenus.cpp.

◆ selectTracks

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

Definition at line 1374 of file EditMenus.cpp.

◆ selectWaveTracks

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

Definition at line 1389 of file EditMenus.cpp.

◆ selectWaveTracks2

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

Definition at line 1397 of file EditMenus.cpp.