Skip to content

Commit

Permalink
Merge 7b6bcfa into db1bc55
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Sep 30, 2018
2 parents db1bc55 + 7b6bcfa commit 85dc934
Show file tree
Hide file tree
Showing 72 changed files with 2,417 additions and 1,932 deletions.
191 changes: 99 additions & 92 deletions engine/src/cuestack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ CueStack::CueStack(Doc* doc)
, m_intensity(1.0)
, m_currentIndex(-1)
, m_flashing(false)
, m_fader(NULL)
, m_elapsed(0)
, m_previous(false)
, m_next(false)
Expand Down Expand Up @@ -403,8 +402,9 @@ bool CueStack::isRunning() const
void CueStack::adjustIntensity(qreal fraction)
{
m_intensity = fraction;
if (m_fader != NULL)
m_fader->adjustIntensity(fraction);

foreach (GenericFader *fader, m_fadersMap.values())
fader->adjustIntensity(fraction);
}

qreal CueStack::intensity() const
Expand All @@ -419,37 +419,64 @@ qreal CueStack::intensity() const
void CueStack::setFlashing(bool enable)
{
qDebug() << Q_FUNC_INFO;
if (m_flashing != enable && m_cues.size() > 0)
{
m_flashing = enable;
if (m_flashing == true)
doc()->masterTimer()->registerDMXSource(this);
else
doc()->masterTimer()->unregisterDMXSource(this);
}
if (m_flashing == enable || m_cues.isEmpty())
return;

m_flashing = enable;
if (m_flashing == true)
doc()->masterTimer()->registerDMXSource(this);
}

bool CueStack::isFlashing() const
{
return m_flashing;
}

void CueStack::writeDMX(MasterTimer* timer, QList<Universe*> ua)
void CueStack::writeDMX(MasterTimer *timer, QList<Universe*> ua)
{
Q_UNUSED(timer);
if (isFlashing() == true && m_cues.size() > 0)
if (m_cues.isEmpty())
return;

if (isFlashing())
{
if (m_fadersMap.isEmpty())
{
QHashIterator <uint,uchar> it(m_cues.first().values());
while (it.hasNext() == true)
{
it.next();
FadeChannel fc(doc(), Fixture::invalidId(), it.key());
quint32 universe = fc.universe();
if (universe == Universe::invalid())
continue;

GenericFader *fader = m_fadersMap.value(universe, NULL);
if (fader == NULL)
{
fader = ua[universe]->requestFader();
m_fadersMap[universe] = fader;
}

fc.setTarget(it.value());
fc.setTypeFlag(FadeChannel::Flashing);
fader->add(fc);
}
}
}
else
{
QHashIterator <uint,uchar> it(m_cues.first().values());
QMapIterator <quint32, GenericFader*> it(m_fadersMap);
while (it.hasNext() == true)
{
it.next();
FadeChannel fc;
fc.setChannel(doc(), it.key());
fc.setTarget(it.value());
int uni = qFloor(fc.channel() / 512);
if (uni < ua.size())
ua[uni]->write(fc.channel() - (uni * 512), fc.target());
quint32 universe = it.key();
GenericFader *fader = it.value();
ua[universe]->dismissFader(fader);
}

m_fadersMap.clear();
doc()->masterTimer()->unregisterDMXSource(this);
}
}

Expand All @@ -459,27 +486,19 @@ void CueStack::writeDMX(MasterTimer* timer, QList<Universe*> ua)

bool CueStack::isStarted() const
{
if (m_fader != NULL)
return true;
else
return false;
return m_fadersMap.isEmpty() ? false : true;
}

void CueStack::preRun()
{
qDebug() << Q_FUNC_INFO;

Q_ASSERT(m_fader == NULL);
m_fader = new GenericFader(doc());
m_fader->adjustIntensity(intensity());
m_elapsed = 0;
emit started();
}

void CueStack::write(QList<Universe*> ua)
{
Q_ASSERT(m_fader != NULL);

if (m_cues.size() == 0 || isRunning() == false)
return;

Expand Down Expand Up @@ -512,40 +531,40 @@ void CueStack::write(QList<Universe*> ua)
emit currentCueChanged(m_currentIndex);
}
*/
m_fader->write(ua);
//m_fader->write(ua);

m_elapsed += MasterTimer::tick();
}

void CueStack::postRun(MasterTimer* timer)
void CueStack::postRun(MasterTimer* timer, QList<Universe *> ua)
{
qDebug() << Q_FUNC_INFO;

Q_ASSERT(timer != NULL);
Q_ASSERT(m_fader != NULL);

// Bounce all intensity channels to MasterTimer's fader for zeroing
QHashIterator <FadeChannel,FadeChannel> it(m_fader->channels());
while (it.hasNext() == true)
/* If no fade out is needed, dismiss all the requested faders.
* Otherwise, set all the faders to fade out and let Universe dismiss them
* when done */
if (fadeOutSpeed() == 0)
{
it.next();
FadeChannel fc = it.value();

if (fc.group(doc()) == QLCChannel::Intensity)
QMapIterator <quint32, GenericFader*> it(m_fadersMap);
while (it.hasNext() == true)
{
fc.setStart(fc.current(intensity()));
fc.setCurrent(fc.current(intensity()));
fc.setTarget(0);
fc.setElapsed(0);
fc.setReady(false);
fc.setFadeTime(fadeOutSpeed());
timer->faderAdd(fc);
it.next();
quint32 universe = it.key();
GenericFader *fader = it.value();
ua[universe]->dismissFader(fader);
}
}
else
{
foreach (GenericFader *fader, m_fadersMap.values())
fader->setFadeOut(true, fadeOutSpeed());
}

m_fadersMap.clear();

m_currentIndex = -1;
delete m_fader;
m_fader = NULL;

emit currentCueChanged(m_currentIndex);
emit stopped();
Expand All @@ -567,6 +586,29 @@ int CueStack::previous()
return m_currentIndex;
}

