Audacity 3.2.0
AutoDuck.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 AutoDuck.cpp
6
7 Markus Meyer
8
9*******************************************************************/
20#include "AutoDuck.h"
21#include "LoadEffects.h"
22
23#include <math.h>
24
25#include <wx/dcclient.h>
26#include <wx/dcmemory.h>
27#include <wx/intl.h>
28
29#include "AColor.h"
30#include "AllThemeResources.h"
31#include "Prefs.h"
32#include "../ShuttleGui.h"
33#include "Theme.h"
34#include "../widgets/valnum.h"
35
36#include "../WaveTrack.h"
37#include "../widgets/AudacityMessageBox.h"
38
40{
44 > parameters;
45 return parameters;
46}
47
48/*
49 * Common constants
50 */
51
52static const size_t kBufSize = 131072u; // number of samples to process at once
53static const size_t kRMSWindowSize = 100u; // samples in circular RMS window buffer
54
55/*
56 * A auto duck region and an array of auto duck regions
57 */
58
60{
61 AutoDuckRegion(double t0, double t1)
62 {
63 this->t0 = t0;
64 this->t1 = t1;
65 }
66
67 double t0;
68 double t1;
69};
70
71/*
72 * Effect implementation
73 */
74
76{ XO("Auto Duck") };
77
79
80BEGIN_EVENT_TABLE(EffectAutoDuck, wxEvtHandler)
81 EVT_TEXT(wxID_ANY, EffectAutoDuck::OnValueChanged)
83
85{
86 Parameters().Reset(*this);
87
88 SetLinearEffectFlag(true);
89
90 mControlTrack = NULL;
91
92 mPanel = NULL;
93}
94
96{
97}
98
99// ComponentInterface implementation
100
102{
103 return Symbol;
104}
105
107{
108 return XO("Reduces (ducks) the volume of one or more tracks whenever the volume of a specified \"control\" track reaches a particular level");
109}
110
112{
113 return L"Auto_Duck";
114}
115
116// EffectDefinitionInterface implementation
117
119{
120 return EffectTypeProcess;
121}
122
123// Effect implementation
124
126{
127 mControlTrack = NULL;
128
129 bool lastWasSelectedWaveTrack = false;
130 const WaveTrack *controlTrackCandidate = NULL;
131
132 for (auto t : inputTracks()->Any())
133 {
134 if (lastWasSelectedWaveTrack && !t->GetSelected()) {
135 // This could be the control track, so remember it
136 controlTrackCandidate = track_cast<const WaveTrack *>(t);
137 }
138
139 lastWasSelectedWaveTrack = false;
140
141 if (t->GetSelected()) {
142 bool ok = t->TypeSwitch<bool>(
143 [&](const WaveTrack *) {
144 lastWasSelectedWaveTrack = true;
145 return true;
146 },
147 [&](const Track *) {
149 /* i18n-hint: Auto duck is the name of an effect that 'ducks' (reduces the volume)
150 * of the audio automatically when there is sound on another track. Not as
151 * in 'Donald-Duck'!*/
152 XO("You selected a track which does not contain audio. AutoDuck can only process audio tracks."),
153 wxICON_ERROR );
154 return false;
155 }
156 );
157 if (!ok)
158 return false;
159 }
160 }
161
162 if (!controlTrackCandidate)
163 {
165 /* i18n-hint: Auto duck is the name of an effect that 'ducks' (reduces the volume)
166 * of the audio automatically when there is sound on another track. Not as
167 * in 'Donald-Duck'!*/
168 XO("Auto Duck needs a control track which must be placed below the selected track(s)."),
169 wxICON_ERROR );
170 return false;
171 }
172
173 mControlTrack = controlTrackCandidate;
174
175 return true;
176}
177
179{
180 if (GetNumWaveTracks() == 0 || !mControlTrack)
181 return false;
182
183 bool cancel = false;
184
185 auto start =
187 auto end =
189
190 if (end <= start)
191 return false;
192
193 // the minimum number of samples we have to wait until the maximum
194 // pause has been exceeded
195 double maxPause = mMaximumPause;
196
197 // We don't fade in until we have time enough to actually fade out again
198 if (maxPause < mOuterFadeDownLen + mOuterFadeUpLen)
200
201 auto minSamplesPause =
203
204 double threshold = DB_TO_LINEAR(mThresholdDb);
205
206 // adjust the threshold so we can compare it to the rmsSum value
207 threshold = threshold * threshold * kRMSWindowSize;
208
209 int rmsPos = 0;
210 double rmsSum = 0;
211 // to make the progress bar appear more natural, we first look for all
212 // duck regions and apply them all at once afterwards
213 std::vector<AutoDuckRegion> regions;
214 bool inDuckRegion = false;
215 {
216 Floats rmsWindow{ kRMSWindowSize, true };
217
218 Floats buf{ kBufSize };
219
220 // initialize the following two variables to prevent compiler warning
221 double duckRegionStart = 0;
222 sampleCount curSamplesPause = 0;
223
224 auto pos = start;
225
226 while (pos < end)
227 {
228 const auto len = limitSampleBufferSize( kBufSize, end - pos );
229
230 mControlTrack->GetFloats(buf.get(), pos, len);
231
232 for (auto i = pos; i < pos + len; i++)
233 {
234 rmsSum -= rmsWindow[rmsPos];
235 // i - pos is bounded by len:
236 auto index = ( i - pos ).as_size_t();
237 rmsWindow[rmsPos] = buf[ index ] * buf[ index ];
238 rmsSum += rmsWindow[rmsPos];
239 rmsPos = (rmsPos + 1) % kRMSWindowSize;
240
241 bool thresholdExceeded = rmsSum > threshold;
242
243 if (thresholdExceeded)
244 {
245 // everytime the threshold is exceeded, reset our count for
246 // the number of pause samples
247 curSamplesPause = 0;
248
249 if (!inDuckRegion)
250 {
251 // the threshold has been exceeded for the first time, so
252 // let the duck region begin here
253 inDuckRegion = true;
254 duckRegionStart = mControlTrack->LongSamplesToTime(i);
255 }
256 }
257
258 if (!thresholdExceeded && inDuckRegion)
259 {
260 // the threshold has not been exceeded and we are in a duck
261 // region, but only fade in if the maximum pause has been
262 // exceeded
263 curSamplesPause += 1;
264
265 if (curSamplesPause >= minSamplesPause)
266 {
267 // do the actual duck fade and reset all values
268 double duckRegionEnd =
269 mControlTrack->LongSamplesToTime(i - curSamplesPause);
270
271 regions.push_back(AutoDuckRegion(
272 duckRegionStart - mOuterFadeDownLen,
273 duckRegionEnd + mOuterFadeUpLen));
274
275 inDuckRegion = false;
276 }
277 }
278 }
279
280 pos += len;
281
282 if (TotalProgress(
283 (pos - start).as_double() /
284 (end - start).as_double() /
285 (GetNumWaveTracks() + 1)
286 ))
287 {
288 cancel = true;
289 break;
290 }
291 }
292
293 // apply last duck fade, if any
294 if (inDuckRegion)
295 {
296 double duckRegionEnd =
297 mControlTrack->LongSamplesToTime(end - curSamplesPause);
298 regions.push_back(AutoDuckRegion(
299 duckRegionStart - mOuterFadeDownLen,
300 duckRegionEnd + mOuterFadeUpLen));
301 }
302 }
303
304 if (!cancel)
305 {
306 CopyInputTracks(); // Set up mOutputTracks.
307
308 int trackNum = 0;
309
310 for( auto iterTrack : mOutputTracks->Selected< WaveTrack >() )
311 {
312 for (size_t i = 0; i < regions.size(); i++)
313 {
314 const AutoDuckRegion& region = regions[i];
315 if (ApplyDuckFade(trackNum, iterTrack, region.t0, region.t1))
316 {
317 cancel = true;
318 break;
319 }
320 }
321
322 if (cancel)
323 break;
324
325 trackNum++;
326 }
327 }
328
329 ReplaceProcessedTracks(!cancel);
330 return !cancel;
331}
332
333std::unique_ptr<EffectUIValidator> EffectAutoDuck::PopulateOrExchange(
335{
336 S.SetBorder(5);
337 S.StartVerticalLay(true);
338 {
339 S.AddSpace(0, 5);
340
341 mPanel = safenew EffectAutoDuck::Panel(S.GetParent(), wxID_ANY, this);
342 S.AddWindow(mPanel);
343
344 S.AddSpace(0, 5);
345
346 S.StartMultiColumn(6, wxCENTER);
347 {
348 mDuckAmountDbBox = S.Validator<FloatingPointValidator<double>>(
349 1, &mDuckAmountDb, NumValidatorStyle::NO_TRAILING_ZEROES,
351 .NameSuffix(XO("db"))
352 .AddTextBox(XXO("Duck &amount:"), wxT(""), 10);
353 S.AddUnits(XO("dB"));
354
355 mMaximumPauseBox = S.Validator<FloatingPointValidator<double>>(
356 2, &mMaximumPause, NumValidatorStyle::NO_TRAILING_ZEROES,
358 .NameSuffix(XO("seconds"))
359 .AddTextBox(XXO("Ma&ximum pause:"), wxT(""), 10);
360 S.AddUnits(XO("seconds"));
361
362 mOuterFadeDownLenBox = S.Validator<FloatingPointValidator<double>>(
363 2, &mOuterFadeDownLen, NumValidatorStyle::NO_TRAILING_ZEROES,
365 .NameSuffix(XO("seconds"))
366 .AddTextBox(XXO("Outer fade &down length:"), wxT(""), 10);
367 S.AddUnits(XO("seconds"));
368
369 mOuterFadeUpLenBox = S.Validator<FloatingPointValidator<double>>(
370 2, &mOuterFadeUpLen, NumValidatorStyle::NO_TRAILING_ZEROES,
372 .NameSuffix(XO("seconds"))
373 .AddTextBox(XXO("Outer fade &up length:"), wxT(""), 10);
374 S.AddUnits(XO("seconds"));
375
376 mInnerFadeDownLenBox = S.Validator<FloatingPointValidator<double>>(
377 2, &mInnerFadeDownLen, NumValidatorStyle::NO_TRAILING_ZEROES,
379 .NameSuffix(XO("seconds"))
380 .AddTextBox(XXO("Inner fade d&own length:"), wxT(""), 10);
381 S.AddUnits(XO("seconds"));
382
383 mInnerFadeUpLenBox = S.Validator<FloatingPointValidator<double>>(
384 2, &mInnerFadeUpLen, NumValidatorStyle::NO_TRAILING_ZEROES,
386 .NameSuffix(XO("seconds"))
387 .AddTextBox(XXO("Inner &fade up length:"), wxT(""), 10);
388 S.AddUnits(XO("seconds"));
389 }
390 S.EndMultiColumn();
391
392 S.StartMultiColumn(3, wxCENTER);
393 {
394 mThresholdDbBox = S.Validator<FloatingPointValidator<double>>(
395 2, &mThresholdDb, NumValidatorStyle::NO_TRAILING_ZEROES,
397 .NameSuffix(XO("db"))
398 .AddTextBox(XXO("&Threshold:"), wxT(""), 10);
399 S.AddUnits(XO("dB"));
400 }
401 S.EndMultiColumn();
402
403 }
404 S.EndVerticalLay();
405
406 return nullptr;
407}
408
410{
411 return DoTransferDataToWindow();
412}
413
415{
416 mPanel->Refresh(false);
417 return true;
418}
419
420// EffectAutoDuck implementation
421
422// this currently does an exponential fade
424 double t0, double t1)
425{
426 bool cancel = false;
427
428 auto start = t->TimeToLongSamples(t0);
429 auto end = t->TimeToLongSamples(t1);
430
431 Floats buf{ kBufSize };
432 auto pos = start;
433
434 auto fadeDownSamples = t->TimeToLongSamples(
436 if (fadeDownSamples < 1)
437 fadeDownSamples = 1;
438
439 auto fadeUpSamples = t->TimeToLongSamples(
441 if (fadeUpSamples < 1)
442 fadeUpSamples = 1;
443
444 float fadeDownStep = mDuckAmountDb / fadeDownSamples.as_double();
445 float fadeUpStep = mDuckAmountDb / fadeUpSamples.as_double();
446
447 while (pos < end)
448 {
449 const auto len = limitSampleBufferSize( kBufSize, end - pos );
450
451 t->GetFloats(buf.get(), pos, len);
452
453 for (auto i = pos; i < pos + len; i++)
454 {
455 float gainDown = fadeDownStep * (i - start).as_float();
456 float gainUp = fadeUpStep * (end - i).as_float();
457
458 float gain;
459 if (gainDown > gainUp)
460 gain = gainDown;
461 else
462 gain = gainUp;
463 if (gain < mDuckAmountDb)
464 gain = mDuckAmountDb;
465
466 // i - pos is bounded by len:
467 buf[ ( i - pos ).as_size_t() ] *= DB_TO_LINEAR(gain);
468 }
469
470 t->Set((samplePtr)buf.get(), floatSample, pos, len);
471
472 pos += len;
473
474 float curTime = t->LongSamplesToTime(pos);
475 float fractionFinished = (curTime - mT0) / (mT1 - mT0);
476 if (TotalProgress( (trackNum + 1 + fractionFinished) /
477 (GetNumWaveTracks() + 1) ))
478 {
479 cancel = true;
480 break;
481 }
482 }
483
484 return cancel;
485}
486
487void EffectAutoDuck::OnValueChanged(wxCommandEvent & WXUNUSED(evt))
488{
489 mPanel->Refresh(false);
490}
491
492/*
493 * EffectAutoDuck::Panel implementation
494 */
495
496#define CONTROL_POINT_REGION 10 // pixel distance to click on a control point
497#define CONTROL_POINT_MIN_MOVE 5 // min mouse move until value is changed
498
499#define TEXT_DISTANCE 15 // pixel distance text <-> center of control point
500
501#define FADE_DOWN_START 150 // x coordinate
502#define FADE_UP_START 450 // x coordinate
503#define DUCK_AMOUNT_START 50 // y coordinate
504
505#define FADE_SCALE 40 // scale factor for second -> pixel conversion
506#define DUCK_AMOUNT_SCALE 8 // scale factor for db -> pixel conversion
507
508static int GetDistance(const wxPoint& first, const wxPoint& second)
509{
510 int distanceX = abs(first.x - second.x);
511 int distanceY = abs(first.y - second.y);
512 if (distanceX > distanceY)
513 return distanceX;
514 else
515 return distanceY;
516}
517
518BEGIN_EVENT_TABLE(EffectAutoDuck::Panel, wxPanelWrapper)
520 EVT_MOUSE_CAPTURE_CHANGED(EffectAutoDuck::Panel::OnMouseCaptureChanged)
521 EVT_MOUSE_CAPTURE_LOST(EffectAutoDuck::Panel::OnMouseCaptureLost)
526
528 wxWindow *parent, wxWindowID winid, EffectAutoDuck *effect)
529: wxPanelWrapper(parent, winid, wxDefaultPosition, wxSize(600, 300))
530{
531 mParent = parent;
532 mEffect = effect;
533 mCurrentControlPoint = none;
534 mBackgroundBitmap = NULL;
535
536 ResetControlPoints();
537}
538
540{
541 if(HasCapture())
542 ReleaseMouse();
543}
544
546{
547 mControlPoints[innerFadeDown] = wxPoint(-100,-100);
548 mControlPoints[innerFadeUp] = wxPoint(-100,-100);
549 mControlPoints[outerFadeDown] = wxPoint(-100,-100);
550 mControlPoints[outerFadeUp] = wxPoint(-100,-100);
551 mControlPoints[duckAmount] = wxPoint(-100,-100);
552}
553
554void EffectAutoDuck::Panel::OnPaint(wxPaintEvent & WXUNUSED(evt))
555{
556 int clientWidth, clientHeight;
557 GetSize(&clientWidth, &clientHeight);
558
559 if (!mBackgroundBitmap || mBackgroundBitmap->GetWidth() != clientWidth ||
560 mBackgroundBitmap->GetHeight() != clientHeight)
561 {
562 mBackgroundBitmap = std::make_unique<wxBitmap>(clientWidth, clientHeight,24);
563 }
564
565 wxMemoryDC dc;
566 dc.SelectObject(*mBackgroundBitmap);
567
568 dc.SetBrush(*wxWHITE_BRUSH);
569 dc.SetPen(*wxBLACK_PEN);
570 dc.DrawRectangle(0, 0, clientWidth, clientHeight);
571
572 dc.SetFont(wxFont(10, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
573 wxFONTWEIGHT_NORMAL));
574 dc.SetTextForeground(*wxBLACK);
575 dc.SetTextBackground(*wxWHITE);
576
577 double duckAmountDb = 0;
578 double innerFadeDownLen = 0;
579 double innerFadeUpLen = 0;
580 double outerFadeDownLen = 0;
581 double outerFadeUpLen = 0;
582 mEffect->mDuckAmountDbBox->GetValue().ToDouble(&duckAmountDb);
583 mEffect->mInnerFadeDownLenBox->GetValue().ToDouble(&innerFadeDownLen);
584 mEffect->mInnerFadeUpLenBox->GetValue().ToDouble(&innerFadeUpLen);
585 mEffect->mOuterFadeDownLenBox->GetValue().ToDouble(&outerFadeDownLen);
586 mEffect->mOuterFadeUpLenBox->GetValue().ToDouble(&outerFadeUpLen);
587
588 if (innerFadeDownLen < InnerFadeDownLen.min || innerFadeDownLen > InnerFadeDownLen.max ||
589 innerFadeUpLen < InnerFadeUpLen.min || innerFadeUpLen > InnerFadeUpLen.max ||
590 outerFadeDownLen < OuterFadeDownLen.min || outerFadeDownLen > OuterFadeDownLen.max ||
591 outerFadeUpLen < OuterFadeUpLen.min || outerFadeUpLen > OuterFadeUpLen.max ||
592 duckAmountDb < DuckAmountDb.min || duckAmountDb > DuckAmountDb.max)
593 {
594 // values are out of range, no preview available
595 wxString message = _("Preview not available");
596 int textWidth = 0, textHeight = 0;
597 dc.GetTextExtent(message, &textWidth, &textHeight);
598 dc.DrawText(message, (clientWidth - textWidth) / 2,
599 (clientHeight - textHeight) / 2);
600
601 ResetControlPoints();
602 } else
603 {
604 // draw preview
605 dc.SetBrush(*wxTRANSPARENT_BRUSH);
606 dc.SetPen(wxPen(theTheme.Colour(clrGraphLines), 3, wxPENSTYLE_SOLID));
607
608 wxPoint points[6];
609
610 points[0].x = 10;
611 points[0].y = DUCK_AMOUNT_START;
612
613 points[1].x = FADE_DOWN_START - (int)(outerFadeDownLen * FADE_SCALE);
614 points[1].y = DUCK_AMOUNT_START;
615
616 points[2].x = FADE_DOWN_START + (int)(innerFadeDownLen * FADE_SCALE);
617 points[2].y = DUCK_AMOUNT_START -
618 (int)(duckAmountDb * DUCK_AMOUNT_SCALE);
619
620 points[3].x = FADE_UP_START - (int)(innerFadeUpLen * FADE_SCALE);
621 points[3].y = DUCK_AMOUNT_START -
622 (int)(duckAmountDb * DUCK_AMOUNT_SCALE);
623
624 points[4].x = FADE_UP_START + (int)(outerFadeUpLen * FADE_SCALE);
625 points[4].y = DUCK_AMOUNT_START;
626
627 points[5].x = clientWidth - 10;
628 points[5].y = DUCK_AMOUNT_START;
629
630 AColor::Lines(dc, 6, points);
631
632 dc.SetPen(wxPen(*wxBLACK, 1, wxPENSTYLE_DOT));
633
634 AColor::Line(dc, FADE_DOWN_START, 10, FADE_DOWN_START, clientHeight - 10);
635 AColor::Line(dc, FADE_UP_START, 10, FADE_UP_START, clientHeight - 10);
636
637 dc.SetPen(AColor::envelopePen);
638 dc.SetBrush(*wxWHITE_BRUSH);
639
640 mControlPoints[outerFadeDown] = points[1];
641 mControlPoints[innerFadeDown] = points[2];
642 mControlPoints[innerFadeUp] = points[3];
643 mControlPoints[outerFadeUp] = points[4];
644 mControlPoints[duckAmount] = wxPoint(
645 (points[2].x + points[3].x) / 2, points[2].y);
646
647 for (int i = 0; i < AUTO_DUCK_PANEL_NUM_CONTROL_POINTS; i++)
648 {
650 int digits;
651 float value;
652
653 if (cp == innerFadeDown)
654 {
655 value = innerFadeDownLen;
656 digits = 2;
657 }
658 else if (cp == innerFadeUp)
659 {
660 value = innerFadeUpLen;
661 digits = 2;
662 }
663 else if (cp == outerFadeDown)
664 {
665 value = outerFadeDownLen;
666 digits = 2;
667 } else if (cp == outerFadeUp)
668 {
669 value = outerFadeUpLen;
670 digits = 2;
671 }
672 else
673 {
674 value = duckAmountDb;
675 digits = 1;
676 }
677
678 wxString valueStr = Internat::ToDisplayString(value, digits);
679 valueStr += wxT(" ");
680
681 if (cp == duckAmount)
682 /* i18n-hint: short form of 'decibels'.*/
683 valueStr += _("dB");
684 else
685 /* i18n-hint: short form of 'seconds'.*/
686 valueStr += _("s");
687
688 int textWidth = 0, textHeight = 0;
689 GetTextExtent(valueStr, &textWidth, &textHeight);
690
691 int textPosX = mControlPoints[i].x - textWidth / 2;
692 int textPosY = mControlPoints[i].y;
693
694 if (cp == duckAmount || cp == outerFadeDown || cp == outerFadeUp)
695 textPosY -= TEXT_DISTANCE + textHeight;
696 else
697 textPosY += TEXT_DISTANCE;
698
699 dc.DrawText(valueStr, textPosX, textPosY);
700
701 dc.DrawEllipse(mControlPoints[i].x - 3,
702 mControlPoints[i].y - 3, 6, 6);
703 }
704 }
705
706 // copy background buffer to paint dc
707 wxPaintDC paintDC(this);
708 paintDC.Blit(0, 0, clientWidth, clientHeight, &dc, 0, 0);
709
710 // clean up: necessary to free resources on Windows
711 dc.SetPen(wxNullPen);
712 dc.SetBrush(wxNullBrush);
713 dc.SetFont(wxNullFont);
714 dc.SelectObject(wxNullBitmap);
715}
716
718 wxMouseCaptureChangedEvent & WXUNUSED(evt))
719{
720 SetCursor(wxNullCursor);
721 mCurrentControlPoint = none;
722}
723
725 wxMouseCaptureLostEvent & WXUNUSED(evt))
726{
727 mCurrentControlPoint = none;
728
729 if (HasCapture())
730 {
731 ReleaseMouse();
732 }
733}
734
737{
739 int i;
740
741 for (i = 0; i < AUTO_DUCK_PANEL_NUM_CONTROL_POINTS; i++)
742 dist[i] = GetDistance(pt, mControlPoints[i]);
743
744 int curMinimum = 0;
745 for (i = 0; i < AUTO_DUCK_PANEL_NUM_CONTROL_POINTS; i++)
746 if (dist[i] < dist[curMinimum])
747 curMinimum = i;
748
749 if (dist[curMinimum] <= CONTROL_POINT_REGION)
750 return (EControlPoint)curMinimum;
751 else
752 return none;
753}
754
755void EffectAutoDuck::Panel::OnLeftDown(wxMouseEvent & evt)
756{
757 EControlPoint nearest = GetNearestControlPoint(evt.GetPosition());
758
759 if (nearest != none)
760 {
761 // this control point has been clicked
762 mMouseDownPoint = evt.GetPosition();
763
764 mCurrentControlPoint = nearest;
765 mControlPointMoveActivated = false;
766
767 for (int i = 0; i < AUTO_DUCK_PANEL_NUM_CONTROL_POINTS; i++)
768 mMoveStartControlPoints[i] = mControlPoints[i];
769
770 if( !HasCapture() )
771 CaptureMouse();
772 }
773}
774
775void EffectAutoDuck::Panel::OnLeftUp(wxMouseEvent & WXUNUSED(evt))
776{
777 if (mCurrentControlPoint != none)
778 {
779 mCurrentControlPoint = none;
780 ReleaseMouse();
781 }
782}
783
784void EffectAutoDuck::Panel::OnMotion(wxMouseEvent & evt)
785{
786 switch (GetNearestControlPoint(evt.GetPosition()))
787 {
788 case none:
789 SetCursor(wxNullCursor);
790 break;
791 case innerFadeDown:
792 case innerFadeUp:
793 case outerFadeDown:
794 case outerFadeUp:
795 SetCursor(wxCursor(wxCURSOR_SIZEWE));
796 break;
797 case duckAmount:
798 SetCursor(wxCursor(wxCURSOR_SIZENS));
799 break;
800 }
801
802 if (mCurrentControlPoint != none)
803 {
804 if (!mControlPointMoveActivated)
805 {
806 int dist;
807
808 if (mCurrentControlPoint == duckAmount)
809 dist = abs(evt.GetY() - mMouseDownPoint.y);
810 else
811 dist = abs(evt.GetX() - mMouseDownPoint.x);
812
813 if (dist >= CONTROL_POINT_MIN_MOVE)
814 mControlPointMoveActivated = true;
815 }
816
817 if (mControlPointMoveActivated)
818 {
819 float newValue;
820
821 switch (mCurrentControlPoint)
822 {
823 case outerFadeDown:
824 newValue = ((double)(FADE_DOWN_START - evt.GetX())) / FADE_SCALE;
825 mEffect->mOuterFadeDownLen = std::clamp<double>(newValue, OuterFadeDownLen.min, OuterFadeDownLen.max);
826 break;
827 case outerFadeUp:
828 newValue = ((double)(evt.GetX() - FADE_UP_START)) / FADE_SCALE;
829 mEffect->mOuterFadeUpLen = std::clamp<double>(newValue, OuterFadeUpLen.min, OuterFadeUpLen.max);
830 break;
831 case innerFadeDown:
832 newValue = ((double)(evt.GetX() - FADE_DOWN_START)) / FADE_SCALE;
833 mEffect->mInnerFadeDownLen = std::clamp<double>(newValue, InnerFadeDownLen.min, InnerFadeDownLen.max);
834 break;
835 case innerFadeUp:
836 newValue = ((double)(FADE_UP_START - evt.GetX())) / FADE_SCALE;
837 mEffect->mInnerFadeUpLen = std::clamp<double>(newValue, InnerFadeUpLen.min, InnerFadeUpLen.max);
838 break;
839 case duckAmount:
840 newValue = ((double)(DUCK_AMOUNT_START - evt.GetY())) / DUCK_AMOUNT_SCALE;
841 mEffect->mDuckAmountDb = std::clamp<double>(newValue, DuckAmountDb.min, DuckAmountDb.max);
842 break;
843 case none:
844 wxASSERT(false); // should not happen
845 }
846 mEffect->DoTransferDataToWindow();
847 Refresh(false);
848 }
849 }
850}
static const size_t kBufSize
Definition: AutoDuck.cpp:52
#define FADE_DOWN_START
Definition: AutoDuck.cpp:501
#define FADE_UP_START
Definition: AutoDuck.cpp:502
#define FADE_SCALE
Definition: AutoDuck.cpp:505
#define CONTROL_POINT_REGION
Definition: AutoDuck.cpp:496
static const size_t kRMSWindowSize
Definition: AutoDuck.cpp:53
static int GetDistance(const wxPoint &first, const wxPoint &second)
Definition: AutoDuck.cpp:508
#define DUCK_AMOUNT_SCALE
Definition: AutoDuck.cpp:506
#define DUCK_AMOUNT_START
Definition: AutoDuck.cpp:503
#define TEXT_DISTANCE
Definition: AutoDuck.cpp:499
#define CONTROL_POINT_MIN_MOVE
Definition: AutoDuck.cpp:497
#define AUTO_DUCK_PANEL_NUM_CONTROL_POINTS
Definition: AutoDuck.h:23
END_EVENT_TABLE()
@ none
Definition: Dither.h:20
EffectType
@ EffectTypeProcess
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
#define _(s)
Definition: Internat.h:75
#define safenew
Definition: MemoryX.h:10
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:535
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:23
@ floatSample
Definition: SampleFormat.h:34
char * samplePtr
Definition: SampleFormat.h:49
THEME_API Theme theTheme
Definition: Theme.cpp:82
#define S(N)
Definition: ToChars.cpp:64
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:187
static void Lines(wxDC &dc, size_t nPoints, const wxPoint points[])
Definition: AColor.cpp:194
static wxPen envelopePen
Definition: AColor.h:110
Generates EffectParameterMethods overrides from variadic template arguments.
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
EControlPoint GetNearestControlPoint(const wxPoint &pt)
Definition: AutoDuck.cpp:736
void OnMotion(wxMouseEvent &evt)
Definition: AutoDuck.cpp:784
void OnLeftDown(wxMouseEvent &evt)
Definition: AutoDuck.cpp:755
void OnMouseCaptureChanged(wxMouseCaptureChangedEvent &evt)
Definition: AutoDuck.cpp:717
void OnLeftUp(wxMouseEvent &evt)
Definition: AutoDuck.cpp:775
void OnPaint(wxPaintEvent &evt)
Definition: AutoDuck.cpp:554
void OnMouseCaptureLost(wxMouseCaptureLostEvent &evt)
Definition: AutoDuck.cpp:724
Implements the Auto Ducking effect.
Definition: AutoDuck.h:26
static constexpr EffectParameter InnerFadeDownLen
Definition: AutoDuck.h:89
double mInnerFadeDownLen
Definition: AutoDuck.h:64
wxTextCtrl * mInnerFadeUpLenBox
Definition: AutoDuck.h:75
ComponentInterfaceSymbol GetSymbol() const override
Definition: AutoDuck.cpp:101
static constexpr EffectParameter InnerFadeUpLen
Definition: AutoDuck.h:91
wxTextCtrl * mInnerFadeDownLenBox
Definition: AutoDuck.h:74
static constexpr EffectParameter OuterFadeDownLen
Definition: AutoDuck.h:93
Panel * mPanel
Definition: AutoDuck.h:81
wxTextCtrl * mOuterFadeDownLenBox
Definition: AutoDuck.h:76
bool Init() override
Call once to set up state for whole list of tracks to be processed.
Definition: AutoDuck.cpp:125
const WaveTrack * mControlTrack
Definition: AutoDuck.h:71
double mThresholdDb
Definition: AutoDuck.h:68
bool ApplyDuckFade(int trackNum, WaveTrack *t, double t0, double t1)
Definition: AutoDuck.cpp:423
static constexpr EffectParameter MaximumPause
Definition: AutoDuck.h:99
bool DoTransferDataToWindow()
Definition: AutoDuck.cpp:414
wxTextCtrl * mThresholdDbBox
Definition: AutoDuck.h:78
static constexpr EffectParameter ThresholdDb
Definition: AutoDuck.h:97
double mMaximumPause
Definition: AutoDuck.h:69
double mDuckAmountDb
Definition: AutoDuck.h:63
std::unique_ptr< EffectUIValidator > PopulateOrExchange(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access) override
Add controls to effect panel; always succeeds.
Definition: AutoDuck.cpp:333
const EffectParameterMethods & Parameters() const override
Definition: AutoDuck.cpp:39
double mInnerFadeUpLen
Definition: AutoDuck.h:65
bool TransferDataToWindow(const EffectSettings &settings) override
Update controls for the settings.
Definition: AutoDuck.cpp:409
virtual ~EffectAutoDuck()
Definition: AutoDuck.cpp:95
void OnValueChanged(wxCommandEvent &evt)
Definition: AutoDuck.cpp:487
static constexpr EffectParameter DuckAmountDb
Definition: AutoDuck.h:87
EffectType GetType() const override
Type determines how it behaves.
Definition: AutoDuck.cpp:118
double mOuterFadeDownLen
Definition: AutoDuck.h:66
static constexpr EffectParameter OuterFadeUpLen
Definition: AutoDuck.h:95
bool Process(EffectInstance &instance, EffectSettings &settings) override
Actually do the effect here.
Definition: AutoDuck.cpp:178
wxTextCtrl * mMaximumPauseBox
Definition: AutoDuck.h:79
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
Definition: AutoDuck.cpp:111
double mOuterFadeUpLen
Definition: AutoDuck.h:67
static const ComponentInterfaceSymbol Symbol
Definition: AutoDuck.h:30
TranslatableString GetDescription() const override
Definition: AutoDuck.cpp:106
wxTextCtrl * mOuterFadeUpLenBox
Definition: AutoDuck.h:77
wxTextCtrl * mDuckAmountDbBox
Definition: AutoDuck.h:73
double mT1
Definition: EffectBase.h:107
std::shared_ptr< TrackList > mOutputTracks
Definition: EffectBase.h:105
const TrackList * inputTracks() const
Definition: EffectBase.h:102
double mT0
Definition: EffectBase.h:106
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: EffectBase.cpp:236
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:739
int MessageBox(const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={}) const
Definition: Effect.cpp:869
bool TotalProgress(double frac, const TranslatableString &={}) const
Definition: Effect.cpp:683
int GetNumWaveTracks() const
Definition: Effect.h:187
Performs effect computation.
Interface for manipulations of an Effect's settings.
static wxString ToDisplayString(double numberToConvert, int digitsAfterDecimalPoint=-1)
Convert a number to a string, uses the user's locale's decimal separator.
Definition: Internat.cpp:162
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
Retrieve samples from a track in floating-point format, regardless of the storage format.
Definition: SampleTrack.h:65
double LongSamplesToTime(sampleCount pos) const
Convert correctly between a number of samples and an (absolute) time in seconds.
Definition: SampleTrack.cpp:40
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: SampleTrack.cpp:35
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:628
wxColour & Colour(int iIndex)
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
Holds a msgid for the translation catalog; may also bind format arguments.
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
void Set(constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len)
Definition: WaveTrack.cpp:2197
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
BuiltinEffectsModule::Registration< EffectAutoDuck > reg
Definition: AutoDuck.cpp:78
a struct that holds a start and end time.
Definition: AutoDuck.cpp:60
AutoDuckRegion(double t0, double t1)
Definition: AutoDuck.cpp:61
const Type min
Minimum value.
Definition: Shuttle.h:30
const Type max
Maximum value.
Definition: Shuttle.h:31
Externalized state of a plug-in.