summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbe_ <be.0@gmx.com>2017-12-16 17:17:16 -0600
committerbe_ <be.0@gmx.com>2017-12-16 17:17:16 -0600
commit3ea97980f6e56e53306b2335d2501647bd112f7d (patch)
tree7ad23ea2aea6f91f892d8f938dad59c9b549cda5
parentf24b95ab6c8335a176bbef303de95880f1623240 (diff)
move ownership of EffectStatesMaps and EffectStatesMapArrays to EffectChain
-rw-r--r--src/effects/defs.h2
-rw-r--r--src/effects/effectchain.cpp21
-rw-r--r--src/effects/effectchain.h2
-rw-r--r--src/effects/effectprocessor.h4
-rw-r--r--src/engine/effects/engineeffect.cpp4
-rw-r--r--src/engine/effects/engineeffect.h2
-rw-r--r--src/engine/effects/engineeffectchain.cpp9
-rw-r--r--src/engine/effects/engineeffectchain.h2
-rw-r--r--src/engine/effects/message.h2
9 files changed, 29 insertions, 19 deletions
diff --git a/src/effects/defs.h b/src/effects/defs.h
index f04bd4d8eb..a944c9deab 100644
--- a/src/effects/defs.h
+++ b/src/effects/defs.h
@@ -14,4 +14,4 @@ const int kNumEffectsPerUnit = 4;
class EffectState;
// For sending EffectStates along the MessagePipe
typedef ChannelHandleMap<EffectState*> EffectStatesMap;
-typedef std::array<std::unique_ptr<EffectStatesMap>, kNumEffectsPerUnit> EffectStatesMapArray;
+typedef std::array<EffectStatesMap, kNumEffectsPerUnit> EffectStatesMapArray;
diff --git a/src/effects/effectchain.cpp b/src/effects/effectchain.cpp
index 2e0acd5765..8d2df12770 100644
--- a/src/effects/effectchain.cpp
+++ b/src/effects/effectchain.cpp
@@ -174,8 +174,11 @@ void EffectChain::enableForInputChannel(const ChannelHandleAndGroup& handle_grou
request->channel = handle_group.handle();
// Allocate EffectStates here in the main thread to avoid allocating
- // memory in the realtime audio callback thread.
- auto pEffectStatesMapArray = std::make_unique<EffectStatesMapArray>();
+ // memory in the realtime audio callback thread. Pointers to the
+ // EffectStates are passed to the EffectRequest and the EffectProcessorImpls
+ // store the pointers. The EffectStatesMapArray and EffectStatesMap containers
+ // are owned by this EffectChain so they do not need be reallocated for each
+ // EffectRequest.
//TODO: get actual configuration of engine
const mixxx::EngineParameters bufferParameters(
@@ -183,16 +186,22 @@ void EffectChain::enableForInputChannel(const ChannelHandleAndGroup& handle_grou
MAX_BUFFER_LEN / mixxx::kEngineChannelCount);
for (int i = 0; i < m_effects.size(); ++i) {
- auto pStatesMap = std::make_unique<EffectStatesMap>();
+ auto& pStatesMap = m_effectStatesMapArray[i];
if (m_effects[i] != nullptr) {
for (const auto& outputChannel : m_pEffectsManager->registeredOutputChannels()) {
- pStatesMap->insert(outputChannel.handle(),
+ pStatesMap.insert(outputChannel.handle(),
m_effects[i]->createState(bufferParameters));
}
+ } else {
+ for (EffectState* pState : pStatesMap) {
+ if (pState != nullptr) {
+ delete pState;
+ }
+ }
+ pStatesMap.clear();
}
- pEffectStatesMapArray->at(i) = std::move(pStatesMap);
}
- request->pEffectStatesMapArray = std::move(pEffectStatesMapArray);
+ request->pEffectStatesMapArray = &m_effectStatesMapArray;
m_pEffectsManager->writeRequest(request);
emit(channelStatusChanged(handle_group.name(), true));
diff --git a/src/effects/effectchain.h b/src/effects/effectchain.h
index e9004652df..916e707bf2 100644
--- a/src/effects/effectchain.h
+++ b/src/effects/effectchain.h
@@ -6,6 +6,7 @@
#include <QList>
#include <QDomDocument>
+#include "effects/defs.h"
#include "effects/effect.h"
#include "engine/channelhandle.h"
#include "util/class.h"
@@ -128,6 +129,7 @@ class EffectChain : public QObject {
QList<EffectPointer> m_effects;
EngineEffectChain* m_pEngineEffectChain;
bool m_bAddedToEngine;
+ EffectStatesMapArray m_effectStatesMapArray;
DISALLOW_COPY_AND_ASSIGN(EffectChain);
};
diff --git a/src/effects/effectprocessor.h b/src/effects/effectprocessor.h
index 5305123335..12fa540c9e 100644
--- a/src/effects/effectprocessor.h
+++ b/src/effects/effectprocessor.h
@@ -68,7 +68,7 @@ class EffectProcessor {
const mixxx::EngineParameters& bufferParameters) = 0;
virtual EffectState* createState(const mixxx::EngineParameters& bufferParameters) = 0;
virtual bool loadStatesForInputChannel(const ChannelHandle& inputChannel,
- const std::unique_ptr<EffectStatesMap> pStatesMap) = 0;
+ const EffectStatesMap* pStatesMap) = 0;
// Called from main thread for garbage collection after the last audio thread
// callback executes process() with EffectEnableState::Disabling
virtual void deleteStatesForInputChannel(const ChannelHandle& inputChannel) = 0;
@@ -183,7 +183,7 @@ class EffectProcessorImpl : public EffectProcessor {
};
bool loadStatesForInputChannel(const ChannelHandle& inputChannel,
- const std::unique_ptr<EffectStatesMap> pStatesMap) final {
+ const EffectStatesMap* pStatesMap) final {
// Can't directly cast a ChannelHandleMap from containing the base
// EffectState* type to EffectSpecificState* type, so iterate through
// the ChannelHandleMap to build a new ChannelHandleMap with
diff --git a/src/engine/effects/engineeffect.cpp b/src/engine/effects/engineeffect.cpp
index 32455f1402..6132aedc5d 100644
--- a/src/engine/effects/engineeffect.cpp
+++ b/src/engine/effects/engineeffect.cpp
@@ -61,12 +61,12 @@ EffectState* EngineEffect::createState(const mixxx::EngineParameters& bufferPara
}
void EngineEffect::loadStatesForInputChannel(const ChannelHandle& inputChannel,
- std::unique_ptr<EffectStatesMap> pStatesMap) {
+ EffectStatesMap* pStatesMap) {
if (kEffectDebugOutput) {
qDebug() << "EngineEffect::loadStatesForInputChannel" << this
<< "loading states for input" << inputChannel;
}
- m_pProcessor->loadStatesForInputChannel(inputChannel, std::move(pStatesMap));
+ m_pProcessor->loadStatesForInputChannel(inputChannel, pStatesMap);
}
// Called from the main thread for garbage collection after an input channel is disabled
diff --git a/src/engine/effects/engineeffect.h b/src/engine/effects/engineeffect.h
index d4bbd4dcbe..456076b2c2 100644
--- a/src/engine/effects/engineeffect.h
+++ b/src/engine/effects/engineeffect.h
@@ -36,7 +36,7 @@ class EngineEffect : public EffectsRequestHandler {
EffectState* createState(const mixxx::EngineParameters& bufferParameters);
void loadStatesForInputChannel(const ChannelHandle& inputChannel,
- std::unique_ptr<EffectStatesMap> pStatesMap);
+ EffectStatesMap* pStatesMap);
void deleteStatesForInputChannel(const ChannelHandle& inputChannel);
bool processEffectsRequest(
diff --git a/src/engine/effects/engineeffectchain.cpp b/src/engine/effects/engineeffectchain.cpp
index 37e88d03f3..9dd19eaf6a 100644
--- a/src/engine/effects/engineeffectchain.cpp
+++ b/src/engine/effects/engineeffectchain.cpp
@@ -142,7 +142,7 @@ bool EngineEffectChain::processEffectsRequest(EffectsRequest& message,
}
bool EngineEffectChain::enableForInputChannel(const ChannelHandle& inputHandle,
- std::unique_ptr<EffectStatesMapArray> statesForEffectsInChain) {
+ EffectStatesMapArray* statesForEffectsInChain) {
if (kEffectDebugOutput) {
qDebug() << "EngineEffectChain::enableForInputChannel" << this << inputHandle;
}
@@ -151,7 +151,7 @@ bool EngineEffectChain::enableForInputChannel(const ChannelHandle& inputHandle,
VERIFY_OR_DEBUG_ASSERT(outputChannelStatus.enable_state !=
EffectEnableState::Enabled) {
for (auto&& pStatesMap : *statesForEffectsInChain) {
- for (auto&& pState : *pStatesMap) {
+ for (auto&& pState : pStatesMap) {
delete pState;
}
}
@@ -165,12 +165,11 @@ bool EngineEffectChain::enableForInputChannel(const ChannelHandle& inputHandle,
qDebug() << "EngineEffectChain::enableForInputChannel" << this
<< "loading states for effect" << i;
}
- std::unique_ptr<EffectStatesMap> pStatesMap =
- std::move(statesForEffectsInChain->at(i));
+ EffectStatesMap* pStatesMap = &(*statesForEffectsInChain)[i];
VERIFY_OR_DEBUG_ASSERT(pStatesMap) {
return false;
}
- m_effects[i]->loadStatesForInputChannel(inputHandle, std::move(pStatesMap));
+ m_effects[i]->loadStatesForInputChannel(inputHandle, pStatesMap);
}
}
return true;
diff --git a/src/engine/effects/engineeffectchain.h b/src/engine/effects/engineeffectchain.h
index ceed13c058..f46373d5c5 100644
--- a/src/engine/effects/engineeffectchain.h
+++ b/src/engine/effects/engineeffectchain.h
@@ -60,7 +60,7 @@ class EngineEffectChain : public EffectsRequestHandler {
bool addEffect(EngineEffect* pEffect, int iIndex);
bool removeEffect(EngineEffect* pEffect, int iIndex);
bool enableForInputChannel(const ChannelHandle& inputHandle,
- std::unique_ptr<EffectStatesMapArray> statesForEffectsInChain);
+ EffectStatesMapArray* statesForEffectsInChain);
bool disableForInputChannel(const ChannelHandle& inputHandle);
// Gets or creates a ChannelStatus entry in m_channelStatus for the provided
diff --git a/src/engine/effects/message.h b/src/engine/effects/message.h
index 31a15684d6..db3027c4d8 100644
--- a/src/engine/effects/message.h
+++ b/src/engine/effects/message.h
@@ -136,7 +136,7 @@ struct EffectsRequest {
ChannelHandle channel;
// Used by ENABLE_EFFECT_CHAIN_FOR_INPUT_CHANNEL
- std::unique_ptr<EffectStatesMapArray> pEffectStatesMapArray;
+ EffectStatesMapArray* pEffectStatesMapArray;
// Used by SET_EFFECT_PARAMETER.
double minimum;