FadeChannel *CueStack::getFader(QList<Universe *> universes, quint32 universeID, quint32 fixtureID, quint32 channel)
{
// get the universe Fader first. If doesn't exist, create it
GenericFader *fader = m_fadersMap.value(universeID, NULL);
if (fader == NULL)
{
fader = universes[universeID]->requestFader();
fader->adjustIntensity(intensity());
m_fadersMap[universeID] = fader;
}

return fader->getChannelFader(doc(), universes[universeID], fixtureID, channel);
}

void CueStack::updateFaderValues(FadeChannel *fc, uchar value, uint fadeTime)
{
fc->setStart(fc->current());
fc->setTarget(value);
fc->setElapsed(0);
fc->setReady(false);
fc->setFadeTime(fadeTime);
}

int CueStack::next()
{
qDebug() << Q_FUNC_INFO;
Expand Down Expand Up @@ -603,58 +645,23 @@ void CueStack::switchCue(int from, int to, const QList<Universe *> ua)
while (oldit.hasNext() == true)
{
oldit.next();
uint absChannel = oldit.key();
quint32 universe = (absChannel >> 9);
FadeChannel *fc = getFader(ua, universe, Fixture::invalidId(), absChannel);

FadeChannel fc(doc(), Fixture::invalidId(), oldit.key());

if (fc.group(doc()) == QLCChannel::Intensity)
{
fc.setElapsed(0);
fc.setReady(false);
fc.setTarget(0);
fc.setFadeTime(oldCue.fadeOutSpeed());
insertStartValue(fc, ua);
m_fader->add(fc);
}
if (fc->type() & FadeChannel::Intensity)
updateFaderValues(fc, 0, oldCue.fadeOutSpeed());
}

// Fade in all channels of the new cue
QHashIterator <uint,uchar> newit(newCue.values());
while (newit.hasNext() == true)
{
newit.next();
FadeChannel fc(doc(), Fixture::invalidId(), newit.key());
fc.setTarget(newit.value());
fc.setElapsed(0);
fc.setReady(false);
fc.setFadeTime(newCue.fadeInSpeed());
insertStartValue(fc, ua);
m_fader->add(fc);
uint absChannel = newit.key();
quint32 universe = (absChannel >> 9);
FadeChannel *fc = getFader(ua, universe, Fixture::invalidId(), absChannel);
updateFaderValues(fc, newit.value(), newCue.fadeInSpeed());
}
}

void CueStack::insertStartValue(FadeChannel& fc, const QList<Universe *> ua)
{
qDebug() << Q_FUNC_INFO;
const QHash <FadeChannel,FadeChannel>& channels(m_fader->channels());
if (channels.contains(fc) == true)
{
// GenericFader contains the channel so grab its current
// value as the new starting value to get a smoother fade
FadeChannel existing = channels[fc];
fc.setStart(existing.current());
fc.setCurrent(fc.start());
}
else
{
// GenericFader didn't have the channel. Grab the starting value from UniverseArray.
quint32 uni = fc.universe();
if (uni != Universe::invalid() && uni < (quint32)ua.count())
{
if (fc.group(doc()) != QLCChannel::Intensity)
fc.setStart(ua[uni]->preGMValue(fc.address()));
else
fc.setStart(0); // HTP channels must start at zero
}
fc.setCurrent(fc.start());
}
}
9 changes: 6 additions & 3 deletions engine/src/cuestack.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <QObject>
#include <QMutex>
#include <QList>
#include <QMap>

#include "dmxsource.h"
#include "cue.h"
Expand Down Expand Up @@ -244,16 +245,18 @@ class CueStack : public QObject, public DMXSource

void preRun();
void write(QList<Universe *> ua);
void postRun(MasterTimer* timer);
void postRun(MasterTimer *timer, QList<Universe *> ua);

private:
int next();
int previous();
FadeChannel *getFader(QList<Universe *> universes, quint32 universeID, quint32 fixtureID, quint32 channel);
void updateFaderValues(FadeChannel *fc, uchar value, uint fadeTime);
void switchCue(int from, int to, const QList<Universe *> ua);
void insertStartValue(FadeChannel& fc, const QList<Universe*> ua);

private:
GenericFader* m_fader;
/** Map used to lookup a GenericFader instance for a Universe ID */
QMap<quint32, GenericFader *> m_fadersMap;
uint m_elapsed;
bool m_previous;
bool m_next;
Expand Down
15 changes: 5 additions & 10 deletions engine/src/dmxsource.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,7 @@ class Universe;
class DMXSource
{
public:
enum SourcePriority
{
Auto = 0,
Override,
SimpleDesk
};

DMXSource() { m_priority = Auto; }
DMXSource() { m_changed = false; }
virtual ~DMXSource() {}

/**
Expand All @@ -53,10 +46,12 @@ class DMXSource
*/
virtual void writeDMX(MasterTimer* timer, QList<Universe*> universes) = 0;

int priority() const { return m_priority; }
/** Get/Set if the DMX source has changed */
bool hasChanged() { return m_changed; }
void setChanged() { m_changed = true; }

protected:
int m_priority;
bool m_changed;
};

/** @} */
Expand Down
1 change: 1 addition & 0 deletions engine/src/doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ bool Doc::addFixture(Fixture* fixture, quint32 id)
{
for (i = inputOutputMap()->universesCount(); i <= uni; i++)
inputOutputMap()->addUniverse(i);
inputOutputMap()->startUniverses();
}

// Add the fixture channels capabilities to the universe they belong
Expand Down

0 comments on commit 85dc934

Please sign in to comment.