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

Namespace for functions for Clip menu. More...

Classes

struct  FoundClip
 
struct  FoundClipBoundary
 
struct  FoundTrack
 

Functions

double AdjustForFindingStartTimes (const WaveTrack::IntervalConstHolders &clips, double time)
 
double AdjustForFindingEndTimes (const WaveTrack::IntervalConstHolders &clips, double time)
 
FoundClipBoundary FindNextClipBoundary (const WaveTrack *wt, double time)
 
FoundClipBoundary FindPrevClipBoundary (const WaveTrack *wt, double time)
 
int FindClipBoundaries (AudacityProject &project, double time, bool next, std::vector< FoundClipBoundary > &finalResults)
 
TranslatableString ClipBoundaryMessage (const std::vector< FoundClipBoundary > &results)
 
void DoSelectClipBoundary (AudacityProject &project, bool next)
 
FoundClip FindNextClip (const WaveTrack *wt, double t0, double t1)
 
FoundClip FindPrevClip (const WaveTrack *wt, double t0, double t1)
 
int FindClips (AudacityProject &project, double t0, double t1, bool next, std::vector< FoundClip > &finalResults)
 
void DoSelectClip (AudacityProject &project, bool next)
 
void DoCursorClipBoundary (AudacityProject &project, bool next)
 
double DoClipMove (AudacityProject &project, TrackList &trackList, bool syncLocked, bool right)
 
void DoClipLeftOrRight (AudacityProject &project, bool right, bool keyUp)
 
void OnSelectPrevClipBoundaryToCursor (const CommandContext &context)
 
void OnSelectCursorToNextClipBoundary (const CommandContext &context)
 
void OnSelectPrevClip (const CommandContext &context)
 
void OnSelectNextClip (const CommandContext &context)
 
void OnCursorPrevClipBoundary (const CommandContext &context)
 
void OnCursorNextClipBoundary (const CommandContext &context)
 
void OnClipLeft (const CommandContext &context)
 
void OnClipRight (const CommandContext &context)
 
auto ClipSelectMenu ()
 
auto ClipCursorItems ()
 
auto ExtraTimeShiftItems ()
 

Variables

AttachedItem sAttachment1 { Indirect(ClipSelectMenu()), wxT("Select/Basic") }
 
AttachedItem sAttachment2
 
AttachedItem sAttachment3
 

Detailed Description

Namespace for functions for Clip menu.

Function Documentation

◆ AdjustForFindingEndTimes()

double anonymous_namespace{ClipMenus.cpp}::AdjustForFindingEndTimes ( const WaveTrack::IntervalConstHolders clips,
double  time 
)

Definition at line 82 of file ClipMenus.cpp.

84{
85 auto q = std::find_if(clips.begin(), clips.end(),
86 [&] (auto& clip) {
87 return clip->GetPlayStartTime() == time; });
88 if (q != clips.end() && q != clips.begin() &&
90 time = (*(q-1))->GetPlayEndTime();
91 }
92
93 return time;
94}
WAVE_TRACK_API bool SharesBoundaryWithNextClip(const WaveTrack::Interval &prev, const WaveTrack::Interval &next)
used by commands which interact with clips using the keyboard

References WaveClipUtilities::SharesBoundaryWithNextClip().

Referenced by FindNextClipBoundary(), and FindPrevClipBoundary().

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

◆ AdjustForFindingStartTimes()

double anonymous_namespace{ClipMenus.cpp}::AdjustForFindingStartTimes ( const WaveTrack::IntervalConstHolders clips,
double  time 
)

Definition at line 60 of file ClipMenus.cpp.

62{
63 auto q = std::find_if(clips.begin(), clips.end(),
64 [&] (const auto& clip) {
65 return clip->GetPlayEndTime() == time; });
66 if (q != clips.end() && q + 1 != clips.end() &&
68 time = (*(q+1))->GetPlayStartTime();
69 }
70
71 return time;
72}

References WaveClipUtilities::SharesBoundaryWithNextClip().

Referenced by FindNextClip(), FindNextClipBoundary(), FindPrevClip(), and FindPrevClipBoundary().

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

◆ ClipBoundaryMessage()

TranslatableString anonymous_namespace{ClipMenus.cpp}::ClipBoundaryMessage ( const std::vector< FoundClipBoundary > &  results)

Definition at line 262 of file ClipMenus.cpp.

