47#include <wx/scrolbar.h>
49#include <wx/splitter.h>
52#include "../images/AudacityLogoAlpha.xpm"
57 bool isMaximized,
bool isIconized) {
75 return std::make_shared< ProjectManager >(
project );
112 if (sbWindowRectAlreadySaved)
116 bool validWindowForSaveWindowSize = FALSE;
118 bool foundIconizedProject = FALSE;
122 if (!window.IsIconized()) {
123 validWindowForSaveWindowSize = TRUE;
124 validProject = &window;
128 foundIconizedProject = TRUE;
131 if (validWindowForSaveWindowSize)
133 wxRect windowRect = validProject->GetRect();
135 bool wndMaximized = validProject->IsMaximized();
141 if (foundIconizedProject) {
143 bool wndMaximized = validProject->IsMaximized();
159 sbWindowRectAlreadySaved =
true;
197 auto ubs = std::make_unique<wxBoxSizer>(wxVERTICAL);
199 topPanel->SetSizer(ubs.release());
204 auto ubs = std::make_unique<wxBoxSizer>(wxVERTICAL);
206 bs->Add(topPanel, 0, wxEXPAND | wxALIGN_TOP);
209 window.SetAutoLayout(
true);
210 window.SetSizer(ubs.release());
230 bs =
static_cast<wxBoxSizer*
>(trackListWindow->GetSizer());
237 auto hs = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
240 hs->Add(&trackPanel, 1, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP);
244 auto vs = std::make_unique<wxBoxSizer>(wxVERTICAL);
247 vs->Add(vsBar, 1, wxEXPAND | wxALIGN_TOP);
248 hs->Add(vs.release(), 0, wxEXPAND | wxALIGN_TOP);
251 bs->Add(&
ruler, 0, wxEXPAND | wxALIGN_TOP);
252 bs->Add(hs.release(), 1, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP);
257 auto hs = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
260 hs->Add(viewInfo.GetLeftOffset() - 1, 0);
261 hs->Add(hsBar, 1, wxALIGN_BOTTOM);
262 hs->Add(vsBar->GetSize().GetWidth(), 0);
263 bs->Add(hs.release(), 0, wxEXPAND | wxALIGN_LEFT);
267 trackListWindow->SetAutoLayout(
true);
268 trackListWindow->Layout();
270 wxASSERT( trackPanel.GetProject() == &
project );
273 trackPanel.SetFocus();
275 viewport.UpdateScrollbarsForTracks();
276 ruler.SetLeftOffset(viewInfo.GetLeftOffset());
283#if !defined(__WXMAC__) && !defined(__WXX11__)
285#if defined(__WXMSW__)
286 wxIcon ic{ wxICON(AudacityLogo) };
287#elif defined(__WXGTK__)
288 wxIcon ic{wxICON(AudacityLogoAlpha)};
298 auto msg =
XO(
"Welcome to Audacity version %s")
299 .Format( AUDACITY_VERSION_STRING );
306 bool bMaximized =
false;
307 bool bIconized =
false;
330 window.SetPosition(wndRect.GetPosition());
335 projectFileManager.OpenNewProject();
337 projectHistory.InitialState();
338 projectManager.RestartTimer();
341 window.Maximize(
true);
343 else if (bIconized) {
350 gAudioIO->SetListener(
397 if (window.IsBeingDeleted())
403 if (event.CanVeto() && (::wxIsBusy() ||
project.mbBusyImporting))
416 if (projectAudioIO.GetAudioIOToken()>0 &&
417 gAudioIO->IsStreamActive(projectAudioIO.GetAudioIOToken())) {
422 projectAudioIO.SetAudioIOToken(0);
425 else if (gAudioIO->IsMonitoring()) {
426 gAudioIO->StopStream();
430 bool bHasTracks = !
tracks.empty();
440 auto Title =
XO(
"%sSave changes to %s?")
442 auto Message =
XO(
"Save project before closing?");
447 wxYES_NO | wxCANCEL | wxICON_QUESTION,
450 if (result == wxCANCEL || (result == wxYES &&
451 !GuardedCall<bool>( [&]{
return projectFileManager.Save(); } )
476 window.ShowFullScreen(
false);
493 window.SetIsBeingDeleted();
502 quitOnClose = !projectFileManager.GetMenuClose();
511 auto clipboardProject = clipboard.Project().lock();
512 if ( clipboardProject.get() == &
mProject ) {
534 constexpr auto doAutoSave =
false;
536 undoManager.GetSavedState(), doAutoSave);
539 projectFileManager.CompactProjectOnClose();
544 projectFileIO.SetBypass();
548 undoManager.ClearStates();
567 window.DestroyChildren();
572 projectFileManager.CloseProject();
596 gAudioIO->SetListener(
605#if !defined(__WXMAC__)
608 wxCommandEvent evt{ wxEVT_MENU, wxID_EXIT };
609 wxTheApp->AddPendingEvent( evt );
630 if (selectedFiles.size() == 0) {
638 auto cleanup =
finally( [] {
642 for (
const auto &fileName : selectedFiles) {
692 if (mpGivenProject) {
697 bool checkReuse = (openingProjectFile || !mReuseNonemptyProject);
699 return *(mpUsedProject = mpGivenProject);
701 return *(mpUsedProject =
New());
706 mpUsedProject =
nullptr;
711 bool addtohistory,
bool reuseNonemptyProject)
715 std::ref(chooser), fileNameArg, addtohistory )) {
719 if( projectFileIO.IsRecovered() ) {
721 viewport.Zoom(viewport.GetZoomOfToFit());
724 undoManager.RemoveStates(0, 1);
745 projectHistory.InitialState();
746 projectHistory.SetDirty(
false);
748 projectFileManager.CloseProject();
749 projectFileManager.OpenProject();
766 for (
auto& meterToolBar : meterToolBars)
767 meterToolBar.get().UpdateControls();
772 if (projectAudioIO.GetAudioIOToken() > 0 && gAudioIO->GetNumCaptureChannels() > 0) {
774 if (freeSpace >= 0) {
777 auto sMessage =
XO(
"Disk space remaining for recording: %s")
800 auto &window = *pWindow;
802 window.UpdateStatusWidths();
829 auto &window = *pWindow;
830 window.GetStatusBar()->SetStatusText(text.
Translation(), number);
837 return XO(
"Less than 1 minute");
840 int iHours = iMinutes / 60;
841 int iMins = iMinutes % 60;
843 auto sHours =
XP(
"%d hour",
"%d hours", 0 )( iHours );
845 auto sMins =
XP(
"%d minute",
"%d minutes", 0 )( iMins );
848 return XO(
"%s and %s.").Format( sHours, sMins );
860 if (lCaptureChannels == 0)
865 if (lFreeSpace < 0) {
870 double dRecTime = 0.0;
872 dRecTime = lFreeSpace.GetHi() * 4294967296.0 + lFreeSpace.GetLo();
873 dRecTime /= bytesOnDiskPerSample;
874 dRecTime /= lCaptureChannels;
878 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.
@ Veto
Extension vetoed the close.
void InitProjectWindow(ProjectWindow &window)
static AudacityProject::AttachedObjects::RegisteredFactory sProjectManagerKey
const int AudacityProjectTimerID
an object holding per-project preferred sample rate
StatusBarField MainStatusBarField()
ID of the second field in the status bar. This field is expandable.
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...
An explicitly nonlocalized string, not meant for the user to see.
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)
void SetStateTo(unsigned int n, bool doAutosave=true)
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)
void SetStatusText(const TranslatableString &text, const StatusBarField &field)
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)
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.
wxStatusBar * CreateProjectStatusBar()
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 */
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)
FILES_API int CompareNoCase(const wxString &first, const wxString &second)
PROJECT_RATE_API sampleFormat SampleFormatChoice()
void DoSelectAll(AudacityProject &project)
AUDACITY_DLL_API void DoRemoveTracks(AudacityProject &)
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
static OnCloseAction OnClose(AudacityProject &project)
static int GetFieldIndex(const AudacityProject &project, const StatusBarField &identifier)
Returns the zero based index of the field or -1 if field is not present.
Message sent when the project window is closed.