Audacity 3.2.0
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ProjectManager Class Referencefinal

Object associated with a project for high-level management of the project's lifetime, including creation, destruction, opening from file, importing, pushing undo states, and reverting to saved states. More...

#include <ProjectManager.h>

Inheritance diagram for ProjectManager:
[legend]
Collaboration diagram for ProjectManager:
[legend]

Classes

class  ProjectChooser
 Callable object that supplies the chooser argument of ProjectFileManager::OpenFile. More...
 

Public Member Functions

 ProjectManager (AudacityProject &project)
 
 ProjectManager (const ProjectManager &)=delete
 
ProjectManageroperator= (const ProjectManager &)=delete
 
 ~ProjectManager () override
 
void ResetProjectToEmpty ()
 
int GetEstimatedRecordingMinsLeftOnDisk (long lCaptureChannels=0)
 
TranslatableString GetHoursMinsString (int iMinutes)
 
void SetStatusText (const TranslatableString &text, int number)
 
void SetSkipSavePrompt (bool bSkip)
 
- Public Member Functions inherited from ClientData::Base
virtual ~Base ()
 

Static Public Member Functions

static ProjectManagerGet (AudacityProject &project)
 
static const ProjectManagerGet (const AudacityProject &project)
 
static AudacityProjectNew ()
 
static void OpenFiles (AudacityProject *proj)
 
static bool SafeToOpenProjectInto (AudacityProject &proj)
 False when it is unsafe to overwrite proj with contents of an .aup3 file. More...
 
static AudacityProjectOpenProject (AudacityProject *pGivenProject, const FilePath &fileNameArg, bool addtohistory, bool reuseNonemptyProject)
 Open a file into an AudacityProject, returning the project, or nullptr for failure. More...
 
static void SaveWindowSize ()
 
static void SetClosingAll (bool closing)
 

Private Member Functions

void OnReconnectionFailure (ProjectFileIOMessage)
 
void OnCloseWindow (wxCloseEvent &event)
 
void OnTimer (wxTimerEvent &event)
 
void OnStatusChange (StatusBarField field)
 
void RestartTimer ()
 

Private Attributes

AudacityProjectmProject
 
std::unique_ptr< wxTimer > mTimer
 
Observer::Subscription mProjectStatusSubscription
 
Observer::Subscription mProjectFileIOSubscription
 

Static Private Attributes

static bool sbWindowRectAlreadySaved = false
 
static bool sbSkipPromptingForSave = false
 

Detailed Description

Object associated with a project for high-level management of the project's lifetime, including creation, destruction, opening from file, importing, pushing undo states, and reverting to saved states.

Definition at line 33 of file ProjectManager.h.

Constructor & Destructor Documentation

◆ ProjectManager() [1/2]

ProjectManager::ProjectManager ( AudacityProject project)
explicit

Definition at line 88 of file ProjectManager.cpp.

89 : mProject{ project }
90 , mTimer{ std::make_unique<wxTimer>(this, AudacityProjectTimerID) }
91{
92 auto &window = ProjectWindow::Get( mProject );
93 window.Bind( wxEVT_CLOSE_WINDOW, &ProjectManager::OnCloseWindow, this );
98}
const int AudacityProjectTimerID
const auto project
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
static ProjectFileIO & Get(AudacityProject &project)
void OnStatusChange(StatusBarField field)
void OnCloseWindow(wxCloseEvent &event)
std::unique_ptr< wxTimer > mTimer
Observer::Subscription mProjectFileIOSubscription
AudacityProject & mProject
Observer::Subscription mProjectStatusSubscription
void OnReconnectionFailure(ProjectFileIOMessage)
static ProjectStatus & Get(AudacityProject &project)
static ProjectWindow & Get(AudacityProject &project)

References ProjectFileIO::Get(), ProjectStatus::Get(), ProjectWindow::Get(), mProject, mProjectFileIOSubscription, mProjectStatusSubscription, OnCloseWindow(), OnReconnectionFailure(), OnStatusChange(), and Observer::Publisher< Message, NotifyAll >::Subscribe().

Here is the call graph for this function:

◆ ProjectManager() [2/2]

ProjectManager::ProjectManager ( const ProjectManager )
delete

◆ ~ProjectManager()

ProjectManager::~ProjectManager ( )
overridedefault

Member Function Documentation

◆ Get() [1/2]

ProjectManager & ProjectManager::Get ( AudacityProject project)
static

Definition at line 78 of file ProjectManager.cpp.

79{
80 return project.AttachedObjects::Get< ProjectManager >( sProjectManagerKey );
81}
static AudacityProject::AttachedObjects::RegisteredFactory sProjectManagerKey
Object associated with a project for high-level management of the project's lifetime,...

References project, and sProjectManagerKey.

