22
33#include < QObject>
44#include < QVarLengthArray>
5+ #include < array>
56#include < atomic>
7+ #include < memory>
68
79#include " audio/types.h"
810#include " control/controlobject.h"
1517#include " recording/recordingmanager.h"
1618#include " soundio/soundmanager.h"
1719#include " soundio/soundmanagerutil.h"
20+ #include " util/parented_ptr.h"
1821#include " util/samplebuffer.h"
1922
2023class EngineWorkerScheduler ;
@@ -68,6 +71,7 @@ class EngineMixer : public QObject, public AudioSource {
6871
6972 // Add an EngineChannel to the mixing engine. This is not thread safe --
7073 // only call it before the engine has started mixing.
74+ // TODO: take std::unique_ptr<EngineChannel> instead.
7175 void addChannel (EngineChannel* pChannel);
7276 EngineChannel* getChannel (const QString& group);
7377 static inline CSAMPLE_GAIN gainForOrientation (EngineChannel::ChannelOrientation orientation,
@@ -87,7 +91,7 @@ class EngineMixer : public QObject, public AudioSource {
8791
8892 // Provide access to the sync lock so enginebuffers can know what their rate controller is.
8993 EngineSync* getEngineSync () const {
90- return m_pEngineSync;
94+ return m_pEngineSync. get () ;
9195 }
9296
9397 // These are really only exposed for tests to use.
@@ -100,23 +104,20 @@ class EngineMixer : public QObject, public AudioSource {
100104 const CSAMPLE * getSidechainBuffer () const ;
101105
102106 EngineSideChain* getSideChain () const {
103- return m_pEngineSideChain;
107+ return m_pEngineSideChain. get () ;
104108 }
105109
106110 CSAMPLE_GAIN getMainGain (int channelIndex) const ;
107111
108112 struct ChannelInfo {
109113 ChannelInfo (int index)
110- : m_pChannel(NULL ),
111- m_pVolumeControl (NULL ),
112- m_pMuteControl(NULL ),
113- m_index(index) {
114+ : m_index(index) {
114115 }
115116 ChannelHandle m_handle;
116- EngineChannel* m_pChannel;
117+ std::unique_ptr< EngineChannel> m_pChannel;
117118 mixxx::SampleBuffer m_pBuffer;
118- ControlObject* m_pVolumeControl;
119- ControlPushButton* m_pMuteControl;
119+ std::unique_ptr< ControlObject> m_pVolumeControl;
120+ std::unique_ptr< ControlPushButton> m_pMuteControl;
120121 GroupFeatureState m_features;
121122 int m_index;
122123 };
@@ -242,9 +243,9 @@ class EngineMixer : public QObject, public AudioSource {
242243
243244 // ControlObjects for switching off unnecessary processing
244245 // These are protected so tests can set them
245- ControlObject* m_pMainEnabled;
246- ControlObject* m_pHeadphoneEnabled;
247- ControlObject* m_pBoothEnabled;
246+ std::unique_ptr< ControlObject> m_pMainEnabled;
247+ std::unique_ptr< ControlObject> m_pHeadphoneEnabled;
248+ std::unique_ptr< ControlObject> m_pBoothEnabled;
248249
249250 private:
250251 // Processes active channels. The sync lock channel (if any) is processed
@@ -261,11 +262,9 @@ class EngineMixer : public QObject, public AudioSource {
261262 int iBufferSize);
262263 bool sidechainMixRequired () const ;
263264
265+ // non-owning. lifetime bound to EffectsManager
264266 EngineEffectsManager* m_pEngineEffectsManager;
265267
266- // List of channels added to the engine.
267- QVarLengthArray<ChannelInfo*, kPreallocatedChannels > m_channels;
268-
269268 // The previous gain of each channel for each mixing output (main,
270269 // headphone, talkover).
271270 QVarLengthArray<GainCache, kPreallocatedChannels > m_channelMainGainCache;
@@ -281,42 +280,42 @@ class EngineMixer : public QObject, public AudioSource {
281280 mixxx::audio::SampleRate m_sampleRate;
282281
283282 // Mixing buffers for each output.
284- mixxx::SampleBuffer m_outputBusBuffers[ 3 ] ;
283+ std::array< mixxx::SampleBuffer, 3 > m_outputBusBuffers ;
285284 mixxx::SampleBuffer m_booth;
286285 mixxx::SampleBuffer m_head;
287286 mixxx::SampleBuffer m_talkover;
288287 mixxx::SampleBuffer m_talkoverHeadphones;
289288 mixxx::SampleBuffer m_sidechainMix;
290289
291- EngineWorkerScheduler* m_pWorkerScheduler;
292- EngineSync* m_pEngineSync;
293-
294- ControlObject* m_pMainGain;
295- ControlObject* m_pBoothGain;
296- ControlObject* m_pHeadGain;
297- ControlObject* m_pSampleRate;
298- ControlObject* m_pOutputLatencyMs;
299- ControlObject* m_pAudioLatencyOverloadCount;
300- ControlObject* m_pAudioLatencyUsage;
301- ControlObject* m_pAudioLatencyOverload;
302- EngineTalkoverDucking* m_pTalkoverDucking;
303- EngineDelay* m_pMainDelay;
304- EngineDelay* m_pHeadDelay;
305- EngineDelay* m_pBoothDelay;
306- EngineDelay* m_pLatencyCompensationDelay;
307-
308- EngineVuMeter* m_pVumeter;
309- EngineSideChain* m_pEngineSideChain;
310-
311- ControlPotmeter* m_pCrossfader;
312- ControlPotmeter* m_pHeadMix;
313- ControlPotmeter* m_pBalance;
314- ControlPushButton* m_pXFaderMode;
315- ControlPotmeter* m_pXFaderCurve;
316- ControlPotmeter* m_pXFaderCalibration;
317- ControlPushButton* m_pXFaderReverse;
318- ControlPushButton* m_pHeadSplitEnabled;
319- ControlObject* m_pKeylockEngine;
290+ parented_ptr< EngineWorkerScheduler> m_pWorkerScheduler;
291+ std::unique_ptr< EngineSync> m_pEngineSync;
292+
293+ std::unique_ptr< ControlObject> m_pMainGain;
294+ std::unique_ptr< ControlObject> m_pBoothGain;
295+ std::unique_ptr< ControlObject> m_pHeadGain;
296+ std::unique_ptr< ControlObject> m_pSampleRate;
297+ std::unique_ptr< ControlObject> m_pOutputLatencyMs;
298+ std::unique_ptr< ControlObject> m_pAudioLatencyOverloadCount;
299+ std::unique_ptr< ControlObject> m_pAudioLatencyUsage;
300+ std::unique_ptr< ControlObject> m_pAudioLatencyOverload;
301+ std::unique_ptr< EngineTalkoverDucking> m_pTalkoverDucking;
302+ std::unique_ptr< EngineDelay> m_pMainDelay;
303+ std::unique_ptr< EngineDelay> m_pHeadDelay;
304+ std::unique_ptr< EngineDelay> m_pBoothDelay;
305+ std::unique_ptr< EngineDelay> m_pLatencyCompensationDelay;
306+
307+ std::unique_ptr< EngineVuMeter> m_pVumeter;
308+ std::unique_ptr< EngineSideChain> m_pEngineSideChain;
309+
310+ std::unique_ptr< ControlPotmeter> m_pCrossfader;
311+ std::unique_ptr< ControlPotmeter> m_pHeadMix;
312+ std::unique_ptr< ControlPotmeter> m_pBalance;
313+ std::unique_ptr< ControlPushButton> m_pXFaderMode;
314+ std::unique_ptr< ControlPotmeter> m_pXFaderCurve;
315+ std::unique_ptr< ControlPotmeter> m_pXFaderCalibration;
316+ std::unique_ptr< ControlPushButton> m_pXFaderReverse;
317+ std::unique_ptr< ControlPushButton> m_pHeadSplitEnabled;
318+ std::unique_ptr< ControlObject> m_pKeylockEngine;
320319
321320 PflGainCalculator m_headphoneGain;
322321 TalkoverGainCalculator m_talkoverGain;
@@ -338,9 +337,14 @@ class EngineMixer : public QObject, public AudioSource {
338337 const ChannelHandleAndGroup m_busCrossfaderRightHandle;
339338
340339 // Mix two Mono channels. This is useful for outdoor gigs
341- ControlObject* m_pMainMonoMixdown;
342- ControlObject* m_pMicMonitorMode;
340+ std::unique_ptr< ControlObject> m_pMainMonoMixdown;
341+ std::unique_ptr< ControlObject> m_pMicMonitorMode;
343342
343+ // TODO (Swiftb0y): remove volatile (probably supposed to be std::atomic instead).
344344 volatile bool m_bBusOutputConnected[3 ];
345345 bool m_bExternalRecordBroadcastInputConnected;
346+
347+ // Owning list of channels added to the engine.
348+ // Keep at last position, it needs to be destroyed first
349+ QVarLengthArray<std::unique_ptr<ChannelInfo>, kPreallocatedChannels > m_channels;
346350};
0 commit comments