Audacity  2.2.2
Public Member Functions | Private Member Functions | Private Attributes | List of all members
EnvelopeEditor Class Reference

#include <Envelope.h>

Public Member Functions

 EnvelopeEditor (Envelope &envelope, bool mirrored)
 
 ~EnvelopeEditor ()
 
bool MouseEvent (const wxMouseEvent &event, wxRect &r, const ZoomInfo &zoomInfo, bool dB, double dBRange, float zoomMin=-1.0, float zoomMax=1.0)
 

Private Member Functions

bool HandleMouseButtonDown (const wxMouseEvent &event, wxRect &r, const ZoomInfo &zoomInfo, bool dB, double dBRange, float zoomMin=-1.0, float zoomMax=1.0)
 
bool HandleDragging (const wxMouseEvent &event, wxRect &r, const ZoomInfo &zoomInfo, bool dB, double dBRange, float zoomMin=-1.0, float zoomMax=1.0, float eMin=0., float eMax=2.)
 
bool HandleMouseButtonUp ()
 
float ValueOfPixel (int y, int height, bool upper, bool dB, double dBRange, float zoomMin, float zoomMax)
 
void MoveDragPoint (const wxMouseEvent &event, wxRect &r, const ZoomInfo &zoomInfo, bool dB, double dBRange, float zoomMin, float zoomMax)
 

Private Attributes

EnvelopemEnvelope
 
const bool mMirrored
 
int mContourOffset
 Number of pixels contour is from the true envelope. More...
 
bool mUpper
 
int mButton
 
bool mDirty
 

Detailed Description

Definition at line 287 of file Envelope.h.

Constructor & Destructor Documentation

EnvelopeEditor::EnvelopeEditor ( Envelope envelope,
bool  mirrored 
)

Definition at line 1799 of file Envelope.cpp.

1800  : mEnvelope(envelope)
1801  , mMirrored(mirrored)
1802  , mContourOffset(-1)
1803  // , mInitialVal(-1.0)
1804  // , mInitialY(-1)
1805  , mUpper(false)
1806  , mButton(wxMOUSE_BTN_NONE)
1807  , mDirty(false)
1808 {
1809 }
const bool mMirrored
Definition: Envelope.h:317
Envelope & mEnvelope
Definition: Envelope.h:316
int mContourOffset
Number of pixels contour is from the true envelope.
Definition: Envelope.h:320
EnvelopeEditor::~EnvelopeEditor ( )

Definition at line 1811 of file Envelope.cpp.

1812 {
1813 }

Member Function Documentation

bool EnvelopeEditor::HandleDragging ( const wxMouseEvent &  event,
wxRect &  r,
const ZoomInfo zoomInfo,
bool  dB,
double  dBRange,
float  zoomMin = -1.0,
float  zoomMax = 1.0,
float  eMin = 0.,
float  eMax = 2. 
)
private

Definition at line 613 of file Envelope.cpp.

References Envelope::GetDragPointValid(), mDirty, mEnvelope, MoveDragPoint(), and Envelope::SetDragPointValid().

Referenced by MouseEvent().

617 {
618  mDirty = true;
619 
620  wxRect larger = r;
621  larger.Inflate(10, 10);
622 
623  if (larger.Contains(event.m_x, event.m_y))
624  {
625  // IF we're in the rect THEN we're not deleting this point (anymore).
626  // ...we're dragging it.
627  MoveDragPoint( event, r, zoomInfo, dB, dBRange, zoomMin, zoomMax);
628  return true;
629  }
630 
632  // IF we already know we're deleting THEN no envelope point to update.
633  return false;
634 
635  // Invalidate the point
637  return true;
638 }
void SetDragPointValid(bool valid)
Definition: Envelope.cpp:149
Envelope & mEnvelope
Definition: Envelope.h:316
void MoveDragPoint(const wxMouseEvent &event, wxRect &r, const ZoomInfo &zoomInfo, bool dB, double dBRange, float zoomMin, float zoomMax)
Definition: Envelope.cpp:594
bool GetDragPointValid() const
Definition: Envelope.h:236
bool EnvelopeEditor::HandleMouseButtonDown ( const wxMouseEvent &  event,
wxRect &  r,
const ZoomInfo zoomInfo,
bool  dB,
double  dBRange,
float  zoomMin = -1.0,
float  zoomMax = 1.0 
)
private

