46#include <wx/scrolbar.h>
48#include <wx/splitter.h>
51#include "../images/AudacityLogoAlpha.xpm"
56 bool isMaximized,
bool isIconized) {
74 return std::make_shared< ProjectManager >(
project );
111 if (sbWindowRectAlreadySaved)
115 bool validWindowForSaveWindowSize = FALSE;
117 bool foundIconizedProject = FALSE;
121 if (!window.IsIconized()) {
122 validWindowForSaveWindowSize = TRUE;
123 validProject = &window;
127 foundIconizedProject = TRUE;
130 if (validWindowForSaveWindowSize)
132 wxRect windowRect = validProject->GetRect();
134 bool wndMaximized = validProject->IsMaximized();
140 if (foundIconizedProject) {
142 bool wndMaximized = validProject->IsMaximized();
158 sbWindowRectAlreadySaved =
true;
169#ifdef EXPERIMENTAL_DA2
179 auto statusBar = window.CreateStatusBar(4);
180#if wxUSE_ACCESSIBILITY
184 statusBar->SetName(
wxT(
"status_line"));
211 auto ubs = std::make_unique<wxBoxSizer>(wxVERTICAL);
213 topPanel->SetSizer(ubs.release());
218 auto ubs = std::make_unique<wxBoxSizer>(wxVERTICAL);
220 bs->Add(topPanel, 0, wxEXPAND | wxALIGN_TOP);
223 window.SetAutoLayout(
true);
224 window.SetSizer(ubs.release());
244 bs =
static_cast<wxBoxSizer*
>(trackListWindow->GetSizer());
251 auto hs = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
254 hs->Add(&trackPanel, 1, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP);
258 auto vs = std::make_unique<wxBoxSizer>(wxVERTICAL);
261 vs->Add(vsBar, 1, wxEXPAND | wxALIGN_TOP);
262 hs->Add(vs.release(), 0, wxEXPAND | wxALIGN_TOP);
265 bs->Add(&
ruler, 0, wxEXPAND | wxALIGN_TOP);
266 bs->Add(hs.release(), 1, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP);
271 auto hs = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
274 hs->Add(viewInfo.GetLeftOffset() - 1, 0);
275 hs->Add(hsBar, 1, wxALIGN_BOTTOM);
276 hs->Add(vsBar->GetSize().GetWidth(), 0);
277 bs->Add(hs.release(), 0, wxEXPAND | wxALIGN_LEFT);
281 trackListWindow->SetAutoLayout(
true);
282 trackListWindow->Layout();
284 wxASSERT( trackPanel.GetProject() == &
project );
287 trackPanel.SetFocus();
289 viewport.UpdateScrollbarsForTracks();
290 ruler.SetLeftOffset(viewInfo.GetLeftOffset());
297#if !defined(__WXMAC__) && !defined(__WXX11__)
299#if defined(__WXMSW__)
300 wxIcon ic{ wxICON(AudacityLogo) };
301#elif defined(__WXGTK__)
302 wxIcon ic{wxICON(AudacityLogoAlpha)};
312 auto msg =
XO(
"Welcome to Audacity version %s")
313 .Format( AUDACITY_VERSION_STRING );
316#ifdef EXPERIMENTAL_DA2
324 bool bMaximized =
false;
325 bool bIconized =
false;
348 window.SetPosition(wndRect.GetPosition());
353 projectFileManager.OpenNewProject();
355 projectHistory.InitialState();
356 projectManager.RestartTimer();
359 window.Maximize(
true);
361 else if (bIconized) {
368 gAudioIO->SetListener(
415 if (window.IsBeingDeleted())
421 if (event.CanVeto() && (::wxIsBusy() ||
project.mbBusyImporting))
434 if (projectAudioIO.GetAudioIOToken()>0 &&
435 gAudioIO->IsStreamActive(projectAudioIO.GetAudioIOToken())) {
440 projectAudioIO.SetAudioIOToken(0);
443 else if (gAudioIO->IsMonitoring()) {
444 gAudioIO->StopStream();
448 bool bHasTracks = !
tracks.empty();
454 && (
settings.EmptyCanBeDirty() || bHasTracks)) {
458 auto Title =
XO(
"%sSave changes to %s?")
460 auto Message =
XO(
"Save project before closing?");
463 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.");
468 wxYES_NO | wxCANCEL | wxICON_QUESTION,
471 if (result == wxCANCEL || (result == wxYES &&
472 !GuardedCall<bool>( [&]{
return projectFileManager.Save(); } )
488 window.ShowFullScreen(
false);
505 window.SetIsBeingDeleted();
514 quitOnClose = !projectFileManager.GetMenuClose();
523 auto clipboardProject = clipboard.Project().lock();
524 if ( clipboardProject.get() == &
mProject ) {
546 projectFileManager.CompactProjectOnClose();
550 projectFileIO.SetBypass();
575 window.DestroyChildren();
580 projectFileManager.CloseProject();
604 gAudioIO->SetListener(
613#if !defined(__WXMAC__)
616 wxCommandEvent evt{ wxEVT_MENU, wxID_EXIT };
617 wxTheApp->AddPendingEvent( evt );
638 if (selectedFiles.size() == 0) {
646 auto cleanup =
finally( [] {
650 for (
const auto &fileName : selectedFiles) {
700 if (mpGivenProject) {
705 bool checkReuse = (openingProjectFile || !mReuseNonemptyProject);
707 return *(mpUsedProject = mpGivenProject);
709 return *(mpUsedProject =
New());
714 mpUsedProject =
nullptr;
719 bool addtohistory,
bool reuseNonemptyProject)
723 std::ref(chooser), fileNameArg, addtohistory )) {
727 if( projectFileIO.IsRecovered() ) {
729 viewport.Zoom(viewport.GetZoomOfToFit());
732 undoManager.RemoveStates(0, 1);
753 projectHistory.InitialState();
754 projectHistory.SetDirty(
false);
756 projectFileManager.CloseProject();
757 projectFileManager.OpenProject();
774 for (
auto& meterToolBar : meterToolBars)
775 meterToolBar.get().UpdateControls();
780 if (projectAudioIO.GetAudioIOToken() > 0 && gAudioIO->GetNumCaptureChannels() > 0) {
782 if (freeSpace >= 0) {
785 auto sMessage =
XO(
"Disk space remaining for recording: %s")
808 auto &window = *pWindow;
810 window.UpdateStatusWidths();
828 auto &window = *pWindow;
829 window.GetStatusBar()->SetStatusText(text.
Translation(), number);
836 return XO(
"Less than 1 minute");
839 int iHours = iMinutes / 60;
840 int iMins = iMinutes % 60;
842 auto sHours =
XP(
"%d hour",
"%d hours", 0 )( iHours );
844 auto sMins =
XP(
"%d minute",
"%d minutes", 0 )( iMins );
847 return XO(
"%s and %s.").Format( sHours, sMins );
859 if (lCaptureChannels == 0)
864 if (lFreeSpace < 0) {
869 double dRecTime = 0.0;
871 dRecTime = lFreeSpace.GetHi() * 4294967296.0 + lFreeSpace.GetLo();
872 dRecTime /= bytesOnDiskPerSample;
873 dRecTime /= lCaptureChannels;
877 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)
ProjectFileIOMessage
Subscribe to ProjectFileIO to receive messages; always in idle time.
void InitProjectWindow(ProjectWindow &window)
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...
static std::shared_ptr< AudacityProject > Create()
Use this factory function.
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,...
static bool sbWindowRectAlreadySaved
static ProjectManager & Get(AudacityProject &project)
void OnStatusChange(StatusBarField field)
void OnCloseWindow(wxCloseEvent &event)
static bool sbSkipPromptingForSave
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)
Observer::Subscription mProjectFileIOSubscription
~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.
Observer::Subscription mProjectStatusSubscription
void OnReconnectionFailure(ProjectFileIOMessage)
void SetStatusText(const TranslatableString &text, int number)
int GetEstimatedRecordingMinsLeftOnDisk(long lCaptureChannels=0)
void ResetProjectToEmpty()
static ProjectRate & Get(AudacityProject &project)
static ProjectSettings & Get(AudacityProject &project)
static ProjectStatus & Get(AudacityProject &project)
std::shared_ptr< AudacityProject > FindProject()
A top-level window associated with a project, and handling scrollbars and zooming.
wxScrollBar & GetHorizontalScrollBar()
static ProjectWindow & Get(AudacityProject &project)
wxScrollBar & GetVerticalScrollBar()
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.
wxSplitterWindow * GetContainerWindow() noexcept
Container is a parent window for both effects panel and track list windows.
void UpdateStatusWidths()
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 */
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 Viewport & 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
Message sent when the project window is closed.