Audacity  2.2.2
Classes | Macros | Typedefs | Enumerations | Functions | Variables
Project.h File Reference
#include "Audacity.h"
#include "Experimental.h"
#include "widgets/OverlayPanel.h"
#include "DirManager.h"
#include "SelectionState.h"
#include "ViewInfo.h"
#include "TrackPanelListener.h"
#include "AudioIOListener.h"
#include "commands/CommandManager.h"
#include "effects/EffectManager.h"
#include "xml/XMLTagHandler.h"
#include "toolbars/SelectionBarListener.h"
#include "toolbars/SpectralSelectionBarListener.h"
#include "MemoryX.h"
#include <wx/defs.h>
#include <wx/event.h>
#include <wx/log.h>
#include <wx/dragimag.h>
#include <wx/generic/dragimgg.h>
#include <wx/frame.h>
#include <wx/intl.h>
#include <wx/dcclient.h>
#include "import/ImportRaw.h"
#include "Menus.h"

Go to the source code of this file.

Classes

class  ImportXMLTagHandler
 
class  AudacityProject
 AudacityProject provides the main window, with tools and tracks contained within it. More...
 
struct  AudacityProject::FoundTrack
 
struct  AudacityProject::FoundClip
 
struct  AudacityProject::FoundClipBoundary
 
class  AudacityProject::OnEffectFlags
 
class  AudacityProject::PlaybackScroller
 

Macros

#define kAudacitySortByTime   (1 << 1)
 
#define kAudacitySortByName   (1 << 2)
 

Typedefs

using AProjectHolder = std::shared_ptr< AudacityProject >
 
using AProjectArray = std::vector< AProjectHolder >
 

Enumerations

enum  PlayMode : int { PlayMode::normalPlay, PlayMode::oneSecondPlay, PlayMode::loopedPlay }
 
enum  StatusBarField { stateStatusBarField = 1, mainStatusBarField = 2, rateStatusBarField = 3 }
 

Functions

AudacityProjectCreateNewAudacityProject ()
 
AUDACITY_DLL_API AudacityProjectGetActiveProject ()
 
void RedrawAllProjects ()
 
void RefreshCursorForAllProjects ()
 
AUDACITY_DLL_API void CloseAllProjects ()
 
void GetDefaultWindowRect (wxRect *defRect)
 
void GetNextWindowPlacement (wxRect *nextRect, bool *pMaximized, bool *pIconized)
 
bool IsWindowAccessible (wxRect *requestedRect)
 
 DECLARE_EXPORTED_EVENT_TYPE (AUDACITY_DLL_API, EVT_CAPTURE_KEY,-1)
 Custom events. More...
 

Variables

const int AudacityProjectTimerID = 5200
 
AProjectArray gAudacityProjects
 

Macro Definition Documentation

#define kAudacitySortByName   (1 << 2)

Definition at line 704 of file Project.h.

Referenced by AudacityProject::OnSortName(), and AudacityProject::SortTracks().

#define kAudacitySortByTime   (1 << 1)

Definition at line 703 of file Project.h.

Referenced by AudacityProject::OnSortTime(), and AudacityProject::SortTracks().

Typedef Documentation

using AProjectArray = std::vector< AProjectHolder >

Definition at line 118 of file Project.h.

using AProjectHolder = std::shared_ptr< AudacityProject >

Definition at line 117 of file Project.h.

Enumeration Type Documentation

enum PlayMode : int
strong
Enumerator
normalPlay 
oneSecondPlay 
loopedPlay 

Definition at line 123 of file Project.h.

123  : int {
124  normalPlay,
125  oneSecondPlay, // Disables auto-scrolling
126  loopedPlay // Disables auto-scrolling
127 };
Enumerator
stateStatusBarField 
mainStatusBarField 
rateStatusBarField 

Definition at line 129 of file Project.h.

Function Documentation

AUDACITY_DLL_API void CloseAllProjects ( )

Definition at line 602 of file Project.cpp.

References gAudacityOffsetInc, gAudacityPosInc, and gAudacityProjects.

603 {
604  size_t len = gAudacityProjects.size();
605  for (size_t i = 0; i < len; i++)
606  gAudacityProjects[i]->Close();
607 
608  //Set the Offset and Position increments to 0
609  gAudacityOffsetInc = 0;
610  gAudacityPosInc = 0;
611 }
static int gAudacityOffsetInc
Definition: Project.cpp:290
AProjectArray gAudacityProjects
Definition: Project.cpp:295
static int gAudacityPosInc
Definition: Project.cpp:291
AudacityProject* CreateNewAudacityProject ( )

Definition at line 540 of file Project.cpp.

