53#include <wx/scrolbar.h>
57#include "../images/AudacityLogoAlpha.xpm"
62 bool isMaximized,
bool isIconized) {
80 return std::make_shared< ProjectManager >( project );
102 project.Bind( EVT_RECONNECTION_FAILURE,
113 EVT_OPEN_AUDIO_FILE, wxCommandEvent);
126 if (sbWindowRectAlreadySaved)
130 bool validWindowForSaveWindowSize = FALSE;
132 bool foundIconizedProject = FALSE;
136 if (!window.IsIconized()) {
137 validWindowForSaveWindowSize = TRUE;
138 validProject = &window;
142 foundIconizedProject = TRUE;
145 if (validWindowForSaveWindowSize)
147 wxRect windowRect = validProject->GetRect();
149 bool wndMaximized = validProject->IsMaximized();
155 if (foundIconizedProject) {
157 bool wndMaximized = validProject->IsMaximized();
173 sbWindowRectAlreadySaved =
true;
180#ifdef EXPERIMENTAL_DA2
190 auto statusBar = window.CreateStatusBar(4);
191#if wxUSE_ACCESSIBILITY
195 statusBar->SetName(wxT(
"status_line"));
222 auto ubs = std::make_unique<wxBoxSizer>(wxVERTICAL);
223 ubs->Add(
ToolManager::Get( project ).GetTopDock(), 0, wxEXPAND | wxALIGN_TOP );
224 topPanel->SetSizer(ubs.release());
229 auto ubs = std::make_unique<wxBoxSizer>(wxVERTICAL);
231 bs->Add(topPanel, 0, wxEXPAND | wxALIGN_TOP);
234 window.SetAutoLayout(
true);
235 window.SetSizer(ubs.release());
255 bs =
static_cast<wxBoxSizer*
>(trackListWindow->GetSizer());
262 auto hs = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
265 hs->Add(&trackPanel, 1, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP);
269 auto vs = std::make_unique<wxBoxSizer>(wxVERTICAL);
272 vs->Add(vsBar, 1, wxEXPAND | wxALIGN_TOP);
273 hs->Add(vs.release(), 0, wxEXPAND | wxALIGN_TOP);
276 bs->Add(&
ruler, 0, wxEXPAND | wxALIGN_TOP);
277 bs->Add(hs.release(), 1, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP);
282 auto hs = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
285 hs->Add(viewInfo.GetLeftOffset() - 1, 0);
286 hs->Add(hsBar, 1, wxALIGN_BOTTOM);
287 hs->Add(vsBar->GetSize().GetWidth(), 0);
288 bs->Add(hs.release(), 0, wxEXPAND | wxALIGN_LEFT);
292 trackListWindow->SetAutoLayout(
true);
293 trackListWindow->Layout();
295 wxASSERT( trackPanel.GetProject() == &project );
298 trackPanel.SetFocus();
301 ruler.SetLeftOffset(viewInfo.GetLeftOffset());
308#if !defined(__WXMAC__) && !defined(__WXX11__)
310#if defined(__WXMSW__)
311 wxIcon ic{ wxICON(AudacityLogo) };
312#elif defined(__WXGTK__)
313 wxIcon ic{wxICON(AudacityLogoAlpha)};
323 auto msg =
XO(
"Welcome to Audacity version %s")
324 .Format( AUDACITY_VERSION_STRING );
327#ifdef EXPERIMENTAL_DA2
335 bool bMaximized =
false;
336 bool bIconized =
false;
341 auto sp = std::make_shared< AudacityProject >();
346 auto &projectManager =
Get( project );
359 window.SetPosition(wndRect.GetPosition());
364 projectFileManager.OpenNewProject();
366 projectHistory.InitialState();
367 projectManager.RestartTimer();
370 window.Maximize(
true);
372 else if (bIconized) {
379 gAudioIO->SetListener(
383#ifdef EXPERIMENTAL_SPECTRAL_EDITING
405 wxTheApp->CallAfter([
this]{
433 if (window.IsBeingDeleted())
439 if (event.CanVeto() && (::wxIsBusy() || project.mbBusyImporting))
452 if (projectAudioIO.GetAudioIOToken()>0 &&
453 gAudioIO->IsStreamActive(projectAudioIO.GetAudioIOToken())) {
458 projectAudioIO.SetAudioIOToken(0);
459 window.RedrawProject();
461 else if (gAudioIO->IsMonitoring()) {
462 gAudioIO->StopStream();
466 bool bHasTracks = !tracks.empty();
472 && (
settings.EmptyCanBeDirty() || bHasTracks)) {
476 auto Title =
XO(
"%sSave changes to %s?")
478 auto Message =
XO(
"Save project before closing?");
481 Message +=
XO(
"\nIf saved, the project will have no tracks.\n\nTo save any previously open tracks:\nCancel, Edit > Undo until all tracks\nare open, then File > Save Project.");
486 wxYES_NO | wxCANCEL | wxICON_QUESTION,
489 if (result == wxCANCEL || (result == wxYES &&
490 !GuardedCall<bool>( [&]{
return projectFileManager.Save(); } )
506 window.ShowFullScreen(
false);
520 window.SetIsBeingDeleted();
529 quitOnClose = !projectFileManager.GetMenuClose();
538 auto clipboardProject = clipboard.Project().lock();
539 if ( clipboardProject.get() == &
mProject ) {
561 projectFileManager.CompactProjectOnClose();
565 projectFileIO.SetBypass();
590 window.DestroyChildren();
595 projectFileManager.CloseProject();
619 gAudioIO->SetListener(
628#if !defined(__WXMAC__)
631 wxCommandEvent evt{ wxEVT_MENU, wxID_EXIT };
632 wxTheApp->AddPendingEvent( evt );
652 const wxString &cmd =
event.GetString();
656 std::ref(chooser), cmd)) {
658 window.RequestUserAttention();
669 if (selectedFiles.size() == 0) {
677 auto cleanup =
finally( [] {
681 for (
const auto &fileName : selectedFiles) {
731 if (mpGivenProject) {
736 bool checkReuse = (openingProjectFile || !mReuseNonemptyProject);
738 return *(mpUsedProject = mpGivenProject);
740 return *(mpUsedProject =
New());
745 mpUsedProject =
nullptr;
750 bool addtohistory,
bool reuseNonemptyProject)
754 std::ref(chooser), fileNameArg, addtohistory )) {
758 if( projectFileIO.IsRecovered() ) {
760 window.Zoom( window.GetZoomOfToFit() );
763 undoManager.RemoveStates(0, 1);
784 projectHistory.InitialState();
785 projectHistory.SetDirty(
false);
787 projectFileManager.CloseProject();
788 projectFileManager.OpenProject();
804 mixerToolBar->UpdateControls();
809 if (projectAudioIO.GetAudioIOToken() > 0 && gAudioIO->GetNumCaptureChannels() > 0) {
811 if (freeSpace >= 0) {
814 auto sMessage =
XO(
"Disk space remaining for recording: %s")
837 auto &window = *pWindow;
839 window.UpdateStatusWidths();
857 auto &window = *pWindow;
858 window.GetStatusBar()->SetStatusText(text.
Translation(), number);
865 return XO(
"Less than 1 minute");
868 int iHours = iMinutes / 60;
869 int iMins = iMinutes % 60;
871 auto sHours =
XP(
"%d hour",
"%d hours", 0 )( iHours );
873 auto sMins =
XP(
"%d minute",
"%d minutes", 0 )( iMins );
876 return XO(
"%s and %s.").Format( sHours, sMins );
888 if (lCaptureChannels == 0)
893 if (lFreeSpace < 0) {
898 double dRecTime = 0.0;
900 dRecTime = lFreeSpace.GetHi() * 4294967296.0 + lFreeSpace.GetLo();
901 dRecTime /= bytesOnDiskPerSample;
902 dRecTime /= lCaptureChannels;
906 int iRecMins = (int)
round(dRecTime / 60.0);
AUDACITY_DLL_API std::weak_ptr< AudacityProject > GetActiveProject()
void SetActiveProject(AudacityProject *project)
Handle changing of active project and keep global project pointer.
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
IntSetting AudioIORecordChannels
#define XP(sing, plur, n)
EVT_COMMAND(wxID_ANY, EVT_FREQUENCYTEXTCTRL_UPDATED, LabelDialog::OnFreqUpdate) LabelDialog
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API, EVT_OPEN_AUDIO_FILE, wxCommandEvent)
void InitProjectWindow(ProjectWindow &window)
wxDEFINE_EVENT(EVT_OPEN_AUDIO_FILE, wxCommandEvent)
static AudacityProject::AttachedObjects::RegisteredFactory sProjectManagerKey
const int AudacityProjectTimerID
an object holding per-project preferred sample rate
IntSetting ProjectWindowY
IntSetting ProjectWindowX
void GetDefaultWindowRect(wxRect *defRect)
IntSetting ProjectWindowWidth
BoolSetting ProjectWindowIconized
BoolSetting ProjectWindowMaximized
IntSetting ProjectWindowNormalHeight
IntSetting ProjectWindowHeight
IntSetting ProjectWindowNormalX
void GetNextWindowPlacement(wxRect *nextRect, bool *pMaximized, bool *pIconized)
IntSetting ProjectWindowNormalWidth
IntSetting ProjectWindowNormalY
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
static Settings & settings()
static AdornedRulerPanel & Get(AudacityProject &project)
static void Destroy(AudacityProject &project)
void Add(const value_type &pProject)
This invalidates iterators.
value_type Remove(AudacityProject &project)
const_iterator begin() const
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
static void SetLastOpenType(const FileNames::FileType &type)
static ModuleManager & Get()
int Dispatch(ModuleDispatchTypes type)
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
static ProjectAudioIO & Get(AudacityProject &project)
void Stop(bool stopStream=true)
static ProjectAudioManager & Get(AudacityProject &project)
static ProjectFileIO & Get(AudacityProject &project)
wxLongLong GetFreeDiskSpace() const
static bool IsAlreadyOpen(const FilePath &projPathName)
static wxArrayString ShowOpenDialog(FileNames::Operation op, const FileNames::FileType &extraType={})
Show an open dialogue for opening audio files, and possibly other sorts of files.
static AudacityProject * OpenFile(const ProjectChooserFn &chooser, const FilePath &fileName, bool addtohistory=true)
static ProjectFileManager & Get(AudacityProject &project)
static ProjectHistory & Get(AudacityProject &project)
Callable object that supplies the chooser argument of ProjectFileManager::OpenFile.
AudacityProject * mpGivenProject
AudacityProject & operator()(bool openingProjectFile)
May create a fresh project.
AudacityProject * mpUsedProject
~ProjectChooser()
Destroy any fresh project, or rollback the existing project, unless committed.
void Commit()
Commit the creation of any fresh project or changes to the existing project.
Object associated with a project for high-level management of the project's lifetime,...
Observer::Subscription mSubscription
static bool sbWindowRectAlreadySaved
static ProjectManager & Get(AudacityProject &project)
void OnStatusChange(StatusBarField field)
void OnCloseWindow(wxCloseEvent &event)
static bool sbSkipPromptingForSave
void OnOpenAudioFile(wxCommandEvent &event)
static AudacityProject * New()
TranslatableString GetHoursMinsString(int iMinutes)
std::unique_ptr< wxTimer > mTimer
void OnTimer(wxTimerEvent &event)
static void SaveWindowSize()
static void OpenFiles(AudacityProject *proj)
static AudacityProject * OpenProject(AudacityProject *pGivenProject, const FilePath &fileNameArg, bool addtohistory, bool reuseNonemptyProject)
Open a file into an AudacityProject, returning the project, or nullptr for failure.
static void SetClosingAll(bool closing)
~ProjectManager() override
ProjectManager(AudacityProject &project)
AudacityProject & mProject
static bool SafeToOpenProjectInto(AudacityProject &proj)
False when it is unsafe to overwrite proj with contents of an .aup3 file.
void SetStatusText(const TranslatableString &text, int number)
int GetEstimatedRecordingMinsLeftOnDisk(long lCaptureChannels=0)
void ResetProjectToEmpty()
void OnReconnectionFailure(wxCommandEvent &event)
static ProjectRate & Get(AudacityProject &project)
static ProjectSelectionManager & Get(AudacityProject &project)
static ProjectSettings & Get(AudacityProject &project)
static ProjectStatus & Get(AudacityProject &project)
AudacityProject & GetProject()
A top-level window associated with a project, and handling scrollbars and zooming.
wxScrollBar & GetHorizontalScrollBar()
static ProjectWindow & Get(AudacityProject &project)
wxScrollBar & GetVerticalScrollBar()
wxWindow * GetContainerWindow() noexcept
Container is a parent window for both effects panel and track list windows.
wxPanel * GetTopPanel() noexcept
Top panel contains project-related controls and tools.
static ProjectWindow * Find(AudacityProject *pProject)
wxRect GetNormalizedWindowState() const
wxWindow * GetTrackListWindow() noexcept
Track list window is the parent container for TrackPanel.
void UpdateStatusWidths()
void SetListener(SelectionBarListener *l)
static SelectionBar & Get(AudacityProject &project)
bool Write(const T &value)
Write value to config and return true if successful.
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined */
static SpectralSelectionBar & Get(AudacityProject &project)
void SetListener(SpectralSelectionBarListener *l)
wxColour & Colour(int iIndex)
wxBitmap & Bitmap(int iIndex)
static TrackList & Get(AudacityProject &project)
static TrackPanel & Get(AudacityProject &project)
static void Destroy(AudacityProject &project)
Holds a msgid for the translation catalog; may also bind format arguments.
wxString Translation() const
static UndoManager & Get(AudacityProject &project)
static ViewInfo & Get(AudacityProject &project)
static void Destroy(AudacityProject &project)
static WaveTrackFactory & Reset(AudacityProject &project)
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
FILES_API int CompareNoCase(const wxString &first, const wxString &second)
PROJECT_RATE_API sampleFormat SampleFormatChoice()
void DoSelectAll(AudacityProject &project)
void DoRemoveTracks(AudacityProject &project)
void SaveWindowPreferences(const wxRect &windowRect, const wxRect &normalRect, bool isMaximized, bool isIconized)
TranslatableString Message(unsigned trackCount)
fastfloat_really_inline void round(adjusted_mantissa &am, callback cb) noexcept