Exemplo n.º 1
0
void Envelope::Draw(wxDC & dc, const wxRect & r, double h, double pps, bool dB,
                    float zoomMin, float zoomMax)
{
    h -= mOffset;

    double tright = h + (r.width / pps);
    double dBr = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE);

    dc.SetPen(AColor::envelopePen);
    dc.SetBrush(*wxWHITE_BRUSH);

    for (int i = 0; i < (int)mEnv.Count(); i++) {
        if (mEnv[i]->t >= h && mEnv[i]->t <= tright) {
            if (i == mDragPoint) {
                dc.SetPen(AColor::envelopePen);
                dc.SetBrush(AColor::envelopeBrush);
            }

            double v = mEnv[i]->val;
            int x = int ((mEnv[i]->t - h) * pps);
            int y, y2;

            y = GetWaveYPos(v, zoomMin, zoomMax, r.height, dB,
                            true, dBr, false);
            if (!mMirror) {
                DrawPoint(dc, r, x, y, true);
            }
            else {
                y2 = GetWaveYPos(-v-.000000001, zoomMin, zoomMax, r.height, dB,
                                 true, dBr, false);

                // This follows the same logic as the envelop drawing in
                // TrackArtist::DrawEnvelope().
                if (y2 - y < 9) {
                    int value = (int)((zoomMax / (zoomMax - zoomMin)) * r.height);
                    y = value - 4;
                    y2 = value + 4;
                }

                DrawPoint(dc, r, x, y, true);
                DrawPoint(dc, r, x, y2, false);

                // Contour
                y = GetWaveYPos(v, zoomMin, zoomMax, r.height, dB,
                                false, dBr, false);
                y2 = GetWaveYPos(-v-.000000001, zoomMin, zoomMax, r.height, dB,
                                 false, dBr, false);
                if (y <= y2) {
                    DrawPoint(dc, r, x, y, true);
                    DrawPoint(dc, r, x, y2, false);
                }
            }

            if (i == mDragPoint) {
                dc.SetPen(AColor::envelopePen);
                dc.SetBrush(*wxWHITE_BRUSH);
            }
        }
    }
}
Exemplo n.º 2
0
/// 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).
bool Envelope::HandleMouseButtonDown(wxMouseEvent & event, wxRect & r,
                                     double h, double pps, bool dB,
                                     float zoomMin, float zoomMax)
{
   int ctr = (int)(r.height * zoomMax / (zoomMax - zoomMin));
   bool upper = !mMirror || (zoomMin >= 0.0) || (event.m_y - r.y < ctr);

   int clip_y = event.m_y - r.y;
   if(clip_y < 0) clip_y = 0; //keeps point in rect r, even if mouse isn't
   if(clip_y > r.GetBottom()) clip_y = r.GetBottom();

   double tleft = h - mOffset;
   double tright = tleft + (r.width / pps);
   int bestNum = -1;
   int bestDist = 10; // Must be within 10 pixel radius.

   // TODO: Cache the gPrefs value.  Reading it every time is inefficient.
   double dBr = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE);

   // Member variables hold state that will be needed in dragging.
   mButton        = event.GetButton();
   mIsDeleting    = false;
   mContourOffset = false;

   //   wxLogDebug(wxT("Y:%i Height:%i Offset:%i"), y, height, mContourOffset );
   int len = mEnv.Count();

   // TODO: extract this into a function FindNearestControlPoint()
   // TODO: also fix it so that we can drag the last point on an envelope.
   for (int i = 0; i < len; i++) { //search for control point nearest click
      if (mEnv[i]->GetT() >= tleft && mEnv[i]->GetT() <= tright) {

         int x = int ((mEnv[i]->GetT() + mOffset - h) * pps) + r.x;
         int y[4];
         int numControlPoints;

         // Outer control points
         y[0] = GetWaveYPos( mEnv[i]->GetVal(), zoomMin, zoomMax, r.height,
                                dB, true, dBr, false);
         y[1] = GetWaveYPos( -mEnv[i]->GetVal(), zoomMin, zoomMax, r.height,
                                dB, true, dBr, false);

         // Inner control points(contour)
         y[2] = GetWaveYPos( mEnv[i]->GetVal(), zoomMin, zoomMax, r.height,
                                dB, false, dBr, false);
         y[3] = GetWaveYPos( -mEnv[i]->GetVal()-.00000001, zoomMin, zoomMax,
                                r.height, dB, false, dBr, false);

         numControlPoints = 4;

         if (y[2] > y[3])
            numControlPoints = 2;

         if (!mMirror)
            numControlPoints = 1;

         for(int j=0; j<numControlPoints; j++){

            int d = (int)(sqrt((double)(SQR(x-event.m_x) + SQR(y[j]-(event.m_y-r.y)))) + 0.5);
            if (d < bestDist) {
               bestNum = i;
               bestDist = d;
               mContourOffset = (bool)(j > 1);
            }
         }
      }
   }

   if (bestNum >= 0) {
      mDragPoint = bestNum;
   }
   else {
      // TODO: Extract this into a function CreateNewPoint
      double when = h + (event.m_x - r.x) / pps - mOffset;

      //      if (when <= 0 || when >= mTrackLen)
      //         return false;

      double v = GetValueAtX( event.m_x, r, h, pps );

      int ct = GetWaveYPos( v, zoomMin, zoomMax, r.height, dB,
                               false, dBr, false) ;
      int cb = GetWaveYPos( -v-.000000001, zoomMin, zoomMax, r.height, dB,
                               false, dBr, false) ;
      if( ct <= cb || !mMirror ){
         int t = GetWaveYPos( v, zoomMin, zoomMax, r.height, dB,
                                 true, dBr, false) ;
         int b = GetWaveYPos( -v, zoomMin, zoomMax, r.height, dB,
                                 true, dBr, false) ;

         ct = (t + ct) / 2;
         cb = (b + cb) / 2;

         if(mMirror &&
            (event.m_y - r.y) > ct &&
            ((event.m_y - r.y) < cb))
            mContourOffset = true;
         else
            mContourOffset = false;
      }

      double newVal = ValueOfPixel(clip_y, r.height, upper, dB,
                                   zoomMin, zoomMax);

      mDragPoint = Insert(when, newVal);
      mDirty = true;
   }

   mUpper = upper;

   mInitialWhen = mEnv[mDragPoint]->GetT();
   mInitialVal = mEnv[mDragPoint]->GetVal();

   mInitialX = event.m_x;
   mInitialY = event.m_y+mContourOffset;

   return true;
}
Exemplo n.º 3
0
/// TODO: This should probably move to track artist.
void Envelope::DrawPoints(wxDC & dc, const wxRect & r, double h, double pps, bool dB,
                    float zoomMin, float zoomMax)
{
   h -= mOffset;

   wxASSERT( pps > 0 );
   double tright = h + (r.width / pps);
   // TODO: Cache the gPrefs value.  Reading it every time is inefficient.
   double dBRange = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE);

   dc.SetPen(AColor::envelopePen);
   dc.SetBrush(*wxWHITE_BRUSH);

   for (int i = 0; i < (int)mEnv.Count(); i++) {
      if (mEnv[i]->GetT() >= h && mEnv[i]->GetT() <= tright) {
         // Change colour if this is the draggable point...
         if (i == mDragPoint) {
            dc.SetPen(AColor::envelopePen);
            dc.SetBrush(AColor::envelopeBrush);
         }

         double v = mEnv[i]->GetVal();
         int x = int ((mEnv[i]->GetT() - h) * pps);
         int y, y2;

         y = GetWaveYPos(v, zoomMin, zoomMax, r.height, dB,
            true, dBRange, false);
         if (!mMirror) {
            DrawPoint(dc, r, x, y, true);
         }
         else {
            y2 = GetWaveYPos(-v-.000000001, zoomMin, zoomMax, r.height, dB,
               true, dBRange, false);

            // This follows the same logic as the envelop drawing in
            // TrackArtist::DrawEnvelope().
            // TODO: make this calculation into a reusable function.
            if (y2 - y < 9) {
               int value = (int)((zoomMax / (zoomMax - zoomMin)) * r.height);
               y = value - 4;
               y2 = value + 4;
            }

            DrawPoint(dc, r, x, y, true);
            DrawPoint(dc, r, x, y2, false);

            // Contour
            y = GetWaveYPos(v, zoomMin, zoomMax, r.height, dB,
               false, dBRange, false);
            y2 = GetWaveYPos(-v-.000000001, zoomMin, zoomMax, r.height, dB,
               false, dBRange, false);
            if (y <= y2) {
               DrawPoint(dc, r, x, y, true);
               DrawPoint(dc, r, x, y2, false);
            }
         }

         // Change colour back again if was the draggable point.
         if (i == mDragPoint) {
            dc.SetPen(AColor::envelopePen);
            dc.SetBrush(*wxWHITE_BRUSH);
         }
      }
   }
}
Exemplo n.º 4
0
bool Envelope::HandleMouseButtonDown(wxMouseEvent & event, wxRect & r,
                                     double h, double pps, bool dB,
                                     float zoomMin, float zoomMax, float eMin, float eMax)
{
    bool upper;
    int ctr = (int)(r.height * zoomMax / (zoomMax - zoomMin));
    upper = (event.m_y - r.y < ctr);
    if(zoomMin == eMin)
        upper = true;

    mButton = event.GetButton();
    int clip_y = event.m_y - r.y;
    if(clip_y < 0) clip_y = 0;	//keeps point in rect r, even if mouse isn't
    if(clip_y > r.height) clip_y = r.height;

    mIsDeleting = false;
    double tleft = h - mOffset;
    double tright = tleft + (r.width / pps);
    int bestNum = -1;
    int bestDist = 10; // Must be within 10 pixel radius.

    double dBr = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE);

    mContourOffset = false;

    //   wxLogDebug(wxT("Y:%i Height:%i Offset:%i"), y, height, mContourOffset );

    int len = mEnv.Count();
    for (int i = 0; i < len; i++) {	//search for control point nearest click
        if (mEnv[i]->t >= tleft && mEnv[i]->t <= tright) {

            int x = int ((mEnv[i]->t + mOffset - h) * pps) + r.x;
            int y[4];
            int numControlPoints;

            // Outer control points
            y[0] = GetWaveYPos( mEnv[i]->val, zoomMin, zoomMax, r.height,
                                dB, true, dBr, false);
            y[1] = GetWaveYPos( -mEnv[i]->val, zoomMin, zoomMax, r.height,
                                dB, true, dBr, false);

            // Inner control points(contour)
            y[2] = GetWaveYPos( mEnv[i]->val, zoomMin, zoomMax, r.height,
                                dB, false, dBr, false);
            y[3] = GetWaveYPos( -mEnv[i]->val-.00000001, zoomMin, zoomMax,
                                r.height, dB, false, dBr, false);

            numControlPoints = 4;

            if (y[2] > y[3])
                numControlPoints = 2;

            if (!mMirror)
                numControlPoints = 1;

            for(int j=0; j<numControlPoints; j++) {

                int d = (int)(sqrt((double)(SQR(x-event.m_x) + SQR(y[j]-(event.m_y-r.y)))) + 0.5);
                if (d < bestDist) {
                    bestNum = i;
                    bestDist = d;
                    mContourOffset = (bool)(j > 1);
                }
            }
        }
    }

    if (bestNum >= 0) {
        mDragPoint = bestNum;
    }
    else {
        // Create new point
        double when = h + (event.m_x - r.x) / pps - mOffset;

        //      if (when <= 0 || when >= mTrackLen)
        //         return false;

        double v = GetValueAtX( event.m_x, r, h, pps );

        int ct = GetWaveYPos( v, zoomMin, zoomMax, r.height, dB,
                              false, dBr, false) ;
        int cb = GetWaveYPos( -v-.000000001, zoomMin, zoomMax, r.height, dB,
                              false, dBr, false) ;
        if( ct <= cb || !mMirror ) {
            int t = GetWaveYPos( v, zoomMin, zoomMax, r.height, dB,
                                 true, dBr, false) ;
            int b = GetWaveYPos( -v, zoomMin, zoomMax, r.height, dB,
                                 true, dBr, false) ;

            ct = (t + ct) / 2;
            cb = (b + cb) / 2;

            if(mMirror &&
                    (event.m_y - r.y) > ct &&
                    ((event.m_y - r.y) < cb))
                mContourOffset = true;
            else
                mContourOffset = false;
        }

        double newVal = ValueOfPixel(clip_y, r.height, upper, dB,
                                     zoomMin, zoomMax, eMin);

        //float MaxAmplify = ( mContourOffset ) ? 1.4 : 1.0;

        if(newVal > eMax)
            newVal = eMax;

        mDragPoint = Insert(when, newVal);
        mDirty = true;
    }

    mUpper = upper;

    mInitialWhen = mEnv[mDragPoint]->t;
    mInitialVal = mEnv[mDragPoint]->val;

    mInitialX = event.m_x;
    mInitialY = event.m_y+mContourOffset;

    return true;
}