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

Functions

void OnTimerRecord (const CommandContext &context)
 

Variables

const auto CanStopFlags = AudioIONotBusyFlag() | CanStopAudioStreamFlag()
 
AttachedItem sAttachment
 

Function Documentation

◆ OnTimerRecord()

void anonymous_namespace{TimerRecordDialog.cpp}::OnTimerRecord ( const CommandContext context)

Definition at line 1109 of file TimerRecordDialog.cpp.

1110{
1111 auto &project = context.project;
1112 const auto &settings = ProjectSettings::Get( project );
1113 auto &undoManager = UndoManager::Get( project );
1114 auto &window = ProjectWindow::Get( project );
1115
1116 // MY: Due to improvements in how Timer Recording saves and/or exports
1117 // it is now safer to disable Timer Recording when there is more than
1118 // one open project.
1119 if (AllProjects{}.size() > 1) {
1121 XO(
1122"Timer Recording cannot be used with more than one open project.\n\nPlease close any additional projects and try again."),
1123 XO("Timer Recording"),
1124 wxICON_INFORMATION | wxOK);
1125 return;
1126 }
1127
1128 // MY: If the project has unsaved changes then we no longer allow access
1129 // to Timer Recording. This decision has been taken as the safest approach
1130 // preventing issues surrounding "dirty" projects when Automatic Save/Export
1131 // is used in Timer Recording.
1132 if ((undoManager.UnsavedChanges()) &&
1133 (TrackList::Get( project ).Any() || settings.EmptyCanBeDirty())) {
1135 XO(
1136"Timer Recording cannot be used while you have unsaved changes.\n\nPlease save or close this project and try again."),
1137 XO("Timer Recording"),
1138 wxICON_INFORMATION | wxOK);
1139 return;
1140 }
1141
1142 // We check the selected tracks to see if there is enough of them to accommodate
1143 // all input channels and all of them have the same sampling rate.
1144 // Those checks will be later performed by recording function anyway,
1145 // but we want to warn the user about potential problems from the very start.
1146 const auto selectedTracks{ GetPropertiesOfSelected(project) };
1147 const int rateOfSelected{ selectedTracks.rateOfSelected };
1148 const int numberOfSelected{ selectedTracks.numberOfSelected };
1149 const bool allSameRate{ selectedTracks.allSameRate };
1150
1151 if (!allSameRate) {
1152 AudacityMessageBox(XO("The tracks selected "
1153 "for recording must all have the same sampling rate"),
1154 XO("Mismatched Sampling Rates"),
1155 wxICON_ERROR | wxCENTRE);
1156
1157 return;
1158 }
1159
1160 const auto existingTracks{ ProjectAudioManager::ChooseExistingRecordingTracks(project, true, rateOfSelected) };
1161 if (existingTracks.empty()) {
1162 if (numberOfSelected > 0 && rateOfSelected !=
1163 ProjectRate::Get(project).GetRate()) {
1165 "Too few tracks are selected for recording at this sample rate.\n"
1166 "(Audacity requires two channels at the same sample rate for\n"
1167 "each stereo track)"),
1168 XO("Too Few Compatible Tracks Selected"),
1169 wxICON_ERROR | wxCENTRE);
1170
1171 return;
1172 }
1173 }
1174
1175 // We use this variable to display "Current Project" in the Timer Recording
1176 // save project field
1177 bool bProjectSaved = !ProjectFileIO::Get( project ).IsModified();
1178
1179 //we break the prompting and waiting dialogs into two sections
1180 //because they both give the user a chance to click cancel
1181 //and therefore remove the newly inserted track.
1182
1183 TimerRecordDialog dialog(
1184 &window, project, bProjectSaved); /* parent, project, project saved? */
1185 int modalResult = dialog.ShowModal();
1186 if (modalResult == wxID_CANCEL)
1187 {
1188 // Cancelled before recording - don't need to do anything.
1189 }
1190 else
1191 {
1192 // Bug #2382
1193 // Allow recording to start at current cursor position.
1194 #if 0
1195 // Timer Record should not record into a selection.
1196 bool bPreferNewTrack;
1197 gPrefs->Read("/GUI/PreferNewTrackRecord",&bPreferNewTrack, false);
1198 if (bPreferNewTrack) {
1199 window.Rewind(false);
1200 } else {
1201 window.SkipEnd(false);
1202 }
1203 #endif
1204
1205 int iTimerRecordingOutcome = dialog.RunWaitDialog();
1206 switch (iTimerRecordingOutcome) {
1208 // Canceled on the wait dialog
1210 break;
1212 // RunWaitDialog() shows the "wait for start" as well as "recording"
1213 // dialog if it returned POST_TIMER_RECORD_CANCEL it means the user
1214 // cancelled while the recording, so throw out the fresh track.
1215 // However, we can't undo it here because the PushState() is called in TrackPanel::OnTimer(),
1216 // which is blocked by this function.
1217 // so instead we mark a flag to undo it there.
1219 break;
1221 // No action required
1222 break;
1224 wxTheApp->CallAfter( []{
1225 // Simulate the application Exit menu item
1226 wxCommandEvent evt{ wxEVT_MENU, wxID_EXIT };
1227 wxTheApp->AddPendingEvent( evt );
1228 } );
1230 break;
1231
1232#ifdef __WINDOWS__
1233 case POST_TIMER_RECORD_RESTART:
1234 // Restart System
1236 system("shutdown /r /f /t 30");
1237 break;
1238 case POST_TIMER_RECORD_SHUTDOWN:
1239 // Shutdown System
1241 system("shutdown /s /f /t 30");
1242 break;
1243#endif
1244 }
1245 }
1246}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
XO("Cut/Copy/Paste")
FileConfig * gPrefs
Definition: Prefs.cpp:70
PropertiesOfSelected GetPropertiesOfSelected(const AudacityProject &proj)
@ POST_TIMER_RECORD_CLOSE
@ POST_TIMER_RECORD_CANCEL
@ POST_TIMER_RECORD_CANCEL_WAIT
@ POST_TIMER_RECORD_NOTHING
static Settings & settings()
Definition: TrackInfo.cpp:87
size_t size() const
Definition: Project.cpp:17
AudacityProject & project
static WritableSampleTrackArray ChooseExistingRecordingTracks(AudacityProject &proj, bool selectedOnly, double targetRate=RATE_NOT_SELECTED)
static ProjectAudioManager & Get(AudacityProject &project)
static ProjectFileIO & Get(AudacityProject &project)
bool IsModified() const
static ProjectHistory & Get(AudacityProject &project)
static ProjectManager & Get(AudacityProject &project)
void SetSkipSavePrompt(bool bSkip)
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
static ProjectSettings & Get(AudacityProject &project)
static ProjectWindow & Get(AudacityProject &project)
Dialog for Timer Record, i.e., timed or long recording.
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1440
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:487
static UndoManager & Get(AudacityProject &project)
Definition: UndoManager.cpp:71