264{
265 TranslatableString message;
266 for (auto& result : results) {
267
268 auto longName = result.ComposeTrackName();
269
271 auto nClips = result.waveTrack->GetNumClips();
272 if (result.nFound < 2) {
273 str = XP(
274 /* i18n-hint:
275 First %s is replaced with the noun "start" or "end"
276 identifying one end of a clip,
277 second string is the name of that clip,
278 first number gives the position of that clip in a sequence
279 of clips,
280 last number counts all clips,
281 and the last string is the name of the track containing the
282 clips.
283 */
284 "%s %s, %d of %d clip %s",
285 "%s %s, %d of %d clips %s",
286 3
287 )(
288 result.clipStart1 ? XO("start") : XO("end"),
289 result.name1,
290 result.index1 + 1,
291 nClips,
292 longName
293 );
294 }
295 else {
296 str = XP(
297 /* i18n-hint:
298 First and third %s are each replaced with the noun "start"
299 or with "end", identifying and end of a clip,
300 second and fourth strings are the names of those clips,
301 first and second numbers give the position of those clips in
302 a sequence of clips,
303 last number counts all clips,
304 and the last string is the name of the track containing the
305 clips.
306 */
307 "%s %s and %s %s, %d and %d of %d clip %s",
308 "%s %s and %s %s, %d and %d of %d clips %s",
309 6
310 )(
311 result.clipStart1 ? XO("start") : XO("end"),
312 result.name1,
313 result.clipStart2 ? XO("start") : XO("end"),
314 result.name2,
315 result.index1 + 1,
316 result.index2 + 1,
317 nClips,
318 longName
319 );
320 }
321
322 if (message.empty())
323 message = str;
324 else
325 message = XO("%s, %s").Format( message, str );
326 }
327
328 return message;
329}
#define str(a)
XO("Cut/Copy/Paste")
#define XP(sing, plur, n)
Definition: Internat.h:94
Holds a msgid for the translation catalog; may also bind format arguments.

References TranslatableString::empty(), str, XO(), and XP.

Referenced by DoCursorClipBoundary(), and DoSelectClipBoundary().

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

◆ ClipCursorItems()

auto anonymous_namespace{ClipMenus.cpp}::ClipCursorItems ( )

Definition at line 768 of file ClipMenus.cpp.

769{
770 static auto items = std::shared_ptr{
771 Items( wxT("Clip"),
772 Command( wxT("CursPrevClipBoundary"), XXO("Pre&vious Clip Boundary"),
775 Options{}.LongName( XO("Cursor to Prev Clip Boundary") ) ),
776 Command( wxT("CursNextClipBoundary"), XXO("Ne&xt Clip Boundary"),
779 Options{}.LongName( XO("Cursor to Next Clip Boundary") ) )
780 ) };
781 return items;
782}
wxT("CloseDown"))
const ReservedCommandFlag & WaveTracksExistFlag()
XXO("&Cut/Copy/Paste Toolbar")
constexpr auto Items
Definition: MenuRegistry.h:427
constexpr auto Command
Definition: MenuRegistry.h:456
void OnCursorPrevClipBoundary(const CommandContext &context)
Definition: ClipMenus.cpp:698
void OnCursorNextClipBoundary(const CommandContext &context)
Definition: ClipMenus.cpp:705
Options && LongName(const TranslatableString &value) &&
Definition: MenuRegistry.h:54

References MenuRegistry::Command, MenuRegistry::Items, MenuRegistry::Options::LongName(), OnCursorNextClipBoundary(), OnCursorPrevClipBoundary(), WaveTracksExistFlag(), wxT(), XO(), and XXO().

Here is the call graph for this function:

◆ ClipSelectMenu()

auto anonymous_namespace{ClipMenus.cpp}::ClipSelectMenu ( )

Definition at line 744 of file ClipMenus.cpp.

