Audacity  2.2.0
TrackPanel Class Referencefinal

The TrackPanel class coordinates updates and operations on the main part of the screen which contains multiple tracks. More...

#include <TrackPanel.h>

Inheritance diagram for TrackPanel:
OverlayPanel BackedPanel wxTabTraversalWrapper< Base >


class  AudacityTimer
 Timer class dedicated to infomring the TrackPanel that it is time to refresh some aspect of the screen. More...
struct  FoundCell

Public Member Functions

 TrackPanel (wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const std::shared_ptr< TrackList > &tracks, ViewInfo *viewInfo, TrackPanelListener *listener, AdornedRulerPanel *ruler)
virtual ~TrackPanel ()
< TrackPanelCellIterator
Cells ()
void UpdatePrefs ()
void ApplyUpdatedTheme ()
void OnPaint (wxPaintEvent &event)
void OnMouseEvent (wxMouseEvent &event)
void OnCaptureLost (wxMouseCaptureLostEvent &event)
 Should handle the case when the mouse capture is lost. More...
void OnCaptureKey (wxCommandEvent &event)
void OnKeyDown (wxKeyEvent &event)
void OnChar (wxKeyEvent &event)
void OnKeyUp (wxKeyEvent &event)
void OnSetFocus (wxFocusEvent &event)
void OnKillFocus (wxFocusEvent &event)
void OnContextMenu (wxContextMenuEvent &event)
void OnPlayback (wxCommandEvent &)
void OnTrackListResizing (wxCommandEvent &event)
void OnTrackListDeletion (wxCommandEvent &event)
void UpdateViewIfNoTracks ()
double GetMostRecentXPos ()
void OnIdle (wxIdleEvent &event)
void OnTimer (wxTimerEvent &event)
 AS: This gets called on our wx timer events. More...
int GetLeftOffset () const
void GetTracksUsableArea (int *width, int *height) const
void Refresh (bool eraseBackground=true, const wxRect *rect=(const wxRect *) NULL) override
void RefreshTrack (Track *trk, bool refreshbacking=true)
void DisplaySelection ()
 Displays the bounds of the selection in the status bar. More...
void HandleInterruptedDrag ()
void Uncapture (wxMouseState *pState=nullptr)
bool CancelDragging ()
bool HandleEscapeKey (bool down)
void UpdateMouseState (const wxMouseState &state)
void HandleModifierKey ()
void HandlePageUpKey ()
void HandlePageDownKey ()
AudacityProjectGetProject () const
void ScrollIntoView (double pos)
void ScrollIntoView (int x)
void OnTrackMenu (Track *t=NULL)
TrackGetFirstSelectedTrack ()
bool IsMouseCaptured ()
 Determines if a modal tool is active. More...
void EnsureVisible (Track *t)
TrackGetFocusedTrack ()
void SetFocusedTrack (Track *t)
void HandleCursorForPresentMouseState (bool doHit=true)
void UpdateVRulers ()
void UpdateVRuler (Track *t)
void UpdateTrackVRuler (const Track *t)
void UpdateVRulerSize ()
double GetScreenEndTime () const
size_t GetTrackCount () const
size_t GetSelectedTrackCount () const
void UpdateAccessibility ()
void MessageForScreenReader (const wxString &message)
void HandleWheelRotation (TrackPanelMouseEvent &tpmEvent)
 Handle mouse wheel rotation (for zoom in/out, vertical and horizontal scrolling) More...
void MakeParentRedrawScrollbars ()
const TrackListGetTracks () const
TrackListGetTracks ()
ViewInfoGetViewInfo ()
TrackPanelListenerGetListener ()
AdornedRulerPanelGetRuler ()
void SetBackgroundCell (const std::shared_ptr< TrackPanelCell > &pCell)
std::shared_ptr< TrackPanelCellGetBackgroundCell ()
LWSliderGainSlider (const WaveTrack *wt)
LWSliderPanSlider (const WaveTrack *wt)
TrackInfoGetTrackInfo ()
const TrackInfoGetTrackInfo () const
TrackPanelAxGetAx ()
UIHandlePtr Target ()
- Public Member Functions inherited from OverlayPanel
 OverlayPanel (wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style=wxTAB_TRAVERSAL|wxNO_BORDER)
void AddOverlay (Overlay *pOverlay)
bool RemoveOverlay (Overlay *pOverlay)
void ClearOverlays ()
void DrawOverlays (bool repaint_all, wxDC *pDC=nullptr)
- Public Member Functions inherited from BackedPanel
 BackedPanel (wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style)
 ~BackedPanel ()
