1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-22 15:20:15 +02:00

Bug 1934 residual

Allow generate type plug-ins spawned from Nyquist Prompt to create
a new track if none selected.

This commit also fixes preview in generators when there is no selection.
This commit is contained in:
Steve Daulton 2018-08-21 13:11:41 +01:00
parent 06b5d2e945
commit b9ec43433e
4 changed files with 34 additions and 32 deletions

View File

@ -4567,18 +4567,12 @@ bool AudacityProject::DoEffect(const PluginID & ID, const CommandContext &WXUNUS
auto nTracksOriginally = GetTrackCount();
TrackListIterator iter(GetTracks());
Track *t = iter.First();
WaveTrack *newTrack{};
wxWindow *focus = wxWindow::FindFocus();
bool success = false;
auto cleanup = finally( [&] {
if (!success) {
if (newTrack) {
mTracks->Remove(newTrack);
mTrackPanel->Refresh(false);
}
// For now, we're limiting realtime preview to a single effect, so
// make sure the menus reflect that fact that one may have just been
// opened.
@ -4587,7 +4581,6 @@ bool AudacityProject::DoEffect(const PluginID & ID, const CommandContext &WXUNUS
} );
//double prevEndTime = mTracks->GetEndTime();
int count = 0;
bool clean = true;
while (t) {
@ -4598,15 +4591,6 @@ bool AudacityProject::DoEffect(const PluginID & ID, const CommandContext &WXUNUS
t = iter.Next();
}
if (count == 0) {
// No tracks were selected...
if (type == EffectTypeGenerate) {
// Create a NEW track for the generated audio...
newTrack = static_cast<WaveTrack*>(mTracks->Add(mTrackFactory->NewWaveTrack()));
newTrack->SetSelected(true);
}
}
EffectManager & em = EffectManager::Get();
success = em.DoEffect(ID, this, mRate,

View File

@ -1173,15 +1173,40 @@ bool Effect::DoEffect(wxWindow *parent,
mProjectRate = projectRate;
mTracks = list;
// Update track/group counts
CountWaveTracks();
bool isSelection = false;
mDuration = 0.0;
if (GetType() == EffectTypeGenerate)
{
GetPrivateConfig(GetCurrentSettingsGroup(), wxT("LastUsedDuration"), mDuration, GetDefaultDuration());
}
WaveTrack *newTrack{};
bool success = false;
auto oldDuration = mDuration;
auto cleanup = finally( [&] {
if (!success) {
if (newTrack) {
mTracks->Remove(newTrack);
}
// LastUsedDuration may have been modified by Preview.
SetDuration(oldDuration);
}
End();
ReplaceProcessedTracks( false );
} );
wxLogDebug("EFFECT TYPE IS: %s", GetPath());
if ((GetType() == EffectTypeGenerate) && (mNumTracks == 0) && GetPath() != NYQUIST_EFFECTS_PROMPT_ID) {
newTrack = static_cast<WaveTrack*>(mTracks->Add(mFactory->NewWaveTrack()));
newTrack->SetSelected(true);
}
mT0 = selectedRegion->t0();
mT1 = selectedRegion->t1();
if (mT1 > mT0)
@ -1192,10 +1217,9 @@ bool Effect::DoEffect(wxWindow *parent,
double quantMT0 = QUANTIZED_TIME(mT0, mProjectRate);
double quantMT1 = QUANTIZED_TIME(mT1, mProjectRate);
mDuration = quantMT1 - quantMT0;
mT1 = mT0 + mDuration;
isSelection = true;
}
mT1 = mT0 + mDuration;
mDurationFormat = isSelection
? NumericConverter::TimeAndSampleFormat()
@ -1228,13 +1252,6 @@ bool Effect::DoEffect(wxWindow *parent,
return false;
}
auto cleanup = finally( [&] {
End();
// In case of failed effect, be sure to free memory.
ReplaceProcessedTracks( false );
} );
bool returnVal = true;
bool skipFlag = CheckWhetherSkipEffect();
if (skipFlag == false)
@ -1255,6 +1272,7 @@ bool Effect::DoEffect(wxWindow *parent,
selectedRegion->setTimes(mT0, mT1);
}
success = returnVal;
return returnVal;
}
@ -2587,7 +2605,6 @@ void Effect::Preview(bool dryOnly)
mT1 -= mT0;
mT0 = 0.0;
// Update track/group counts
CountWaveTracks();

View File

@ -565,6 +565,10 @@ bool NyquistEffect::Init()
if (!mIsPrompt && !mExternal)
{
//TODO: (bugs):
// 1) If there is more than one plug-in with the same name, GetModificationTime may pick the wrong one.
// 2) If the ;type is changed after the effect has been registered, the plug-in will appear in the wrong menu.
//TODO: If we want to auto-add parameters from spectral selection,
//we will need to modify this test.
//Note that removing it stops the caching of parameter values,
@ -593,8 +597,6 @@ bool NyquistEffect::CheckWhetherSkipEffect()
static void RegisterFunctions();
bool NyquistEffect::Process()
{
// Check for reentrant Nyquist commands.
@ -1024,7 +1026,6 @@ bool NyquistEffect::TransferDataFromWindow()
{
return TransferDataFromPromptWindow();
}
return TransferDataFromEffectWindow();
}