References TrackList::Any(), AudacityMessageBox(), ProjectAudioManager::ChooseExistingRecordingTracks(), ProjectFileIO::Get(), ProjectHistory::Get(), UndoManager::Get(), ProjectRate::Get(), TrackList::Get(), ProjectAudioManager::Get(), ProjectManager::Get(), ProjectSettings::Get(), ProjectWindow::Get(), GetPropertiesOfSelected(), anonymous_namespace{TimeTrack.cpp}::GetRate(), gPrefs, ProjectFileIO::IsModified(), POST_TIMER_RECORD_CANCEL, POST_TIMER_RECORD_CANCEL_WAIT, POST_TIMER_RECORD_CLOSE, POST_TIMER_RECORD_NOTHING, CommandContext::project, PropertiesOfSelected::rateOfSelected, ProjectHistory::RollbackState(), TimerRecordDialog::RunWaitDialog(), ProjectManager::SetSkipSavePrompt(), ProjectAudioManager::SetTimerRecordCancelled(), settings(), AllProjects::size(), and XO().

Here is the call graph for this function:

Variable Documentation

◆ CanStopFlags

const auto anonymous_namespace{TimerRecordDialog.cpp}::CanStopFlags = AudioIONotBusyFlag() | CanStopAudioStreamFlag()

◆ sAttachment

AttachedItem anonymous_namespace{TimerRecordDialog.cpp}::sAttachment
Initial value:
{
{ wxT("Transport/Basic/Record"),
{ OrderingHint::After, wxT("Record2ndChoice") } },
Command( wxT("TimerRecord"), XXO("&Timer Record..."),
}
wxT("CloseDown"))
XXO("&Cut/Copy/Paste Toolbar")
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())
void OnTimerRecord(const CommandContext &context)

Definition at line 1251 of file TimerRecordDialog.cpp.