References ModuleManager::Dispatch(), gAudacityProjects, gAudioIO, ModuleManager::Get(), GetNextWindowPlacement(), ProjectInitialized, safenew, SetActiveProject(), and AudioIO::SetListener().

Referenced by AudacityProject::OnCloseWindow(), AudacityApp::OnInit(), AudacityApp::OnMenuNew(), AudacityProject::OnNew(), and AudacityProject::OpenProject().

541 {
542  wxRect wndRect;
543  bool bMaximized = false;
544  bool bIconized = false;
545  GetNextWindowPlacement(&wndRect, &bMaximized, &bIconized);
546 
547  // Create and show a NEW project
548  // Use a non-default deleter in the smart pointer!
549  gAudacityProjects.push_back( AProjectHolder {
551  nullptr, -1,
552  wxDefaultPosition,
553  wxSize(wndRect.width, wndRect.height)
554  ),
556  } );
557  const auto p = gAudacityProjects.back().get();
558 
559  // wxGTK3 seems to need to require creating the window using default position
560  // and then manually positioning it.
561  p->SetPosition(wndRect.GetPosition());
562 
563  if(bMaximized) {
564  p->Maximize(true);
565  }
566  else if (bIconized) {
567  // if the user close down and iconized state we could start back up and iconized state
568  // p->Iconize(TRUE);
569  }
570 
571  //Initialise the Listener
572  gAudioIO->SetListener(p);
573 
574  //Set the NEW project as active:
575  SetActiveProject(p);
576 
577  // Okay, GetActiveProject() is ready. Now we can get its CommandManager,
578  // and add the shortcut keys to the tooltips.
579  p->GetToolManager()->RegenerateTooltips();
580 
582 
583  p->Show(true);
584 
585  return p;
586 }
void GetNextWindowPlacement(wxRect *nextRect, bool *pMaximized, bool *pIconized)
Definition: Project.cpp:709
static ModuleManager & Get()
AProjectArray gAudacityProjects
Definition: Project.cpp:295
std::shared_ptr< AudacityProject > AProjectHolder
Definition: Project.h:117
#define safenew
Definition: Audacity.h:223
int Dispatch(ModuleDispatchTypes type)
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:158
AudioIO * gAudioIO
Definition: AudioIO.cpp:481
void SetListener(AudioIOListener *listener)
Definition: AudioIO.cpp:4089
static void SetActiveProject(AudacityProject *project)
Definition: Project.cpp:305
DECLARE_EXPORTED_EVENT_TYPE ( AUDACITY_DLL_API  ,
EVT_CAPTURE_KEY  ,
1 
)

Custom events.

AUDACITY_DLL_API AudacityProject* GetActiveProject ( )

Definition at line 300 of file Project.cpp.

301 {
302  return gActiveProject;
303 }
static AudacityProject * gActiveProject
Definition: Project.cpp:293
void GetDefaultWindowRect ( wxRect *  defRect)

Definition at line 614 of file Project.cpp.

Referenced by GetNextWindowPlacement(), and SaveWindowSize().

615 {
616  *defRect = wxGetClientDisplayRect();
617 
618  int width = 940;
619  int height = 674;
620 
621  //These conditional values assist in improving placement and size
622  //of NEW windows on different platforms.
623 #ifdef __WXGTK__
624  height += 20;
625 #endif
626 
627 #ifdef __WXMSW__
628  height += 40;
629 #endif
630 
631 #ifdef __WXMAC__
632  height += 55;
633 #endif
634 
635  // Use screen size where it is smaller than the values we would like.
636  // Otherwise use the values we would like, and centred.
637  if (width < defRect->width)
638  {
639  defRect->x = (defRect->width - width)/2;
640  defRect->width = width;
641  }
642 
643  if (height < defRect->height)
644  {
645  defRect->y = (defRect->height - height)/2;
646  // Bug 1119 workaround
647  // Small adjustment for very small Mac screens.
648  // If there is only a tiny space at the top
649  // then instead of vertical centre, align to bottom.
650  const int pixelsFormenu = 60;
651  if( defRect->y < pixelsFormenu )
652  defRect->y *=2;
653  defRect->height = height;
654  }
655 }
void GetNextWindowPlacement ( wxRect *  nextRect,
bool *  pMaximized,
bool *  pIconized 
)

Definition at line 709 of file Project.cpp.

References CornersOnScreen(), gAudacityProjects, GetDefaultWindowRect(), gPrefs, IsWindowAccessible(), and ScreenContaining().

Referenced by CreateNewAudacityProject(), and AudacityApp::OnInit().

