Moved the factory to unique pointers
This commit is contained in:
parent
28c12f32f3
commit
7532291545
5 changed files with 13 additions and 14 deletions
|
|
@ -29,7 +29,7 @@ void EffectFactory::registerEffectType(absl::string_view name, Effect::MakeInsta
|
|||
_entries.push_back(std::move(ent));
|
||||
}
|
||||
|
||||
Effect* EffectFactory::makeEffect(absl::Span<const Opcode> members)
|
||||
std::unique_ptr<Effect> EffectFactory::makeEffect(absl::Span<const Opcode> members)
|
||||
{
|
||||
const Opcode* opcode = nullptr;
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ Effect* EffectFactory::makeEffect(absl::Span<const Opcode> members)
|
|||
|
||||
if (!opcode) {
|
||||
DBG("The effect does not specify a type");
|
||||
return new sfz::fx::Nothing;
|
||||
return std::make_unique<sfz::fx::Nothing>();
|
||||
}
|
||||
|
||||
absl::string_view type = opcode->value;
|
||||
|
|
@ -52,13 +52,13 @@ Effect* EffectFactory::makeEffect(absl::Span<const Opcode> members)
|
|||
|
||||
if (it == end) {
|
||||
DBG("Unsupported effect type: " << type);
|
||||
return new sfz::fx::Nothing;
|
||||
return std::make_unique<sfz::fx::Nothing>();
|
||||
}
|
||||
|
||||
Effect* fx = it->make(members);
|
||||
auto fx = std::unique_ptr<Effect>(it->make(members));
|
||||
if (!fx) {
|
||||
DBG("Could not instantiate effect of type: " << type);
|
||||
return new sfz::fx::Nothing;
|
||||
return std::make_unique<sfz::fx::Nothing>();
|
||||
}
|
||||
|
||||
return fx;
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public:
|
|||
@brief Type of the factory function used to instantiate an effect given
|
||||
the contents of the <effect> block
|
||||
*/
|
||||
typedef Effect* (MakeInstance)(absl::Span<const Opcode> members);
|
||||
typedef std::unique_ptr<Effect> (MakeInstance)(absl::Span<const Opcode> members);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -67,7 +67,7 @@ public:
|
|||
/**
|
||||
@brief Instantiates an effect given the contents of the <effect> block.
|
||||
*/
|
||||
Effect* makeEffect(absl::Span<const Opcode> members);
|
||||
std::unique_ptr<Effect> makeEffect(absl::Span<const Opcode> members);
|
||||
|
||||
private:
|
||||
struct FactoryEntry {
|
||||
|
|
|
|||
|
|
@ -256,10 +256,9 @@ void sfz::Synth::handleEffectOpcodes(const std::vector<Opcode>& members)
|
|||
|
||||
// create the effect and add it
|
||||
EffectBus& bus = getOrCreateBus(busIndex);
|
||||
Effect* fx = effectFactory.makeEffect(members);
|
||||
bus.addEffect(std::unique_ptr<Effect>(fx));
|
||||
|
||||
auto fx = effectFactory.makeEffect(members);
|
||||
fx->init(sampleRate);
|
||||
bus.addEffect(std::move(fx));
|
||||
}
|
||||
|
||||
void addEndpointsToVelocityCurve(sfz::Region& region)
|
||||
|
|
|
|||
|
|
@ -72,9 +72,9 @@ namespace fx {
|
|||
}
|
||||
}
|
||||
|
||||
Effect* Lofi::makeInstance(absl::Span<const Opcode> members)
|
||||
std::unique_ptr<Effect> Lofi::makeInstance(absl::Span<const Opcode> members)
|
||||
{
|
||||
std::unique_ptr<Lofi> fx { new Lofi };
|
||||
auto fx = std::make_unique<Lofi>();
|
||||
|
||||
for (const Opcode& opcode : members) {
|
||||
switch (opcode.lettersOnlyHash) {
|
||||
|
|
@ -87,7 +87,7 @@ namespace fx {
|
|||
}
|
||||
}
|
||||
|
||||
return fx.release();
|
||||
return fx;
|
||||
}
|
||||
|
||||
///
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace fx {
|
|||
/**
|
||||
* @brief Instantiates given the contents of the <effect> block.
|
||||
*/
|
||||
static Effect* makeInstance(absl::Span<const Opcode> members);
|
||||
static std::unique_ptr<Effect> makeInstance(absl::Span<const Opcode> members);
|
||||
|
||||
private:
|
||||
float _bitred_depth = 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue