Skip to content

Commit

Permalink
Amplify renders stretch before finding the peak and default gain
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Licameli committed Oct 13, 2023
1 parent fc93184 commit f72b6e0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/effects/Amplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
#include <wx/valtext.h>
#include <wx/log.h>

#include "EffectOutputTracks.h"
#include "ShuttleGui.h"
#include "WaveTrack.h"
#include "WaveTrackUtilities.h"
#include "../widgets/valnum.h"


Expand Down Expand Up @@ -89,7 +91,11 @@ BEGIN_EVENT_TABLE(EffectAmplify, wxEvtHandler)
EVT_CHECKBOX(ID_Clip, EffectAmplify::OnClipCheckBox)
END_EVENT_TABLE()

EffectAmplify::Instance::~Instance() = default;
EffectAmplify::Instance::~Instance()
{
// In case the dialog is cancelled before effect processing
static_cast<EffectAmplify&>(GetEffect()).DestroyOutputTracks();
}

EffectAmplify::EffectAmplify()
{
Expand Down Expand Up @@ -183,8 +189,14 @@ OptionalMessage EffectAmplify::DoLoadFactoryDefaults(EffectSettings &settings)

bool EffectAmplify::Init()
{
auto range = inputTracks()->Selected<const WaveTrack>();
bool hasStretch = any_of(begin(range), end(range),
[this](auto *pTrack){
return WaveTrackUtilities::HasStretch(*pTrack, mT0, mT1); });
if (hasStretch)
range = MakeOutputTracks()->Get().Selected<const WaveTrack>();
mPeak = 0.0;
for (auto t : inputTracks()->Selected<const WaveTrack>()) {
for (auto t : range) {
for (const auto pChannel : t->Channels()) {
auto pair = pChannel->GetMinMax(mT0, mT1); // may throw
const float min = pair.first, max = pair.second;
Expand Down

0 comments on commit f72b6e0

Please sign in to comment.