Audacity 3.2.0
CommonTrackView.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5CommonTrackView.cpp
6
7Paul Licameli split from class TrackView
8
9**********************************************************************/
10
11#include "CommonTrackView.h"
12
13#include "BackgroundCell.h"
14#include "TimeShiftHandle.h"
15#include "TrackControls.h"
16#include "ZoomHandle.h"
17#include "../ui/SelectHandle.h"
18#include "AColor.h"
19#include "../../ProjectSettings.h"
20#include "Track.h"
21#include "../../TrackArtist.h"
22#include "../../TrackInfo.h"
23#include "../../TrackPanelDrawingContext.h"
24#include "../../TrackPanelMouseEvent.h"
25
26#include <wx/dc.h>
27#include <wx/graphics.h>
28
29std::vector<UIHandlePtr> CommonTrackView::HitTest
30(const TrackPanelMouseState &st,
31 const AudacityProject *pProject)
32{
33 UIHandlePtr result;
34 using namespace ToolCodes;
35 std::vector<UIHandlePtr> results;
36 const auto &settings = ProjectSettings::Get( *pProject );
37 const auto currentTool = settings.GetTool();
38 const bool isMultiTool = ( currentTool == multiTool );
39
40 // In other tools, let subclasses determine detailed hits.
41 results =
42 DetailedHitTest( st, pProject, currentTool, isMultiTool );
43
44 // There are still some general cases.
45
46 #if 0
47 // Sliding applies in more than one track type.
48 if ( !isMultiTool && currentTool == slideTool ) {
50 mTimeShiftHandle, FindTrack(), false);
51 if (result)
52 results.push_back(result);
53 }
54 #endif
55
56 // Let the multi-tool right-click handler apply only in default of all
57 // other detailed hits.
58 if ( isMultiTool ) {
59 result = ZoomHandle::HitTest(
60 BackgroundCell::Get( *pProject ).mZoomHandle, st.state);
61 if (result)
62 results.push_back(result);
63 }
64
65 // Finally, default of all is adjustment of the selection box.
66 if ( isMultiTool || currentTool == selectTool ) {
67 result = SelectHandle::HitTest(
68 mSelectHandle, st, pProject, shared_from_this() );
69 if (result)
70 results.push_back(result);
71 }
72
73 return results;
74}
75
76std::shared_ptr<TrackPanelCell> CommonTrackView::ContextMenuDelegate()
77{
78 return TrackControls::Get( *FindTrack() ).shared_from_this();
79}
80
82{
83 auto height = TrackInfo::MinimumTrackHeight();
84 const auto pTrack = FindTrack();
85 auto channels = TrackList::Channels(pTrack->SubstituteOriginalTrack().get());
86 auto nChannels = channels.size();
87 auto begin = channels.begin();
88 auto index =
89 std::distance(begin, std::find(begin, channels.end(), pTrack.get()));
90 return (height * (index + 1) / nChannels) - (height * index / nChannels);
91}
92
93#include "Envelope.h"
94#include "ZoomInfo.h"
96 double alignedTime, double sampleDur,
97 double *buffer, int bufferLen, int leftOffset,
98 const ZoomInfo &zoomInfo )
99{
100 // Getting many envelope values, corresponding to pixel columns, which may
101 // not be uniformly spaced in time when there is a fisheye.
102
103 double prevDiscreteTime=0.0, prevSampleVal=0.0, nextSampleVal=0.0;
104 for ( int xx = 0; xx < bufferLen; ++xx ) {
105 auto time = zoomInfo.PositionToTime( xx, -leftOffset );
106 if ( sampleDur <= 0 )
107 // Sample interval not defined (as for time track)
108 buffer[xx] = env.GetValue( time );
109 else {
110 // The level of zoom-in may resolve individual samples.
111 // If so, then instead of evaluating the envelope directly,
112 // we draw a piecewise curve with knees at each sample time.
113 // This actually makes clearer what happens as you drag envelope
114 // points and make discontinuities.
115 auto leftDiscreteTime = alignedTime +
116 sampleDur * floor( ( time - alignedTime ) / sampleDur );
117 if ( xx == 0 || leftDiscreteTime != prevDiscreteTime ) {
118 prevDiscreteTime = leftDiscreteTime;
119 prevSampleVal =
120 env.GetValue( prevDiscreteTime, sampleDur );
121 nextSampleVal =
122 env.GetValue( prevDiscreteTime + sampleDur, sampleDur );
123 }
124 auto ratio = ( time - leftDiscreteTime ) / sampleDur;
125 if ( env.GetExponential() )
126 buffer[ xx ] = exp(
127 ( 1.0 - ratio ) * log( prevSampleVal )
128 + ratio * log( nextSampleVal ) );
129 else
130 buffer[ xx ] =
131 ( 1.0 - ratio ) * prevSampleVal + ratio * nextSampleVal;
132 }
133 }
134}
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
declares abstract base class Track, TrackList, and iterators over TrackList
static Settings & settings()
Definition: TrackInfo.cpp:87
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
static BackgroundCell & Get(AudacityProject &project)
std::weak_ptr< ZoomHandle > mZoomHandle
std::shared_ptr< Track > FindTrack()
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &, const AudacityProject *pProject) final override
std::weak_ptr< TimeShiftHandle > mTimeShiftHandle
virtual int GetMinimizedHeight() const override
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.
std::weak_ptr< SelectHandle > mSelectHandle
virtual std::vector< UIHandlePtr > DetailedHitTest(const TrackPanelMouseState &, const AudacityProject *pProject, int currentTool, bool bMultiTool)=0
std::shared_ptr< TrackPanelCell > ContextMenuDelegate() override
Piecewise linear or piecewise exponential function from double to double.
Definition: Envelope.h:72
double GetValue(double t, double sampleDur=0) const
Get envelope value at time t.
Definition: Envelope.cpp:823
bool GetExponential() const
Definition: Envelope.h:93
static ProjectSettings & Get(AudacityProject &project)
static UIHandlePtr HitTest(std::weak_ptr< SelectHandle > &holder, const TrackPanelMouseState &state, const AudacityProject *pProject, const std::shared_ptr< TrackView > &pTrackView)
static UIHandlePtr HitAnywhere(std::weak_ptr< TimeShiftHandle > &holder, const std::shared_ptr< Track > &pTrack, bool gripHit)
static TrackControls & Get(Track &track)
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1539
static UIHandlePtr HitTest(std::weak_ptr< ZoomHandle > &holder, const wxMouseState &state)
Definition: ZoomHandle.cpp:73
double PositionToTime(wxInt64 position, wxInt64 origin=0, bool ignoreFisheye=false) const
Definition: ZoomInfo.cpp:41
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150
AUDACITY_DLL_API unsigned MinimumTrackHeight()
Definition: TrackInfo.cpp:196