HandleMouseButtonDown either finds an existing control point or adds a NEW one which is then recorded as the point to drag. This is slightly complicated by there possibly being four control points for a given time value: We have an upper and lower envelope line. Also we may be showing an inner envelope (at 0.5 the range).

Definition at line 478 of file Envelope.cpp.

References Envelope::GetNumberOfPoints(), Envelope::GetOffset(), Envelope::GetValue(), GetWaveYPos(), Envelope::InsertOrReplace(), mButton, mContourOffset, mDirty, mEnvelope, mMirrored, mUpper, ZoomInfo::PositionToTime(), Envelope::SetDragPoint(), ZoomInfo::TimeToPosition(), and ValueOfPixel().

Referenced by MouseEvent().

482 {
483  int ctr = (int)(r.height * zoomMax / (zoomMax - zoomMin));
484  bool upper = !mMirrored || (zoomMin >= 0.0) || (event.m_y - r.y < ctr);
485 
486  int clip_y = event.m_y - r.y;
487  if(clip_y < 0) clip_y = 0; //keeps point in rect r, even if mouse isn't
488  if(clip_y > r.GetBottom()) clip_y = r.GetBottom();
489 
490  int bestNum = -1;
491  int bestDistSqr = 100; // Must be within 10 pixel radius.
492 
493  // Member variables hold state that will be needed in dragging.
494  mButton = event.GetButton();
495  mContourOffset = false;
496 
497  // wxLogDebug(wxT("Y:%i Height:%i Offset:%i"), y, height, mContourOffset );
498  int len = mEnvelope.GetNumberOfPoints();
499 
500  // TODO: extract this into a function FindNearestControlPoint()
501  // TODO: also fix it so that we can drag the last point on an envelope.
502  for (int i = 0; i < len; i++) { //search for control point nearest click
503  const double time = mEnvelope[i].GetT() + mEnvelope.GetOffset();
504  const wxInt64 position = zoomInfo.TimeToPosition(time);
505  if (position >= 0 && position < r.width) {
506 
507  int x = (int)(position);
508  int y[4];
509  int numControlPoints;
510 
511  // Outer control points
512  double value = mEnvelope[i].GetVal();
513  y[0] = GetWaveYPos(value, zoomMin, zoomMax, r.height,
514  dB, true, dBRange, false);
515  y[1] = GetWaveYPos(-value, zoomMin, zoomMax, r.height,
516  dB, true, dBRange, false);
517 
518  // Inner control points(contour)
519  y[2] = GetWaveYPos(value, zoomMin, zoomMax, r.height,
520  dB, false, dBRange, false);
521  y[3] = GetWaveYPos(-value -.00000001, zoomMin, zoomMax,
522  r.height, dB, false, dBRange, false);
523 
524  numControlPoints = 4;
525 
526  if (y[2] > y[3])
527  numControlPoints = 2;
528 
529  if (!mMirrored)
530  numControlPoints = 1;
531 
532  const int deltaXSquared = SQR(x - (event.m_x - r.x));
533  for(int j=0; j<numControlPoints; j++){
534 
535  const int dSqr = deltaXSquared + SQR(y[j] - (event.m_y - r.y));
536  if (dSqr < bestDistSqr) {
537  bestNum = i;
538  bestDistSqr = dSqr;
539  mContourOffset = (bool)(j > 1);
540  }
541  }
542  }
543  }
544 
545  if (bestNum >= 0) {
546  mEnvelope.SetDragPoint(bestNum);
547  }
548  else {
549  // TODO: Extract this into a function CreateNewPoint
550  const double when = zoomInfo.PositionToTime(event.m_x, r.x);
551 
552  // if (when <= 0 || when >= mTrackLen)
553  // return false;
554 
555  const double v = mEnvelope.GetValue( when );
556 
557  int ct = GetWaveYPos( v, zoomMin, zoomMax, r.height, dB,
558  false, dBRange, false) ;
559  int cb = GetWaveYPos( -v-.000000001, zoomMin, zoomMax, r.height, dB,
560  false, dBRange, false) ;
561  if (ct <= cb || !mMirrored) {
562  int t = GetWaveYPos( v, zoomMin, zoomMax, r.height, dB,
563  true, dBRange, false) ;
564  int b = GetWaveYPos( -v, zoomMin, zoomMax, r.height, dB,
565  true, dBRange, false) ;
566 
567  ct = (t + ct) / 2;
568  cb = (b + cb) / 2;
569 
570  if (mMirrored &&
571  (event.m_y - r.y) > ct &&
572  ((event.m_y - r.y) < cb))
573  mContourOffset = true;
574  else
575  mContourOffset = false;
576  }
577 
578  double newVal = ValueOfPixel(clip_y, r.height, upper, dB, dBRange,
579  zoomMin, zoomMax);
580 
582  mDirty = true;
583  }
584 
585  mUpper = upper;
586 
587  // const int dragPoint = mEnvelope.GetDragPoint();
588  // mInitialVal = mEnvelope[dragPoint].GetVal();
589  // mInitialY = event.m_y+mContourOffset;
590 
591  return true;
592 }
const bool mMirrored
Definition: Envelope.h:317
size_t GetNumberOfPoints() const
Return number of points.
Definition: Envelope.cpp:980
double PositionToTime(wxInt64 position, wxInt64 origin=0, bool ignoreFisheye=false) const
Definition: ViewInfo.cpp:49
void SetDragPoint(int dragPoint)
Definition: Envelope.cpp:143
Envelope & mEnvelope
Definition: Envelope.h:316
int InsertOrReplace(double when, double value)
Add a point at a particular absolute time coordinate.
Definition: Envelope.h:194
int mContourOffset
Number of pixels contour is from the true envelope.
Definition: Envelope.h:320
float ValueOfPixel(int y, int height, bool upper, bool dB, double dBRange, float zoomMin, float zoomMax)
Definition: Envelope.cpp:458
wxInt64 TimeToPosition(double time, wxInt64 origin=0, bool ignoreFisheye=false) const
STM: Converts a project time to screen x position.
Definition: ViewInfo.cpp:59
double GetValue(double t, double sampleDur=0) const
Get envelope value at time t.
Definition: Envelope.cpp:1114
int GetWaveYPos(float value, float min, float max, int height, bool dB, bool outer, float dBr, bool clip)
double GetOffset() const
Definition: Envelope.h:95
bool EnvelopeEditor::HandleMouseButtonUp ( )
private

