Skip to content

Commit

Permalink
Merge pull request #398 from plugz/chaser_vccuelist_fix_2
Browse files Browse the repository at this point in the history
Chaser on multiple vccuelist
  • Loading branch information
mcallegari committed Nov 27, 2014
2 parents eaaf2d2 + 42c5fa9 commit 0a3483b
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 274 deletions.
141 changes: 114 additions & 27 deletions engine/src/chaser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ Chaser::Chaser(Doc* doc)
, m_fadeOutMode(Default)
, m_holdMode(Common)
, m_startStepIndex(-1)
, m_hasStartIntensity(false)
, m_runnerMutex(QMutex::Recursive)
, m_runner(NULL)
, m_useInternalRunner(true)
{
setName(tr("New Chaser"));

Expand Down Expand Up @@ -546,74 +547,155 @@ void Chaser::postLoad()

/*****************************************************************************
* Next/Previous
* Protected ChaserRunner wrappers
*****************************************************************************/

void Chaser::tap()
{
if (m_useInternalRunner && m_runner != NULL && durationMode() == Common)
QMutexLocker runnerLocker(&m_runnerMutex);
if (m_runner != NULL && durationMode() == Common)
m_runner->tap();
}

void Chaser::setStepIndex(int idx)
{
if (m_useInternalRunner && m_runner != NULL)
QMutexLocker runnerLocker(&m_runnerMutex);
if (m_runner != NULL)
m_runner->setCurrentStep(idx);
else
m_startStepIndex = idx;
}

void Chaser::setStartIntensity(qreal startIntensity)
{
m_startIntensity = startIntensity;
m_hasStartIntensity = true;
}

void Chaser::previous()
{
if (m_useInternalRunner && m_runner != NULL)
QMutexLocker runnerLocker(&m_runnerMutex);
if (m_runner != NULL)
m_runner->previous();
}

void Chaser::next()
{
if (m_useInternalRunner && m_runner != NULL)
QMutexLocker runnerLocker(&m_runnerMutex);
if (m_runner != NULL)
m_runner->next();
}

/*****************************************************************************
* Running
*****************************************************************************/
void Chaser::stopStep(int stepIndex)
{
QMutexLocker runnerLocker(&m_runnerMutex);
if (m_runner != NULL)
m_runner->stopStep(stepIndex);
}

ChaserRunner* Chaser::createRunner(Chaser* self, Doc* doc, quint32 startTime, int startStepIdx)
void Chaser::setCurrentStep(int step, qreal intensity)
{
if (self == NULL || doc == NULL)
return NULL;
QMutexLocker runnerLocker(&m_runnerMutex);
if (m_runner != NULL)
m_runner->setCurrentStep(step, intensity);
}

ChaserRunner* runner = new ChaserRunner(doc, self, startTime);
Q_ASSERT(runner != NULL);
runner->moveToThread(QCoreApplication::instance()->thread());
runner->setParent(self);
if (startStepIdx != -1)
runner->setCurrentStep(startStepIdx);
int Chaser::currentStepIndex() const
{
int ret = m_startStepIndex;
{
QMutexLocker runnerLocker(const_cast<QMutex*>(&m_runnerMutex));
if (m_runner != NULL)
ret = m_runner->currentStepIndex();
}
return ret;
}

int Chaser::computeNextStep(int currentStepIndex) const
{
int ret = m_startStepIndex;
{
QMutexLocker runnerLocker(const_cast<QMutex*>(&m_runnerMutex));
if (m_runner != NULL)
ret = m_runner->computeNextStep(currentStepIndex);
}
return ret;
}

int Chaser::runningStepsNumber() const
{
int ret = 0;
{
QMutexLocker runnerLocker(const_cast<QMutex*>(&m_runnerMutex));
if (m_runner != NULL)
ret = m_runner->runningStepsNumber();
}
return ret;
}

return runner;
ChaserRunnerStep Chaser::currentRunningStep() const
{
ChaserRunnerStep ret;
ret.m_function = NULL;
{
QMutexLocker runnerLocker(const_cast<QMutex*>(&m_runnerMutex));
if (m_runner != NULL)
{
ChaserRunnerStep* step = m_runner->currentRunningStep();
if (step != NULL)
{
ret = *step;
}
}
}
return ret;
}

void Chaser::useInternalRunner(bool enable)
void Chaser::adjustIntensity(qreal fraction, int stepIndex)
{
m_useInternalRunner = enable;
QMutexLocker runnerLocker(&m_runnerMutex);
if (m_runner != NULL)
m_runner->adjustIntensity(fraction, stepIndex);
}

/*****************************************************************************
* Running
*****************************************************************************/

void Chaser::createRunner(quint32 startTime, int startStepIdx)
{
Q_ASSERT(m_runner == NULL);

{
QMutexLocker stepListLocker(&m_stepListMutex);
m_runner = new ChaserRunner(doc(), this, startTime);
}
m_runner->moveToThread(QCoreApplication::instance()->thread());
m_runner->setParent(this);
if (startStepIdx != -1)
m_runner->setCurrentStep(startStepIdx);
}

void Chaser::preRun(MasterTimer* timer)
{
if (m_useInternalRunner)
{
Q_ASSERT(m_runner == NULL);
m_runner = createRunner(this, doc(), elapsed(), m_startStepIndex);
QMutexLocker runnerLocker(&m_runnerMutex);
createRunner(elapsed(), m_startStepIndex);
if (m_hasStartIntensity)
m_runner->setCurrentStep(m_startStepIndex, m_startIntensity);
m_hasStartIntensity = false;
m_startStepIndex = -1;
connect(m_runner, SIGNAL(currentStepChanged(int)), this, SIGNAL(currentStepChanged(int)));
}

Function::preRun(timer);
}

void Chaser::write(MasterTimer* timer, QList<Universe *> universes)
{
if (m_useInternalRunner)
{
QMutexLocker runnerLocker(&m_runnerMutex);
QMutexLocker stepListLocker(&m_stepListMutex);
Q_ASSERT(m_runner != NULL);

if (m_runner->write(timer, universes) == false)
Expand All @@ -625,8 +707,9 @@ void Chaser::write(MasterTimer* timer, QList<Universe *> universes)

void Chaser::postRun(MasterTimer* timer, QList<Universe *> universes)
{
if (m_useInternalRunner && m_runner != NULL)
{
QMutexLocker runnerLocker(&m_runnerMutex);
Q_ASSERT(m_runner != NULL);
m_runner->postRun(timer, universes);

delete m_runner;
Expand All @@ -642,7 +725,11 @@ void Chaser::postRun(MasterTimer* timer, QList<Universe *> universes)

void Chaser::adjustAttribute(qreal fraction, int attributeIndex)
{
if (m_useInternalRunner && m_runner != NULL && attributeIndex == Intensity)
m_runner->adjustIntensity(fraction);
{
QMutexLocker runnerLocker(&m_runnerMutex);
QMutexLocker stepListLocker(&m_stepListMutex);
if (m_runner != NULL && attributeIndex == Intensity)
m_runner->adjustIntensity(fraction);
}
Function::adjustAttribute(fraction, attributeIndex);
}
43 changes: 36 additions & 7 deletions engine/src/chaser.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

#include "function.h"
#include "scene.h"
#include "chaserrunner.h"

class QFile;
class QString;
class ChaserStep;
class MasterTimer;
class ChaserRunner;
class QDomDocument;

/** @addtogroup engine_functions Functions
Expand Down Expand Up @@ -273,11 +273,16 @@ public slots:

/*********************************************************************
* Start/Next/Previous
* ChaserRunner wrappers
*********************************************************************/
public:
/** Set the intensity at start */
void setStartIntensity(qreal startIntensity);

/** @reimpl */
void tap();

/** Set the current step index, or the startup step index if not started */
void setStepIndex(int idx);

/** Skip to the previous step */
Expand All @@ -286,13 +291,39 @@ public slots:
/** Skip to the next step */
void next();

/** Stop a specific running step */
void stopStep(int stepIndex);

/** Set the NEW current step number */
void setCurrentStep(int step, qreal intensity = 1.0);

/** Get the current step number */
int currentStepIndex() const;

/** Compute next step for manual fading */
int computeNextStep(int currentStepIndex) const;

/** Get the running step number. */
int runningStepsNumber() const;

/** Get the first step of the running list. If none is running this returns NULL */
ChaserRunnerStep currentRunningStep() const;

/** Adjust the intensities of chaser steps. */
void adjustIntensity(qreal fraction, int stepIndex = -1);

private:
/** Step index at chaser start */
int m_startStepIndex;

/** Intensity at start */
qreal m_startIntensity;
bool m_hasStartIntensity;

/*********************************************************************
* Running
*********************************************************************/
public:
private:
/**
* Create a ChaserRunner object from the given Chaser. The chaser's
* step mutex is locked & unlocked in this method.
Expand All @@ -301,10 +332,8 @@ public slots:
* @param doc The engine object
* @return NULL if unsuccessful, otherwise a new ChaserRunner*
*/
static ChaserRunner* createRunner(Chaser* self, Doc* doc, quint32 startTime = 0, int startStepIdx = 0);

void useInternalRunner(bool enable);

void createRunner(quint32 startTime = 0, int startStepIdx = 0);
public:
/** @reimpl */
void preRun(MasterTimer* timer);

Expand All @@ -319,8 +348,8 @@ public slots:
void currentStepChanged(int stepNumber);

private:
QMutex m_runnerMutex;
ChaserRunner* m_runner;
bool m_useInternalRunner;

/*************************************************************************
* Intensity
Expand Down
7 changes: 5 additions & 2 deletions engine/src/chaserrunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ void ChaserRunner::stopStep(int stepIndex)
step->m_function->stop();
step->m_function = NULL;
m_runnerSteps.removeOne(step);
delete step;
}
}
}
Expand Down Expand Up @@ -262,7 +263,7 @@ int ChaserRunner::runningStepsNumber() const
return m_runnerSteps.count();
}

ChaserRunnerStep *ChaserRunner::currentRunningStep()
ChaserRunnerStep* ChaserRunner::currentRunningStep() const
{
if (m_runnerSteps.count() > 0)
return m_runnerSteps.at(0);
Expand Down Expand Up @@ -409,6 +410,7 @@ void ChaserRunner::clearRunningList()
step->m_function->stop();
step->m_function = NULL;
}
delete step;
}
m_runnerSteps.clear();
}
Expand Down Expand Up @@ -468,7 +470,7 @@ void ChaserRunner::startNewStep(int index, MasterTimer* timer, bool manualFade)
int ChaserRunner::getNextStepIndex()
{
int currentStepIndex = m_lastRunStepIdx;

if (m_chaser->runOrder() == Function::Random)
{
currentStepIndex = m_order.indexOf(currentStepIndex);
Expand Down Expand Up @@ -608,6 +610,7 @@ bool ChaserRunner::write(MasterTimer* timer, QList<Universe *> universes)
}

m_runnerSteps.removeOne(step);
delete step;
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions engine/src/chaserrunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private slots:
/************************************************************************
* Speed
************************************************************************/
public:
private:
/** Get the currently active fade in value (See Chaser::SpeedMode) */
uint stepFadeIn(int stepIdx) const;

Expand Down Expand Up @@ -100,7 +100,7 @@ private slots:
void tap();

/**
* Stop a specific runnign step
* Stop a specific running step
* @param stepIndex Index of the running step to stop
*/
void stopStep(int stepIndex);
Expand Down Expand Up @@ -137,7 +137,7 @@ private slots:
* Get the first step of the running list.
* If none is running this returns NULL
*/
ChaserRunnerStep *currentRunningStep();
ChaserRunnerStep* currentRunningStep() const;

private:
/**
Expand Down

0 comments on commit 0a3483b

Please sign in to comment.