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