Skip to content

Commit

Permalink
Moved setter for Loopingcontrol to constructor, added assertion for !…
Browse files Browse the repository at this point in the history
…= Null

and added Constructor overload to bypass the assertions for the test case.
  • Loading branch information
daschuer committed Mar 28, 2015
1 parent 18feb6d commit 8b6206b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/engine/enginebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ EngineBuffer::EngineBuffer(QString group, ConfigObject<ConfigValue>* _config,
m_pCueControl = new CueControl(group, _config);
addControl(m_pCueControl);

m_pReadAheadManager = new ReadAheadManager(m_pReader);
m_pReadAheadManager->addLoopingControl(m_pLoopingControl);
m_pReadAheadManager = new ReadAheadManager(m_pReader,
m_pLoopingControl);
m_pReadAheadManager->addRateControl(m_pRateControl);

// Construct scaling objects
Expand Down
33 changes: 19 additions & 14 deletions src/engine/readaheadmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,24 @@
#include "engine/ratecontrol.h"
#include "cachingreader.h"

ReadAheadManager::ReadAheadManager(CachingReader* pReader) :
m_pLoopingControl(NULL),
m_pRateControl(NULL),
m_iCurrentPosition(0),
m_pReader(pReader),
m_pCrossFadeBuffer(SampleUtil::alloc(MAX_BUFFER_LEN)) {
// zero out crossfade buffer
ReadAheadManager::ReadAheadManager()
: m_pLoopingControl(NULL),
m_pRateControl(NULL),
m_iCurrentPosition(0),
m_pReader(NULL),
m_pCrossFadeBuffer(SampleUtil::alloc(MAX_BUFFER_LEN)) {
// For testing only: ReadAheadManagerMock
}

ReadAheadManager::ReadAheadManager(CachingReader* pReader,
LoopingControl* pLoopingControl)
: m_pLoopingControl(pLoopingControl),
m_pRateControl(NULL),
m_iCurrentPosition(0),
m_pReader(pReader),
m_pCrossFadeBuffer(SampleUtil::alloc(MAX_BUFFER_LEN)) {
DEBUG_ASSERT(m_pLoopingControl != NULL);
DEBUG_ASSERT(m_pReader != NULL);
SampleUtil::clear(m_pCrossFadeBuffer, MAX_BUFFER_LEN);
}

Expand Down Expand Up @@ -118,10 +129,6 @@ int ReadAheadManager::getNextSamples(double dRate, CSAMPLE* buffer,
return samples_read;
}

void ReadAheadManager::addLoopingControl(LoopingControl* pLoopingControl) {
m_pLoopingControl = pLoopingControl;
}

void ReadAheadManager::addRateControl(RateControl* pRateControl) {
m_pRateControl = pRateControl;
}
Expand Down Expand Up @@ -201,9 +208,7 @@ int ReadAheadManager::getEffectiveVirtualPlaypositionFromLog(double currentVirtu

// Notify EngineControls that we have taken a seek.
if (shouldNotifySeek) {
if (m_pLoopingControl) {
m_pLoopingControl->notifySeek(entry.virtualPlaypositionStart);
}
m_pLoopingControl->notifySeek(entry.virtualPlaypositionStart);
if (m_pRateControl) {
m_pRateControl->notifySeek(entry.virtualPlaypositionStart);
}
Expand Down
6 changes: 4 additions & 2 deletions src/engine/readaheadmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class CachingReader;
// point.
class ReadAheadManager {
public:
explicit ReadAheadManager(CachingReader* reader);
explicit ReadAheadManager(); // Only for testing: ReadAheadManagerMock
explicit ReadAheadManager(CachingReader* reader,
LoopingControl* pLoopingControl);
virtual ~ReadAheadManager();

// Call this method to fill buffer with requested_samples out of the
Expand All @@ -41,7 +43,7 @@ class ReadAheadManager {

// Used to add a new EngineControls that ReadAheadManager will use to decide
// which samples to return.
void addLoopingControl(LoopingControl* pLoopingControl);
void addLoopingControl();
void addRateControl(RateControl* pRateControl);

// Get the current read-ahead position in samples.
Expand Down
2 changes: 1 addition & 1 deletion src/test/enginebufferscalelineartest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace {
class ReadAheadManagerMock : public ReadAheadManager {
public:
ReadAheadManagerMock()
: ReadAheadManager(NULL),
: ReadAheadManager(),
m_pBuffer(NULL),
m_iBufferSize(0),
m_iReadPosition(0),
Expand Down
4 changes: 2 additions & 2 deletions src/test/readaheadmanager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class ReadAheadManagerTest : public MixxxTest {
SampleUtil::clear(m_pBuffer, MAX_BUFFER_LEN);
m_pReader.reset(new StubReader());
m_pLoopControl.reset(new StubLoopControl());
m_pReadAheadManager.reset(new ReadAheadManager(m_pReader.data()));
m_pReadAheadManager->addLoopingControl(m_pLoopControl.data());
m_pReadAheadManager.reset(new ReadAheadManager(m_pReader.data(),
m_pLoopControl.data()));
}

QScopedPointer<StubReader> m_pReader;
Expand Down

0 comments on commit 8b6206b

Please sign in to comment.