Referenced by Get(), InitProjectWindow(), New(), ApplyMacroDialog::OnApplyToFiles(), TimerRecordDialog::OnOK(), anonymous_namespace{FileMenus.cpp}::OnProjectReset(), and anonymous_namespace{TimerRecordDialog.cpp}::OnTimerRecord().

Here is the caller graph for this function:

◆ Get() [2/2]

const ProjectManager & ProjectManager::Get ( const AudacityProject project)
static

Definition at line 83 of file ProjectManager.cpp.

84{
85 return Get( const_cast< AudacityProject & >( project ) );
86}
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static ProjectManager & Get(AudacityProject &project)

References Get(), and project.

Here is the call graph for this function:

◆ GetEstimatedRecordingMinsLeftOnDisk()

int ProjectManager::GetEstimatedRecordingMinsLeftOnDisk ( long  lCaptureChannels = 0)

Definition at line 854 of file ProjectManager.cpp.

854 {
855 auto &project = mProject;
856
857 // Obtain the current settings
858 auto oCaptureFormat = QualitySettings::SampleFormatChoice();
859 if (lCaptureChannels == 0)
860 lCaptureChannels = AudioIORecordChannels.Read();
861
862 // Find out how much free space we have on disk
863 wxLongLong lFreeSpace = ProjectFileIO::Get( project ).GetFreeDiskSpace();
864 if (lFreeSpace < 0) {
865 return 0;
866 }
867
868 // Calculate the remaining time
869 double dRecTime = 0.0;
870 double bytesOnDiskPerSample = SAMPLE_SIZE_DISK(oCaptureFormat);
871 dRecTime = lFreeSpace.GetHi() * 4294967296.0 + lFreeSpace.GetLo();
872 dRecTime /= bytesOnDiskPerSample;
873 dRecTime /= lCaptureChannels;
874 dRecTime /= ProjectRate::Get( project ).GetRate();
875
876 // Convert to minutes before returning
877 int iRecMins = (int)round(dRecTime / 60.0);
878 return iRecMins;
879}
IntSetting AudioIORecordChannels
#define SAMPLE_SIZE_DISK(SampleFormat)
Return the size on disk of one uncompressed sample (bytes)
Definition: SampleFormat.h:67
wxLongLong GetFreeDiskSpace() const
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
double GetRate() const
Definition: ProjectRate.cpp:53
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:205
PROJECT_RATE_API sampleFormat SampleFormatChoice()
fastfloat_really_inline void round(adjusted_mantissa &am, callback cb) noexcept
Definition: fast_float.h:2512

References AudioIORecordChannels, ProjectFileIO::Get(), ProjectRate::Get(), ProjectFileIO::GetFreeDiskSpace(), ProjectRate::GetRate(), mProject, project, Setting< T >::Read(), fast_float::round(), SAMPLE_SIZE_DISK, and QualitySettings::SampleFormatChoice().

Referenced by OnTimer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetHoursMinsString()

TranslatableString ProjectManager::GetHoursMinsString ( int  iMinutes)

Definition at line 832 of file ProjectManager.cpp.

833{
834 if (iMinutes < 1)
835 // Less than a minute...
836 return XO("Less than 1 minute");
837
838 // Calculate
839 int iHours = iMinutes / 60;
840 int iMins = iMinutes % 60;
841
842 auto sHours = XP( "%d hour", "%d hours", 0 )( iHours );
843
844 auto sMins = XP( "%d minute", "%d minutes", 0 )( iMins );
845
846 /* i18n-hint: A time in hours and minutes. Only translate the "and". */
847 return XO("%s and %s.").Format( sHours, sMins );
848}
XO("Cut/Copy/Paste")
#define XP(sing, plur, n)
Definition: Internat.h:94

References XO(), and XP.

Referenced by OnTimer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ New()

AudacityProject * ProjectManager::New ( )
static

Definition at line 321 of file ProjectManager.cpp.

