Audacity 3.2.0
DropoutDetector.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5@file DropoutDetector.cpp
6@brief Attaches recording dropout event handler to each project
7
8Paul Licameli split from ProjectAudioManager.cpp
9
10**********************************************************************/
11
12#include "ClientData.h"
13#include "LabelTrack.h"
14#include "Observer.h"
15#include "Project.h"
16#include "ProjectAudioManager.h"
17#include "ProjectHistory.h"
18#include "ProjectWindows.h"
19#include "widgets/Warning.h"
20#include <wx/app.h>
21#include <wx/frame.h>
22
23namespace {
26 {
28 [&project](const RecordingDropoutEvent &evt){
29 // Make a track with labels for recording errors
30 auto &tracks = TrackList::Get( project );
31
32 /* i18n-hint: A name given to a track, appearing as its menu button.
33 The translation should be short or else it will not display well.
34 At most, about 11 Latin characters.
35 Dropout is a loss of a short sequence of audio sample data from the
36 recording */
37 auto pTrack = LabelTrack::Create(tracks, tracks.MakeUniqueTrackName(_("Dropouts")));
38 long counter = 1;
39 for (auto &interval : evt.intervals)
40 pTrack->AddLabel(
41 SelectedRegion{ interval.first,
42 interval.first + interval.second },
43 wxString::Format(wxT("%ld"), counter++));
44
45 auto &history = ProjectHistory::Get( project );
46 history.ModifyState( true ); // this might fail and throw
47
48 // CallAfter so that we avoid any problems of yielding
49 // to the event loop while still inside the timer callback,
50 // entering StopStream() recursively
51 auto &window = GetProjectFrame( project );
52 wxTheApp->CallAfter( [&window] {
53 ShowWarningDialog(&window, wxT("DropoutDetected"), XO("\
54Recorded audio was lost at the labeled locations. Possible causes:\n\
55\n\
56Other applications are competing with Audacity for processor time\n\
57\n\
58You are saving directly to a slow external storage device\n\
59"
60 ),
61 false,
62 XXO("Turn off dropout detection"));
63 });
64 });
65 }
67};
68}
69
72 return std::make_shared<DropoutSubscription>(project);
73 }
74};
wxT("CloseDown"))
Utility ClientData::Site to register hooks into a host class that attach client data.
static AudacityProject::AttachedObjects::RegisteredFactory sKey
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#define _(s)
Definition: Internat.h:73
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 ...
accessors for certain important windows associated with each project
const auto tracks
const auto project
int ShowWarningDialog(wxWindow *parent, const wxString &internalDialogName, const TranslatableString &message, bool showCancelButton, const TranslatableString &footer)
Definition: Warning.cpp:90
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:275
static LabelTrack * Create(TrackList &trackList, const wxString &name)
Create a new LabelTrack with specified name and append it to the trackList.
Definition: LabelTrack.cpp:109
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
static ProjectAudioManager & Get(AudacityProject &project)
static ProjectHistory & Get(AudacityProject &project)
Defines a selected portion of a project.
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
A convenient default parameter for class template Site.
Definition: ClientData.h:29
Notification, after recording has stopped, when dropouts have been detected.
const Intervals & intervals
Disjoint and sorted increasingly.