745{
746 static auto menu = std::shared_ptr{
747 Menu( wxT("Clip"), XXO("Audi&o Clips"),
748 Command( wxT("SelPrevClipBoundaryToCursor"),
749 XXO("Pre&vious Clip Boundary to Cursor"),
752 Command( wxT("SelCursorToNextClipBoundary"),
753 XXO("Cursor to Ne&xt Clip Boundary"),
756 Command( wxT("SelPrevClip"), XXO("Previo&us Clip"),
758 Options{ wxT("Alt+,"), XO("Select Previous Clip") } ),
759 Command( wxT("SelNextClip"), XXO("N&ext Clip"), OnSelectNextClip,
761 Options{ wxT("Alt+."), XO("Select Next Clip") } )
762 ) };
763 return menu;
764}
constexpr auto Menu
Items will appear in a main toolbar menu or in a sub-menu.
Definition: MenuRegistry.h:445
void OnSelectPrevClip(const CommandContext &context)
Definition: ClipMenus.cpp:686
void OnSelectCursorToNextClipBoundary(const CommandContext &context)
Definition: ClipMenus.cpp:680
void OnSelectNextClip(const CommandContext &context)
Definition: ClipMenus.cpp:692
void OnSelectPrevClipBoundaryToCursor(const CommandContext &context)
Definition: ClipMenus.cpp:673

References MenuRegistry::Command, MenuRegistry::Menu, OnSelectCursorToNextClipBoundary(), OnSelectNextClip(), OnSelectPrevClip(), OnSelectPrevClipBoundaryToCursor(), WaveTracksExistFlag(), wxT(), XO(), and XXO().

Here is the call graph for this function:

◆ DoClipLeftOrRight()

void anonymous_namespace{ClipMenus.cpp}::DoClipLeftOrRight ( AudacityProject project,
bool  right,
bool  keyUp 
)

Definition at line 625 of file ClipMenus.cpp.

627{
628 auto &undoManager = UndoManager::Get( project );
629 auto &viewport = Viewport::Get(project);
630
631 if (keyUp) {
632 undoManager.StopConsolidating();
633 return;
634 }
635
636 auto &trackFocus = TrackFocus::Get( project );
637 auto &viewInfo = ViewInfo::Get( project );
638 auto &selectedRegion = viewInfo.selectedRegion;
639 auto &tracks = TrackList::Get( project );
640 auto isSyncLocked = SyncLockState::Get(project).IsSyncLocked();
641
642 auto amount = DoClipMove(project, tracks, isSyncLocked, right);
643
644 viewport.ScrollIntoView(selectedRegion.t0());
645
646 if (amount != 0.0) {
647 auto message = right? XO("Moved clips to the right") :
648 XO("Moved clips to the left");
649
650 // The following use of the UndoPush flags is so that both a single
651 // keypress (keydown, then keyup), and holding down a key
652 // (multiple keydowns followed by a keyup) result in a single
653 // entry in Audacity's history dialog.
655 .PushState(message, XO("Move audio clips"), UndoPush::CONSOLIDATE);
656 }
657
658 if ( amount == 0.0 )
659 trackFocus.MessageForScreenReader( XO("clip not moved"));
660}
const auto tracks
const auto project
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
bool IsSyncLocked() const
Definition: SyncLock.cpp:44
static SyncLockState & Get(AudacityProject &project)
Definition: SyncLock.cpp:27
Track * Get()
Definition: TrackFocus.cpp:156
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
static UndoManager & Get(AudacityProject &project)
Definition: UndoManager.cpp:71
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
static Viewport & Get(AudacityProject &project)
Definition: Viewport.cpp:33
double DoClipMove(AudacityProject &project, TrackList &trackList, bool syncLocked, bool right)
Definition: ClipMenus.cpp:578

References CONSOLIDATE, DoClipMove(), TrackFocus::Get(), ProjectHistory::Get(), UndoManager::Get(), ViewInfo::Get(), SyncLockState::Get(), TrackList::Get(), Viewport::Get(), SyncLockState::IsSyncLocked(), project, ProjectHistory::PushState(), tracks, and XO().

Referenced by OnClipLeft(), and OnClipRight().

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

◆ DoClipMove()

double anonymous_namespace{ClipMenus.cpp}::DoClipMove ( AudacityProject project,
TrackList trackList,
bool  syncLocked,
bool  right 
)

Definition at line 578 of file ClipMenus.cpp.

580{
581 auto &trackFocus = TrackFocus::Get(project);
582 auto &viewInfo = ViewInfo::Get(project);
583 auto &selectedRegion = viewInfo.selectedRegion;
584
585 auto track = trackFocus.Get();
586 if (track) {
587 ClipMoveState state;
588
589 auto t0 = selectedRegion.t0();
590
591 std::unique_ptr<TrackShifter> uShifter;
592
593 auto hitTestResult = TrackShifter::HitTestResult::Track;
594 uShifter = MakeTrackShifter::Call(*track, project);
595 if ((hitTestResult = uShifter->HitTest(t0, viewInfo)) ==
597 return 0.0;
598
599 auto pShifter = uShifter.get();
600 auto desiredT0 = viewInfo.OffsetTimeByPixels(t0, (right ? 1 : -1));
601 auto desiredSlideAmount = pShifter->HintOffsetLarger(desiredT0 - t0);
602
603 state.Init(project, pShifter->GetTrack(), hitTestResult, move(uShifter),
604 t0, viewInfo, trackList, syncLocked);
605
606 auto hSlideAmount = state.DoSlideHorizontal(desiredSlideAmount);
607
608 double newT0 = t0 + hSlideAmount;
609 if (hitTestResult != TrackShifter::HitTestResult::Track) {
610 // If necessary, correct for rounding errors. For example,
611 // for a wavetrack, ensure that t0 is still in the clip
612 // which it was within before the move.
613 // (pShifter is still undestroyed in the ClipMoveState.)
614 newT0 = pShifter->AdjustT0(newT0);
615 }
616
617 double diff = selectedRegion.duration();
618 selectedRegion.setTimes(newT0, newT0 + diff);
619
620 return hSlideAmount;
621 };
622 return 0.0;
623}
static Return Call(This &obj, Arguments ...arguments)
Invoke the method – but only after static initialization time.
@ Track
Shift selected track and sister channels only, as a whole.
@ Miss
Don't shift anything.
double DoSlideHorizontal(double desiredSlideAmount)
Do sliding of tracks and intervals, maybe adjusting the offset.
void Init(AudacityProject &project, Track &capturedTrack, TrackShifter::HitTestResult hitTestResult, std::unique_ptr< TrackShifter > pHit, double clickTime, const ViewInfo &viewInfo, TrackList &trackList, bool syncLocked)
Will associate a TrackShifter with each track in the list.

References AttachedVirtualFunction< Tag, Return, This, Arguments >::Call(), ClipMoveState::DoSlideHorizontal(), TrackFocus::Get(), ViewInfo::Get(), ClipMoveState::Init(), TrackShifter::Miss, project, and TrackShifter::Track.

Referenced by DoClipLeftOrRight().

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

◆ DoCursorClipBoundary()

void anonymous_namespace{ClipMenus.cpp}::DoCursorClipBoundary ( AudacityProject project,
bool  next 
)

Definition at line 553 of file ClipMenus.cpp.

555{
556 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
557 auto &trackFocus = TrackFocus::Get( project );
558 auto &viewport = Viewport::Get(project);
559
560 std::vector<FoundClipBoundary> results;
561 FindClipBoundaries(project, next ? selectedRegion.t1() :
562 selectedRegion.t0(), next, results);
563
564 if (results.size() > 0) {
565 // note that if there is more than one result, each has the same time
566 // value.
567 double time = results[0].time;
568 selectedRegion.setTimes(time, time);
570 viewport.ScrollIntoView(selectedRegion.t0());
571
572 auto message = ClipBoundaryMessage(results);
573 trackFocus.MessageForScreenReader(message);
574 }
575}
void ModifyState(bool bWantsAutoSave)
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
int FindClipBoundaries(AudacityProject &project, double time, bool next, std::vector< FoundClipBoundary > &finalResults)
Definition: ClipMenus.cpp:213
TranslatableString ClipBoundaryMessage(const std::vector< FoundClipBoundary > &results)
Definition: ClipMenus.cpp:262

References ClipBoundaryMessage(), FindClipBoundaries(), TrackFocus::Get(), ProjectHistory::Get(), ViewInfo::Get(), Viewport::Get(), ProjectHistory::ModifyState(), project, and ViewInfo::selectedRegion.

Referenced by OnCursorNextClipBoundary(), and OnCursorPrevClipBoundary().

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

◆ DoSelectClip()

void anonymous_namespace{ClipMenus.cpp}::DoSelectClip ( AudacityProject project,
bool  next 
)

Definition at line 503 of file ClipMenus.cpp.

504{
505 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
506 auto &trackFocus = TrackFocus::Get( project );
507 auto &viewport = Viewport::Get(project);
508
509 std::vector<FoundClip> results;
510 FindClips(project, selectedRegion.t0(),
511 selectedRegion.t1(), next, results);
512
513 if (results.size() > 0) {
514 // note that if there is more than one result, each has the same start
515 // and end time
516 double t0 = results[0].startTime;
517 double t1 = results[0].endTime;
518 selectedRegion.setTimes(t0, t1);
520 viewport.ScrollIntoView(selectedRegion.t0());
521
522 // create and send message to screen reader
523 TranslatableString message;
524 for (auto& result : results) {
525 auto longName = result.ComposeTrackName();
526 auto nClips = result.waveTrack->GetNumClips();
527 auto str = XP(
528 /* i18n-hint:
529 first string is the name of a clip,
530 first number gives the position of that clip
531 in a sequence of clips,
532 last number counts all clips,
533 last string names a track */
534 "%s, %d of %d clip %s",
535 "%s, %d of %d clips %s",
536 2
537 )(
538 result.name,
539 result.index + 1,
540 nClips,
541 longName
542 );
543
544 if (message.empty())
545 message = str;
546 else
547 message = XO("%s, %s").Format( message, str );
548 }
549 trackFocus.MessageForScreenReader(message);
550 }
551}
int FindClips(AudacityProject &project, double t0, double t1, bool next, std::vector< FoundClip > &finalResults)
Definition: ClipMenus.cpp:436

References TranslatableString::empty(), FindClips(), TrackFocus::Get(), ProjectHistory::Get(), ViewInfo::Get(), Viewport::Get(), ProjectHistory::ModifyState(), project, ViewInfo::selectedRegion, str, XO(), and XP.

Referenced by OnSelectNextClip(), and OnSelectPrevClip().

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

◆ DoSelectClipBoundary()

void anonymous_namespace{ClipMenus.cpp}::DoSelectClipBoundary ( AudacityProject project,
bool  next 
)

Definition at line 331 of file ClipMenus.cpp.

332{
333 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
334 auto &trackFocus = TrackFocus::Get( project );
335
336 std::vector<FoundClipBoundary> results;
337 FindClipBoundaries(project, next ? selectedRegion.t1() :
338 selectedRegion.t0(), next, results);
339
340 if (results.size() > 0) {
341 // note that if there is more than one result, each has the same time
342 // value.
343 if (next)
344 selectedRegion.setT1(results[0].time);
345 else
346 selectedRegion.setT0(results[0].time);
347
349
350 auto message = ClipBoundaryMessage(results);
351 trackFocus.MessageForScreenReader(message);
352 }
353}

References ClipBoundaryMessage(), FindClipBoundaries(), TrackFocus::Get(), ProjectHistory::Get(), ViewInfo::Get(), ProjectHistory::ModifyState(), project, and ViewInfo::selectedRegion.

Referenced by OnSelectCursorToNextClipBoundary(), and OnSelectPrevClipBoundaryToCursor().

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

◆ ExtraTimeShiftItems()

auto anonymous_namespace{ClipMenus.cpp}::ExtraTimeShiftItems ( )

Definition at line 789 of file ClipMenus.cpp.

790{
791 static auto items = std::shared_ptr{
792 Items( wxT("TimeShift"),
793 Command( wxT("ClipLeft"), XXO("Time Shift &Left"), OnClipLeft,
795 Command( wxT("ClipRight"), XXO("Time Shift &Right"), OnClipRight,
797 ) };
798 return items;
799}
const ReservedCommandFlag & TracksExistFlag()
const ReservedCommandFlag & TrackPanelHasFocus()
void OnClipLeft(const CommandContext &context)
Definition: ClipMenus.cpp:714
void OnClipRight(const CommandContext &context)
Definition: ClipMenus.cpp:726
Options && WantKeyUp() &&
Definition: MenuRegistry.h:60

References MenuRegistry::Command, MenuRegistry::Items, OnClipLeft(), OnClipRight(), TrackPanelHasFocus(), TracksExistFlag(), MenuRegistry::Options::WantKeyUp(), wxT(), and XXO().

Here is the call graph for this function:

◆ FindClipBoundaries()

int anonymous_namespace{ClipMenus.cpp}::FindClipBoundaries ( AudacityProject project,
double  time,
bool  next,
std::vector< FoundClipBoundary > &  finalResults 
)

Definition at line 212 of file ClipMenus.cpp.

215{
216 auto &tracks = TrackList::Get( project );
217 finalResults.clear();
218
219 bool anyWaveTracksSelected{ tracks.Selected<const WaveTrack>() };
220
221
222 // first search the tracks individually
223
224 std::vector<FoundClipBoundary> results;
225
226 int nTracksSearched = 0;
227 auto all = tracks.Any();
228 auto waveTracks = all.Filter<const WaveTrack>();
229 if (anyWaveTracksSelected)
230 waveTracks = waveTracks + &Track::GetSelected;
231 for (auto waveTrack : waveTracks) {
232 auto result = next ? FindNextClipBoundary(waveTrack, time) :
233 FindPrevClipBoundary(waveTrack, time);
234 if (result.nFound > 0) {
235 result.trackNum =
236 1 + std::distance(all.begin(), all.find(waveTrack));
237 results.push_back(result);
238 }
239
240 nTracksSearched++;
241 }
242
243
244 if (results.size() > 0) {
245 // If any clip boundaries were found
246 // find the clip boundary or boundaries with the min/max time
247 auto compare = [] (const FoundClipBoundary& a, const FoundClipBoundary&b)
248 { return a.time < b.time; };
249
250 auto p = next ? min_element(results.begin(), results.end(), compare ) :
251 max_element(results.begin(), results.end(), compare);
252
253 for ( auto &r : results )
254 if ( r.time == (*p).time )
255 finalResults.push_back( r );
256 }
257
258 return nTracksSearched; // can be used for screen reader messages if required
259}
bool GetSelected() const
Selectedness is always the same for all channels of a group.
Definition: Track.cpp:78
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
FoundClipBoundary FindNextClipBoundary(const WaveTrack *wt, double time)
Definition: ClipMenus.cpp:96
FoundClipBoundary FindPrevClipBoundary(const WaveTrack *wt, double time)
Definition: ClipMenus.cpp:149
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101

References FindNextClipBoundary(), FindPrevClipBoundary(), TrackList::Get(), Track::GetSelected(), project, anonymous_namespace{ClipMenus.cpp}::FoundClipBoundary::time, and tracks.

Referenced by DoCursorClipBoundary(), and DoSelectClipBoundary().

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

◆ FindClips()

int anonymous_namespace{ClipMenus.cpp}::FindClips ( AudacityProject project,
double  t0,
double  t1,
bool  next,
std::vector< FoundClip > &  finalResults 
)

Definition at line 435 of file ClipMenus.cpp.

438{
439 auto &tracks = TrackList::Get( project );
440 finalResults.clear();
441
442 bool anyWaveTracksSelected{ tracks.Selected<const WaveTrack>() };
443
444 // first search the tracks individually
445
446 std::vector<FoundClip> results;
447
448 int nTracksSearched = 0;
449 auto all = tracks.Any();
450 auto waveTracks = all.Filter<const WaveTrack>();
451 if (anyWaveTracksSelected)
452 waveTracks = waveTracks + &Track::GetSelected;
453 for (auto waveTrack : waveTracks) {
454 auto result = next ? FindNextClip(waveTrack, t0, t1) :
455 FindPrevClip(waveTrack, t0, t1);
456 if (result.found) {
457 result.trackNum =
458 1 + std::distance(all.begin(), all.find(waveTrack));
459 results.push_back(result);
460 }
461 nTracksSearched++;
462 }
463
464
465 if (results.size() > 0) {
466 // if any clips were found,
467 // find the clip or clips with the min/max start time
468 auto compareStart = [] (const FoundClip& a, const FoundClip& b)
469 { return a.startTime < b.startTime; };
470
471 auto pStart = next
472 ? std::min_element(results.begin(), results.end(), compareStart)
473 : std::max_element(results.begin(), results.end(), compareStart);
474
475 std::vector<FoundClip> resultsStartTime;
476 for ( auto &r : results )
477 if ( r.startTime == (*pStart).startTime )
478 resultsStartTime.push_back( r );
479
480 if (resultsStartTime.size() > 1) {
481 // more than one clip with same start time so
482 // find the clip or clips with the min/max end time
483 auto compareEnd = [] (const FoundClip& a, const FoundClip& b)
484 { return a.endTime < b.endTime; };
485
486 auto pEnd = next ? std::min_element(resultsStartTime.begin(),
487 resultsStartTime.end(), compareEnd) :
488 std::max_element(resultsStartTime.begin(),
489 resultsStartTime.end(), compareEnd);
490
491 for ( auto &r : resultsStartTime )
492 if ( r.endTime == (*pEnd).endTime )
493 finalResults.push_back( r );
494 }
495 else {
496 finalResults = resultsStartTime;
497 }
498 }
499
500 return nTracksSearched; // can be used for screen reader messages if required
501}
FoundClip FindPrevClip(const WaveTrack *wt, double t0, double t1)
Definition: ClipMenus.cpp:394
FoundClip FindNextClip(const WaveTrack *wt, double t0, double t1)
Definition: ClipMenus.cpp:355
STL namespace.

References anonymous_namespace{ClipMenus.cpp}::FoundClip::endTime, FindNextClip(), FindPrevClip(), TrackList::Get(), Track::GetSelected(), project, anonymous_namespace{ClipMenus.cpp}::FoundClip::startTime, and tracks.

Referenced by DoSelectClip().

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

◆ FindNextClip()

FoundClip anonymous_namespace{ClipMenus.cpp}::FindNextClip ( const WaveTrack wt,
double  t0,
double  t1 
)

Definition at line 355 of file ClipMenus.cpp.

356{
357 FoundClip result{};
358 result.waveTrack = wt;
359 const auto clips = wt->SortedIntervalArray();
360
361 t0 = AdjustForFindingStartTimes(clips, t0);
362
363 {
364 auto p = std::find_if(clips.begin(), clips.end(),
365 [&] (const auto& clip) {
366 return clip->GetPlayStartTime() == t0; });
367 if (p != clips.end() && (*p)->GetPlayEndTime() > t1) {
368 result.found = true;
369 result.startTime = (*p)->GetPlayStartTime();
370 result.endTime = (*p)->GetPlayEndTime();
371 result.name = (*p)->GetName();
372 result.index = std::distance(clips.begin(), p);
373 return result;
374 }
375 }
376
377 {
378 auto p = std::find_if(clips.begin(), clips.end(),
379 [&] (const auto& clip) {
380 return clip->GetPlayStartTime() > t0; });
381 if (p != clips.end()) {
382 result.found = true;
383 result.startTime = (*p)->GetPlayStartTime();
384 result.endTime = (*p)->GetPlayEndTime();
385 result.name = (*p)->GetName();
386 result.index = std::distance(clips.begin(), p);
387 return result;
388 }
389 }
390
391 return result;
392}
IntervalHolders SortedIntervalArray()
Return all WaveClips sorted by clip play start time.
Definition: WaveTrack.cpp:3297
double AdjustForFindingStartTimes(const WaveTrack::IntervalConstHolders &clips, double time)
Definition: ClipMenus.cpp:60

References AdjustForFindingStartTimes(), WaveTrack::SortedIntervalArray(), and anonymous_namespace{ClipMenus.cpp}::FoundTrack::waveTrack.

Referenced by FindClips().

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

◆ FindNextClipBoundary()

FoundClipBoundary anonymous_namespace{ClipMenus.cpp}::FindNextClipBoundary ( const WaveTrack wt,
double  time 
)

Definition at line 96 of file ClipMenus.cpp.

97{
98 FoundClipBoundary result{};
99 result.waveTrack = wt;
100 const auto clips = wt->SortedIntervalArray();
101 double timeStart = AdjustForFindingStartTimes(clips, time);
102 double timeEnd = AdjustForFindingEndTimes(clips, time);
103
104 auto pStart = std::find_if(clips.begin(), clips.end(),
105 [&] (const auto& clip) {
106 return clip->GetPlayStartTime() > timeStart; });
107 auto pEnd = std::find_if(clips.begin(), clips.end(),
108 [&] (const auto& clip) {
109 return clip->GetPlayEndTime() > timeEnd; });
110
111 if (pStart != clips.end() && pEnd != clips.end()) {
112 if (WaveClipUtilities::SharesBoundaryWithNextClip(**pEnd, **pStart)) {
113 // boundary between two clips which are immediately next to each other.
114 result.nFound = 2;
115 result.time = (*pEnd)->GetPlayEndTime();
116 result.index1 = std::distance(clips.begin(), pEnd);
117 result.name1 = (*pEnd)->GetName();
118 result.clipStart1 = false;
119 result.index2 = std::distance(clips.begin(), pStart);
120 result.name2 = (*pStart)->GetName();
121 result.clipStart2 = true;
122 }
123 else if ((*pStart)->GetPlayStartTime() < (*pEnd)->GetPlayEndTime()) {
124 result.nFound = 1;
125 result.time = (*pStart)->GetPlayStartTime();
126 result.index1 = std::distance(clips.begin(), pStart);
127 result.name1 = (*pStart)->GetName();
128 result.clipStart1 = true;
129 }
130 else {
131 result.nFound = 1;
132 result.time = (*pEnd)->GetPlayEndTime();
133 result.index1 = std::distance(clips.begin(), pEnd);
134 result.name1 = (*pEnd)->GetName();
135 result.clipStart1 = false;
136 }
137 }
138 else if (pEnd != clips.end()) {
139 result.nFound = 1;
140 result.time = (*pEnd)->GetPlayEndTime();
141 result.index1 = std::distance(clips.begin(), pEnd);
142 result.name1 = (*pEnd)->GetName();
143 result.clipStart1 = false;
144 }
145
146 return result;
147}
double AdjustForFindingEndTimes(const WaveTrack::IntervalConstHolders &clips, double time)
Definition: ClipMenus.cpp:82

References AdjustForFindingEndTimes(), AdjustForFindingStartTimes(), WaveClipUtilities::SharesBoundaryWithNextClip(), WaveTrack::SortedIntervalArray(), and anonymous_namespace{ClipMenus.cpp}::FoundTrack::waveTrack.

Referenced by FindClipBoundaries().

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

◆ FindPrevClip()

FoundClip anonymous_namespace{ClipMenus.cpp}::FindPrevClip ( const WaveTrack wt,
double  t0,
double  t1 
)

Definition at line 394 of file ClipMenus.cpp.

395{
396 FoundClip result{};
397 result.waveTrack = wt;
398 const auto clips = wt->SortedIntervalArray();
399
400 t0 = AdjustForFindingStartTimes(clips, t0);
401
402 {
403 auto p = std::find_if(clips.begin(), clips.end(),
404 [&] (const auto& clip) {
405 return clip->GetPlayStartTime() == t0; });
406 if (p != clips.end() && (*p)->GetPlayEndTime() < t1) {
407 result.found = true;
408 result.startTime = (*p)->GetPlayStartTime();
409 result.endTime = (*p)->GetPlayEndTime();
410 result.name = (*p)->GetName();
411 result.index = std::distance(clips.begin(), p);
412 return result;
413 }
414 }
415
416 {
417 auto p = std::find_if(clips.rbegin(), clips.rend(),
418 [&] (const auto& clip) {
419 return clip->GetPlayStartTime() < t0; });
420 if (p != clips.rend()) {
421 result.found = true;
422 result.startTime = (*p)->GetPlayStartTime();
423 result.endTime = (*p)->GetPlayEndTime();
424 result.name = (*p)->GetName();
425 result.index =
426 static_cast<int>(clips.size()) - 1 -
427 std::distance(clips.rbegin(), p);
428 return result;
429 }
430 }
431
432 return result;
433}

References AdjustForFindingStartTimes(), WaveTrack::SortedIntervalArray(), and anonymous_namespace{ClipMenus.cpp}::FoundTrack::waveTrack.

Referenced by FindClips().

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

◆ FindPrevClipBoundary()

FoundClipBoundary anonymous_namespace{ClipMenus.cpp}::FindPrevClipBoundary ( const WaveTrack wt,
double  time 
)

Definition at line 149 of file ClipMenus.cpp.

150{
151 FoundClipBoundary result{};
152 result.waveTrack = wt;
153 const auto clips = wt->SortedIntervalArray();
154 double timeStart = AdjustForFindingStartTimes(clips, time);
155 double timeEnd = AdjustForFindingEndTimes(clips, time);
156
157 auto pStart = std::find_if(clips.rbegin(), clips.rend(),
158 [&] (const auto& clip) {
159 return clip->GetPlayStartTime() < timeStart; });
160 auto pEnd = std::find_if(clips.rbegin(), clips.rend(),
161 [&] (const auto& clip) {
162 return clip->GetPlayEndTime() < timeEnd; });
163
164 if (pStart != clips.rend() && pEnd != clips.rend()) {
165 if (WaveClipUtilities::SharesBoundaryWithNextClip(**pEnd, **pStart)) {
166 // boundary between two clips which are immediately next to each other.
167 result.nFound = 2;
168 result.time = (*pStart)->GetPlayStartTime();
169 result.index1 =
170 static_cast<int>(clips.size()) - 1 -
171 std::distance(clips.rbegin(), pStart);
172 result.name1 = (*pStart)->GetName();
173 result.clipStart1 = true;
174 result.index2 =
175 static_cast<int>(clips.size()) - 1 -
176 std::distance(clips.rbegin(), pEnd);
177 result.name2 = (*pEnd)->GetName();
178 result.clipStart2 = false;
179 }
180 else if ((*pStart)->GetPlayStartTime() > (*pEnd)->GetPlayEndTime()) {
181 result.nFound = 1;
182 result.time = (*pStart)->GetPlayStartTime();
183 result.index1 =
184 static_cast<int>(clips.size()) - 1 -
185 std::distance(clips.rbegin(), pStart);
186 result.name1 = (*pStart)->GetName();
187 result.clipStart1 = true;
188 }
189 else {
190 result.nFound = 1;
191 result.time = (*pEnd)->GetPlayEndTime();
192 result.index1 =
193 static_cast<int>(clips.size()) - 1 -
194 std::distance(clips.rbegin(), pEnd);
195 result.name1 = (*pEnd)->GetName();
196 result.clipStart1 = false;
197 }
198 }
199 else if (pStart != clips.rend()) {
200 result.nFound = 1;
201 result.time = (*pStart)->GetPlayStartTime();
202 result.index1 =
203 static_cast<int>(clips.size()) - 1 -
204 std::distance(clips.rbegin(), pStart);
205 result.name1 = (*pStart)->GetName();
206 result.clipStart1 = true;
207 }
208
209 return result;
210}

References AdjustForFindingEndTimes(), AdjustForFindingStartTimes(), WaveClipUtilities::SharesBoundaryWithNextClip(), WaveTrack::SortedIntervalArray(), and anonymous_namespace{ClipMenus.cpp}::FoundTrack::waveTrack.

Referenced by FindClipBoundaries().

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

◆ OnClipLeft()

void anonymous_namespace{ClipMenus.cpp}::OnClipLeft ( const CommandContext context)

Definition at line 714 of file ClipMenus.cpp.

715{
716 auto &project = context.project;
717 auto evt = context.pEvt;
718 if (evt)
719 DoClipLeftOrRight( project, false, evt->GetEventType() == wxEVT_KEY_UP );
720 else { // called from menu, so simulate keydown and keyup
721 DoClipLeftOrRight( project, false, false );
722 DoClipLeftOrRight( project, false, true );
723 }
724}
const wxEvent * pEvt
AudacityProject & project
void DoClipLeftOrRight(AudacityProject &project, bool right, bool keyUp)
Definition: ClipMenus.cpp:626

References DoClipLeftOrRight(), CommandContext::pEvt, CommandContext::project, and project.

Referenced by ExtraTimeShiftItems().

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

◆ OnClipRight()

void anonymous_namespace{ClipMenus.cpp}::OnClipRight ( const CommandContext context)

Definition at line 726 of file ClipMenus.cpp.

727{
728 auto &project = context.project;
729 auto evt = context.pEvt;
730 if (evt)
731 DoClipLeftOrRight( project, true, evt->GetEventType() == wxEVT_KEY_UP );
732 else { // called from menu, so simulate keydown and keyup
733 DoClipLeftOrRight( project, true, false );
734 DoClipLeftOrRight( project, true, true );
735 }
736}

References DoClipLeftOrRight(), CommandContext::pEvt, CommandContext::project, and project.

Referenced by ExtraTimeShiftItems().

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

◆ OnCursorNextClipBoundary()

void anonymous_namespace{ClipMenus.cpp}::OnCursorNextClipBoundary ( const CommandContext context)

Definition at line 705 of file ClipMenus.cpp.

706{
708
710}
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
void DoCursorClipBoundary(AudacityProject &project, bool next)
Definition: ClipMenus.cpp:554

References DoCursorClipBoundary(), CommandContext::project, and project.

Referenced by ClipCursorItems().

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

◆ OnCursorPrevClipBoundary()

void anonymous_namespace{ClipMenus.cpp}::OnCursorPrevClipBoundary ( const CommandContext context)

Definition at line 698 of file ClipMenus.cpp.

699{
701
703}

References DoCursorClipBoundary(), CommandContext::project, and project.

Referenced by ClipCursorItems().

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

◆ OnSelectCursorToNextClipBoundary()

void anonymous_namespace{ClipMenus.cpp}::OnSelectCursorToNextClipBoundary ( const CommandContext context)

Definition at line 679 of file ClipMenus.cpp.

681{
682 auto &project = context.project;
684}
void DoSelectClipBoundary(AudacityProject &project, bool next)
Definition: ClipMenus.cpp:331

References DoSelectClipBoundary(), CommandContext::project, and project.

Referenced by ClipSelectMenu().

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

◆ OnSelectNextClip()

void anonymous_namespace{ClipMenus.cpp}::OnSelectNextClip ( const CommandContext context)

Definition at line 692 of file ClipMenus.cpp.

693{
694 auto &project = context.project;
695 DoSelectClip(project, true);
696}
void DoSelectClip(AudacityProject &project, bool next)
Definition: ClipMenus.cpp:503

References DoSelectClip(), CommandContext::project, and project.

Referenced by ClipSelectMenu().

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

◆ OnSelectPrevClip()

void anonymous_namespace{ClipMenus.cpp}::OnSelectPrevClip ( const CommandContext context)

Definition at line 686 of file ClipMenus.cpp.

687{
688 auto &project = context.project;
689 DoSelectClip(project, false);
690}

References DoSelectClip(), CommandContext::project, and project.

Referenced by ClipSelectMenu().

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

◆ OnSelectPrevClipBoundaryToCursor()

void anonymous_namespace{ClipMenus.cpp}::OnSelectPrevClipBoundaryToCursor ( const CommandContext context)

Definition at line 672 of file ClipMenus.cpp.

674{
675 auto &project = context.project;
677}

References DoSelectClipBoundary(), CommandContext::project, and project.

Referenced by ClipSelectMenu().

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

Variable Documentation

◆ sAttachment1

AttachedItem anonymous_namespace{ClipMenus.cpp}::sAttachment1 { Indirect(ClipSelectMenu()), wxT("Select/Basic") }

Definition at line 766 of file ClipMenus.cpp.

◆ sAttachment2

AttachedItem anonymous_namespace{ClipMenus.cpp}::sAttachment2
Initial value:
{ wxT("Transport/Basic/Cursor"),
{ OrderingHint::Before, wxT("CursProjectStart") } }
}
std::unique_ptr< detail::IndirectItem< Item > > Indirect(const std::shared_ptr< Item > &ptr)
A convenience function.
Definition: Registry.h:175

Definition at line 784 of file ClipMenus.cpp.

◆ sAttachment3

AttachedItem anonymous_namespace{ClipMenus.cpp}::sAttachment3
Initial value:
{ wxT("Optional/Extra/Part1/Edit"), { OrderingHint::End, {} } }
}

Definition at line 801 of file ClipMenus.cpp.