322{
323 wxRect wndRect;
324 bool bMaximized = false;
325 bool bIconized = false;
326 GetNextWindowPlacement(&wndRect, &bMaximized, &bIconized);
327
328 // Create and show a NEW project
329 // Use a non-default deleter in the smart pointer!
330 auto sp = AudacityProject::Create();
331 AllProjects{}.Add( sp );
332 auto p = sp.get();
333 auto &project = *p;
334 auto &projectHistory = ProjectHistory::Get( project );
335 auto &projectManager = Get( project );
336 auto &window = ProjectWindow::Get( *p );
337
338 // Issue #2569
339 // There is a dependency on the order of initialisation.
340 // The menus must be created, and registered, before
341 // InitProjectWindows can UpdateMenus.
343
344 InitProjectWindow( window );
345
346 // wxGTK3 seems to need to require creating the window using default position
347 // and then manually positioning it.
348 window.SetPosition(wndRect.GetPosition());
349
350 auto &projectFileManager = ProjectFileManager::Get( *p );
351
352 // This may report an error.
353 projectFileManager.OpenNewProject();
354
355 projectHistory.InitialState();
356 projectManager.RestartTimer();
357
358 if(bMaximized) {
359 window.Maximize(true);
360 }
361 else if (bIconized) {
362 // if the user close down and iconized state we could start back up and iconized state
363 // window.Iconize(TRUE);
364 }
365
366 //Initialise the Listeners
367 auto gAudioIO = AudioIO::Get();
368 gAudioIO->SetListener(
369 ProjectAudioManager::Get( project ).shared_from_this() );
370
371 //Set the NEW project as active:
373
374 // Okay, GetActiveProject() is ready. Now we can get its CommandManager,
375 // and add the shortcut keys to the tooltips.
377
379
380 window.Show(true);
381
382 return p;
383}
void SetActiveProject(AudacityProject *project)
@ ProjectInitialized
void InitProjectWindow(ProjectWindow &window)
void GetNextWindowPlacement(wxRect *nextRect, bool *pMaximized, bool *pIconized)
void Add(const value_type &pProject)
This invalidates iterators.
Definition: Project.cpp:56
static std::shared_ptr< AudacityProject > Create()
Use this factory function.
Definition: Project.cpp:78
static AudioIO * Get()
Definition: AudioIO.cpp:126
void CreateMenusAndCommands()
static MenuCreator & Get(AudacityProject &project)
Definition: MenuCreator.cpp:91
static ModuleManager & Get()
int Dispatch(ModuleDispatchTypes type)
static ProjectAudioManager & Get(AudacityProject &project)
static ProjectFileManager & Get(AudacityProject &project)
static ProjectHistory & Get(AudacityProject &project)
static ToolManager & Get(AudacityProject &project)
void RegenerateTooltips()

References AllProjects::Add(), AudacityProject::Create(), MenuCreator::CreateMenusAndCommands(), ModuleManager::Dispatch(), AudioIO::Get(), ModuleManager::Get(), ProjectHistory::Get(), MenuCreator::Get(), ProjectAudioManager::Get(), ProjectFileManager::Get(), Get(), ProjectWindow::Get(), ToolManager::Get(), GetNextWindowPlacement(), InitProjectWindow(), project, ProjectInitialized, ToolManager::RegenerateTooltips(), and SetActiveProject().

Referenced by AudacityApp::InitPart2(), AudacityApp::MacNewFile(), OnCloseWindow(), AudacityApp::OnMenuNew(), anonymous_namespace{FileMenus.cpp}::OnNew(), and ProjectManager::ProjectChooser::operator()().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnCloseWindow()

void ProjectManager::OnCloseWindow ( wxCloseEvent &  event)
private

Definition at line 398 of file ProjectManager.cpp.