Definition at line 641 of file Envelope.cpp.

References Envelope::ClearDragPoint(), mButton, and mEnvelope.

Referenced by MouseEvent().

642 {
644  mButton = wxMOUSE_BTN_NONE;
645  return true;
646 }
void ClearDragPoint()
Definition: Envelope.cpp:212
Envelope & mEnvelope
Definition: Envelope.h:316
bool EnvelopeEditor::MouseEvent ( const wxMouseEvent &  event,
wxRect &  r,
const ZoomInfo zoomInfo,
bool  dB,
double  dBRange,
float  zoomMin = -1.0,
float  zoomMax = 1.0 
)

Definition at line 659 of file Envelope.cpp.

References Envelope::GetDragPoint(), HandleDragging(), HandleMouseButtonDown(), HandleMouseButtonUp(), mButton, and mEnvelope.

662 {
663  if (event.ButtonDown() && mButton == wxMOUSE_BTN_NONE)
664  return HandleMouseButtonDown( event, r, zoomInfo, dB, dBRange,
665  zoomMin, zoomMax);
666  if (event.Dragging() && mEnvelope.GetDragPoint() >= 0)
667  return HandleDragging( event, r, zoomInfo, dB, dBRange,
668  zoomMin, zoomMax);
669  if (event.ButtonUp() && event.GetButton() == mButton)
670  return HandleMouseButtonUp();
671  return false;
672 }
bool HandleDragging(const wxMouseEvent &event, wxRect &r, const ZoomInfo &zoomInfo, bool dB, double dBRange, float zoomMin=-1.0, float zoomMax=1.0, float eMin=0., float eMax=2.)
Definition: Envelope.cpp:613
int GetDragPoint() const
Definition: Envelope.h:231
bool HandleMouseButtonUp()
Definition: Envelope.cpp:641
Envelope & mEnvelope
Definition: Envelope.h:316
bool HandleMouseButtonDown(const wxMouseEvent &event, wxRect &r, const ZoomInfo &zoomInfo, bool dB, double dBRange, float zoomMin=-1.0, float zoomMax=1.0)
Definition: Envelope.cpp:478
void EnvelopeEditor::MoveDragPoint ( const wxMouseEvent &  event,
wxRect &  r,
const ZoomInfo zoomInfo,
bool  dB,
double  dBRange,
float  zoomMin,
float  zoomMax 
)
private

