1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-21 15:08:01 +02:00

Make TrackInfo a namespace, not a class...

... Its functions take a pointer to TrackPanel when necessary, just to do the
reparenting of the global slider instances
This commit is contained in:
Paul Licameli 2018-11-04 10:37:27 -05:00
parent b5d4a828d1
commit 38005054f4
2 changed files with 81 additions and 113 deletions

View File

@ -37,19 +37,20 @@
*//*****************************************************************//** *//*****************************************************************//**
\class TrackInfo \namespace TrackInfo
\brief \brief
The TrackInfo is shown to the side of a track Functions for drawing the track control panel, which is shown to the side
of a track
It has the menus, pan and gain controls displayed in it. It has the menus, pan and gain controls displayed in it.
So "Info" is somewhat a misnomer. Should possibly be "TrackControls". So "Info" is somewhat a misnomer. Should possibly be "TrackControls".
In its current implementation TrackInfo is not derived from a It maintains global slider widget instances that are reparented and
wxWindow. Following the original coding style, it has repositioned as needed for drawing and interaction with the user,
been coded as a 'flyweight' class, which is passed interoperating with the custom panel subdivision implemented in CellularPanel
state as needed, except for the array of gains and pans. and avoiding wxWidgets sizers
If we'd instead coded it as a wxWindow, we would have an instance If we'd instead coded it as a wxWindow, we would have an instance
of this class for each instance displayed. of this class for each track displayed.
*//**************************************************************//** *//**************************************************************//**
@ -206,7 +207,6 @@ TrackPanel::TrackPanel(wxWindow * parent, wxWindowID id,
AdornedRulerPanel * ruler) AdornedRulerPanel * ruler)
: CellularPanel(parent, id, pos, size, viewInfo, : CellularPanel(parent, id, pos, size, viewInfo,
wxWANTS_CHARS | wxNO_BORDER), wxWANTS_CHARS | wxNO_BORDER),
mTrackInfo(this),
mListener(listener), mListener(listener),
mTracks(tracks), mTracks(tracks),
mRuler(ruler), mRuler(ruler),
@ -217,6 +217,9 @@ TrackPanel::TrackPanel(wxWindow * parent, wxWindowID id,
#pragma warning( default: 4355 ) #pragma warning( default: 4355 )
#endif #endif
{ {
TrackInfo::ReCreateSliders( this );
TrackInfo::UpdatePrefs( this );
SetLayoutDirection(wxLayout_LeftToRight); SetLayoutDirection(wxLayout_LeftToRight);
SetLabel(_("Track Panel")); SetLabel(_("Track Panel"));
SetName(_("Track Panel")); SetName(_("Track Panel"));
@ -312,14 +315,14 @@ void TrackPanel::UpdatePrefs()
// frequences may have been changed. // frequences may have been changed.
UpdateVRulers(); UpdateVRulers();
mTrackInfo.UpdatePrefs(); TrackInfo::UpdatePrefs( this );
Refresh(); Refresh();
} }
void TrackPanel::ApplyUpdatedTheme() void TrackPanel::ApplyUpdatedTheme()
{ {
mTrackInfo.ReCreateSliders(); TrackInfo::ReCreateSliders( this );
} }
@ -1628,7 +1631,7 @@ void TrackPanel::DrawOutside
int labelw = GetLabelWidth(); int labelw = GetLabelWidth();
int vrul = GetVRulerOffset(); int vrul = GetVRulerOffset();
mTrackInfo.DrawBackground( dc, rect, t->GetSelected(), vrul ); TrackInfo::DrawBackground( dc, rect, t->GetSelected(), vrul );
// Vaughan, 2010-08-24: No longer doing this. // Vaughan, 2010-08-24: No longer doing this.
// Draw sync-lock tiles in ruler area. // Draw sync-lock tiles in ruler area.
@ -2237,24 +2240,27 @@ void TrackPanel::SetFocusedTrack( Track *t )
/********************************************************************** /**********************************************************************
TrackInfo code is destined to move out of this file. TrackInfo code is destined to move out of this file.
Code should become a lot cleaner when we have sizers.
**********************************************************************/ **********************************************************************/
TrackInfo::TrackInfo(TrackPanel * pParentIn) namespace {
{
pParent = pParentIn;
ReCreateSliders(); wxFont gFont;
std::unique_ptr<LWSlider>
gGainCaptured
, gPanCaptured
, gGain
, gPan
#ifdef EXPERIMENTAL_MIDI_OUT
, gVelocityCaptured
, gVelocity
#endif
;
UpdatePrefs();
} }
TrackInfo::~TrackInfo() void TrackInfo::ReCreateSliders( wxWindow *pParent ){
{
}
void TrackInfo::ReCreateSliders(){
const wxPoint point{ 0, 0 }; const wxPoint point{ 0, 0 };
wxRect sliderRect; wxRect sliderRect;
GetGainRect(point, sliderRect); GetGainRect(point, sliderRect);
@ -2307,7 +2313,7 @@ void TrackInfo::ReCreateSliders(){
} }
int TrackInfo::GetTrackInfoWidth() const int TrackInfo::GetTrackInfoWidth()
{ {
return kTrackInfoWidth; return kTrackInfoWidth;
} }
@ -2487,8 +2493,6 @@ void TrackInfo::GetMidiControlsRect(const wxRect & rect, wxRect & dest)
} }
#endif #endif
wxFont TrackInfo::gFont;
/// \todo Probably should move to 'Utils.cpp'. /// \todo Probably should move to 'Utils.cpp'.
void TrackInfo::SetTrackInfoFont(wxDC * dc) void TrackInfo::SetTrackInfoFont(wxDC * dc)
{ {
@ -2552,7 +2556,7 @@ void TrackInfo::DrawBordersWithin
// Paint the whole given rectangle some fill color // Paint the whole given rectangle some fill color
void TrackInfo::DrawBackground( void TrackInfo::DrawBackground(
wxDC * dc, const wxRect & rect, bool bSelected, const int vrul) const wxDC * dc, const wxRect & rect, bool bSelected, const int vrul)
{ {
// fill in label // fill in label
wxRect fill = rect; wxRect fill = rect;
@ -2608,17 +2612,6 @@ unsigned TrackInfo::DefaultWaveTrackHeight()
return DefaultTrackHeight( waveTrackTCPLines ); return DefaultTrackHeight( waveTrackTCPLines );
} }
std::unique_ptr<LWSlider>
TrackInfo::gGainCaptured
, TrackInfo::gPanCaptured
, TrackInfo::gGain
, TrackInfo::gPan
#ifdef EXPERIMENTAL_MIDI_OUT
, TrackInfo::gVelocityCaptured
, TrackInfo::gVelocity
#endif
;
LWSlider * TrackInfo::GainSlider LWSlider * TrackInfo::GainSlider
(const wxRect &sliderRect, const WaveTrack *t, bool captured, wxWindow *pParent) (const wxRect &sliderRect, const WaveTrack *t, bool captured, wxWindow *pParent)
{ {
@ -2669,7 +2662,7 @@ LWSlider * TrackInfo::VelocitySlider
} }
#endif #endif
void TrackInfo::UpdatePrefs() void TrackInfo::UpdatePrefs( wxWindow *pParent )
{ {
// Calculation of best font size depends on language, so it should be redone in case // Calculation of best font size depends on language, so it should be redone in case
// the language preference changed. // the language preference changed.

View File

@ -64,171 +64,152 @@ enum {
}; };
class AUDACITY_DLL_API TrackInfo namespace TrackInfo
{ {
public: void ReCreateSliders( wxWindow *pParent );
TrackInfo(TrackPanel * pParentIn);
~TrackInfo();
void ReCreateSliders();
static unsigned MinimumTrackHeight(); unsigned MinimumTrackHeight();
struct TCPLine; struct TCPLine;
static void DrawItems void DrawItems
( TrackPanelDrawingContext &context, ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track &track ); const wxRect &rect, const Track &track );
static void DrawItems void DrawItems
( TrackPanelDrawingContext &context, ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack, const wxRect &rect, const Track *pTrack,
const std::vector<TCPLine> &topLines, const std::vector<TCPLine> &topLines,
const std::vector<TCPLine> &bottomLines ); const std::vector<TCPLine> &bottomLines );
static void CloseTitleDrawFunction void CloseTitleDrawFunction
( TrackPanelDrawingContext &context, ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack ); const wxRect &rect, const Track *pTrack );
static void MinimizeSyncLockDrawFunction void MinimizeSyncLockDrawFunction
( TrackPanelDrawingContext &context, ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack ); const wxRect &rect, const Track *pTrack );
static void MidiControlsDrawFunction void MidiControlsDrawFunction
( TrackPanelDrawingContext &context, ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack ); const wxRect &rect, const Track *pTrack );
template<typename TrackClass> template<typename TrackClass>
static void SliderDrawFunction void SliderDrawFunction
( LWSlider *(*Selector) ( LWSlider *(*Selector)
(const wxRect &sliderRect, const TrackClass *t, bool captured, (const wxRect &sliderRect, const TrackClass *t, bool captured,
wxWindow*), wxWindow*),
wxDC *dc, const wxRect &rect, const Track *pTrack, wxDC *dc, const wxRect &rect, const Track *pTrack,
bool captured, bool highlight ); bool captured, bool highlight );
static void PanSliderDrawFunction void PanSliderDrawFunction
( TrackPanelDrawingContext &context, ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack ); const wxRect &rect, const Track *pTrack );
static void GainSliderDrawFunction void GainSliderDrawFunction
( TrackPanelDrawingContext &context, ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack ); const wxRect &rect, const Track *pTrack );
#ifdef EXPERIMENTAL_MIDI_OUT #ifdef EXPERIMENTAL_MIDI_OUT
static void VelocitySliderDrawFunction void VelocitySliderDrawFunction
( TrackPanelDrawingContext &context, ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack ); const wxRect &rect, const Track *pTrack );
#endif #endif
static void MuteOrSoloDrawFunction void MuteOrSoloDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, bool down, ( wxDC *dc, const wxRect &rect, const Track *pTrack, bool down,
bool captured, bool solo, bool hit ); bool captured, bool solo, bool hit );
static void WideMuteDrawFunction void WideMuteDrawFunction
( TrackPanelDrawingContext &context, ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack ); const wxRect &rect, const Track *pTrack );
static void WideSoloDrawFunction void WideSoloDrawFunction
( TrackPanelDrawingContext &context, ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack ); const wxRect &rect, const Track *pTrack );
static void MuteAndSoloDrawFunction void MuteAndSoloDrawFunction
( TrackPanelDrawingContext &context, ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack ); const wxRect &rect, const Track *pTrack );
static void StatusDrawFunction void StatusDrawFunction
( const wxString &string, wxDC *dc, const wxRect &rect ); ( const wxString &string, wxDC *dc, const wxRect &rect );
static void Status1DrawFunction void Status1DrawFunction
( TrackPanelDrawingContext &context, ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack ); const wxRect &rect, const Track *pTrack );
static void Status2DrawFunction void Status2DrawFunction
( TrackPanelDrawingContext &context, ( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack ); const wxRect &rect, const Track *pTrack );
public: int GetTrackInfoWidth();
int GetTrackInfoWidth() const; void SetTrackInfoFont(wxDC *dc);
static void SetTrackInfoFont(wxDC *dc);
void DrawBackground( void DrawBackground(
wxDC * dc, const wxRect & rect, bool bSelected, const int vrul ) const; wxDC * dc, const wxRect & rect, bool bSelected, const int vrul );
// void DrawBordersWithin( // void DrawBordersWithin(
// wxDC * dc, const wxRect & rect, const Track &track ) const; // wxDC * dc, const wxRect & rect, const Track &track ) const;
static void GetCloseBoxHorizontalBounds( const wxRect & rect, wxRect &dest ); void GetCloseBoxHorizontalBounds( const wxRect & rect, wxRect &dest );
static void GetCloseBoxRect(const wxRect & rect, wxRect &dest); void GetCloseBoxRect(const wxRect & rect, wxRect &dest);
static void GetTitleBarHorizontalBounds( const wxRect & rect, wxRect &dest ); void GetTitleBarHorizontalBounds( const wxRect & rect, wxRect &dest );
static void GetTitleBarRect(const wxRect & rect, wxRect &dest); void GetTitleBarRect(const wxRect & rect, wxRect &dest);
static void GetNarrowMuteHorizontalBounds void GetNarrowMuteHorizontalBounds
( const wxRect & rect, wxRect &dest ); ( const wxRect & rect, wxRect &dest );
static void GetNarrowSoloHorizontalBounds void GetNarrowSoloHorizontalBounds
( const wxRect & rect, wxRect &dest ); ( const wxRect & rect, wxRect &dest );
static void GetWideMuteSoloHorizontalBounds void GetWideMuteSoloHorizontalBounds
( const wxRect & rect, wxRect &dest ); ( const wxRect & rect, wxRect &dest );
static void GetMuteSoloRect void GetMuteSoloRect
(const wxRect & rect, wxRect &dest, bool solo, bool bHasSoloButton, (const wxRect & rect, wxRect &dest, bool solo, bool bHasSoloButton,
const Track *pTrack); const Track *pTrack);
static void GetSliderHorizontalBounds( const wxPoint &topleft, wxRect &dest ); void GetSliderHorizontalBounds( const wxPoint &topleft, wxRect &dest );
static void GetGainRect(const wxPoint & topLeft, wxRect &dest); void GetGainRect(const wxPoint & topLeft, wxRect &dest);
static void GetPanRect(const wxPoint & topLeft, wxRect &dest); void GetPanRect(const wxPoint & topLeft, wxRect &dest);
#ifdef EXPERIMENTAL_MIDI_OUT #ifdef EXPERIMENTAL_MIDI_OUT
static void GetVelocityRect(const wxPoint & topLeft, wxRect &dest); void GetVelocityRect(const wxPoint & topLeft, wxRect &dest);
#endif #endif
static void GetMinimizeHorizontalBounds( const wxRect &rect, wxRect &dest ); void GetMinimizeHorizontalBounds( const wxRect &rect, wxRect &dest );
static void GetMinimizeRect(const wxRect & rect, wxRect &dest); void GetMinimizeRect(const wxRect & rect, wxRect &dest);
static void GetSyncLockHorizontalBounds( const wxRect &rect, wxRect &dest ); void GetSyncLockHorizontalBounds( const wxRect &rect, wxRect &dest );
static void GetSyncLockIconRect(const wxRect & rect, wxRect &dest); void GetSyncLockIconRect(const wxRect & rect, wxRect &dest);
#ifdef USE_MIDI #ifdef USE_MIDI
static void GetMidiControlsHorizontalBounds void GetMidiControlsHorizontalBounds
( const wxRect &rect, wxRect &dest ); ( const wxRect &rect, wxRect &dest );
static void GetMidiControlsRect(const wxRect & rect, wxRect &dest); void GetMidiControlsRect(const wxRect & rect, wxRect &dest);
#endif #endif
static bool HideTopItem( const wxRect &rect, const wxRect &subRect, bool HideTopItem( const wxRect &rect, const wxRect &subRect,
int allowance = 0 ); int allowance = 0 );
static unsigned DefaultNoteTrackHeight(); unsigned DefaultNoteTrackHeight();
static unsigned DefaultWaveTrackHeight(); unsigned DefaultWaveTrackHeight();
static LWSlider * GainSlider LWSlider * GainSlider
(const wxRect &sliderRect, const WaveTrack *t, bool captured, (const wxRect &sliderRect, const WaveTrack *t, bool captured,
wxWindow *pParent); wxWindow *pParent);
static LWSlider * PanSlider LWSlider * PanSlider
(const wxRect &sliderRect, const WaveTrack *t, bool captured, (const wxRect &sliderRect, const WaveTrack *t, bool captured,
wxWindow *pParent); wxWindow *pParent);
#ifdef EXPERIMENTAL_MIDI_OUT #ifdef EXPERIMENTAL_MIDI_OUT
static LWSlider * VelocitySlider LWSlider * VelocitySlider
(const wxRect &sliderRect, const NoteTrack *t, bool captured, (const wxRect &sliderRect, const NoteTrack *t, bool captured,
wxWindow *pParent); wxWindow *pParent);
#endif #endif
private: void UpdatePrefs( wxWindow *pParent );
void UpdatePrefs();
TrackPanel * pParent;
static wxFont gFont;
// These are on separate lines to work around an MSVC 2013 compiler bug.
static std::unique_ptr<LWSlider> gGainCaptured;
static std::unique_ptr<LWSlider> gPanCaptured;
static std::unique_ptr<LWSlider> gGain;
static std::unique_ptr<LWSlider> gPan;
#ifdef EXPERIMENTAL_MIDI_OUT
static std::unique_ptr<LWSlider> gVelocityCaptured;
static std::unique_ptr<LWSlider> gVelocity;
#endif
friend class TrackPanel;
}; };
@ -341,10 +322,11 @@ protected:
std::shared_ptr<TrackPanelNode> Root() override; std::shared_ptr<TrackPanelNode> Root() override;
int GetVRulerWidth() const; int GetVRulerWidth() const;
int GetVRulerOffset() const { return mTrackInfo.GetTrackInfoWidth(); } int GetVRulerOffset() const { return TrackInfo::GetTrackInfoWidth(); }
public: public:
int GetLabelWidth() const { return mTrackInfo.GetTrackInfoWidth() + GetVRulerWidth(); } int GetLabelWidth() const
{ return TrackInfo::GetTrackInfoWidth() + GetVRulerWidth(); }
// JKC Nov-2011: These four functions only used from within a dll such as mod-track-panel // JKC Nov-2011: These four functions only used from within a dll such as mod-track-panel
// They work around some messy problems with constructors. // They work around some messy problems with constructors.
@ -397,10 +379,6 @@ public:
// Accessors... // Accessors...
static bool HasSoloButton(){ return gSoloPref!=wxT("None");} static bool HasSoloButton(){ return gSoloPref!=wxT("None");}
protected:
TrackInfo mTrackInfo;
public: public:
LWSlider *GainSlider( const WaveTrack *wt ); LWSlider *GainSlider( const WaveTrack *wt );
@ -409,9 +387,6 @@ public:
LWSlider *VelocitySlider( const NoteTrack *nt ); LWSlider *VelocitySlider( const NoteTrack *nt );
#endif #endif
TrackInfo *GetTrackInfo() { return &mTrackInfo; }
const TrackInfo *GetTrackInfo() const { return &mTrackInfo; }
protected: protected:
TrackPanelListener *mListener; TrackPanelListener *mListener;