399{
400 auto &project = mProject;
401 auto &projectFileIO = ProjectFileIO::Get( project );
402 auto &projectFileManager = ProjectFileManager::Get( project );
403 const auto &settings = ProjectSettings::Get( project );
404 auto &projectAudioIO = ProjectAudioIO::Get( project );
405 auto &tracks = TrackList::Get( project );
406 auto &viewport = Viewport::Get(project);
407 auto &window = ProjectWindow::Get( project );
408 auto gAudioIO = AudioIO::Get();
409
410 // We are called for the wxEVT_CLOSE_WINDOW, wxEVT_END_SESSION, and
411 // wxEVT_QUERY_END_SESSION, so we have to protect against multiple
412 // entries. This is a hack until the whole application termination
413 // process can be reviewed and reworked. (See bug #964 for ways
414 // to exercise the bug that instigated this hack.)
415 if (window.IsBeingDeleted())
416 {
417 event.Skip();
418 return;
419 }
420
421 if (event.CanVeto() && (::wxIsBusy() || project.mbBusyImporting))
422 {
423 event.Veto();
424 return;
425 }
426
427 // Check to see if we were playing or recording
428 // audio, and if so, make sure Audio I/O is completely finished.
429 // The main point of this is to properly push the state
430 // and flush the tracks once we've completely finished
431 // recording NEW state.
432 // This code is derived from similar code in
433 // AudacityProject::~AudacityProject() and TrackPanel::OnTimer().
434 if (projectAudioIO.GetAudioIOToken()>0 &&
435 gAudioIO->IsStreamActive(projectAudioIO.GetAudioIOToken())) {
436
437 // We were playing or recording audio, but we've stopped the stream.
439
440 projectAudioIO.SetAudioIOToken(0);
441 viewport.Redraw();
442 }
443 else if (gAudioIO->IsMonitoring()) {
444 gAudioIO->StopStream();
445 }
446
447 // MY: Use routine here so other processes can make same check
448 bool bHasTracks = !tracks.empty();
449
450 // We may not bother to prompt the user to save, if the
451 // project is now empty.
453 && event.CanVeto()
454 && (settings.EmptyCanBeDirty() || bHasTracks)) {
455 if ( UndoManager::Get( project ).UnsavedChanges() ) {
456 TitleRestorer Restorer( window, project );// RAII
457 /* i18n-hint: The first %s numbers the project, the second %s is the project name.*/
458 auto Title = XO("%sSave changes to %s?")
459 .Format( Restorer.sProjNumber, Restorer.sProjName );
460 auto Message = XO("Save project before closing?");
461 if( !bHasTracks )
462 {
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.");
464 }
465 int result = AudacityMessageBox(
466 Message,
467 Title,
468 wxYES_NO | wxCANCEL | wxICON_QUESTION,
469 &window);
470
471 if (result == wxCANCEL || (result == wxYES &&
472 !GuardedCall<bool>( [&]{ return projectFileManager.Save(); } )
473 )) {
474 event.Veto();
475 return;
476 }
477 }
478 }
479#ifdef __WXMAC__
480 // Fix bug apparently introduced into 2.1.2 because of wxWidgets 3:
481 // closing a project that was made full-screen (as by clicking the green dot
482 // or command+/; not merely "maximized" as by clicking the title bar or
483 // Zoom in the Window menu) leaves the screen black.
484 // Fix it by un-full-screening.
485 // (But is there a different way to do this? What do other applications do?
486 // I don't see full screen windows of Safari shrinking, but I do see
487 // momentary blackness.)
488 window.ShowFullScreen(false);
489#endif
490
491 // This achieves auto save on close of project before other important
492 // project state is destroyed
493 window.Publish(ProjectWindowDestroyedMessage {});
495
496 // Stop the timer since there's no need to update anything anymore
497 mTimer.reset();
498
499 // DMM: Save the size of the last window the user closes
500 //
501 // LL: Save before doing anything else to the window that might make
502 // its size change.
504
505 window.SetIsBeingDeleted();
506
507 // Mac: we never quit as the result of a close.
508 // Other systems: we quit only when the close is the result of an external
509 // command (on Windows, those are taskbar closes, "X" box, Alt+F4, etc.)
510 bool quitOnClose;
511#ifdef __WXMAC__
512 quitOnClose = false;
513#else
514 quitOnClose = !projectFileManager.GetMenuClose();
515#endif
516
517 // DanH: If we're definitely about to quit, clear the clipboard.
518 auto &clipboard = Clipboard::Get();
519 if ((AllProjects{}.size() == 1) &&
520 (quitOnClose || sbClosingAll))
521 clipboard.Clear();
522 else {
523 auto clipboardProject = clipboard.Project().lock();
524 if ( clipboardProject.get() == &mProject ) {
525 // Closing the project from which content was cut or copied.
526 // For 3.0.0, clear the clipboard, because accessing clipboard contents
527 // would depend on a database connection to the closing project, but
528 // that connection should closed now so that the project file can be
529 // freely moved.
530 // Notes:
531 // 1) maybe clipboard contents could be saved by migrating them to
532 // another temporary database, but that extra effort is beyond the
533 // scope of 3.0.0.
534 // 2) strictly speaking this is necessary only when the clipboard
535 // contains WaveTracks.
536 clipboard.Clear();
537 }
538 }
539
540 // JKC: For Win98 and Linux do not detach the menu bar.
541 // We want wxWidgets to clean it up for us.
542 // TODO: Is there a Mac issue here??
543 // SetMenuBar(NULL);
544
545 // Compact the project.
546 projectFileManager.CompactProjectOnClose();
547
548 // Set (or not) the bypass flag to indicate that deletes that would happen during
549 // the UndoManager::ClearStates() below are not necessary.
550 projectFileIO.SetBypass();
551
552 {
553 // This can reduce reference counts of sample blocks in the project's
554 // tracks.
556
557 // Delete all the tracks to free up memory
558 tracks.Clear();
559 }
560
561 // Some of the AdornedRulerPanel functions refer to the TrackPanel, so destroy this
562 // before the TrackPanel is destroyed. This change was needed to stop Audacity
563 // crashing when running with Jaws on Windows 10 1703.
565
566 // Destroy the TrackPanel early so it's not around once we start
567 // deleting things like tracks and such out from underneath it.
568 // Check validity of mTrackPanel per bug 584 Comment 1.
569 // Deeper fix is in the Import code, but this failsafes against crash.
571 // Finalize the tool manager before the children since it needs
572 // to save the state of the toolbars.
574
575 window.DestroyChildren();
576
577 // Close project only now, because TrackPanel might have been holding
578 // some shared_ptr to WaveTracks keeping SampleBlocks alive.
579 // We're all done with the project file, so close it now
580 projectFileManager.CloseProject();
581
583
584 // Remove self from the global array, but defer destruction of self
585 auto pSelf = AllProjects{}.Remove( project );
586 wxASSERT( pSelf );
587
588 if (GetActiveProject().lock().get() == &project) {
589 // Find a NEW active project
590 if ( !AllProjects{}.empty() ) {
592 }
593 else {
594 SetActiveProject(nullptr);
595 }
596 }
597
598 // Since we're going to be destroyed, make sure we're not to
599 // receive audio notifications anymore.
600 // PRL: Maybe all this is unnecessary now that the listener is managed
601 // by a weak pointer.
602 if ( gAudioIO->GetListener().get() == &ProjectAudioManager::Get( project ) ) {
603 auto active = GetActiveProject().lock();
604 gAudioIO->SetListener(
605 active
606 ? ProjectAudioManager::Get( *active ).shared_from_this()
607 : nullptr
608 );
609 }
610
611 if (AllProjects{}.empty() && !sbClosingAll) {
612
613#if !defined(__WXMAC__)
614 if (quitOnClose) {
615 // Simulate the application Exit menu item
616 wxCommandEvent evt{ wxEVT_MENU, wxID_EXIT };
617 wxTheApp->AddPendingEvent( evt );
618 }
619 else {
621 // For non-Mac, always keep at least one project window open
622 (void) New();
623 }
624#endif
625 }
626
627 window.Destroy();
628
629 // Destroys this
630 pSelf.reset();
631}
AUDACITY_DLL_API std::weak_ptr< AudacityProject > GetActiveProject()
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
@ ProjectClosing
static bool sbClosingAll
const auto tracks
static Settings & settings()
Definition: TrackInfo.cpp:69
static void Destroy(AudacityProject &project)
size_t size() const
Definition: Project.cpp:17
value_type Remove(AudacityProject &project)
Definition: Project.cpp:42
const_iterator begin() const
Definition: Project.cpp:22
bool empty() const
Definition: Project.h:47
static Clipboard & Get()
Definition: Clipboard.cpp:28
static ProjectAudioIO & Get(AudacityProject &project)
void Stop(bool stopStream=true)
static bool sbWindowRectAlreadySaved
static bool sbSkipPromptingForSave
static AudacityProject * New()
static void SaveWindowSize()
static ProjectSettings & Get(AudacityProject &project)
void Destroy()
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:347
static void Destroy(AudacityProject &project)
Definition: TrackPanel.cpp:243
void ClearStates()
static UndoManager & Get(AudacityProject &project)
Definition: UndoManager.cpp:71
static Viewport & Get(AudacityProject &project)
Definition: Viewport.cpp:32
static void Destroy(AudacityProject &project)
Definition: WaveTrack.cpp:4510
TranslatableString Message(unsigned trackCount)
Message sent when the project window is closed.
Definition: ProjectWindow.h:29

