Audacity  2.2.2
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
EnvelopeHandle Class Referencefinal

#include <EnvelopeHandle.h>

Inheritance diagram for EnvelopeHandle:
UIHandle

Public Member Functions

 EnvelopeHandle (Envelope *pEnvelope)
 
virtual ~EnvelopeHandle ()
 
EnvelopeGetEnvelope () const
 
void Enter (bool forward) override
 
Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
HitTestPreview Preview (const TrackPanelMouseState &state, const AudacityProject *pProject) override
 
Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
 
Result Cancel (AudacityProject *pProject) override
 
bool StopsOnKeystroke () override
 
- Public Member Functions inherited from UIHandle
virtual ~UIHandle ()=0
 
virtual bool HasRotation () const
 
virtual bool Rotate (bool forward)
 
virtual bool HasEscape () const
 
virtual bool Escape ()
 
virtual void DrawExtras (DrawingPass pass, wxDC *dc, const wxRegion &updateRegion, const wxRect &panelRect)
 
virtual void OnProjectChange (AudacityProject *pProject)
 
Result GetChangeHighlight () const
 
void SetChangeHighlight (Result val)
 

Static Public Member Functions

static UIHandlePtr HitAnywhere (std::weak_ptr< EnvelopeHandle > &holder, Envelope *envelope, bool timeTrack)
 
static UIHandlePtr TimeTrackHitTest (std::weak_ptr< EnvelopeHandle > &holder, const wxMouseState &state, const wxRect &rect, const AudacityProject *pProject, const std::shared_ptr< TimeTrack > &tt)
 
static UIHandlePtr WaveTrackHitTest (std::weak_ptr< EnvelopeHandle > &holder, const wxMouseState &state, const wxRect &rect, const AudacityProject *pProject, const std::shared_ptr< WaveTrack > &wt)
 
- Static Public Member Functions inherited from UIHandle
static UIHandle::Result NeedChangeHighlight (const UIHandle &, const UIHandle &)
 

Private Member Functions

 EnvelopeHandle (const EnvelopeHandle &)=delete
 
EnvelopeHandleoperator= (const EnvelopeHandle &)=delete
 
bool ForwardEventToEnvelopes (const wxMouseEvent &event, const ViewInfo &viewInfo)
 

Static Private Member Functions

static UIHandlePtr HitEnvelope (std::weak_ptr< EnvelopeHandle > &holder, const wxMouseState &state, const wxRect &rect, const AudacityProject *pProject, Envelope *envelope, float zoomMin, float zoomMax, bool dB, float dBRange, bool timeTrack)
 

Private Attributes

wxRect mRect {}
 
bool mLog {}
 
float mLower {}
 
float mUpper {}
 
double mdBRange {}
 
EnvelopemEnvelope {}
 
std::unique_ptr< EnvelopeEditormEnvelopeEditor
 
std::unique_ptr< EnvelopeEditormEnvelopeEditorRight
 
bool mTimeTrack {}
 

Additional Inherited Members

- Public Types inherited from UIHandle
enum  DrawingPass { Cells, Panel }
 
using Result = unsigned
 
using Cell = TrackPanelCell
 
- Protected Attributes inherited from UIHandle
Result mChangeHighlight { 0 }
 

Detailed Description

Definition at line 27 of file EnvelopeHandle.h.

Constructor & Destructor Documentation

EnvelopeHandle::EnvelopeHandle ( const EnvelopeHandle )
privatedelete
EnvelopeHandle::EnvelopeHandle ( Envelope pEnvelope)
explicit

Definition at line 29 of file EnvelopeHandle.cpp.

30  : mEnvelope{ pEnvelope }
31 {
32 }
Envelope * mEnvelope
EnvelopeHandle::~EnvelopeHandle ( )
virtual

Definition at line 41 of file EnvelopeHandle.cpp.

42 {}

Member Function Documentation

UIHandle::Result EnvelopeHandle::Cancel ( AudacityProject pProject)
overridevirtual

Implements UIHandle.

Definition at line 290 of file EnvelopeHandle.cpp.

References mEnvelopeEditor, mEnvelopeEditorRight, RefreshCode::RefreshCell, and AudacityProject::RollbackState().

291 {
292  pProject->RollbackState();
293  mEnvelopeEditor.reset();
294  mEnvelopeEditorRight.reset();
296 }
std::unique_ptr< EnvelopeEditor > mEnvelopeEditor
std::unique_ptr< EnvelopeEditor > mEnvelopeEditorRight
void RollbackState()
Definition: Project.cpp:4742
UIHandle::Result EnvelopeHandle::Click ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 170 of file EnvelopeHandle.cpp.