wxDC & GetBackingDC ()
wxDC & GetBackingDCForRepaint ()
void ResizeBacking ()
void RepairBitmap (wxDC &dc, wxCoord x, wxCoord y, wxCoord width, wxCoord height)
void DisplayBitmap (wxDC &dc)
void OnSize (wxSizeEvent &event)
- Public Member Functions inherited from wxTabTraversalWrapper< Base >
template<typename... Args>
 wxTabTraversalWrapper (Args &&...args)
 ~wxTabTraversalWrapper ()

Static Public Member Functions

static bool HasSoloButton ()

Public Attributes

wxSize vrulerSize

Static Public Attributes

static TrackPanel *(* FactoryFunction )(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const std::shared_ptr< TrackList > &tracks, ViewInfo *viewInfo, TrackPanelListener *listener, AdornedRulerPanel *ruler) = TrackPanelFactory

Protected Member Functions

bool IsAudioActive ()
void HandleClick (const TrackPanelMouseEvent &tpmEvent)
void UpdateSelectionDisplay ()
void MakeParentModifyState (bool bWantsAutoSave)
FoundCell FindCell (int mouseX, int mouseY)
void HandleMotion (wxMouseState &state, bool doHit=true)
void HandleMotion (const TrackPanelMouseState &tpmState, bool doHit=true)
wxRect FindTrackRect (const Track *target, bool label)
int GetVRulerWidth () const
int GetVRulerOffset () const
int GetLabelWidth () const
void DrawTracks (wxDC *dc)
void DrawEverythingElse (TrackPanelDrawingContext &context, const wxRegion &region, const wxRect &clip)
void DrawOutside (TrackPanelDrawingContext &context, Track *t, const wxRect &rec)
void HighlightFocusedTrack (wxDC *dc, const wxRect &rect)
 Draw a three-level highlight gradient around the focused track. More...
void DrawShadow (Track *t, wxDC *dc, const wxRect &rect)
void DrawBordersAroundTrack (Track *t, wxDC *dc, const wxRect &rect, const int labelw, const int vrul)
void DrawOutsideOfTrack (TrackPanelDrawingContext &context, Track *t, const wxRect &rect)
void ClearTargets ()
bool HasRotation ()
bool HasEscape ()
bool ChangeTarget (bool forward, bool cycle)

Protected Attributes

TrackInfo mTrackInfo
std::shared_ptr< TrackListmTracks
std::unique_ptr< TrackArtistmTrackArtist
TrackPanel::AudacityTimer mTimer
int mTimeCount
bool mRefreshBacking
bool mRedrawAfterStop
wxMouseState mLastMouseState
int mMouseMostRecentX
int mMouseMostRecentY
std::unique_ptr< TrackPanelAxmAx
SelectedRegion mLastDrawnSelectedRegion {}
std::weak_ptr< TrackPanelCellmLastCell
std::vector< UIHandlePtrmTargets
size_t mTarget {}
unsigned mMouseOverUpdateFlags {}
std::weak_ptr< TrackmpClickedTrack
UIHandlePtr mUIHandle
std::shared_ptr< TrackPanelCellmpBackground
bool mEnableTab {}

Static Protected Attributes

static wxString gSoloPref


class TrackPanelAx
class ScreenshotCommand

Detailed Description

The TrackPanel class coordinates updates and operations on the main part of the screen which contains multiple tracks.

It uses many other classes, but in particular it uses the TrackInfo class to draw the controls area on the left of a track, and the TrackArtist class to draw the actual waveforms.

Note that in some of the older code here, e.g., GetLabelWidth(), "Label" means the TrackInfo plus the vertical ruler. Confusing relative to LabelTrack labels.

The TrackPanel manages multiple tracks and their TrackInfos.

Note that with stereo tracks there will be one TrackInfo being used by two wavetracks.

Constructor & Destructor Documentation

