Skip to content

Commit

Permalink
Merge b9c9918 into fe2b812
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Jul 30, 2019
2 parents fe2b812 + b9c9918 commit c52d942
Show file tree
Hide file tree
Showing 16 changed files with 255 additions and 117 deletions.
33 changes: 18 additions & 15 deletions engine/src/chaser.cpp
Expand Up @@ -62,7 +62,8 @@ Chaser::Chaser(Doc *doc)
this, SLOT(slotFunctionRemoved(quint32)));

m_startupAction.m_action = ChaserNoAction;
m_startupAction.m_intensity = 1.0;
m_startupAction.m_masterIntensity = 1.0;
m_startupAction.m_stepIntensity = 1.0;
m_startupAction.m_fadeMode = FromFunction;
m_startupAction.m_stepIndex = -1;
}
Expand Down Expand Up @@ -498,7 +499,8 @@ void Chaser::setAction(ChaserAction &action)
{
m_startupAction.m_action = action.m_action;
m_startupAction.m_stepIndex = action.m_stepIndex;
m_startupAction.m_intensity = action.m_intensity;
m_startupAction.m_masterIntensity = action.m_masterIntensity;
m_startupAction.m_stepIntensity = action.m_stepIntensity;
m_startupAction.m_fadeMode = action.m_fadeMode;
}
}
Expand Down Expand Up @@ -553,19 +555,6 @@ ChaserRunnerStep Chaser::currentRunningStep() const
return ret;
}

void Chaser::adjustStepIntensity(qreal fraction, int stepIndex, FadeControlMode fadeControl)
{
QMutexLocker runnerLocker(&m_runnerMutex);
if (m_runner != NULL)
{
m_runner->adjustStepIntensity(fraction * getAttributeValue(Intensity), stepIndex, fadeControl);
}
else
{
m_startupAction.m_intensity = fraction * getAttributeValue(Intensity);
}
}

bool Chaser::contains(quint32 functionId)
{
Doc *doc = this->doc();
Expand Down Expand Up @@ -683,3 +672,17 @@ int Chaser::adjustAttribute(qreal fraction, int attributeId)

return attrIndex;
}

void Chaser::adjustStepIntensity(qreal fraction, int stepIndex, FadeControlMode fadeControl)
{
QMutexLocker runnerLocker(&m_runnerMutex);
if (m_runner != NULL)
{
m_runner->adjustStepIntensity(fraction, stepIndex, fadeControl);
}
else
{
m_startupAction.m_masterIntensity = getAttributeValue(Function::Intensity);
m_startupAction.m_stepIntensity = fraction;
}
}
7 changes: 4 additions & 3 deletions engine/src/chaser.h
Expand Up @@ -238,9 +238,6 @@ public slots:
/** 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 adjustStepIntensity(qreal fraction, int stepIndex = -1, FadeControlMode fadeControl = FromFunction);

private:
ChaserAction m_startupAction;

Expand Down Expand Up @@ -292,6 +289,10 @@ public slots:
public:
/** @reimp */
int adjustAttribute(qreal fraction, int attributeId);

/** Adjust the intensities of chaser steps. */
void adjustStepIntensity(qreal fraction, int stepIndex = -1,
FadeControlMode fadeControl = FromFunction);
};