References RefreshCode::Cancelled, WaveformSettings::dBRange, TrackPanelMouseEvent::event, WaveTrack::GetDisplay(), WaveTrack::GetDisplayBounds(), WaveTrack::GetEnvelopeAtX(), Track::GetLink(), AudacityProject::GetViewInfo(), WaveTrack::GetWaveformSettings(), AudacityProject::IsAudioActive(), WaveformSettings::isLinear(), TrackPanelMouseEvent::pCell, TrackPanelMouseEvent::rect, RefreshCode::RefreshCell, RefreshCode::RefreshNone, Track::Time, Track::Wave, and WaveTrack::Waveform.

171 {
172  using namespace RefreshCode;
173  const bool unsafe = pProject->IsAudioActive();
174  if ( unsafe )
175  return Cancelled;
176 
177  const wxMouseEvent &event = evt.event;
178  const ViewInfo &viewInfo = pProject->GetViewInfo();
179  const auto pTrack = static_cast<Track*>(evt.pCell.get());
180 
181  if (pTrack->GetKind() == Track::Wave) {
182  WaveTrack *const wt = static_cast<WaveTrack*>(pTrack);
183  if (wt->GetDisplay() != WaveTrack::Waveform)
184  return Cancelled;
185 
186  if (!mEnvelope)
187  return Cancelled;
188 
189  mLog = !wt->GetWaveformSettings().isLinear();
193  std::make_unique< EnvelopeEditor >( *mEnvelope, true );
194  mEnvelopeEditorRight.reset();
195 
196  // Assume linked track is wave or null
197  auto partner = static_cast<WaveTrack*>(wt->GetLink());
198  if (partner)
199  {
200  auto clickedEnvelope = partner->GetEnvelopeAtX(event.GetX());
201  if (clickedEnvelope)
203  std::make_unique< EnvelopeEditor >( *clickedEnvelope, true );
204  }
205  }
206  else if (pTrack->GetKind() == Track::Time)
207  {
208  TimeTrack *const tt = static_cast<TimeTrack*>(pTrack);
209  if (!mEnvelope)
210  return Cancelled;
211  GetTimeTrackData( *pProject, *tt, mdBRange, mLog, mLower, mUpper);
213  std::make_unique< EnvelopeEditor >( *mEnvelope, false );
214  mEnvelopeEditorRight.reset();
215  }
216  else
217  return Cancelled;
218 
219  mRect = evt.rect;
220 
221  const bool needUpdate = ForwardEventToEnvelopes(event, viewInfo);
222  return needUpdate ? RefreshCell : RefreshNone;
223 }
std::unique_ptr< EnvelopeEditor > mEnvelopeEditor
std::unique_ptr< EnvelopeEditor > mEnvelopeEditorRight
bool isLinear() const
ViewInfo is used mainly to hold the zooming, selection and scroll information. It also has some statu...
Definition: ViewInfo.h:141
const WaveformSettings & GetWaveformSettings() const
Definition: WaveTrack.cpp:738
Envelope * mEnvelope
Envelope * GetEnvelopeAtX(int xcoord)
Definition: WaveTrack.cpp:2211
bool ForwardEventToEnvelopes(const wxMouseEvent &event, const ViewInfo &viewInfo)
void GetDisplayBounds(float *min, float *max) const
Definition: WaveTrack.cpp:325
A kind of Track used to 'warp time'.
Definition: TimeTrack.h:29
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
bool IsAudioActive() const
Definition: Project.cpp:1454
Track * GetLink() const
Definition: Track.cpp:269
WaveTrackDisplay GetDisplay() const
Definition: WaveTrack.h:593
const ViewInfo & GetViewInfo() const
Definition: Project.h:207
UIHandle::Result EnvelopeHandle::Drag ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 226 of file EnvelopeHandle.cpp.

References RefreshCode::Cancelled, TrackPanelMouseEvent::event, AudacityProject::GetViewInfo(), AudacityProject::IsAudioActive(), RefreshCode::RefreshCell, and RefreshCode::RefreshNone.