710 {
711  int inc = 25;
712 
713  wxRect defaultRect;
714  GetDefaultWindowRect(&defaultRect);
715 
716  gPrefs->Read(wxT("/Window/Maximized"), pMaximized, false);
717  gPrefs->Read(wxT("/Window/Iconized"), pIconized, false);
718 
719  wxRect windowRect;
720  gPrefs->Read(wxT("/Window/X"), &windowRect.x, defaultRect.x);
721  gPrefs->Read(wxT("/Window/Y"), &windowRect.y, defaultRect.y);
722  gPrefs->Read(wxT("/Window/Width"), &windowRect.width, defaultRect.width);
723  gPrefs->Read(wxT("/Window/Height"), &windowRect.height, defaultRect.height);
724 
725  wxRect normalRect;
726  gPrefs->Read(wxT("/Window/Normal_X"), &normalRect.x, defaultRect.x);
727  gPrefs->Read(wxT("/Window/Normal_Y"), &normalRect.y, defaultRect.y);
728  gPrefs->Read(wxT("/Window/Normal_Width"), &normalRect.width, defaultRect.width);
729  gPrefs->Read(wxT("/Window/Normal_Height"), &normalRect.height, defaultRect.height);
730 
731  // Workaround 2.1.1 and earlier bug on OSX...affects only normalRect, but let's just
732  // validate for all rects and plats
733  if (normalRect.width == 0 || normalRect.height == 0) {
734  normalRect = defaultRect;
735  }
736  if (windowRect.width == 0 || windowRect.height == 0) {
737  windowRect = defaultRect;
738  }
739 
740 
741  wxRect screenRect( wxGetClientDisplayRect());
742 #if defined(__WXMAC__)
743 
744  // On OSX, the top of the window should never be less than the menu height,
745  // so something is amiss if it is
746  if (normalRect.y < screenRect.y) {
747  normalRect = defaultRect;
748  }
749  if (windowRect.y < screenRect.y) {
750  windowRect = defaultRect;
751  }
752 #endif
753 
754  // IF projects empty, THEN it's the first window.
755  // It lands where the config says it should, and can straddle screen.
756  if (gAudacityProjects.empty()) {
757  if (*pMaximized || *pIconized) {
758  *nextRect = normalRect;
759  }
760  else {
761  *nextRect = windowRect;
762  }
763  // Resize, for example if one monitor that was on is now off.
764  if (!CornersOnScreen( wxRect(*nextRect).Deflate( 32, 32 ))) {
765  *nextRect = defaultRect;
766  }
767  if (!IsWindowAccessible(nextRect)) {
768  *nextRect = defaultRect;
769  }
770  // Do not trim the first project window down.
771  // All corners are on screen (or almost so), and
772  // the rect may straddle screens.
773  return;
774  }
775 
776 
777  // ELSE a subsequent NEW window. It will NOT straddle screens.
778 
779  // We don't mind being 32 pixels off the screen in any direction.
780  // Make sure initial sizes (pretty much) fit within the display bounds
781  // We used to trim the sizes which could result in ridiculously small windows.
782  // contributing to bug 1243.
783  // Now instead if the window significantly doesn't fit the screen, we use the default
784  // window instead, which we know does.
785  if (ScreenContaining( wxRect(normalRect).Deflate( 32, 32 ))<0) {
786  normalRect = defaultRect;
787  }
788  if (ScreenContaining( wxRect(windowRect).Deflate( 32, 32 ) )<0) {
789  windowRect = defaultRect;
790  }
791 
792  bool validWindowSize = false;
793  AudacityProject * validProject = NULL;
794  size_t numProjects = gAudacityProjects.size();
795  for (int i = numProjects; i > 0 ; i--) {
796  if (!gAudacityProjects[i-1]->IsIconized()) {
797  validWindowSize = true;
798  validProject = gAudacityProjects[i-1].get();
799  break;
800  }
801  }
802  if (validWindowSize) {
803  *nextRect = validProject->GetRect();
804  *pMaximized = validProject->IsMaximized();
805  *pIconized = validProject->IsIconized();
806  // Do not straddle screens.
807  if (ScreenContaining( wxRect(*nextRect).Deflate( 32, 32 ) )<0) {
808  *nextRect = defaultRect;
809  }
810  }
811  else {
812  *nextRect = normalRect;
813  }
814 
815  //Placement depends on the increments
816  nextRect->x += inc;
817  nextRect->y += inc;
818 
819  // defaultrect is a rectangle on the first screen. It's the right fallback to
820  // use most of the time if things are not working out right with sizing.
821  // windowRect is a saved rectangle size.
822  // normalRect seems to be a substitute for windowRect when iconized or maximised.
823 
824  // Windows can say that we are off screen when actually we are not.
825  // On Windows 10 I am seeing miscalculation by about 6 pixels.
826  // To fix this we allow some sloppiness on the edge being counted as off screen.
827  // This matters most when restoring very carefully sized windows that are maximised
828  // in one dimension (height or width) but not both.
829  const int edgeSlop = 10;
830 
831  // Next four lines are getting the rectangle for the screen that contains the
832  // top left corner of nextRect (and defaulting to rect of screen 0 otherwise).
833  wxPoint p = nextRect->GetLeftTop();
834  int scr = std::max( 0, wxDisplay::GetFromPoint( p ));
835  wxDisplay d( scr );
836  screenRect = d.GetClientArea();
837 
838  // Now we (possibly) start trimming our rectangle down.
839  // Have we hit the right side of the screen?
840  wxPoint bottomRight = nextRect->GetBottomRight();
841  if (bottomRight.x > (screenRect.GetRight()+edgeSlop)) {
842  int newWidth = screenRect.GetWidth() - nextRect->GetLeft();
843  if (newWidth < defaultRect.GetWidth()) {
844  nextRect->x = windowRect.x;
845  nextRect->y = windowRect.y;
846  nextRect->width = windowRect.width;
847  }
848  else {
849  nextRect->width = newWidth;
850  }
851  }
852 
853  // Have we hit the bottom of the screen?
854  bottomRight = nextRect->GetBottomRight();
855  if (bottomRight.y > (screenRect.GetBottom()+edgeSlop)) {
856  nextRect->y -= inc;
857  bottomRight = nextRect->GetBottomRight();
858  if (bottomRight.y > (screenRect.GetBottom()+edgeSlop)) {
859  nextRect->SetBottom(screenRect.GetBottom());
860  }
861  }
862 
863  // After all that we could have a window that does not have a visible
864  // top bar. [It is unlikely, but something might have gone wrong]
865  // If so, use the safe fallback size.
866  if (!IsWindowAccessible(nextRect)) {
867  *nextRect = defaultRect;
868  }
869 }
AProjectArray gAudacityProjects
Definition: Project.cpp:295
int ScreenContaining(wxRect &r)
Definition: Project.cpp:684
bool IsWindowAccessible(wxRect *requestedRect)
Definition: Project.cpp:658
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:158
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
bool CornersOnScreen(wxRect &r)
Definition: Project.cpp:699
void GetDefaultWindowRect(wxRect *defRect)
Definition: Project.cpp:614
bool IsWindowAccessible ( wxRect *  requestedRect)