Definition at line 594 of file Envelope.cpp.

References Envelope::GetOffset(), mEnvelope, Envelope::MoveDragPoint(), mUpper, ZoomInfo::PositionToTime(), and ValueOfPixel().

Referenced by HandleDragging().

597 {
598  int clip_y = event.m_y - r.y;
599  if(clip_y < 0) clip_y = 0;
600  if(clip_y > r.height) clip_y = r.height;
601  double newVal = ValueOfPixel(clip_y, r.height, mUpper, dB, dBRange,
602  zoomMin, zoomMax);
603 
604  // We no longer tolerate multiple envelope points at the same t.
605  // epsilon is less than the time offset of a single sample
606  // TODO: However because mTrackEpsilon assumes 200KHz this use
607  // of epsilon is a tad bogus. What we need to do instead is DELETE
608  // a duplicated point on a mouse up.
609  double newWhen = zoomInfo.PositionToTime(event.m_x, r.x) - mEnvelope.GetOffset();
610  mEnvelope.MoveDragPoint(newWhen, newVal);
611 }
void MoveDragPoint(double newWhen, double value)
Definition: Envelope.cpp:186
double PositionToTime(wxInt64 position, wxInt64 origin=0, bool ignoreFisheye=false) const
Definition: ViewInfo.cpp:49
Envelope & mEnvelope
Definition: Envelope.h:316
float ValueOfPixel(int y, int height, bool upper, bool dB, double dBRange, float zoomMin, float zoomMax)
Definition: Envelope.cpp:458
double GetOffset() const
Definition: Envelope.h:95
float EnvelopeEditor::ValueOfPixel ( int  y,
int  height,
bool  upper,
bool  dB,
double  dBRange,
float  zoomMin,
float  zoomMax 
)
private

ValueOfPixel() converts a y position on screen to an envelope value.

Parameters
y- y position, usually of the mouse.relative to the clip.
height- height of the rectangle we are in. - true if we are on the upper line, false if on lower. - display mode either linear or log. - vertical scale, typically -1.0 - vertical scale, typically +1.0

Definition at line 458 of file Envelope.cpp.

References Envelope::ClampValue(), mContourOffset, and mEnvelope.

Referenced by HandleMouseButtonDown(), and MoveDragPoint().

461 {
462  float v = ::ValueOfPixel(y, height, 0 != mContourOffset, dB, dBRange, zoomMin, zoomMax);
463 
464  // MB: this is mostly equivalent to what the old code did, I'm not sure
465  // if anything special is needed for asymmetric ranges
466  if(upper)
467  return mEnvelope.ClampValue(v);
468  else
469  return mEnvelope.ClampValue(-v);
470 }
Envelope & mEnvelope
Definition: Envelope.h:316
int mContourOffset
Number of pixels contour is from the true envelope.
Definition: Envelope.h:320
float ValueOfPixel(int y, int height, bool upper, bool dB, double dBRange, float zoomMin, float zoomMax)
Definition: Envelope.cpp:458
double ClampValue(double value)
Definition: Envelope.h:107

Member Data Documentation

int EnvelopeEditor::mButton
private

Definition at line 326 of file Envelope.h.

Referenced by HandleMouseButtonDown(), HandleMouseButtonUp(), and MouseEvent().

int EnvelopeEditor::mContourOffset
private

Number of pixels contour is from the true envelope.

Definition at line 320 of file Envelope.h.

Referenced by HandleMouseButtonDown(), and ValueOfPixel().

bool EnvelopeEditor::mDirty
private

Definition at line 327 of file Envelope.h.

Referenced by HandleDragging(), and HandleMouseButtonDown().

Envelope& EnvelopeEditor::mEnvelope
private
const bool EnvelopeEditor::mMirrored
private

Definition at line 317 of file Envelope.h.

Referenced by HandleMouseButtonDown().

bool EnvelopeEditor::mUpper
private

Definition at line 325 of file Envelope.h.

Referenced by HandleMouseButtonDown(), and MoveDragPoint().


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