References AudacityMessageBox(), AllProjects::begin(), UndoManager::ClearStates(), ToolManager::Destroy(), WaveTrackFactory::Destroy(), AdornedRulerPanel::Destroy(), TrackPanel::Destroy(), ModuleManager::Dispatch(), AllProjects::empty(), AudioIO::Get(), ModuleManager::Get(), Clipboard::Get(), ProjectAudioIO::Get(), ProjectFileIO::Get(), UndoManager::Get(), TrackList::Get(), Viewport::Get(), ProjectAudioManager::Get(), ProjectFileManager::Get(), ProjectSettings::Get(), ProjectWindow::Get(), ToolManager::Get(), GetActiveProject(), anonymous_namespace{TrackSelectHandle.cpp}::Message(), mProject, mTimer, New(), project, ProjectClosing, AllProjects::Remove(), SaveWindowSize(), sbClosingAll, sbSkipPromptingForSave, sbWindowRectAlreadySaved, SetActiveProject(), settings(), AllProjects::size(), TitleRestorer::sProjName, TitleRestorer::sProjNumber, ProjectAudioManager::Stop(), tracks, and XO().

Referenced by ProjectManager().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnReconnectionFailure()

void ProjectManager::OnReconnectionFailure ( ProjectFileIOMessage  message)
private

Definition at line 385 of file ProjectManager.cpp.

386{
388 ProjectWindow::Get(mProject).Close(true);
389}

References ProjectWindow::Get(), mProject, and ReconnectionFailure.

Referenced by ProjectManager().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnStatusChange()

void ProjectManager::OnStatusChange ( StatusBarField  field)
private

Definition at line 798 of file ProjectManager.cpp.