227 {
228  using namespace RefreshCode;
229  const wxMouseEvent &event = evt.event;
230  const ViewInfo &viewInfo = pProject->GetViewInfo();
231  const bool unsafe = pProject->IsAudioActive();
232  if (unsafe) {
233  this->Cancel(pProject);
234  return RefreshCell | Cancelled;
235  }
236 
237  const bool needUpdate = ForwardEventToEnvelopes(event, viewInfo);
238  return needUpdate ? RefreshCell : RefreshNone;
239 }
ViewInfo is used mainly to hold the zooming, selection and scroll information. It also has some statu...
Definition: ViewInfo.h:141
Result Cancel(AudacityProject *pProject) override
bool ForwardEventToEnvelopes(const wxMouseEvent &event, const ViewInfo &viewInfo)
bool IsAudioActive() const
Definition: Project.cpp:1454
const ViewInfo & GetViewInfo() const
Definition: Project.h:207
void EnvelopeHandle::Enter ( bool  forward)
overridevirtual

Reimplemented from UIHandle.

Definition at line 34 of file EnvelopeHandle.cpp.

References UIHandle::mChangeHighlight, and RefreshCode::RefreshCell.

35 {
36 #ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
38 #endif
39 }
Result mChangeHighlight
Definition: UIHandle.h:150
bool EnvelopeHandle::ForwardEventToEnvelopes ( const wxMouseEvent &  event,
const ViewInfo viewInfo 
)
private

The Envelope class actually handles things at the mouse event level, so we have to forward the events over. Envelope will then tell us whether or not we need to redraw.

Definition at line 299 of file EnvelopeHandle.cpp.

300 {
304 
305  // AS: I'm not sure why we can't let the Envelope take care of
306  // redrawing itself. ?
307  bool needUpdate =
308  mEnvelopeEditor->MouseEvent(
309  event, mRect, viewInfo, mLog, mdBRange, mLower, mUpper);
310 
312  needUpdate |=
313  mEnvelopeEditorRight->MouseEvent(
314  event, mRect, viewInfo, mLog, mdBRange, mLower, mUpper);
315 
316  return needUpdate;
317 }
std::unique_ptr< EnvelopeEditor > mEnvelopeEditor
std::unique_ptr< EnvelopeEditor > mEnvelopeEditorRight
Envelope* EnvelopeHandle::GetEnvelope ( ) const
inline

Definition at line 56 of file EnvelopeHandle.h.

References mEnvelope.

Referenced by TimeTrack::Draw(), TrackArtist::DrawClipWaveform(), and Envelope::DrawPoints().

56 { return mEnvelope; }
Envelope * mEnvelope
UIHandlePtr EnvelopeHandle::HitAnywhere ( std::weak_ptr< EnvelopeHandle > &  holder,
Envelope envelope,
bool  timeTrack 
)
static

Definition at line 45 of file EnvelopeHandle.cpp.

Referenced by WaveTrack::DetailedHitTest().

46 {
47  auto result = std::make_shared<EnvelopeHandle>( envelope );
48  result->mTimeTrack = timeTrack;
49  return result;
50 }
UIHandlePtr EnvelopeHandle::HitEnvelope ( std::weak_ptr< EnvelopeHandle > &  holder,
const wxMouseState &  state,
const wxRect &  rect,
const AudacityProject pProject,
Envelope envelope,
float  zoomMin,
float  zoomMax,
bool  dB,
float  dBRange,
bool  timeTrack 
)
staticprivate

Definition at line 117 of file EnvelopeHandle.cpp.

References Envelope::GetValue(), AudacityProject::GetViewInfo(), GetWaveYPos(), and ZoomInfo::PositionToTime().

Referenced by TimeTrackHitTest(), and WaveTrackHitTest().

