Audacity  3.0.3
TimeTrackView.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 TimeTrackView.cpp
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 #include "TimeTrackView.h"
12 #include "../../../TimeTrack.h"
13 
14 #include "TimeTrackControls.h"
15 
17 #include "AColor.h"
18 #include "AllThemeResources.h"
19 #include "../../../Envelope.h"
20 #include "../../../EnvelopeEditor.h"
21 #include "../../../HitTestResult.h"
22 #include "Theme.h"
23 #include "../../../TrackArtist.h"
24 #include "../../../TrackPanelDrawingContext.h"
25 #include "../../../TrackPanelMouseEvent.h"
26 #include "ViewInfo.h"
27 #include "../../../widgets/Ruler.h"
28 
29 #include "../../ui/EnvelopeHandle.h"
30 
31 #include <wx/dc.h>
32 
33 TimeTrackView::TimeTrackView( const std::shared_ptr<Track> &pTrack )
34  : CommonTrackView{ pTrack }
35 {
36 }
37 
39 {
40 }
41 
42 std::vector<UIHandlePtr> TimeTrackView::DetailedHitTest
43 (const TrackPanelMouseState &st,
44  const AudacityProject *pProject, int, bool)
45 {
46  std::vector<UIHandlePtr> results;
48  ( mEnvelopeHandle, st.state, st.rect, pProject,
49  std::static_pointer_cast< TimeTrack >( FindTrack() ) );
50  if (result)
51  results.push_back(result);
52  return results;
53 }
54 
57  return [](TimeTrack &track) {
58  return std::make_shared<TimeTrackView>( track.SharedPointer() );
59  };
60 }
61 
62 std::shared_ptr<TrackVRulerControls> TimeTrackView::DoGetVRulerControls()
63 {
64  return
65  std::make_shared<TimeTrackVRulerControls>( shared_from_this() );
66 }
67 
68 namespace {
70 ( TrackPanelDrawingContext &context, const wxRect & r,
71  const TimeTrack &track, Ruler &ruler )
72 {
73  auto &dc = context.dc;
74  const auto artist = TrackArtist::Get( context );
75  const auto &zoomInfo = *artist->pZoomInfo;
76 
77  bool highlight = false;
78 #ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
79  auto target = dynamic_cast<EnvelopeHandle*>(context.target.get());
80  highlight = target && target->GetEnvelope() == this->GetEnvelope();
81 #endif
82 
83  double min = zoomInfo.PositionToTime(0);
84  double max = zoomInfo.PositionToTime(r.width);
85  if (min > max)
86  {
87  wxASSERT(false);
88  min = max;
89  }
90 
91  AColor::UseThemeColour( &dc, clrUnselected );
92  dc.DrawRectangle(r);
93 
94  //copy this rectangle away for future use.
95  wxRect mid = r;
96 
97  // Draw the Ruler
98  ruler.SetBounds(r.x, r.y, r.x + r.width - 1, r.y + r.height - 1);
99  ruler.SetRange(min, max);
100  ruler.SetFlip(true); // tick marks at top of track.
101  ruler.Invalidate(); // otherwise does not redraw.
102  ruler.SetTickColour( theTheme.Colour( clrTrackPanelText ));
103  ruler.Draw(dc, track.GetEnvelope());
104 
105  Doubles envValues{ size_t(mid.width) };
107  0, 0, envValues.get(), mid.width, 0, zoomInfo );
108 
109  wxPen &pen = highlight ? AColor::uglyPen : AColor::envelopePen;
110  dc.SetPen( pen );
111 
112  auto rangeLower = track.GetRangeLower(), rangeUpper = track.GetRangeUpper();
113  double logLower = log(std::max(1.0e-7, rangeLower)),
114  logUpper = log(std::max(1.0e-7, rangeUpper));
115 
116  for (int x = 0; x < mid.width; x++)
117  {
118  double y;
119  if ( track.GetDisplayLog() )
120  y = (double)mid.height * (logUpper - log(envValues[x])) / (logUpper - logLower);
121  else
122  y = (double)mid.height * (rangeUpper - envValues[x]) / (rangeUpper - rangeLower);
123  int thisy = r.y + (int)y;
124  AColor::Line(dc, mid.x + x, thisy - 1, mid.x + x, thisy+2);
125  }
126 }
127 
129  const TimeTrack &track, Ruler &ruler,
130  const wxRect & rect)
131 {
132  // Ruler and curve...
133  DrawHorzRulerAndCurve( context, rect, track, ruler );
134 
135  // ... then the control points
136  wxRect envRect = rect;
137  envRect.height -= 2;
138  double lower = track.GetRangeLower(), upper = track.GetRangeUpper();
139  const auto artist = TrackArtist::Get( context );
140  const auto dbRange = artist->mdBrange;
141  if(track.GetDisplayLog()) {
142  // MB: silly way to undo the work of GetWaveYPos while still getting a logarithmic scale
143  lower = LINEAR_TO_DB(std::max(1.0e-7, lower)) / dbRange + 1.0;
144  upper = LINEAR_TO_DB(std::max(1.0e-7, upper)) / dbRange + 1.0;
145  }
147  context, envRect,
148  track.GetDisplayLog(), dbRange, lower, upper, false );
149 }
150 }
151 
153  TrackPanelDrawingContext &context,
154  const wxRect &rect, unsigned iPass )
155 {
156  if ( iPass == TrackArtist::PassTracks ) {
157  const auto tt = std::static_pointer_cast<const TimeTrack>(
158  FindTrack()->SubstitutePendingChangedTrack());
159  DrawTimeTrack( context, *tt, tt->GetRuler(), rect );
160  }
161  CommonTrackView::Draw( context, rect, iPass );
162 }
TimeTrackView::Draw
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
Definition: TimeTrackView.cpp:152
AColor::UseThemeColour
static void UseThemeColour(wxDC *dc, int iBrush, int iPen=-1, int alpha=255)
Definition: AColor.cpp:280
TimeTrack::GetRangeLower
double GetRangeLower() const
Definition: TimeTrack.cpp:117
CommonTrackView
Definition: CommonTrackView.h:20
EnvelopeHandle::GetEnvelope
Envelope * GetEnvelope() const
Definition: EnvelopeHandle.h:59
AllThemeResources.h
TimeTrack::GetRangeUpper
double GetRangeUpper() const
Definition: TimeTrack.cpp:122
CommonTrackPanelCell::FindTrack
std::shared_ptr< Track > FindTrack()
Definition: CommonTrackPanelCell.h:46
TrackPanelDrawingContext
Definition: TrackPanelDrawingContext.h:22
AColor::Line
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:109
Ruler::SetTickColour
void SetTickColour(const wxColour &colour)
Definition: Ruler.h:148
Ruler::Draw
void Draw(wxDC &dc) const
Definition: Ruler.cpp:1428
TrackPanelDrawingContext::dc
wxDC & dc
Definition: TrackPanelDrawingContext.h:23
EnvelopeHandle
Definition: EnvelopeHandle.h:28
AColor::envelopePen
static wxPen envelopePen
Definition: AColor.h:104
anonymous_namespace{TimeTrackVRulerControls.cpp}::ruler
Ruler & ruler()
Definition: TimeTrackVRulerControls.cpp:34
TrackPanelMouseState::rect
const wxRect & rect
Definition: TrackPanelMouseEvent.h:39
TimeTrack::GetDisplayLog
bool GetDisplayLog() const
Definition: TimeTrack.h:88
Ruler::SetFlip
void SetFlip(bool flip)
Definition: Ruler.cpp:239
TimeTrackVRulerControls.h
TrackArtist::Get
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:79
Ruler
Used to display a Ruler.
Definition: Ruler.h:26
Theme.h
anonymous_namespace{TimeTrackView.cpp}::DrawTimeTrack
void DrawTimeTrack(TrackPanelDrawingContext &context, const TimeTrack &track, Ruler &ruler, const wxRect &rect)
Definition: TimeTrackView.cpp:128
TimeTrack::GetEnvelope
BoundedEnvelope * GetEnvelope()
Definition: TimeTrack.h:77
TimeTrackView::DetailedHitTest
std::vector< UIHandlePtr > DetailedHitTest(const TrackPanelMouseState &state, const AudacityProject *pProject, int currentTool, bool bMultiTool) override
Definition: TimeTrackView.cpp:43
Ruler::Invalidate
void Invalidate()
Definition: Ruler.cpp:345
Ruler::SetRange
void SetRange(double min, double max)
Definition: Ruler.cpp:188
AColor::uglyPen
static wxPen uglyPen
Definition: AColor.h:130
EnvelopeEditor::DrawPoints
static void DrawPoints(const Envelope &env, TrackPanelDrawingContext &context, const wxRect &r, bool dB, double dBRange, float zoomMin, float zoomMax, bool mirrored)
Definition: EnvelopeEditor.cpp:36
TimeTrackView::TimeTrackView
TimeTrackView(const TimeTrackView &)=delete
TimeTrackView::~TimeTrackView
~TimeTrackView() override
Definition: TimeTrackView.cpp:38
ViewInfo.h
theTheme
THEME_API Theme theTheme
Definition: Theme.cpp:79
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
TimeTrackControls.h
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
Ruler::SetBounds
void SetBounds(int left, int top, int right, int bottom)
Definition: Ruler.cpp:332
TrackPanelMouseState
Definition: TrackPanelMouseEvent.h:28
TrackPanelDrawingContext::target
UIHandlePtr target
Definition: TrackPanelDrawingContext.h:24
ThemeBase::Colour
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1189
TimeTrackView.h
LINEAR_TO_DB
#define LINEAR_TO_DB(x)
Definition: MemoryX.h:631
AttachedVirtualFunction::Override
For defining overrides of the method.
Definition: AttachedVirtualFunction.h:184
EnvelopeHandle::TimeTrackHitTest
static UIHandlePtr TimeTrackHitTest(std::weak_ptr< EnvelopeHandle > &holder, const wxMouseState &state, const wxRect &rect, const AudacityProject *pProject, const std::shared_ptr< TimeTrack > &tt)
Definition: EnvelopeHandle.cpp:71
TrackArtist::PassTracks
@ PassTracks
Definition: TrackArtist.h:81
TimeTrackView::mEnvelopeHandle
std::weak_ptr< EnvelopeHandle > mEnvelopeHandle
Definition: TimeTrackView.h:36
TimeTrackView::DoGetVRulerControls
std::shared_ptr< TrackVRulerControls > DoGetVRulerControls() override
Definition: TimeTrackView.cpp:62
anonymous_namespace{TimeTrackView.cpp}::DrawHorzRulerAndCurve
void DrawHorzRulerAndCurve(TrackPanelDrawingContext &context, const wxRect &r, const TimeTrack &track, Ruler &ruler)
Definition: TimeTrackView.cpp:70
AColor.h
ArrayOf< double >
TimeTrack
A kind of Track used to 'warp time'.
Definition: TimeTrack.h:24
Envelope::GetValues
static void GetValues(const Envelope &env, double aligned_time, double sampleDur, double *buffer, int bufferLen, int leftOffset, const ZoomInfo &zoomInfo)
Get many envelope points for pixel columns at once, but don't assume uniform time per pixel.
Definition: Envelope.cpp:1472
DEFINE_ATTACHED_VIRTUAL_OVERRIDE
DEFINE_ATTACHED_VIRTUAL_OVERRIDE(DoGetTimeTrackView)
Definition: TimeTrackView.cpp:56
TrackPanelMouseState::state
wxMouseState & state
Definition: TrackPanelMouseEvent.h:38
TrackPanelDrawable::Draw
virtual void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
Definition: TrackPanelDrawable.cpp:17