TrackPanel::TrackPanel ( wxWindow *  parent,
wxWindowID  id,
const wxPoint &  pos,
const wxSize &  size,
const std::shared_ptr< TrackList > &  tracks,
ViewInfo viewInfo,
TrackPanelListener listener,
AdornedRulerPanel ruler 
TrackPanel::~TrackPanel ( )

Member Function Documentation

void TrackPanel::ApplyUpdatedTheme ( )
IteratorRange< TrackPanelCellIterator > TrackPanel::Cells ( )

Referenced by FindCell().

bool TrackPanel::ChangeTarget ( bool  forward,
bool  cycle 

References IsMouseCaptured(), mTarget, mTargets, and Target().

Referenced by HandleEscapeKey(), and OnKeyDown().

void TrackPanel::ClearTargets ( )
void TrackPanel::DisplaySelection ( )

Displays the bounds of the selection in the status bar.

References mListener, and TrackPanelListener::TP_DisplaySelection().

Referenced by OnTimer(), Refresh(), and UpdateSelectionDisplay().

void TrackPanel::DrawBordersAroundTrack ( Track t,
wxDC *  dc,
const wxRect &  rect,
const int  labelw,
const int  vrul 
void TrackPanel::DrawEverythingElse ( TrackPanelDrawingContext context,
const wxRegion &  region,
const wxRect &  clip 
void TrackPanel::DrawOutsideOfTrack ( TrackPanelDrawingContext context,
Track t,
const wxRect &  rect 
void TrackPanel::DrawShadow ( Track t,
wxDC *  dc,
const wxRect &  rect 

References AColor::Dark(), and AColor::Line().

void TrackPanel::DrawTracks ( wxDC *  dc)

Draw the actual track areas. We only draw the borders and the little buttons and menues and whatnot here, the actual contents of each track are drawn by the TrackArtist.

References DrawEverythingElse(), drawTool, envelopeTool, AudacityProject::GetFirstVisible(), GetLabelWidth(), GetProject(), GetTracks(), ToolsToolBar::IsDown(), mLastMouseState, mListener, mTrackArtist, multiTool, mViewInfo, ViewInfo::selectedRegion, Target(), TrackPanelListener::TP_GetToolsToolBar(), and ZoomInfo::vpos.

Referenced by OnPaint().

TrackPanel::FoundCell TrackPanel::FindCell ( int  mouseX,
int  mouseY 

Determines which cell is under the mouse

mouseX- mouse X position.
mouseY- mouse Y position.

References Cells().

Referenced by HandleMotion(), and OnMouseEvent().

TrackPanelAx& TrackPanel::GetAx ( )
std::shared_ptr< TrackPanelCell > TrackPanel::GetBackgroundCell ( )
int TrackPanel::GetLabelWidth ( ) const

Referenced by DrawTracks(), and GetMostRecentXPos().

TrackPanelListener* TrackPanel::GetListener ( )
AudacityProject * TrackPanel::GetProject ( ) const
AdornedRulerPanel* TrackPanel::GetRuler ( )
size_t TrackPanel::GetSelectedTrackCount ( ) const
size_t TrackPanel::GetTrackCount ( ) const
TrackInfo* TrackPanel::GetTrackInfo ( )
const TrackInfo* TrackPanel::GetTrackInfo ( ) const
TrackList* TrackPanel::GetTracks ( )
ViewInfo* TrackPanel::GetViewInfo ( )
int TrackPanel::GetVRulerOffset ( ) const
int TrackPanel::GetVRulerWidth ( ) const

References vrulerSize.

Referenced by DrawEverythingElse(), and UpdateTrackVRuler().

void TrackPanel::HandleCursorForPresentMouseState ( bool  doHit = true)
bool TrackPanel::HandleEscapeKey ( bool  down)
void TrackPanel::HandleInterruptedDrag ( )

References mUIHandle.

Referenced by OnCaptureKey().

void TrackPanel::HandleModifierKey ( )

References HandleCursorForPresentMouseState().

Referenced by OnKeyDown(), and OnKeyUp().

void TrackPanel::HandleMotion ( wxMouseState &  inState,
bool  doHit = true 

TrackPanel::HandleMotion( ) sets the cursor drawn at the mouse location, and updates the status bar message. We treat certain other changes of mouse button and key state as "motions" too, and also starting and stopping of playback or recording, all of which may cause the appropriate cursor and message to change. As this procedure checks which region the mouse is over, it is appropriate to establish the message in the status bar.

References FindCell(), mLastMouseState, and UpdateMouseState().

Referenced by HandleClick(), HandleCursorForPresentMouseState(), OnMouseEvent(), and Uncapture().

void TrackPanel::HandleMotion ( const TrackPanelMouseState tpmState,
bool  doHit = true 
void TrackPanel::HandlePageDownKey ( )
void TrackPanel::HandlePageUpKey ( )
void TrackPanel::HandleWheelRotation ( TrackPanelMouseEvent tpmEvent)

Handle mouse wheel rotation (for zoom in/out, vertical and horizontal scrolling)

References TrackPanelMouseEvent::event, GetProject(), mRuler, TrackPanelMouseEvent::pCell, and TrackPanelMouseEvent::steps.

Referenced by OnMouseEvent().

bool TrackPanel::HasEscape ( )
bool TrackPanel::HasRotation ( )

References mTargets, and Target().

Referenced by OnCaptureKey(), and OnKeyDown().

static bool TrackPanel::HasSoloButton ( )
void TrackPanel::HighlightFocusedTrack ( wxDC *  dc,
const wxRect &  rect 

Draw a three-level highlight gradient around the focused track.

References kLeftInset, kTopInset, and AColor::TrackFocusPen().

Referenced by DrawEverythingElse().

bool TrackPanel::IsAudioActive ( )

References GetProject(), and AudacityProject::IsAudioActive().

Referenced by OnTimer().

bool TrackPanel::IsMouseCaptured ( )

Determines if a modal tool is active.

References mUIHandle.

Referenced by ChangeTarget(), HasEscape(), OnMouseEvent(), AudacityProject::OnRedo(), and AudacityProject::OnUndo().

void TrackPanel::MakeParentModifyState ( bool  bWantsAutoSave)
void TrackPanel::MakeParentRedrawScrollbars ( )
void TrackPanel::MessageForScreenReader ( const wxString &  message)
void TrackPanel::OnCaptureKey ( wxCommandEvent &  event)
void TrackPanel::OnCaptureLost ( wxMouseCaptureLostEvent &  event)

Should handle the case when the mouse capture is lost.

References ClearTargets(), mMouseMostRecentX, mMouseMostRecentY, and OnMouseEvent().

void TrackPanel::OnChar ( wxKeyEvent &  event)

References GetFocusedTrack(), mRuler, and mViewInfo.

void TrackPanel::OnContextMenu ( wxContextMenuEvent &  event)

References OnTrackMenu().

void TrackPanel::OnIdle ( wxIdleEvent &  event)

References GetProject(), kTimerInterval, and mTimer.

Referenced by TrackPanel().

void TrackPanel::OnKeyUp ( wxKeyEvent &  event)
void TrackPanel::OnKillFocus ( wxFocusEvent &  event)
void TrackPanel::OnMouseEvent ( wxMouseEvent &  event)
void TrackPanel::OnPaint ( wxPaintEvent &  event)
void TrackPanel::OnPlayback ( wxCommandEvent &  e)
void TrackPanel::OnSetFocus ( wxFocusEvent &  event)
void TrackPanel::OnTrackListDeletion ( wxCommandEvent &  event)
void TrackPanel::OnTrackListResizing ( wxCommandEvent &  event)

References UpdateVRuler().

Referenced by TrackPanel(), and ~TrackPanel().

void TrackPanel::OnTrackMenu ( Track t = NULL)
void TrackPanel::Refresh ( bool  eraseBackground = true,
const wxRect *  rect = (const wxRect *) NULL 

This method overrides Refresh() of wxWindow so that the boolean play indictaor can be set to false, so that an old play indicator that is no longer there won't get XORed (to erase it), thus redrawing it on the TrackPanel

References DisplaySelection(), and mRefreshBacking.

Referenced by AudacityProject::AS_ModifySelection(), AudacityProject::AS_SetSelectionFormat(), WaveformPrefs::Commit(), AudacityProject::DoNextPeakFrequency(), AudacityProject::DoScroll(), AudacityProject::DoTrackMute(), AudacityProject::DoTrackSolo(), EnsureVisible(), AudacityProject::FixScrollbars(), AudacityProject::MoveTrack(), AudacityProject::OnBoundaryMove(), AudacityProject::OnCopy(), AudacityProject::OnCopyLabels(), AudacityProject::OnCursorClipBoundary(), AudacityProject::OnCursorSelEnd(), AudacityProject::OnCursorSelStart(), AudacityProject::OnCursorTrackEnd(), AudacityProject::OnCursorTrackStart(), AudacityProject::OnCut(), AudacityProject::OnEffect(), OnKillFocus(), AudacityProject::OnNextTool(), AudacityProject::OnODTaskComplete(), AudacityProject::OnODTaskUpdate(), AudacityProject::OnPrevTool(), AudacityProject::OnRemoveTracks(), AudacityProject::OnSelectClip(), AudacityProject::OnSelectClipBoundary(), AudacityProject::OnSelectCursorEnd(), AudacityProject::OnSelectCursorStoredCursor(), AudacityProject::OnSelectionRestore(), AudacityProject::OnSelectStartCursor(), AudacityProject::OnSelectSyncLockSel(), AudacityProject::OnSelectTimeAndTracks(), OnSetFocus(), AudacityProject::OnSetLeftSelection(), AudacityProject::OnSetRightSelection(), AudacityProject::OnShowClipping(), AudacityProject::OnSilence(), AudacityProject::OnSilenceLabels(), AudacityProject::OnSortName(), AudacityProject::OnSortTime(), AudacityProject::OnSplit(), AudacityProject::OnSyncLock(), OnTimer(), AudacityProject::PlaybackScroller::OnTimer(), SelectHandle::TimerHandler::OnTimer(), AudacityProject::OnToggleSpectralSelection(), AudacityProject::OnTrackClose(), AudacityProject::OnTrackMoveBottom(), AudacityProject::OnTrackMoveDown(), AudacityProject::OnTrackMoveTop(), AudacityProject::OnTrackMoveUp(), AudacityProject::OnZeroCrossing(), AudacityProject::OnZoomNormal(), AudacityProject::OpenFile(), SpectrumPrefs::Preview(), AudacityProject::RedrawProject(), RefreshTrack(), AudacityProject::RemoveTrack(), SpectrumPrefs::Rollback(), ScrollIntoView(), AudacityProject::SelectNone(), SetFocusedTrack(), AudacityProject::SetStateTo(), AudacityProject::SetSyncLock(), AudacityProject::SetTool(), AudacityProject::SkipEnd(), AudacityProject::SSBL_ModifySpectralSelection(), UpdatePrefs(), UpdateSelectionDisplay(), UpdateVRulerSize(), and AudacityProject::ZoomInByFactor().

void TrackPanel::ScrollIntoView ( int  x)
void TrackPanel::SetBackgroundCell ( const std::shared_ptr< TrackPanelCell > &  pCell)
void TrackPanel::Uncapture ( wxMouseState *  pState = nullptr)

References HandleMotion().

Referenced by CancelDragging(), and OnMouseEvent().

void TrackPanel::UpdateAccessibility ( )
void TrackPanel::UpdateMouseState ( const wxMouseState &  state)

References mLastMouseState.

Referenced by HandleMotion(), and OnMouseEvent().

void TrackPanel::UpdateSelectionDisplay ( )
void TrackPanel::UpdateTrackVRuler ( const Track t)
void TrackPanel::UpdateVRuler ( Track t)

Friends And Related Function Documentation

friend class ScreenshotCommand
friend class TrackPanelAx

Member Data Documentation

TrackPanel *(* TrackPanel::FactoryFunction)(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const std::shared_ptr< TrackList > &tracks, ViewInfo *viewInfo, TrackPanelListener *listener, AdornedRulerPanel *ruler) = TrackPanelFactory
wxString TrackPanel::gSoloPref

Referenced by UpdatePrefs().

bool TrackPanel::mEnableTab {}

Referenced by OnCaptureKey(), and OnKeyDown().

std::weak_ptr<TrackPanelCell> TrackPanel::mLastCell
SelectedRegion TrackPanel::mLastDrawnSelectedRegion {}

Referenced by OnPaint(), and OnTimer().

wxMouseState TrackPanel::mLastMouseState
int TrackPanel::mMouseMostRecentX
int TrackPanel::mMouseMostRecentY

Referenced by OnCaptureLost(), and OnMouseEvent().

unsigned TrackPanel::mMouseOverUpdateFlags {}
std::shared_ptr<TrackPanelCell> TrackPanel::mpBackground

Referenced by GetBackgroundCell().

std::weak_ptr<Track> TrackPanel::mpClickedTrack
bool TrackPanel::mRedrawAfterStop

Referenced by OnTimer(), and TrackPanel().

bool TrackPanel::mRefreshBacking
size_t TrackPanel::mTarget {}

Referenced by ChangeTarget(), and HasEscape().

std::vector<UIHandlePtr> TrackPanel::mTargets
int TrackPanel::mTimeCount

Referenced by OnTimer(), and TrackPanel().

TrackPanel::AudacityTimer TrackPanel::mTimer
std::unique_ptr<TrackArtist> TrackPanel::mTrackArtist
TrackInfo TrackPanel::mTrackInfo

Referenced by ApplyUpdatedTheme(), and UpdatePrefs().

std::shared_ptr<TrackList> TrackPanel::mTracks
wxSize TrackPanel::vrulerSize

Referenced by GetVRulerWidth(), and UpdateVRulerSize().

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