121 {
122  const ViewInfo &viewInfo = pProject->GetViewInfo();
123 
124  const double envValue =
125  envelope->GetValue(viewInfo.PositionToTime(state.m_x, rect.x));
126 
127  // Get y position of envelope point.
128  int yValue = GetWaveYPos(envValue,
129  zoomMin, zoomMax,
130  rect.height, dB, true, dBRange, false) + rect.y;
131 
132  // Get y position of center line
133  int ctr = GetWaveYPos(0.0,
134  zoomMin, zoomMax,
135  rect.height, dB, true, dBRange, false) + rect.y;
136 
137  // Get y distance of mouse from center line (in pixels).
138  int yMouse = abs(ctr - state.m_y);
139  // Get y distance of envelope from center line (in pixels)
140  yValue = abs(ctr - yValue);
141 
142  // JKC: It happens that the envelope is actually drawn offset from its
143  // 'true' position (it is 3 pixels wide). yMisalign is really a fudge
144  // factor to allow us to hit it exactly, but I wouldn't dream of
145  // calling it yFudgeFactor :)
146  const int yMisalign = 2;
147  // Perhaps yTolerance should be put into preferences?
148  const int yTolerance = 5; // how far from envelope we may be and count as a hit.
149  int distance;
150 
151  // For amplification using the envelope we introduced the idea of contours.
152  // The contours have the same shape as the envelope, which may be partially off-screen.
153  // The contours are closer in to the center line.
154  int ContourSpacing = (int)(rect.height / (2 * (zoomMax - zoomMin)));
155  const int MaxContours = 2;
156 
157  // Adding ContourSpacing/2 selects a region either side of the contour.
158  int yDisplace = yValue - yMisalign - yMouse + ContourSpacing / 2;
159  if (yDisplace > (MaxContours * ContourSpacing))
160  return {};
161  // Subtracting the ContourSpacing/2 we added earlier ensures distance is centred on the contour.
162  distance = abs((yDisplace % ContourSpacing) - ContourSpacing / 2);
163  if (distance >= yTolerance)
164  return {};
165 
166  return HitAnywhere(holder, envelope, timeTrack);
167 }
ViewInfo is used mainly to hold the zooming, selection and scroll information. It also has some statu...
Definition: ViewInfo.h:141
double PositionToTime(wxInt64 position, wxInt64 origin=0, bool ignoreFisheye=false) const
Definition: ViewInfo.cpp:49
double GetValue(double t, double sampleDur=0) const
Get envelope value at time t.
Definition: Envelope.cpp:1114
static UIHandlePtr HitAnywhere(std::weak_ptr< EnvelopeHandle > &holder, Envelope *envelope, bool timeTrack)
int GetWaveYPos(float value, float min, float max, int height, bool dB, bool outer, float dBr, bool clip)
const ViewInfo & GetViewInfo() const
Definition: Project.h:207
EnvelopeHandle& EnvelopeHandle::operator= ( const EnvelopeHandle )
privatedelete
HitTestPreview EnvelopeHandle::Preview ( const TrackPanelMouseState state,
const AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 242 of file EnvelopeHandle.cpp.

References _(), AudacityProject::IsAudioActive(), MakeCursor(), and Release().

243 {
244  const bool unsafe = pProject->IsAudioActive();
245  static auto disabledCursor =
246  ::MakeCursor(wxCURSOR_NO_ENTRY, DisabledCursorXpm, 16, 16);
247  static auto envelopeCursor =
248  ::MakeCursor(wxCURSOR_ARROW, EnvCursorXpm, 16, 16);
249 
250  wxString message;
251  if (mTimeTrack)
252  message = _("Click and drag to warp playback time");
253  else
254  message = _("Click and drag to edit the amplitude envelope");
255 
256  return {
257  message,
258  (unsafe
259  ? &*disabledCursor
260  : &*envelopeCursor)
261  };
262 }
bool IsAudioActive() const
Definition: Project.cpp:1454
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:274
UIHandle::Result EnvelopeHandle::Release ( const TrackPanelMouseEvent event,
AudacityProject pProject,
wxWindow *  pParent 
)
overridevirtual

Implements UIHandle.

Definition at line 265 of file EnvelopeHandle.cpp.

References _(), TrackPanelMouseEvent::event, AudacityProject::GetViewInfo(), AudacityProject::IsAudioActive(), AudacityProject::PushState(), RefreshCode::RefreshCell, and RefreshCode::RefreshNone.

Referenced by Preview().

267 {
268  const wxMouseEvent &event = evt.event;
269  const ViewInfo &viewInfo = pProject->GetViewInfo();
270  const bool unsafe = pProject->IsAudioActive();
271  if (unsafe)
272  return this->Cancel(pProject);
273 
274  const bool needUpdate = ForwardEventToEnvelopes(event, viewInfo);
275 
276  pProject->PushState(
277  /* i18n-hint: (verb) Audacity has just adjusted the envelope .*/
278  _("Adjusted envelope."),
279  /* i18n-hint: The envelope is a curve that controls the audio loudness.*/
280  _("Envelope")
281  );
282 
283  mEnvelopeEditor.reset();
284  mEnvelopeEditorRight.reset();
285 
286  using namespace RefreshCode;
287  return needUpdate ? RefreshCell : RefreshNone;
288 }
std::unique_ptr< EnvelopeEditor > mEnvelopeEditor
std::unique_ptr< EnvelopeEditor > mEnvelopeEditorRight
ViewInfo is used mainly to hold the zooming, selection and scroll information. It also has some statu...
Definition: ViewInfo.h:141
Result Cancel(AudacityProject *pProject) override
bool ForwardEventToEnvelopes(const wxMouseEvent &event, const ViewInfo &viewInfo)
bool IsAudioActive() const
Definition: Project.cpp:1454
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void PushState(const wxString &desc, const wxString &shortDesc)
Definition: Project.cpp:4702
const ViewInfo & GetViewInfo() const
Definition: Project.h:207
bool EnvelopeHandle::StopsOnKeystroke ( )
inlineoverridevirtual

Reimplemented from UIHandle.

Definition at line 76 of file EnvelopeHandle.h.

76 { return true; }
UIHandlePtr EnvelopeHandle::TimeTrackHitTest ( std::weak_ptr< EnvelopeHandle > &  holder,
const wxMouseState &  state,
const wxRect &  rect,
const AudacityProject pProject,
const std::shared_ptr< TimeTrack > &  tt 
)
static

Definition at line 70 of file EnvelopeHandle.cpp.

References HitEnvelope().

Referenced by TimeTrack::DetailedHitTest().

73 {
74  auto envelope = tt->GetEnvelope();
75  if (!envelope)
76  return {};
77  bool dB;
78  double dBRange;
79  float zoomMin, zoomMax;
80  GetTimeTrackData( *pProject, *tt, dBRange, dB, zoomMin, zoomMax);
82  (holder, state, rect, pProject, envelope, zoomMin, zoomMax, dB, dBRange,
83  true);
84 }
static UIHandlePtr HitEnvelope(std::weak_ptr< EnvelopeHandle > &holder, const wxMouseState &state, const wxRect &rect, const AudacityProject *pProject, Envelope *envelope, float zoomMin, float zoomMax, bool dB, float dBRange, bool timeTrack)
UIHandlePtr EnvelopeHandle::WaveTrackHitTest ( std::weak_ptr< EnvelopeHandle > &  holder,
const wxMouseState &  state,
const wxRect &  rect,
const AudacityProject pProject,
const std::shared_ptr< WaveTrack > &  wt 
)
static

method that tells us if the mouse event landed on an envelope boundary.

Definition at line 87 of file EnvelopeHandle.cpp.

References HitEnvelope(), and WaveTrack::Waveform.

Referenced by WaveTrack::DetailedHitTest().

90 {
93  Envelope *const envelope = wt->GetEnvelopeAtX(state.GetX());
94 
95  if (!envelope)
96  return {};
97 
98  const int displayType = wt->GetDisplay();
99  // Not an envelope hit, unless we're using a type of wavetrack display
100  // suitable for envelopes operations, ie one of the Wave displays.
101  if (displayType != WaveTrack::Waveform)
102  return {}; // No envelope, not a hit, so return.
103 
104  // Get envelope point, range 0.0 to 1.0
105  const bool dB = !wt->GetWaveformSettings().isLinear();
106 
107  float zoomMin, zoomMax;
108  wt->GetDisplayBounds(&zoomMin, &zoomMax);
109 
110  const float dBRange = wt->GetWaveformSettings().dBRange;
111 
113  (holder, state, rect, pProject, envelope, zoomMin, zoomMax, dB, dBRange, false);
114 }
Draggable curve used in TrackPanel for varying amplification.
Definition: Envelope.h:77
static UIHandlePtr HitEnvelope(std::weak_ptr< EnvelopeHandle > &holder, const wxMouseState &state, const wxRect &rect, const AudacityProject *pProject, Envelope *envelope, float zoomMin, float zoomMax, bool dB, float dBRange, bool timeTrack)

Member Data Documentation

double EnvelopeHandle::mdBRange {}
private

Definition at line 85 of file EnvelopeHandle.h.

Envelope* EnvelopeHandle::mEnvelope {}
private

Definition at line 87 of file EnvelopeHandle.h.

Referenced by GetEnvelope().

std::unique_ptr<EnvelopeEditor> EnvelopeHandle::mEnvelopeEditor
private

Definition at line 88 of file EnvelopeHandle.h.

Referenced by Cancel().

std::unique_ptr<EnvelopeEditor> EnvelopeHandle::mEnvelopeEditorRight
private

Definition at line 89 of file EnvelopeHandle.h.

Referenced by Cancel().

bool EnvelopeHandle::mLog {}
private

Definition at line 83 of file EnvelopeHandle.h.

float EnvelopeHandle::mLower {}
private

Definition at line 84 of file EnvelopeHandle.h.

wxRect EnvelopeHandle::mRect {}
private

Definition at line 82 of file EnvelopeHandle.h.

bool EnvelopeHandle::mTimeTrack {}
private

Definition at line 91 of file EnvelopeHandle.h.

float EnvelopeHandle::mUpper {}
private

Definition at line 84 of file EnvelopeHandle.h.


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