Definition at line 658 of file Project.cpp.

References monitor.

Referenced by GetNextWindowPlacement().

659 {
660  wxDisplay display;
661  wxRect targetTitleRect(requestedRect->GetLeftTop(), requestedRect->GetBottomRight());
662  // Hackery to approximate a window top bar size from a window size.
663  // and exclude the open/close and borders.
664  targetTitleRect.x += 15;
665  targetTitleRect.width -= 100;
666  if (targetTitleRect.width < 165) targetTitleRect.width = 165;
667  targetTitleRect.height = 15;
668  int targetBottom = targetTitleRect.GetBottom();
669  int targetRight = targetTitleRect.GetRight();
670  // This looks like overkill to check each and every pixel in the ranges.
671  // and decide that if any is visible on screen we are OK.
672  for (int i = targetTitleRect.GetLeft(); i < targetRight; i++) {
673  for (int j = targetTitleRect.GetTop(); j < targetBottom; j++) {
674  int monitor = display.GetFromPoint(wxPoint(i, j));
675  if (monitor != wxNOT_FOUND) {
676  return TRUE;
677  }
678  }
679  }
680  return FALSE;
681 }
CommandManagerEventMonitor monitor
void RedrawAllProjects ( )

Definition at line 588 of file Project.cpp.

References gAudacityProjects.

Referenced by ToolsToolBar::OnTool().

589 {
590  size_t len = gAudacityProjects.size();
591  for (size_t i = 0; i < len; i++)
592  gAudacityProjects[i]->RedrawProject();
593 }
AProjectArray gAudacityProjects
Definition: Project.cpp:295
void RefreshCursorForAllProjects ( )

Definition at line 595 of file Project.cpp.

References gAudacityProjects.

Referenced by ToolsToolBar::SetCurrentTool().

596 {
597  size_t len = gAudacityProjects.size();
598  for (size_t i = 0; i < len; i++)
599  gAudacityProjects[i]->RefreshCursor();
600 }
AProjectArray gAudacityProjects
Definition: Project.cpp:295

Variable Documentation

const int AudacityProjectTimerID = 5200

Definition at line 49 of file Project.h.

Referenced by AudacityProject::AudacityProject().

AProjectArray gAudacityProjects