799{
800 auto &project = mProject;
801
802 // Be careful to null-check the window. We might get to this function
803 // during shut-down, but a timer hasn't been told to stop sending its
804 // messages yet.
805 auto pWindow = ProjectWindow::Find( &project );
806 if ( !pWindow )
807 return;
808 auto &window = *pWindow;
809
810 window.UpdateStatusWidths();
811
812 const auto &msg = ProjectStatus::Get( project ).Get( field );
813 SetStatusText( msg, field );
814
815 if ( field == mainStatusBarField )
816 // When recording, let the NEW status message stay at least as long as
817 // the timer interval (if it is not replaced again by this function),
818 // before replacing it with the message about remaining disk capacity.
819 RestartTimer();
820}
#define field(n, t)
Definition: ImportAUP.cpp:165
@ mainStatusBarField
Definition: ProjectStatus.h:26
void SetStatusText(const TranslatableString &text, int number)
static ProjectWindow * Find(AudacityProject *pProject)

References field, ProjectWindow::Find(), ProjectStatus::Get(), mainStatusBarField, mProject, project, RestartTimer(), and SetStatusText().

Referenced by ProjectManager().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnTimer()

void ProjectManager::OnTimer ( wxTimerEvent &  event)
private

Definition at line 768 of file ProjectManager.cpp.

769{
770 auto &project = mProject;
771 auto &projectAudioIO = ProjectAudioIO::Get( project );
772 auto meterToolBars = MeterToolBar::GetToolBars( project );
773
774 for (auto& meterToolBar : meterToolBars)
775 meterToolBar.get().UpdateControls();
776
777 auto gAudioIO = AudioIO::Get();
778 // gAudioIO->GetNumCaptureChannels() should only be positive
779 // when we are recording.
780 if (projectAudioIO.GetAudioIOToken() > 0 && gAudioIO->GetNumCaptureChannels() > 0) {
781 wxLongLong freeSpace = ProjectFileIO::Get(project).GetFreeDiskSpace();
782 if (freeSpace >= 0) {
783
784 int iRecordingMins = GetEstimatedRecordingMinsLeftOnDisk(gAudioIO->GetNumCaptureChannels());
785 auto sMessage = XO("Disk space remaining for recording: %s")
786 .Format( GetHoursMinsString(iRecordingMins) );
787
788 // Do not change mLastMainStatusMessage
790 }
791 }
792
793 // As also with the TrackPanel timer: wxTimer may be unreliable without
794 // some restarts
795 RestartTimer();
796}
static MeterToolBars GetToolBars(AudacityProject &project)
TranslatableString GetHoursMinsString(int iMinutes)
int GetEstimatedRecordingMinsLeftOnDisk(long lCaptureChannels=0)

References AudioIO::Get(), ProjectAudioIO::Get(), ProjectFileIO::Get(), GetEstimatedRecordingMinsLeftOnDisk(), ProjectFileIO::GetFreeDiskSpace(), GetHoursMinsString(), MeterToolBar::GetToolBars(), mainStatusBarField, mProject, project, RestartTimer(), SetStatusText(), and XO().

Here is the call graph for this function:

◆ OpenFiles()

void ProjectManager::OpenFiles ( AudacityProject proj)
static

Definition at line 634 of file ProjectManager.cpp.

635{
636 auto selectedFiles =
637 ProjectFileManager::ShowOpenDialog(FileNames::Operation::Open);
638 if (selectedFiles.size() == 0) {
640 return;
641 }
642
643 //first sort selectedFiles.
644 selectedFiles.Sort(FileNames::CompareNoCase);
645
646 auto cleanup = finally( [] {
648 } );
649
650 for (const auto &fileName : selectedFiles) {
651 // Make sure it isn't already open.
653 continue; // Skip ones that are already open.
654
655 proj = OpenProject( proj, fileName,
656 true /* addtohistory */, false /* reuseNonemptyProject */ );
657 }
658}
static void SetLastOpenType(const FileNames::FileType &type)
Definition: Import.cpp:253
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 * OpenProject(AudacityProject *pGivenProject, const FilePath &fileNameArg, bool addtohistory, bool reuseNonemptyProject)
Open a file into an AudacityProject, returning the project, or nullptr for failure.
FILES_API int CompareNoCase(const wxString &first, const wxString &second)

References FileNames::CompareNoCase(), ProjectFileManager::IsAlreadyOpen(), OpenProject(), Importer::SetLastOpenType(), and ProjectFileManager::ShowOpenDialog().

Referenced by OpenProjectCommand::Apply(), AudacityApp::OnMenuOpen(), and anonymous_namespace{FileMenus.cpp}::OnOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenProject()

AudacityProject * ProjectManager::OpenProject ( AudacityProject pGivenProject,
const FilePath fileNameArg,
bool  addtohistory,
bool  reuseNonemptyProject 
)
static

