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 "./commands/CommandFlag.h"
#include "../include/audacity/EffectInterface.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 >
 
typedef wxArrayString PluginIDList
 

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 720 of file Project.h.

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

#define kAudacitySortByTime   (1 << 1)

Definition at line 719 of file Project.h.

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

Typedef Documentation

using AProjectArray = std::vector< AProjectHolder >

Definition at line 120 of file Project.h.

using AProjectHolder = std::shared_ptr< AudacityProject >

Definition at line 119 of file Project.h.

typedef wxArrayString PluginIDList

Definition at line 160 of file Project.h.

Enumeration Type Documentation

enum PlayMode : int
strong
Enumerator
normalPlay 
oneSecondPlay 
loopedPlay 

Definition at line 125 of file Project.h.

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

Definition at line 131 of file Project.h.

Function Documentation

AUDACITY_DLL_API void CloseAllProjects ( )

Definition at line 611 of file Project.cpp.

References gAudacityOffsetInc, gAudacityPosInc, and gAudacityProjects.

612 {
613  size_t len = gAudacityProjects.size();
614  for (size_t i = 0; i < len; i++)
615  gAudacityProjects[i]->Close();
616 
617  //Set the Offset and Position increments to 0
618  gAudacityOffsetInc = 0;
619  gAudacityPosInc = 0;
620 }
static int gAudacityOffsetInc
Definition: Project.cpp:298
AProjectArray gAudacityProjects
Definition: Project.cpp:303
static int gAudacityPosInc
Definition: Project.cpp:299
AudacityProject* CreateNewAudacityProject ( )

Definition at line 549 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().

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

Custom events.

AUDACITY_DLL_API AudacityProject* GetActiveProject ( )

Definition at line 308 of file Project.cpp.

309 {
310  return gActiveProject;
311 }
static AudacityProject * gActiveProject
Definition: Project.cpp:301
void GetDefaultWindowRect ( wxRect *  defRect)

Definition at line 623 of file Project.cpp.

Referenced by GetNextWindowPlacement(), and SaveWindowSize().

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

Definition at line 718 of file Project.cpp.

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

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

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

Definition at line 667 of file Project.cpp.

References monitor.

Referenced by GetNextWindowPlacement().

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

Definition at line 597 of file Project.cpp.

References gAudacityProjects.

Referenced by ToolsToolBar::OnTool().

598 {
599  size_t len = gAudacityProjects.size();
600  for (size_t i = 0; i < len; i++)
601  gAudacityProjects[i]->RedrawProject();
602 }
AProjectArray gAudacityProjects
Definition: Project.cpp:303
void RefreshCursorForAllProjects ( )

Definition at line 604 of file Project.cpp.

References gAudacityProjects.

Referenced by ToolsToolBar::SetCurrentTool().

605 {
606  size_t len = gAudacityProjects.size();
607  for (size_t i = 0; i < len; i++)
608  gAudacityProjects[i]->RefreshCursor();
609 }
AProjectArray gAudacityProjects
Definition: Project.cpp:303

Variable Documentation

const int AudacityProjectTimerID = 5200

Definition at line 49 of file Project.h.

Referenced by AudacityProject::AudacityProject().

AProjectArray gAudacityProjects