1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-21 08:27:13 +01:00

Revert "Bug 2431 - Mac: Real-time effects - Enable checkbox has no effect"

... so I can make a more general fix, for more than only AudioUnit effects

This reverts commit 5e8cfb0c5a.
This commit is contained in:
Paul Licameli
2020-05-29 20:42:18 -04:00
parent a4b0635dd5
commit 9894abc4f4
2 changed files with 36 additions and 99 deletions

View File

@@ -87,13 +87,9 @@ BlackList[] =
}; };
struct CFReleaser struct CFReleaser
{ { void operator () (const void *p) const { if (p) CFRelease(p); } };
void operator () (const void *p) const template <typename T>
{ using CFunique_ptr = std::unique_ptr<T, CFReleaser>;
if (p) CFRelease(p);
}
};
template <typename T> using CFunique_ptr = std::unique_ptr<T, CFReleaser>;
// Uncomment to include parameter IDs in the final name. Only needed if it's // Uncomment to include parameter IDs in the final name. Only needed if it's
// discovered that many effects have duplicate names. It could even be done // discovered that many effects have duplicate names. It could even be done
@@ -362,21 +358,17 @@ unsigned AudioUnitEffectsModule::DiscoverPluginsAtPath(
return 0; return 0;
} }
if (callback) if(callback)
{
callback(this, &effect); callback(this, &effect);
}
return 1; return 1;
} }
bool AudioUnitEffectsModule::IsPluginValid(const PluginPath & path, bool bFast) bool AudioUnitEffectsModule::IsPluginValid(
const PluginPath & path, bool bFast)
{ {
if (bFast) if( bFast )
{
return true; return true;
}
wxString name; wxString name;
return FindAudioUnit(path, name) != NULL; return FindAudioUnit(path, name) != NULL;
} }
@@ -564,13 +556,13 @@ void AudioUnitEffectOptionsDialog::PopulateOrExchange(ShuttleGui & S)
{ {
S.StartStatic(XO("Latency Compensation")); S.StartStatic(XO("Latency Compensation"));
{ {
S.AddVariableText(XO( S.AddVariableText( XO(
"As part of their processing, some Audio Unit effects must delay returning " "As part of their processing, some Audio Unit effects must delay returning "
"audio to Audacity. When not compensating for this delay, you will " "audio to Audacity. When not compensating for this delay, you will "
"notice that small silences have been inserted into the audio. " "notice that small silences have been inserted into the audio. "
"Enabling this option will provide that compensation, but it may " "Enabling this option will provide that compensation, but it may "
"not work for all Audio Unit effects."), "not work for all Audio Unit effects."),
false, 0, 650); false, 0, 650 );
S.StartHorizontalLay(wxALIGN_LEFT); S.StartHorizontalLay(wxALIGN_LEFT);
{ {
@@ -583,7 +575,7 @@ void AudioUnitEffectOptionsDialog::PopulateOrExchange(ShuttleGui & S)
S.StartStatic(XO("User Interface")); S.StartStatic(XO("User Interface"));
{ {
S.AddVariableText(XO( S.AddVariableText( XO(
"Select \"Full\" to use the graphical interface if supplied by the Audio Unit." "Select \"Full\" to use the graphical interface if supplied by the Audio Unit."
" Select \"Generic\" to use the system supplied generic interface." " Select \"Generic\" to use the system supplied generic interface."
#if defined(HAVE_AUDIOUNIT_BASIC_SUPPORT) #if defined(HAVE_AUDIOUNIT_BASIC_SUPPORT)
@@ -693,7 +685,7 @@ void AudioUnitEffectImportDialog::PopulateOrExchange(ShuttleGui & S)
{ {
mList = S.Style(wxLC_REPORT | wxLC_HRULES | wxLC_VRULES | mList = S.Style(wxLC_REPORT | wxLC_HRULES | wxLC_VRULES |
wxLC_NO_SORT_HEADER) wxLC_NO_SORT_HEADER)
.AddListControlReportMode({ XO("Preset"), XO("Location") }); .AddListControlReportMode( { XO("Preset"), XO("Location") } );
} }
S.EndStatic(); S.EndStatic();
} }
@@ -770,7 +762,7 @@ TranslatableString AudioUnitEffectImportDialog::Import(
wxFFile f(fullPath, wxT("r")); wxFFile f(fullPath, wxT("r"));
if (!f.IsOpened()) if (!f.IsOpened())
{ {
return XO("Couldn't open \"%s\"").Format(fullPath); return XO("Couldn't open \"%s\"").Format( fullPath );
} }
// Load it into the buffer // Load it into the buffer
@@ -778,13 +770,13 @@ TranslatableString AudioUnitEffectImportDialog::Import(
wxMemoryBuffer buf(len); wxMemoryBuffer buf(len);
if (f.Read(buf.GetData(), len) != len || f.Error()) if (f.Read(buf.GetData(), len) != len || f.Error())
{ {
return XO("Unable to read the preset from \"%s\"").Format(fullPath); return XO("Unable to read the preset from \"%s\"").Format( fullPath );
} }
wxString parms = wxBase64Encode(buf.GetData(), len); wxString parms = wxBase64Encode(buf.GetData(), len);
if (parms.IsEmpty()) if (parms.IsEmpty())
{ {
return XO("Failed to encode preset from \"%s\"").Format(fullPath); return XO("Failed to encode preset from \"%s\"").Format( fullPath );
} }
// And write it to the config // And write it to the config
@@ -818,7 +810,7 @@ void AudioUnitEffectImportDialog::OnOk(wxCommandEvent & evt)
if (!msg.empty()) if (!msg.empty())
{ {
AudacityMessageBox( AudacityMessageBox(
XO("Could not import \"%s\" preset\n\n%s").Format(name, msg), XO("Could not import \"%s\" preset\n\n%s").Format( name, msg ),
XO("Import Audio Unit Presets"), XO("Import Audio Unit Presets"),
wxOK | wxCENTRE, wxOK | wxCENTRE,
this); this);
@@ -860,8 +852,6 @@ AudioUnitEffect::AudioUnitEffect(const PluginPath & path,
mUnitInitialized = false; mUnitInitialized = false;
mEventListenerRef = NULL; mEventListenerRef = NULL;
mReady = false;
} }
AudioUnitEffect::~AudioUnitEffect() AudioUnitEffect::~AudioUnitEffect()
@@ -1226,7 +1216,7 @@ sampleCount AudioUnitEffect::GetLatency()
&latency, &latency,
&dataSize); &dataSize);
return sampleCount(latency * mSampleRate); return sampleCount( latency * mSampleRate );
} }
return 0; return 0;
@@ -1256,10 +1246,10 @@ bool AudioUnitEffect::ProcessInitialize(sampleCount WXUNUSED(totalLen), ChannelN
{ {
OSStatus result; OSStatus result;
mInputList.reinit(mAudioIns); mInputList.reinit( mAudioIns );
mInputList[0].mNumberBuffers = mAudioIns; mInputList[0].mNumberBuffers = mAudioIns;
mOutputList.reinit(mAudioOuts); mOutputList.reinit( mAudioOuts );
mOutputList[0].mNumberBuffers = mAudioOuts; mOutputList[0].mNumberBuffers = mAudioOuts;
memset(&mTimeStamp, 0, sizeof(AudioTimeStamp)); memset(&mTimeStamp, 0, sizeof(AudioTimeStamp));
@@ -1349,7 +1339,7 @@ size_t AudioUnitEffect::ProcessBlock(float **inBlock, float **outBlock, size_t b
bool AudioUnitEffect::RealtimeInitialize() bool AudioUnitEffect::RealtimeInitialize()
{ {
mMasterIn.reinit(mAudioIns, mBlockSize, true); mMasterIn.reinit(mAudioIns, mBlockSize, true);
mMasterOut.reinit(mAudioOuts, mBlockSize); mMasterOut.reinit( mAudioOuts, mBlockSize );
return ProcessInitialize(0); return ProcessInitialize(0);
} }
@@ -1357,18 +1347,14 @@ bool AudioUnitEffect::RealtimeAddProcessor(unsigned numChannels, float sampleRat
{ {
auto slave = std::make_unique<AudioUnitEffect>(mPath, mName, mComponent, this); auto slave = std::make_unique<AudioUnitEffect>(mPath, mName, mComponent, this);
if (!slave->SetHost(NULL)) if (!slave->SetHost(NULL))
{
return false; return false;
}
slave->SetBlockSize(mBlockSize); slave->SetBlockSize(mBlockSize);
slave->SetChannelCount(numChannels); slave->SetChannelCount(numChannels);
slave->SetSampleRate(sampleRate); slave->SetSampleRate(sampleRate);
if (!CopyParameters(mUnit, slave->mUnit)) if (!CopyParameters(mUnit, slave->mUnit))
{
return false; return false;
}
auto pSlave = slave.get(); auto pSlave = slave.get();
mSlaves.push_back(std::move(slave)); mSlaves.push_back(std::move(slave));
@@ -1379,9 +1365,7 @@ bool AudioUnitEffect::RealtimeAddProcessor(unsigned numChannels, float sampleRat
bool AudioUnitEffect::RealtimeFinalize() bool AudioUnitEffect::RealtimeFinalize()
{ {
for (size_t i = 0, cnt = mSlaves.size(); i < cnt; i++) for (size_t i = 0, cnt = mSlaves.size(); i < cnt; i++)
{
mSlaves[i]->ProcessFinalize(); mSlaves[i]->ProcessFinalize();
}
mSlaves.clear(); mSlaves.clear();
mMasterIn.reset(); mMasterIn.reset();
@@ -1392,46 +1376,26 @@ bool AudioUnitEffect::RealtimeFinalize()
bool AudioUnitEffect::RealtimeSuspend() bool AudioUnitEffect::RealtimeSuspend()
{ {
if (!BypassEffect(true))
{
return false;
}
for (size_t i = 0, cnt = mSlaves.size(); i < cnt; i++)
{
if (!mSlaves[i]->BypassEffect(true))
{
return false;
}
}
return true; return true;
} }
bool AudioUnitEffect::RealtimeResume() bool AudioUnitEffect::RealtimeResume()
{ {
if (!BypassEffect(false)) OSStatus result;
result = AudioUnitReset(mUnit, kAudioUnitScope_Global, 0);
if (result != noErr)
{ {
return false; return false;
} }
for (size_t i = 0, cnt = mSlaves.size(); i < cnt; i++)
{
if (!mSlaves[i]->BypassEffect(false))
{
return false;
}
}
return true; return true;
} }
bool AudioUnitEffect::RealtimeProcessStart() bool AudioUnitEffect::RealtimeProcessStart()
{ {
for (size_t i = 0; i < mAudioIns; i++) for (size_t i = 0; i < mAudioIns; i++)
{
memset(mMasterIn[i].get(), 0, mBlockSize * sizeof(float)); memset(mMasterIn[i].get(), 0, mBlockSize * sizeof(float));
}
mNumSamples = 0; mNumSamples = 0;
@@ -1459,34 +1423,29 @@ size_t AudioUnitEffect::RealtimeProcess(int group,
bool AudioUnitEffect::RealtimeProcessEnd() bool AudioUnitEffect::RealtimeProcessEnd()
{ {
ProcessBlock(reinterpret_cast<float**>(mMasterIn.get()), ProcessBlock(
reinterpret_cast<float**>(mMasterOut.get()), reinterpret_cast<float**>(mMasterIn.get()),
mNumSamples); reinterpret_cast<float**>(mMasterOut.get()),
mNumSamples);
return true; return true;
} }
bool AudioUnitEffect::ShowInterface(wxWindow &parent, bool AudioUnitEffect::ShowInterface(
const EffectDialogFactory &factory, wxWindow &parent, const EffectDialogFactory &factory, bool forceModal)
bool forceModal)
{ {
if (mDialog) if (mDialog)
{ {
if (mDialog->Close(true)) if( mDialog->Close(true) )
{
mDialog = nullptr; mDialog = nullptr;
}
return false; return false;
} }
// mDialog is null // mDialog is null
auto cleanup = valueRestorer(mDialog); auto cleanup = valueRestorer( mDialog );
if (factory) if ( factory )
{
mDialog = factory(parent, mHost, this); mDialog = factory(parent, mHost, this);
}
if (!mDialog) if (!mDialog)
{ {
return false; return false;
@@ -1752,7 +1711,7 @@ bool AudioUnitEffect::PopulateUI(ShuttleGui &S)
else else
#endif #endif
{ {
auto pControl = Destroy_ptr<AUControl>(safenew AUControl); auto pControl = Destroy_ptr<AUControl>( safenew AUControl );
if (!pControl) if (!pControl)
{ {
return false; return false;
@@ -1895,7 +1854,7 @@ void AudioUnitEffect::ExportPresets()
if (!msg.empty()) if (!msg.empty())
{ {
AudacityMessageBox( AudacityMessageBox(
XO("Could not export \"%s\" preset\n\n%s").Format(path, msg), XO("Could not export \"%s\" preset\n\n%s").Format( path, msg ),
XO("Export Audio Unit Presets"), XO("Export Audio Unit Presets"),
wxOK | wxCENTRE, wxOK | wxCENTRE,
mParent); mParent);
@@ -1937,7 +1896,7 @@ void AudioUnitEffect::ImportPresets()
if (!msg.empty()) if (!msg.empty())
{ {
AudacityMessageBox( AudacityMessageBox(
XO("Could not import \"%s\" preset\n\n%s").Format(path, msg), XO("Could not import \"%s\" preset\n\n%s").Format( path, msg ),
XO("Import Audio Unit Presets"), XO("Import Audio Unit Presets"),
wxOK | wxCENTRE, wxOK | wxCENTRE,
mParent); mParent);
@@ -2516,7 +2475,7 @@ void AudioUnitEffect::EventListener(const AudioUnitEvent *inEvent,
} }
} }
} }
// static // static
void AudioUnitEffect::EventListenerCallback(void *inCallbackRefCon, void AudioUnitEffect::EventListenerCallback(void *inCallbackRefCon,
void *inObject, void *inObject,
@@ -2688,24 +2647,4 @@ void AudioUnitEffect::GetChannelCounts()
return; return;
} }
bool AudioUnitEffect::BypassEffect(bool bypass)
{
OSStatus result;
UInt32 value = (bypass ? 1 : 0);
result = AudioUnitSetProperty(mUnit,
kAudioUnitProperty_BypassEffect,
kAudioUnitScope_Global,
0,
&value,
sizeof(value));
if (result != noErr)
{
return false;
}
return true;
}
#endif #endif

View File

@@ -172,8 +172,6 @@ private:
bool CreatePlain(wxWindow *parent); bool CreatePlain(wxWindow *parent);
#endif #endif
bool BypassEffect(bool bypass);
private: private:
PluginPath mPath; PluginPath mPath;