Open a file into an AudacityProject, returning the project, or nullptr for failure.

If an exception escapes this function, no projects are created.

Parameters
pGivenProjectif not null, a project that may be reused
fileNameArgpath to the file to open; not always an Audacity project file, may be an import
addtohistorywhether to add .aup3 files to the MRU list (but always done for imports)
reuseNonemptyProjectif true, may reuse the given project when nonempty, but only if importing (not for a project file)

Definition at line 717 of file ProjectManager.cpp.

720{
721 ProjectManager::ProjectChooser chooser{ pGivenProject, reuseNonemptyProject };
722 if (auto pProject = ProjectFileManager::OpenFile(
723 std::ref(chooser), fileNameArg, addtohistory )) {
724 chooser.Commit();
725
726 auto &projectFileIO = ProjectFileIO::Get( *pProject );
727 if( projectFileIO.IsRecovered() ) {
728 auto &viewport = Viewport::Get(*pProject);
729 viewport.Zoom(viewport.GetZoomOfToFit());
730 // "Project was recovered" replaces "Create new project" in Undo History.
731 auto &undoManager = UndoManager::Get( *pProject );
732 undoManager.RemoveStates(0, 1);
733 }
734 return pProject;
735 }
736 return nullptr;
737}
static AudacityProject * OpenFile(const ProjectChooserFn &chooser, const FilePath &fileName, bool addtohistory=true)
Callable object that supplies the chooser argument of ProjectFileManager::OpenFile.

References ProjectFileIO::Get(), UndoManager::Get(), Viewport::Get(), and ProjectFileManager::OpenFile().

Referenced by EVT_MENU_RANGE(), LOFImportFileHandle::lofOpenFiles(), OpenFiles(), and RecoverAllProjects().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

ProjectManager & ProjectManager::operator= ( const ProjectManager )
delete

◆ ResetProjectToEmpty()

void ProjectManager::ResetProjectToEmpty ( )

Definition at line 740 of file ProjectManager.cpp.

740 {
741 auto &project = mProject;
742 auto &projectFileIO = ProjectFileIO::Get( project );
743 auto &projectFileManager = ProjectFileManager::Get( project );
744 auto &projectHistory = ProjectHistory::Get( project );
745 auto &viewInfo = ViewInfo::Get( project );
746
749
751
752 // InitialState will reset UndoManager
753 projectHistory.InitialState();
754 projectHistory.SetDirty(false);
755
756 projectFileManager.CloseProject();
757 projectFileManager.OpenProject();
758}
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
static WaveTrackFactory & Reset(AudacityProject &project)
Definition: WaveTrack.cpp:4503
void DoSelectAll(AudacityProject &project)
void DoRemoveTracks(AudacityProject &project)

References TrackUtilities::DoRemoveTracks(), SelectUtilities::DoSelectAll(), ProjectFileIO::Get(), ProjectHistory::Get(), ViewInfo::Get(), ProjectFileManager::Get(), mProject, project, and WaveTrackFactory::Reset().

Referenced by ApplyMacroDialog::OnApplyToFiles(), and anonymous_namespace{FileMenus.cpp}::OnProjectReset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RestartTimer()

void ProjectManager::RestartTimer ( )
private

Definition at line 760 of file ProjectManager.cpp.

761{
762 if (mTimer) {
763 // mTimer->Stop(); // not really needed
764 mTimer->Start( 3000 ); // Update messages as needed once every 3 s.
765 }
766}

References mTimer.

Referenced by OnStatusChange(), and OnTimer().

Here is the caller graph for this function:

◆ SafeToOpenProjectInto()

bool ProjectManager::SafeToOpenProjectInto ( AudacityProject proj)
static

False when it is unsafe to overwrite proj with contents of an .aup3 file.

Definition at line 660 of file ProjectManager.cpp.

661{
662 // DMM: If the project is dirty, that means it's been touched at
663 // all, and it's not safe to open a fresh project directly in its
664 // place. Only if the project is brandnew clean and the user
665 // hasn't done any action at all is it safe for Open to take place
666 // inside the current project.
667 //
668 // If you try to Open a fresh project inside the current window when
669 // there are no tracks, but there's an Undo history, etc, then
670 // bad things can happen, including orphan blocks, or tracks
671 // referring to non-existent blocks
672 if (
673 ProjectHistory::Get( proj ).GetDirty() ||
674 !TrackList::Get( proj ).empty()
675 )
676 return false;
677 // This project is clean; it's never been touched. Therefore
678 // all relevant member variables are in their initial state,
679 // and it's okay to open a NEW project inside its window.
680 return true;
681}

References ProjectHistory::Get(), and TrackList::Get().

Referenced by ProjectManager::ProjectChooser::operator()().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SaveWindowSize()

void ProjectManager::SaveWindowSize ( )
static