/** @} */
Expand Down
3 changes: 2 additions & 1 deletion engine/src/chaseraction.h
Expand Up @@ -34,7 +34,8 @@ enum ChaserActionType
typedef struct
{
ChaserActionType m_action;
qreal m_intensity;
qreal m_masterIntensity;
qreal m_stepIntensity;
int m_fadeMode;
int m_stepIndex;
} ChaserAction;
Expand Down
103 changes: 69 additions & 34 deletions engine/src/chaserrunner.cpp
Expand Up @@ -40,13 +40,15 @@ ChaserRunner::ChaserRunner(const Doc *doc, const Chaser *chaser, quint32 startTi
, m_updateOverrideSpeeds(false)
, m_startOffset(0)
, m_lastRunStepIdx(-1)
, m_lastFunctionID(Function::invalidId())
, m_roundTime(new QElapsedTimer())
, m_order()
{
Q_ASSERT(chaser != NULL);

m_pendingAction.m_action = ChaserNoAction;
m_pendingAction.m_intensity = 1.0;
m_pendingAction.m_masterIntensity = 1.0;
m_pendingAction.m_stepIntensity = 1.0;
m_pendingAction.m_fadeMode = Chaser::FromFunction;
m_pendingAction.m_stepIndex = -1;

Expand Down Expand Up @@ -232,7 +234,8 @@ void ChaserRunner::setAction(ChaserAction &action)
switch (action.m_action)
{
case ChaserNoAction:
m_pendingAction.m_intensity = action.m_intensity;
m_pendingAction.m_masterIntensity = action.m_masterIntensity;
m_pendingAction.m_stepIntensity = action.m_stepIntensity;
break;

case ChaserStopStep:
Expand All @@ -244,9 +247,8 @@ void ChaserRunner::setAction(ChaserAction &action)
if (action.m_stepIndex == step->m_index)
{
qDebug() << "Stopping step idx:" << action.m_stepIndex << "(running:" << m_runnerSteps.count() << ")";
m_lastFunctionID = step->m_function->type() == Function::SceneType ? step->m_function->id() : Function::invalidId();
step->m_function->stop(functionParent());
// restore the original Function blend mode
step->m_function->setBlendMode(step->m_blendMode);
m_runnerSteps.removeOne(step);
delete step;
stopped = true;
Expand All @@ -257,10 +259,6 @@ void ChaserRunner::setAction(ChaserAction &action)
{
ChaserRunnerStep *lastStep = m_runnerSteps.at(0);
m_lastRunStepIdx = lastStep->m_index;
// when only one step remains in the running list,
// it has to run with its original blend mode
if (lastStep->m_function)
lastStep->m_function->setBlendMode(lastStep->m_blendMode);
emit currentStepChanged(m_lastRunStepIdx);
}
}
Expand All @@ -269,7 +267,8 @@ void ChaserRunner::setAction(ChaserAction &action)
// copy to pending action. Will be processed at the next write call
default:
m_pendingAction.m_stepIndex = action.m_stepIndex;
m_pendingAction.m_intensity = action.m_intensity;
m_pendingAction.m_masterIntensity = action.m_masterIntensity;
m_pendingAction.m_stepIntensity = action.m_stepIntensity;
m_pendingAction.m_fadeMode = action.m_fadeMode;
m_pendingAction.m_action = action.m_action;
break;
Expand Down Expand Up @@ -421,20 +420,23 @@ void ChaserRunner::adjustStepIntensity(qreal fraction, int requestedStepIndex, i
if (stepIndex == -1)
{
stepIndex = m_lastRunStepIdx;
// store the intensity to be applied
// at the next step startup
m_pendingAction.m_intensity = fraction;
// store the intensity to be applied at the next step startup
m_pendingAction.m_masterIntensity = fraction;
}

foreach(ChaserRunnerStep *step, m_runnerSteps)
{
if (stepIndex == step->m_index && step->m_function != NULL)
{
if (fadeControl == Chaser::BlendedCrossfade && fraction != 1.0)
step->m_function->setBlendMode(Universe::AdditiveBlend);
if (requestedStepIndex == -1 && step->m_function->type() == Function::SceneType)
{
Scene *scene = qobject_cast<Scene *>(step->m_function);
scene->adjustAttribute(fraction, step->m_pIntensityOverrideId);
}
else
step->m_function->setBlendMode(step->m_blendMode);
step->m_function->adjustAttribute(fraction, step->m_intensityOverrideId);
{
step->m_function->adjustAttribute(fraction, step->m_intensityOverrideId);
}
return;
}
}
Expand All @@ -448,31 +450,31 @@ void ChaserRunner::adjustStepIntensity(qreal fraction, int requestedStepIndex, i
return;

// not found ? It means we need to start a new step and crossfade kicks in !
startNewStep(stepIndex, m_doc->masterTimer(), fraction, fadeControl);
startNewStep(stepIndex, m_doc->masterTimer(), m_pendingAction.m_masterIntensity, fraction, fadeControl);
}

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

void ChaserRunner::clearRunningList()
{
// empty the running queue
foreach(ChaserRunnerStep *step, m_runnerSteps)
{
if (step->m_function)
{
// restore the original Function blend mode and fade out time
step->m_function->setBlendMode(step->m_blendMode);
// restore the original Function fade out time
step->m_function->setOverrideFadeOutSpeed(stepFadeOut(step->m_index));
step->m_function->stop(functionParent());
m_lastFunctionID = step->m_function->type() == Function::SceneType ? step->m_function->id() : Function::invalidId();
}
delete step;
}
m_runnerSteps.clear();
}

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

void ChaserRunner::startNewStep(int index, MasterTimer *timer, qreal intensity,
void ChaserRunner::startNewStep(int index, MasterTimer *timer, qreal mIntensity, qreal sIntensity,
int fadeControl, quint32 elapsed)
{
if (m_chaser == NULL || m_chaser->stepsCount() == 0)
Expand All @@ -488,7 +490,29 @@ void ChaserRunner::startNewStep(int index, MasterTimer *timer, qreal intensity,

ChaserRunnerStep *newStep = new ChaserRunnerStep();
newStep->m_index = index;
newStep->m_blendMode = func->blendMode();

// check if blending between Scenes is needed
if (m_lastFunctionID != Function::invalidId() &&
func->type() == Function::SceneType)
{
Scene *scene = qobject_cast<Scene *>(func);
scene->setBlendFunctionID(m_lastFunctionID);
}

// this happens only during crossfades
if (m_runnerSteps.count())
{
ChaserRunnerStep *lastStep = m_runnerSteps.last();
if (lastStep->m_function &&
lastStep->m_function->type() == Function::SceneType &&
func->type() == Function::SceneType)
{
Scene *lastScene = qobject_cast<Scene *>(lastStep->m_function);
lastScene->setBlendFunctionID(Function::invalidId());
Scene *scene = qobject_cast<Scene *>(func);
scene->setBlendFunctionID(lastStep->m_function->id());
}
}

switch (fadeControl)
{
Expand All @@ -499,8 +523,6 @@ void ChaserRunner::startNewStep(int index, MasterTimer *timer, qreal intensity,
case Chaser::Blended:
newStep->m_fadeIn = stepFadeIn(index);
newStep->m_fadeOut = stepFadeOut(index);
if (newStep->m_fadeIn)
func->setBlendMode(Universe::AdditiveBlend);
break;
case Chaser::Crossfade:
newStep->m_fadeIn = 0;
Expand All @@ -509,7 +531,6 @@ void ChaserRunner::startNewStep(int index, MasterTimer *timer, qreal intensity,
case Chaser::BlendedCrossfade:
newStep->m_fadeIn = 0;
newStep->m_fadeOut = 0;
func->setBlendMode(Universe::AdditiveBlend);
break;
}

Expand All @@ -535,15 +556,26 @@ void ChaserRunner::startNewStep(int index, MasterTimer *timer, qreal intensity,
}

qDebug() << "Starting step" << index << "fade in" << newStep->m_fadeIn
<< "fade out" << newStep->m_fadeOut << "intensity" << intensity
<< "fade out" << newStep->m_fadeOut << "intensity" << mIntensity
<< "fadeMode" << fadeControl;

// Set intensity before starting the function. Otherwise the intensity
// might momentarily jump too high.
newStep->m_intensityOverrideId = newStep->m_function->requestAttributeOverride(Function::Intensity, intensity);
if (func->type() == Function::SceneType)
{
Scene *scene = qobject_cast<Scene *>(func);
newStep->m_intensityOverrideId = func->requestAttributeOverride(Function::Intensity, sIntensity);
newStep->m_pIntensityOverrideId = scene->requestAttributeOverride(Scene::ParentIntensity, mIntensity);
qDebug() << "Set step intensity:" << sIntensity << ", master:" << mIntensity;
}
else
{
newStep->m_intensityOverrideId = func->requestAttributeOverride(Function::Intensity, mIntensity * sIntensity);
}

// Start the fire up !
newStep->m_function->start(timer, functionParent(), 0, newStep->m_fadeIn, newStep->m_fadeOut,
newStep->m_function->defaultSpeed(), m_chaser->tempoType());
func->start(timer, functionParent(), 0, newStep->m_fadeIn, newStep->m_fadeOut,
func->defaultSpeed(), m_chaser->tempoType());
m_runnerSteps.append(newStep);
m_roundTime->restart();
}
Expand Down Expand Up @@ -694,7 +726,8 @@ bool ChaserRunner::write(MasterTimer *timer, QList<Universe *> universes)
clearRunningList();
m_lastRunStepIdx = m_pendingAction.m_stepIndex;
qDebug() << "Starting from step" << m_lastRunStepIdx << "@ offset" << m_startOffset;
startNewStep(m_lastRunStepIdx, timer, m_pendingAction.m_intensity, m_pendingAction.m_fadeMode);
startNewStep(m_lastRunStepIdx, timer, m_pendingAction.m_masterIntensity,
m_pendingAction.m_stepIntensity, m_pendingAction.m_fadeMode);
emit currentStepChanged(m_lastRunStepIdx);
}
break;
Expand All @@ -719,6 +752,7 @@ bool ChaserRunner::write(MasterTimer *timer, QList<Universe *> universes)
if (step->m_duration != 0)
prevStepRoundElapsed = step->m_elapsed % step->m_duration;

m_lastFunctionID = step->m_function->type() == Function::SceneType ? step->m_function->id() : Function::invalidId();
step->m_function->stop(functionParent(), m_chaser->type() == Function::SequenceType);
delete step;
m_runnerSteps.removeOne(step);
Expand Down Expand Up @@ -750,7 +784,8 @@ bool ChaserRunner::write(MasterTimer *timer, QList<Universe *> universes)
{
int blend = m_pendingAction.m_action == ChaserNoAction ? Chaser::FromFunction : m_pendingAction.m_fadeMode;

startNewStep(m_lastRunStepIdx, timer, m_pendingAction.m_intensity, blend, prevStepRoundElapsed);
startNewStep(m_lastRunStepIdx, timer, m_pendingAction.m_masterIntensity,
m_pendingAction.m_stepIntensity, blend, prevStepRoundElapsed);
emit currentStepChanged(m_lastRunStepIdx);
}
else
Expand Down
9 changes: 6 additions & 3 deletions engine/src/chaserrunner.h
Expand Up @@ -51,6 +51,7 @@ typedef struct
uint m_duration; //! Step hold in ms
Universe::BlendMode m_blendMode; //! The original Function blend mode
int m_intensityOverrideId; //! An ID to control the step intensity
int m_pIntensityOverrideId; //! An ID to control the step parent intensity
} ChaserRunnerStep;

class ChaserRunner : public QObject
Expand Down Expand Up @@ -154,6 +155,7 @@ private slots:
quint32 m_startOffset; //! Start step offset time in milliseconds
ChaserAction m_pendingAction; //! Action to be performed on steps at the next write call
int m_lastRunStepIdx; //! Index of the last step ran
quint32 m_lastFunctionID; //! ID of the last Function ran (Scene only)
QElapsedTimer *m_roundTime; //! Counts the time between steps
QVector<int> m_order; //! Array of step indices in a randomized order

Expand All @@ -174,8 +176,8 @@ private slots:
void clearRunningList();

/**
* Start a Chaser step Function with the given $index, at the given $intensity
* and from the given $elapsed time.
* Start a Chaser step Function with the given $index, at the given
* master and step intensity and from the given $elapsed time.
* $fadeControl specifies how the step Function should fade, according to
* the Chaser::FadeControlMode enumeration:
* - Chaser::FromFunction will use the original Function fadeIn time
Expand All @@ -184,7 +186,8 @@ private slots:
* - Chaser::LinkedCrossfade is like Crossfade, and the Function will also be requested
* to use the Universe::AdditiveBlend mode
*/
void startNewStep(int index, MasterTimer *timer, qreal intensity, int fadeControl, quint32 elapsed = 0);
void startNewStep(int index, MasterTimer *timer, qreal mIntensity, qreal sIntensity,
int fadeControl, quint32 elapsed = 0);

/**
* Get the index of the next step that should be started,
Expand Down
3 changes: 2 additions & 1 deletion engine/src/fadechannel.h
Expand Up @@ -51,7 +51,8 @@ class FadeChannel
Flashing = (1 << 4), /** Is flashing */
Relative = (1 << 5), /** Relative position */
Override = (1 << 6), /** Override the current universe value */
Autoremove = (1 << 7) /** Automatically remove the channel once value is written */
Autoremove = (1 << 7), /** Automatically remove the channel once value is written */
CrossFade = (1 << 8) /** Channel subject to crossfade */
};

/** Create a new FadeChannel with empty/invalid values */
Expand Down

0 comments on commit c52d942

Please sign in to comment.