Skip to content

Commit 469d79a

Browse files
committed
fix some calls to virtual methods in virtual class constructors (identified by clang-tidy)
1 parent e3c0d11 commit 469d79a

File tree

6 files changed

+47
-54
lines changed

6 files changed

+47
-54
lines changed

dfx-library/dfxplugin.cpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ This is our class for E-Z plugin-making and E-Z multiple-API support.
4545

4646
#if defined(TARGET_API_VST) && TARGET_PLUGIN_HAS_GUI
4747
#include "dfxguieditor.h"
48-
extern AEffEditor* DFXGUI_NewEditorInstance(DfxPlugin* inEffectInstance);
48+
[[nodiscard]] extern std::unique_ptr<DfxGuiEditor> DFXGUI_NewEditorInstance(DGEditorListenerInstance inEffectInstance);
4949
#endif
5050

5151
#ifdef TARGET_API_RTAS
@@ -204,13 +204,13 @@ DfxPlugin::DfxPlugin(
204204
mNumInputs = VST_NUM_INPUTS;
205205
mNumOutputs = VST_NUM_OUTPUTS;
206206

207-
setUniqueID(PLUGIN_ID);
208-
setNumInputs(VST_NUM_INPUTS);
209-
setNumOutputs(VST_NUM_OUTPUTS);
207+
TARGET_API_BASE_CLASS::setUniqueID(PLUGIN_ID);
208+
TARGET_API_BASE_CLASS::setNumInputs(VST_NUM_INPUTS);
209+
TARGET_API_BASE_CLASS::setNumOutputs(VST_NUM_OUTPUTS);
210210

211211
TARGET_API_BASE_CLASS::setProgram(0); // set the current preset number to 0
212212

213-
noTail(true); // until the plugin declares otherwise
213+
TARGET_API_BASE_CLASS::noTail(true); // until the plugin declares otherwise
214214

215215
// check to see if the host supports sending tempo and time information to VST plugins
216216
// Note that the VST2 SDK (probably erroneously) wants a non-const string here,
@@ -220,18 +220,15 @@ DfxPlugin::DfxPlugin(
220220

221221
#if TARGET_PLUGIN_USES_MIDI
222222
// tell host that we want to use special data chunks for settings storage
223-
programsAreChunks();
223+
TARGET_API_BASE_CLASS::programsAreChunks();
224224
#endif
225225

226226
#if TARGET_PLUGIN_IS_INSTRUMENT
227-
isSynth();
227+
TARGET_API_BASE_CLASS::isSynth();
228228
#endif
229229

230230
#if TARGET_PLUGIN_HAS_GUI
231-
// XXX AEffGUIEditor registers itself, so we probably don't need to assign this
232-
// to the member variable here (and probably should be using AEffect::setEditor?).
233-
// Instead we can probably just call getEditor() if we need it.
234-
editor = DFXGUI_NewEditorInstance(this);
231+
setEditor(DFXGUI_NewEditorInstance(this).release());
235232
#endif
236233
#endif
237234
// end VST stuff
@@ -1126,14 +1123,17 @@ void DfxPlugin::setsamplerate(double inSampleRate)
11261123
if ((mSampleRateChanged = (inSampleRate != DfxPlugin::mSampleRate)))
11271124
{
11281125
#ifdef TARGET_API_AUDIOUNIT
1129-
// assume that sample-specified properties change in absolute duration when sample rate changes
1130-
if (auto const latencySamples = std::get_if<long>(&mLatency); latencySamples && (*latencySamples != 0))
1126+
if (mAUElementsHaveBeenCreated)
11311127
{
1132-
postupdate_latency();
1133-
}
1134-
if (auto const tailSizeSamples = std::get_if<long>(&mTailSize); tailSizeSamples && (*tailSizeSamples != 0))
1135-
{
1136-
postupdate_tailsize();
1128+
// assume that sample-specified properties change in absolute duration when sample rate changes
1129+
if (auto const latencySamples = std::get_if<long>(&mLatency); latencySamples && (*latencySamples != 0))
1130+
{
1131+
postupdate_latency();
1132+
}
1133+
if (auto const tailSizeSamples = std::get_if<long>(&mTailSize); tailSizeSamples && (*tailSizeSamples != 0))
1134+
{
1135+
postupdate_tailsize();
1136+
}
11371137
}
11381138
#endif
11391139
}

dfx-library/dfxplugin.h

+18-18
Original file line numberDiff line numberDiff line change
@@ -826,11 +826,11 @@ class DfxPlugin : public TARGET_API_BASE_CLASS
826826

827827
#if TARGET_PLUGIN_USES_DSPCORE
828828
template <class DSPCoreClass>
829-
std::unique_ptr<DSPCoreClass> dspCoreFactory();
829+
[[nodiscard]] std::unique_ptr<DSPCoreClass> dspCoreFactory();
830830
#ifdef TARGET_API_AUDIOUNIT
831831
ausdk::AUBufferList mAsymmetricalInputBufferList;
832832
#else
833-
std::unique_ptr<DfxPluginCore> dspCoreFactory();
833+
[[nodiscard]] std::unique_ptr<DfxPluginCore> dspCoreFactory();
834834
std::vector<std::unique_ptr<DfxPluginCore>> mDSPCores; // we have to manage this ourselves outside of the AU SDK
835835
std::vector<float> mAsymmetricalInputAudioBuffer;
836836
#endif
@@ -1391,10 +1391,10 @@ class CPluginControl_DfxCurvedFrequency : public CPluginControl_Frequency, publi
13911391
// call this in the plugin's constructor if it uses DSP cores for processing
13921392
#if TARGET_PLUGIN_USES_DSPCORE
13931393
// DFX_CORE_ENTRY is not useful for APIs other than AU, so it is defined as nothing
1394-
#define DFX_CORE_ENTRY(PluginCoreClass) \
1395-
std::unique_ptr<DfxPluginCore> DfxPlugin::dspCoreFactory() \
1396-
{ \
1397-
return dspCoreFactory<PluginCoreClass>(); \
1394+
#define DFX_CORE_ENTRY(PluginCoreClass) \
1395+
[[nodiscard]] std::unique_ptr<DfxPluginCore> DfxPlugin::dspCoreFactory() \
1396+
{ \
1397+
return dspCoreFactory<PluginCoreClass>(); \
13981398
}
13991399
#endif
14001400

@@ -1419,17 +1419,17 @@ class CPluginControl_DfxCurvedFrequency : public CPluginControl_Frequency, publi
14191419
#ifdef TARGET_API_AUDIOSUITE
14201420
#define DFX_NewEffectProcess DFX_NewEffectProcessAS
14211421
#endif
1422-
#define DFX_EFFECT_ENTRY(PluginClass) \
1423-
CEffectProcess* DFX_NewEffectProcess() \
1424-
{ \
1425-
try \
1426-
{ \
1427-
return new PluginClass(nullptr); \
1428-
} \
1429-
catch (...) \
1430-
{ \
1431-
return nullptr; \
1432-
} \
1422+
#define DFX_EFFECT_ENTRY(PluginClass) \
1423+
[[nodiscard]] CEffectProcess* DFX_NewEffectProcess() \
1424+
{ \
1425+
try \
1426+
{ \
1427+
return new PluginClass(nullptr); \
1428+
} \
1429+
catch (...) \
1430+
{ \
1431+
return nullptr; \
1432+
} \
14331433
}
14341434

14351435
#endif // TARGET_API_RTAS
@@ -1439,7 +1439,7 @@ class CPluginControl_DfxCurvedFrequency : public CPluginControl_Frequency, publi
14391439

14401440
#if TARGET_PLUGIN_USES_DSPCORE
14411441
template <class DSPCoreClass>
1442-
std::unique_ptr<DSPCoreClass> DfxPlugin::dspCoreFactory()
1442+
[[nodiscard]] std::unique_ptr<DSPCoreClass> DfxPlugin::dspCoreFactory()
14431443
{
14441444
static_assert(std::is_base_of_v<DfxPluginCore, DSPCoreClass>);
14451445
auto core = std::make_unique<DSPCoreClass>(this);

dfxgui/dfxgui-auviewfactory.mm

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ - (NSView*) uiViewForAudioUnit:(AudioUnit)inAU withSize:(NSSize)inPreferredSize
117117
@implementation DGNSViewForAU
118118
//-----------------------------------------------------------------------------
119119

120-
extern DfxGuiEditor* DFXGUI_NewEditorInstance(AudioUnit inEffectInstance);
120+
[[nodiscard]] extern std::unique_ptr<DfxGuiEditor> DFXGUI_NewEditorInstance(DGEditorListenerInstance inEffectInstance);
121121

122122
//-----------------------------------------------------------------------------
123123
- (id) initWithAU:(AudioUnit)inAU preferredSize:(NSSize)inSize
@@ -129,7 +129,7 @@ - (id) initWithAU:(AudioUnit)inAU preferredSize:(NSSize)inSize
129129
return nil;
130130
}
131131

132-
mDfxGuiEditor.reset(DFXGUI_NewEditorInstance(inAU));
132+
mDfxGuiEditor = DFXGUI_NewEditorInstance(inAU);
133133
if (!mDfxGuiEditor)
134134
{
135135
return nil;

dfxgui/dfxguidialog.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static bool DFXGUI_PressButton(VSTGUI::CTextButton* inButton, bool inState)
6363
//-----------------------------------------------------------------------------
6464
// Dialog Button
6565
//-----------------------------------------------------------------------------
66-
class DGDialogButton : public VSTGUI::CTextButton
66+
class DGDialogButton final : public VSTGUI::CTextButton
6767
{
6868
public:
6969
DGDialogButton(VSTGUI::IControlListener* inListener, DGRect const& inRegion, DGDialog::Selection inSelection, VSTGUI::UTF8StringPtr inTitle)
@@ -179,7 +179,7 @@ class DGDialogButton : public VSTGUI::CTextButton
179179
//-----------------------------------------------------------------------------
180180
// Dialog Text Edit
181181
//-----------------------------------------------------------------------------
182-
class DGDialogTextEdit : public VSTGUI::CTextEdit
182+
class DGDialogTextEdit final : public VSTGUI::CTextEdit
183183
{
184184
public:
185185
DGDialogTextEdit(VSTGUI::CRect const& inRegion, VSTGUI::IControlListener* inListener)

dfxgui/dfxguieditor.cpp

+3-10
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,10 @@ DfxGuiEditor::DfxGuiEditor(DGEditorListenerInstance inInstance)
140140
//-----------------------------------------------------------------------------
141141
DfxGuiEditor::~DfxGuiEditor()
142142
{
143+
assert(!IsOpen());
143144
#ifdef TARGET_API_AUDIOUNIT
144145
RemoveAUEventListeners();
145146
#endif
146-
147-
if (IsOpen())
148-
{
149-
close();
150-
}
151147
}
152148

153149

@@ -231,7 +227,7 @@ void DfxGuiEditor::close()
231227
CloseEditor();
232228

233229
frame->unregisterMouseObserver(this);
234-
// zero the member frame before we delete it so that other asynchronous calls don't crash
230+
// zero the member frame before we release it so that other asynchronous calls don't crash
235231
auto const frame_temp = std::exchange(frame, nullptr);
236232

237233
for (auto& control : mControlsList)
@@ -240,10 +236,7 @@ void DfxGuiEditor::close()
240236
}
241237
mControlsList.clear();
242238

243-
if (frame_temp)
244-
{
245-
frame_temp->forget();
246-
}
239+
frame_temp->forget();
247240

248241
TARGET_API_EDITOR_BASE_CLASS::close();
249242
}

dfxgui/dfxguieditor.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ To contact the author, use the contact form at http://destroyfx.org/
7676

7777

7878
//-----------------------------------------------------------------------------
79-
#define DFX_EDITOR_ENTRY(PluginEditorClass) \
80-
DfxGuiEditor* DFXGUI_NewEditorInstance(DGEditorListenerInstance inEffectInstance) \
81-
{ \
82-
return new PluginEditorClass(inEffectInstance); \
79+
#define DFX_EDITOR_ENTRY(PluginEditorClass) \
80+
[[nodiscard]] std::unique_ptr<DfxGuiEditor> DFXGUI_NewEditorInstance(DGEditorListenerInstance inEffectInstance) \
81+
{ \
82+
return std::make_unique<PluginEditorClass>(inEffectInstance); \
8383
}
8484

8585

0 commit comments

Comments
 (0)