Definition at line 109 of file ProjectManager.cpp.

110{
112 {
113 return;
114 }
115 bool validWindowForSaveWindowSize = FALSE;
116 ProjectWindow * validProject = nullptr;
117 bool foundIconizedProject = FALSE;
118 for ( auto pProject : AllProjects{} )
119 {
120 auto &window = ProjectWindow::Get( *pProject );
121 if (!window.IsIconized()) {
122 validWindowForSaveWindowSize = TRUE;
123 validProject = &window;
124 break;
125 }
126 else
127 foundIconizedProject = TRUE;
128 }
129
130 if (validWindowForSaveWindowSize)
131 {
132 wxRect windowRect = validProject->GetRect();
133 wxRect normalRect = validProject->GetNormalizedWindowState();
134 bool wndMaximized = validProject->IsMaximized();
135
136 SaveWindowPreferences(windowRect, normalRect, wndMaximized, false);
137 }
138 else
139 {
140 if (foundIconizedProject) {
141 validProject = &ProjectWindow::Get( **AllProjects{}.begin() );
142 bool wndMaximized = validProject->IsMaximized();
143 wxRect normalRect = validProject->GetNormalizedWindowState();
144
145 // store only the normal rectangle because the itemized rectangle
146 // makes no sense for an opening project window
147 SaveWindowPreferences(normalRect, normalRect, wndMaximized, true);
148 }
149 else {
150 // this would be a very strange case that might possibly occur on the Mac
151 // Audacity would have to be running with no projects open
152 // in this case we are going to write only the default values
153 wxRect defWndRect;
154 GetDefaultWindowRect(&defWndRect);
155 SaveWindowPreferences(defWndRect, defWndRect, false, false);
156 }
157 }
159}
void GetDefaultWindowRect(wxRect *defRect)
A top-level window associated with a project, and handling scrollbars and zooming.
Definition: ProjectWindow.h:36
wxRect GetNormalizedWindowState() const
void SaveWindowPreferences(const wxRect &windowRect, const wxRect &normalRect, bool isMaximized, bool isIconized)

References AllProjects::begin(), ProjectWindow::Get(), GetDefaultWindowRect(), ProjectWindow::GetNormalizedWindowState(), and anonymous_namespace{ProjectManager.cpp}::SaveWindowPreferences().

Referenced by OnCloseWindow(), AudacityApp::OnEndSession(), and QuitAudacity().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetClosingAll()

void ProjectManager::SetClosingAll ( bool  closing)
static

Definition at line 393 of file ProjectManager.cpp.

394{
395 sbClosingAll = closing;
396}

References sbClosingAll.

Referenced by CloseAllProjects().

Here is the caller graph for this function:

◆ SetSkipSavePrompt()

void ProjectManager::SetSkipSavePrompt ( bool  bSkip)
inline

Definition at line 114 of file ProjectManager.h.

114{ sbSkipPromptingForSave = bSkip; };

Referenced by anonymous_namespace{TimerRecordDialog.cpp}::OnTimerRecord().

Here is the caller graph for this function:

◆ SetStatusText()

void ProjectManager::SetStatusText ( const TranslatableString text,
int  number 
)

Definition at line 822 of file ProjectManager.cpp.

823{
824 auto &project = mProject;
825 auto pWindow = ProjectWindow::Find( &project );
826 if ( !pWindow )
827 return;
828 auto &window = *pWindow;
829 window.GetStatusBar()->SetStatusText(text.Translation(), number);
830}
wxString Translation() const

References ProjectWindow::Find(), mProject, project, and TranslatableString::Translation().

Referenced by InitProjectWindow(), OnStatusChange(), and OnTimer().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mProject

AudacityProject& ProjectManager::mProject
private

◆ mProjectFileIOSubscription

Observer::Subscription ProjectManager::mProjectFileIOSubscription
private

Definition at line 132 of file ProjectManager.h.

Referenced by ProjectManager().

◆ mProjectStatusSubscription

Observer::Subscription ProjectManager::mProjectStatusSubscription
private

Definition at line 131 of file ProjectManager.h.

Referenced by ProjectManager().

◆ mTimer

std::unique_ptr<wxTimer> ProjectManager::mTimer
private

Definition at line 129 of file ProjectManager.h.

Referenced by OnCloseWindow(), and RestartTimer().

◆ sbSkipPromptingForSave

bool ProjectManager::sbSkipPromptingForSave = false
staticprivate

Definition at line 137 of file ProjectManager.h.

Referenced by OnCloseWindow().

◆ sbWindowRectAlreadySaved

bool ProjectManager::sbWindowRectAlreadySaved = false
staticprivate

Definition at line 136 of file ProjectManager.h.

Referenced by OnCloseWindow().


The documentation for this class was generated from the following files: