From 85a533be7912804db1917bca0a4d59888db190e6 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 2 Jun 2015 23:22:09 -0400 Subject: [PATCH 1/7] Remove unused variables; fewer casts --- src/TrackPanel.cpp | 37 ++++++++++++++++--------------------- src/TrackPanel.h | 3 +-- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index ed3bf67cf..e8bf22a64 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -4956,7 +4956,8 @@ bool TrackPanel::IsSampleEditingPossible( wxMouseEvent & WXUNUSED(event), Track //Get out of here if we shouldn't be drawing right now: //If we aren't displaying the waveform, Display a message dialog - if(((WaveTrack *)t)->GetDisplay() != WaveTrack::WaveformDisplay) + WaveTrack *const wt = static_cast(t); + if(wt->GetDisplay() != WaveTrack::WaveformDisplay) { wxMessageBox(_("To use Draw, choose 'Waveform' in the Track Drop-down Menu."), wxT("Draw Tool")); return false; @@ -4964,8 +4965,8 @@ bool TrackPanel::IsSampleEditingPossible( wxMouseEvent & WXUNUSED(event), Track //Get rate in order to calculate the critical zoom threshold //Find out the zoom level - double rate = ((WaveTrack *)t)->GetRate(); - bool showPoints = (mViewInfo->zoom / rate > 3.0); + const double rate = wt->GetRate(); + const bool showPoints = (mViewInfo->zoom / rate > 3.0); //If we aren't zoomed in far enough, show a message dialog. if(!showPoints) @@ -4991,11 +4992,10 @@ void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event ) { //declare a rectangle to determine clicking position wxRect r; - Track *t; //Get the track the mouse is over, and save it away for future events mDrawingTrack = NULL; - t = FindTrack(event.m_x, event.m_y, false, false, &r); + Track *const t = FindTrack(event.m_x, event.m_y, false, false, &r); if (!t || (t->GetKind() != Track::Wave)) return; @@ -5009,7 +5009,7 @@ void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event ) SetCapturedTrack( t, IsAdjustingSample); /// \todo Should mCapturedTrack take the place of mDrawingTrack?? - mDrawingTrack = t; + mDrawingTrack = static_cast(t); mDrawingTrackTop=r.y; //If we are still around, we are drawing in earnest. Set some member data structures up: @@ -5051,7 +5051,7 @@ void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event ) float * newSampleRegion = new float[1 + 2 * SMOOTHING_BRUSH_RADIUS]; //Get a sample from the track to do some tricks on. - ((WaveTrack*)mDrawingTrack)->Get((samplePtr)sampleRegion, floatSample, + mDrawingTrack->Get((samplePtr)sampleRegion, floatSample, (int)mDrawingStartSample - SMOOTHING_KERNEL_RADIUS - SMOOTHING_BRUSH_RADIUS, sampleRegionSize); int i, j; @@ -5093,7 +5093,7 @@ void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event ) sampleRegion[SMOOTHING_BRUSH_RADIUS + SMOOTHING_KERNEL_RADIUS + j] * (1 - prob); } //Set the sample to the point of the mouse event - ((WaveTrack*)mDrawingTrack)->Set((samplePtr)newSampleRegion, floatSample, mDrawingStartSample - SMOOTHING_BRUSH_RADIUS, 1 + 2 * SMOOTHING_BRUSH_RADIUS); + mDrawingTrack->Set((samplePtr)newSampleRegion, floatSample, mDrawingStartSample - SMOOTHING_BRUSH_RADIUS, 1 + 2 * SMOOTHING_BRUSH_RADIUS); //Clean this up right away to avoid a memory leak delete[] sampleRegion; @@ -5107,15 +5107,14 @@ void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event ) //Otherwise (e.g., the alt button is not down) do normal redrawing, based on the mouse position. // Calculate where the mouse is located vertically (between +/- 1) - ((WaveTrack*)mDrawingTrack)->Get((samplePtr)&mDrawingStartSampleValue, floatSample,(int) mDrawingStartSample, 1); float zoomMin, zoomMax; - ((WaveTrack *)mDrawingTrack)->GetDisplayBounds(&zoomMin, &zoomMax); + mDrawingTrack->GetDisplayBounds(&zoomMin, &zoomMax); newLevel = zoomMax - ((event.m_y - mDrawingTrackTop)/(float)mDrawingTrack->GetHeight()) * (zoomMax - zoomMin); //Take the envelope into account - Envelope *env = ((WaveTrack *)mDrawingTrack)->GetEnvelopeAtX(event.GetX()); + Envelope *env = mDrawingTrack->GetEnvelopeAtX(event.GetX()); if (env) { @@ -5131,7 +5130,7 @@ void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event ) } //Set the sample to the point of the mouse event - ((WaveTrack*)mDrawingTrack)->Set((samplePtr)&newLevel, floatSample, mDrawingStartSample, 1); + mDrawingTrack->Set((samplePtr)&newLevel, floatSample, mDrawingStartSample, 1); } //Set the member data structures for drawing @@ -5186,21 +5185,18 @@ void TrackPanel::HandleSampleEditingDrag( wxMouseEvent & event ) s0 = (sampleCount) (double)(t0 * rate + 0.5); } - //Sequence *seq = ((WaveTrack *)mDrawingTrack)->GetSequence(); - ((WaveTrack*)mDrawingTrack)->Get((samplePtr)&mDrawingStartSampleValue, floatSample, (int)mDrawingStartSample, 1); - //Otherwise, do normal redrawing, based on the mouse position. // Calculate where the mouse is located vertically (between +/- 1) float zoomMin, zoomMax; - ((WaveTrack *)mDrawingTrack)->GetDisplayBounds(&zoomMin, &zoomMax); + mDrawingTrack->GetDisplayBounds(&zoomMin, &zoomMax); newLevel = zoomMax - ((event.m_y - mDrawingTrackTop)/(float)mDrawingTrack->GetHeight()) * (zoomMax - zoomMin); //Take the envelope into account - Envelope *env = ((WaveTrack *)mDrawingTrack)->GetEnvelopeAtX(event.GetX()); + Envelope *env = mDrawingTrack->GetEnvelopeAtX(event.GetX()); if (env) { double envValue = env->GetValue(t0); @@ -5223,7 +5219,7 @@ void TrackPanel::HandleSampleEditingDrag( wxMouseEvent & event ) // avoid division by zero.... #define LLABS(n) ((n) < 0 ? -(n) : (n)) if(LLABS(s0 - mDrawingLastDragSample) <= 1){ - ((WaveTrack*)mDrawingTrack)->Set((samplePtr)&newLevel, floatSample, s0, 1); + mDrawingTrack->Set((samplePtr)&newLevel, floatSample, s0, 1); } else { @@ -5234,9 +5230,10 @@ void TrackPanel::HandleSampleEditingDrag( wxMouseEvent & event ) //This interpolates each sample linearly: tmpvalue=mDrawingLastDragSampleValue + (newLevel - mDrawingLastDragSampleValue) * (float)(i-mDrawingLastDragSample)/(s0-mDrawingLastDragSample ); - ((WaveTrack*)mDrawingTrack)->Set((samplePtr)&tmpvalue, floatSample, i, 1); + mDrawingTrack->Set((samplePtr)&tmpvalue, floatSample, i, 1); } } + //Update the member data structures. mDrawingLastDragSample=s0; mDrawingLastDragSampleValue = newLevel; @@ -5266,7 +5263,6 @@ void TrackPanel::HandleSampleEditingButtonUp( wxMouseEvent & WXUNUSED(event)) /// jump to a new track /// - mDrawingTrackTop: The top position of the drawing track--makes drawing easier. /// - mDrawingStartSample: The sample you clicked down on, so that you can hold it steady -/// - mDrawingStartSampleValue: The original value of the initial sample /// - mDrawingLastDragSample: When drag-drawing, this keeps track of the last sample you dragged over, /// so it can smoothly redraw samples that got skipped over /// - mDrawingLastDragSampleValue: The value of the last @@ -8500,7 +8496,6 @@ void TrackPanel::OnTrackMenu(Track *t) theMenu->Enable(OnSplitStereoMonoID, t->GetLinked()); // We only need to set check marks. Clearing checks causes problems on Linux (bug 851) - int channels = t->GetChannel(); switch (t->GetChannel()) { case Track::LeftChannel: theMenu->Check(OnChannelLeftID, true); diff --git a/src/TrackPanel.h b/src/TrackPanel.h index 55f3777f8..e3ce514d2 100644 --- a/src/TrackPanel.h +++ b/src/TrackPanel.h @@ -676,10 +676,9 @@ protected: NumericConverter mConverter; - Track * mDrawingTrack; // Keeps track of which track you are drawing on between events cf. HandleDraw() + WaveTrack * mDrawingTrack; // Keeps track of which track you are drawing on between events cf. HandleDraw() int mDrawingTrackTop; // Keeps track of the top position of the drawing track. sampleCount mDrawingStartSample; // sample of last click-down - float mDrawingStartSampleValue; // value of last click-down sampleCount mDrawingLastDragSample; // sample of last drag-over float mDrawingLastDragSampleValue; // value of last drag-over From f332df1f36e841571a642c13c5d820fadbbc60e4 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 3 Jun 2015 01:43:06 -0400 Subject: [PATCH 2/7] Pulled repeated code into a function; share some calcs with Envelope editor --- src/TrackPanel.cpp | 75 +++++++++++++++++++--------------------------- src/TrackPanel.h | 1 + 2 files changed, 32 insertions(+), 44 deletions(-) diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index e8bf22a64..93af900f2 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -4986,6 +4986,34 @@ bool TrackPanel::IsSampleEditingPossible( wxMouseEvent & WXUNUSED(event), Track return true; } +float TrackPanel::FindSampleEditingLevel(wxMouseEvent &event, double t0) +{ + // Calculate where the mouse is located vertically (between +/- 1) + float zoomMin, zoomMax; + mDrawingTrack->GetDisplayBounds(&zoomMin, &zoomMax); + + const int y = event.m_y - mDrawingTrackTop; + const int height = mDrawingTrack->GetHeight(); + const bool dB = (WaveTrack::WaveformDBDisplay == mDrawingTrack->GetDisplay()); + float newLevel = ::ValueOfPixel(y, height, false, dB, mdBr, zoomMin, zoomMax); + + //Take the envelope into account + Envelope *const env = mDrawingTrack->GetEnvelopeAtX(event.m_x); + if (env) + { + double envValue = env->GetValue(t0); + if (envValue > 0) + newLevel /= envValue; + else + newLevel = 0; + + //Make sure the new level is between +/-1 + newLevel = std::max(-1.0f, std::min(1.0f, newLevel)); + } + + return newLevel; +} + /// We're in a track view and zoomed enough to see the samples. /// Someone has just clicked the mouse. What do we do? void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event ) @@ -5106,28 +5134,7 @@ void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event ) //************************************************* //Otherwise (e.g., the alt button is not down) do normal redrawing, based on the mouse position. - // Calculate where the mouse is located vertically (between +/- 1) - float zoomMin, zoomMax; - mDrawingTrack->GetDisplayBounds(&zoomMin, &zoomMax); - newLevel = zoomMax - - ((event.m_y - mDrawingTrackTop)/(float)mDrawingTrack->GetHeight()) * - (zoomMax - zoomMin); - - //Take the envelope into account - Envelope *env = mDrawingTrack->GetEnvelopeAtX(event.GetX()); - - if (env) - { - double envValue = env->GetValue(t0); - if (envValue > 0) - newLevel /= envValue; - else - newLevel = 0; - - //Make sure the new level is between +/-1 - newLevel = newLevel > 1.0 ? 1.0: newLevel; - newLevel = newLevel < -1.0 ? -1.0: newLevel; - } + const float newLevel = FindSampleEditingLevel(event, t0); //Set the sample to the point of the mouse event mDrawingTrack->Set((samplePtr)&newLevel, floatSample, mDrawingStartSample, 1); @@ -5163,7 +5170,7 @@ void TrackPanel::HandleSampleEditingDrag( wxMouseEvent & event ) // Figure out what time the click was at double t0 = PositionToTime(event.m_x, GetLeftOffset()); - float newLevel; + //Find the point that we want to redraw at. If the control button is down, //adjust only the originally clicked-on sample @@ -5188,27 +5195,7 @@ void TrackPanel::HandleSampleEditingDrag( wxMouseEvent & event ) //Otherwise, do normal redrawing, based on the mouse position. // Calculate where the mouse is located vertically (between +/- 1) - - float zoomMin, zoomMax; - mDrawingTrack->GetDisplayBounds(&zoomMin, &zoomMax); - newLevel = zoomMax - - ((event.m_y - mDrawingTrackTop)/(float)mDrawingTrack->GetHeight()) * - (zoomMax - zoomMin); - - //Take the envelope into account - Envelope *env = mDrawingTrack->GetEnvelopeAtX(event.GetX()); - if (env) - { - double envValue = env->GetValue(t0); - if (envValue > 0) - newLevel /= envValue; - else - newLevel = 0; - - //Make sure the new level is between +/-1 - newLevel = newLevel > 1.0 ? 1.0: newLevel; - newLevel = newLevel < -1.0 ? -1.0: newLevel; - } + const float newLevel = FindSampleEditingLevel(event, t0); //Now, redraw all samples between current and last redrawn sample diff --git a/src/TrackPanel.h b/src/TrackPanel.h index e3ce514d2..3b7510f24 100644 --- a/src/TrackPanel.h +++ b/src/TrackPanel.h @@ -396,6 +396,7 @@ protected: // Handle sample editing using the 'draw' tool. virtual bool IsSampleEditingPossible( wxMouseEvent & event, Track * t ); virtual void HandleSampleEditing(wxMouseEvent & event); + float FindSampleEditingLevel(wxMouseEvent &event, double t0); virtual void HandleSampleEditingClick( wxMouseEvent & event ); virtual void HandleSampleEditingDrag( wxMouseEvent & event ); virtual void HandleSampleEditingButtonUp( wxMouseEvent & event ); From a2bceee698e0faaa0842a83047129d751b54ec8d Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 2 Jun 2015 23:28:40 -0400 Subject: [PATCH 3/7] Bug1004: undo history message --- src/TrackPanel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index 93af900f2..1b6e77bc4 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -5237,7 +5237,7 @@ void TrackPanel::HandleSampleEditingButtonUp( wxMouseEvent & WXUNUSED(event)) SetCapturedTrack( NULL ); //On up-click, send the state to the undo stack mDrawingTrack=NULL; //Set this to NULL so it will catch improper drag events. - MakeParentPushState(_("Moved Sample"), + MakeParentPushState(_("Moved Samples"), _("Sample Edit"), PUSH_CONSOLIDATE|PUSH_AUTOSAVE); } From 7c48a76d18316d87d300ca03cce6bde9ba0d97c1 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 2 Jun 2015 19:32:43 -0400 Subject: [PATCH 4/7] Bug1002: Alt-click in pencil tool never starts a drag --- src/TrackPanel.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index 1b6e77bc4..6ce02d9fb 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -5034,7 +5034,6 @@ void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event ) ReleaseMouse(); return; } - SetCapturedTrack( t, IsAdjustingSample); /// \todo Should mCapturedTrack take the place of mDrawingTrack?? mDrawingTrack = static_cast(t); @@ -5133,6 +5132,8 @@ void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event ) //*** PLAIN DOWN-CLICK (NORMAL DRAWING) *** //************************************************* + SetCapturedTrack(t, IsAdjustingSample); + //Otherwise (e.g., the alt button is not down) do normal redrawing, based on the mouse position. const float newLevel = FindSampleEditingLevel(event, t0); @@ -5161,7 +5162,7 @@ void TrackPanel::HandleSampleEditingDrag( wxMouseEvent & event ) return; //Exit dragging if the alt key is down--Don't allow left-right dragging for smoothing operation - if (event.m_altDown) + if (mMouseCapture != IsAdjustingSample) return; //Get the rate of the sequence, for use later From 6faf4c98c143f2fa7efa529a45c97a8ea301f596 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 2 Jun 2015 19:42:15 -0400 Subject: [PATCH 5/7] Bug1003: Use correct envelope value in pencil tool drag --- src/TrackPanel.cpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index 6ce02d9fb..87f38e037 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -5042,19 +5042,15 @@ void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event ) //If we are still around, we are drawing in earnest. Set some member data structures up: //First, calculate the starting sample. To get this, we need the time double t0 = PositionToTime(event.m_x, GetLeftOffset()); - double rate = ((WaveTrack *)mDrawingTrack)->GetRate(); // Default to zero for ALT case, so it doesn't cause a runtime fault on MSVC in // the mDrawingLastDragSampleValue assignment at the bottom of this method. float newLevel = 0.0f; //Declare this for use later //convert t0 to samples - mDrawingStartSample = (sampleCount) (double)(t0 * rate + 0.5 ); - - //Now, figure out what the value of that sample is. - //First, get the sequence of samples so you can mess with it - //Sequence *seq = ((WaveTrack *)mDrawingTrack)->GetSequence(); - + mDrawingStartSample = mDrawingTrack->TimeToLongSamples(t0); + // quantize + t0 = mDrawingTrack->LongSamplesToTime(mDrawingStartSample); //Determine how drawing should occur. If alt is down, //do a smoothing, instead of redrawing. @@ -5125,6 +5121,8 @@ void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event ) //Clean this up right away to avoid a memory leak delete[] sampleRegion; delete[] newSampleRegion; + + mDrawingLastDragSampleValue = 0; } else { @@ -5139,11 +5137,12 @@ void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event ) //Set the sample to the point of the mouse event mDrawingTrack->Set((samplePtr)&newLevel, floatSample, mDrawingStartSample, 1); + + mDrawingLastDragSampleValue = newLevel; } //Set the member data structures for drawing mDrawingLastDragSample=mDrawingStartSample; - mDrawingLastDragSampleValue = newLevel; //Redraw the region of the selected track RefreshTrack(mDrawingTrack); @@ -5165,13 +5164,8 @@ void TrackPanel::HandleSampleEditingDrag( wxMouseEvent & event ) if (mMouseCapture != IsAdjustingSample) return; - //Get the rate of the sequence, for use later - float rate = ((WaveTrack *)mDrawingTrack)->GetRate(); sampleCount s0; //declare this for use below. It designates the sample number which to draw. - // Figure out what time the click was at - double t0 = PositionToTime(event.m_x, GetLeftOffset()); - //Find the point that we want to redraw at. If the control button is down, //adjust only the originally clicked-on sample @@ -5190,9 +5184,12 @@ void TrackPanel::HandleSampleEditingDrag( wxMouseEvent & event ) //Otherwise, adjust the sample you are dragging over right now. //convert this to samples - s0 = (sampleCount) (double)(t0 * rate + 0.5); + const double t = PositionToTime(event.m_x, GetLeftOffset()); + s0 = mDrawingTrack->TimeToLongSamples(t); } + const double t0 = mDrawingTrack->LongSamplesToTime(s0); + //Otherwise, do normal redrawing, based on the mouse position. // Calculate where the mouse is located vertically (between +/- 1) From 00ab1932466948f9f9dacee871df02f75f92ad3d Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 3 Jun 2015 01:51:16 -0400 Subject: [PATCH 6/7] Bug1005: draw tool performance --- src/TrackPanel.cpp | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index 87f38e037..a66e4044b 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -5195,28 +5195,23 @@ void TrackPanel::HandleSampleEditingDrag( wxMouseEvent & event ) const float newLevel = FindSampleEditingLevel(event, t0); - //Now, redraw all samples between current and last redrawn sample - - float tmpvalue; - //Handle cases of 0 or 1 special, to improve speed - //JKC I don't think this makes any noticeable difference to speed - // whatsoever! The real reason for the special case is probably to - // avoid division by zero.... -#define LLABS(n) ((n) < 0 ? -(n) : (n)) - if(LLABS(s0 - mDrawingLastDragSample) <= 1){ - mDrawingTrack->Set((samplePtr)&newLevel, floatSample, s0, 1); + //Now, redraw all samples between current and last redrawn sample, inclusive + //Go from the smaller to larger sample. + const int start = std::min( s0, mDrawingLastDragSample); + const int end = std::max( s0, mDrawingLastDragSample); + const int size = end - start + 1; + if (size == 1) { + mDrawingTrack->Set((samplePtr)&newLevel, floatSample, start, size); } - else - { - //Go from the smaller to larger sample. - int start = wxMin( s0, mDrawingLastDragSample) +1; - int end = wxMax( s0, mDrawingLastDragSample); - for(sampleCount i= start; i<= end; i++) { + else { + std::vector values(size); + for (sampleCount i = start; i <= end; ++i) { //This interpolates each sample linearly: - tmpvalue=mDrawingLastDragSampleValue + (newLevel - mDrawingLastDragSampleValue) * - (float)(i-mDrawingLastDragSample)/(s0-mDrawingLastDragSample ); - mDrawingTrack->Set((samplePtr)&tmpvalue, floatSample, i, 1); + values[i - start] = + mDrawingLastDragSampleValue + (newLevel - mDrawingLastDragSampleValue) * + (float)(i - mDrawingLastDragSample) / (s0 - mDrawingLastDragSample); } + mDrawingTrack->Set((samplePtr)&values[0], floatSample, start, size); } //Update the member data structures. From 1b57335dca3cac1babf9470d4e3ceea699682c50 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 3 Jun 2015 01:52:35 -0400 Subject: [PATCH 7/7] Enable draw tool in Waveform dB view --- src/TrackPanel.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index a66e4044b..5b2102588 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -4957,11 +4957,21 @@ bool TrackPanel::IsSampleEditingPossible( wxMouseEvent & WXUNUSED(event), Track //Get out of here if we shouldn't be drawing right now: //If we aren't displaying the waveform, Display a message dialog WaveTrack *const wt = static_cast(t); - if(wt->GetDisplay() != WaveTrack::WaveformDisplay) + const int display = wt->GetDisplay(); +#if 1 + if (!(WaveTrack::WaveformDisplay == display || + WaveTrack::WaveformDBDisplay == display)) + { + wxMessageBox(_("To use Draw, choose 'Waveform' or 'Waveform dB' in the Track Drop-down Menu."), wxT("Draw Tool")); + return false; + } +#else + if(WaveTrack::WaveformDisplay != display) { wxMessageBox(_("To use Draw, choose 'Waveform' in the Track Drop-down Menu."), wxT("Draw Tool")); return false; } +#endif //Get rate in order to calculate the critical zoom threshold //Find out the zoom level @@ -5043,10 +5053,6 @@ void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event ) //First, calculate the starting sample. To get this, we need the time double t0 = PositionToTime(event.m_x, GetLeftOffset()); - // Default to zero for ALT case, so it doesn't cause a runtime fault on MSVC in - // the mDrawingLastDragSampleValue assignment at the bottom of this method. - float newLevel = 0.0f; //Declare this for use later - //convert t0 to samples mDrawingStartSample = mDrawingTrack->TimeToLongSamples(t0); // quantize @@ -5166,18 +5172,18 @@ void TrackPanel::HandleSampleEditingDrag( wxMouseEvent & event ) sampleCount s0; //declare this for use below. It designates the sample number which to draw. + // Figure out what time the click was at //Find the point that we want to redraw at. If the control button is down, //adjust only the originally clicked-on sample - //************************************************* - //*** CTRL-DOWN (Hold Initial Sample Constant *** - //************************************************* - if( event.m_controlDown) { + //************************************************* + //*** CTRL-DOWN (Hold Initial Sample Constant *** + //************************************************* + s0 = mDrawingStartSample; } - else - { + else { //************************************************* //*** Normal CLICK-drag (Normal drawing) *** //************************************************* @@ -7073,7 +7079,8 @@ bool TrackPanel::HitTestSamples(Track *track, wxRect &r, wxMouseEvent & event) return false; int displayType = wavetrack->GetDisplay(); - if ( displayType > 1) + bool dB = (WaveTrack::WaveformDBDisplay == displayType); + if (!(WaveTrack::WaveformDisplay == displayType) || dB) return false; // Not a wave, so return. float oneSample; @@ -7085,7 +7092,6 @@ bool TrackPanel::HitTestSamples(Track *track, wxRect &r, wxMouseEvent & event) wavetrack->Get((samplePtr)&oneSample, floatSample, s0, 1); // Get y distance of envelope point from center line (in pixels). - bool dB = (displayType == 1); float zoomMin, zoomMax; wavetrack->GetDisplayBounds(&zoomMin, &zoomMax);