Skip to content

Commit

Permalink
engine: fix 16bit byte order
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Jan 9, 2024
1 parent 40d210c commit ceec55d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 38 deletions.
35 changes: 10 additions & 25 deletions engine/src/fadechannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,11 @@ void FadeChannel::addChannel(quint32 num)
}
}

int FadeChannel::channelCount()
int FadeChannel::channelCount() const
{
if (m_channels.isEmpty())
return 1;

return m_channels.count();
}

Expand Down Expand Up @@ -262,50 +265,32 @@ quint32 FadeChannel::addressInUniverse() const

void FadeChannel::setStart(uchar value, int index)
{
if (m_channels.count() == 1)
m_start = value;
else
((uchar *)&m_start)[index] = value;
((uchar *)&m_start)[channelCount() - 1 - index] = value;
}

uchar FadeChannel::start(int index) const
{
if (index >= m_channels.count())
return uchar(m_start);

return uchar(m_start >> (8 * (m_channels.count() - 1 - index)));
return ((uchar *)&m_start)[channelCount() - 1 - index];
}

void FadeChannel::setTarget(uchar value, int index)
{
if (m_channels.count() == 1)
m_target = value;
else
((uchar *)&m_target)[index] = value;
((uchar *)&m_target)[channelCount() - 1 - index] = value;
}

uchar FadeChannel::target(int index) const
{
if (index >= m_channels.count())
return uchar(m_target);

return uchar(m_target >> (8 * (m_channels.count() - 1 - index)));
return ((uchar *)&m_target)[channelCount() - 1 - index];
}

void FadeChannel::setCurrent(uchar value, int index)
{
if (m_channels.count() == 1)
m_current = value;
else
((uchar *)&m_current)[index] = value;
((uchar *)&m_current)[channelCount() - 1 - index] = value;
}

uchar FadeChannel::current(int index) const
{
if (index >= m_channels.count())
return uchar(m_current);

return uchar(m_current >> (8 * (m_channels.count() - 1 - index)));
return ((uchar *)&m_current)[channelCount() - 1 - index];
}

uchar FadeChannel::current(qreal intensity, int index) const
Expand Down
2 changes: 1 addition & 1 deletion engine/src/fadechannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class FadeChannel
void addChannel(quint32 num);

/** Get the number of channels handled by this fader */
int channelCount();
int channelCount() const;

/** Get the first (or master) channel handled by this fader */
quint32 channel() const;
Expand Down
16 changes: 8 additions & 8 deletions engine/src/genericfader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,19 @@ void GenericFader::write(Universe *universe)
int address = int(fc.addressInUniverse());
uchar value;

if (flags & FadeChannel::SetTarget)
{
fc.removeFlag(FadeChannel::SetTarget);
fc.addFlag(FadeChannel::AutoRemove);
fc.setTarget(universe->preGMValue(address));
}

// counter used at the end to detect channels to remove
int removeCount = fc.channelCount();

// iterate through all the channels handled by this fader
for (int i = 0; i < fc.channelCount(); i++)
{
if (flags & FadeChannel::SetTarget)
{
fc.removeFlag(FadeChannel::SetTarget);
fc.addFlag(FadeChannel::AutoRemove);
fc.setTarget(universe->preGMValue(address + i), i);
}

// Calculate the next step
if (i == 0 && m_paused == false)
fc.nextStep(MasterTimer::tick());
Expand Down Expand Up @@ -346,7 +346,7 @@ void GenericFader::setFadeOut(bool enable, uint fadeTime)

for (int i = 0; i < fc.channelCount(); i++)
{
fc.setStart(fc.current(), i);
fc.setStart(fc.current(i), i);
fc.setTarget(0, i);
}
fc.setElapsed(0);
Expand Down
8 changes: 4 additions & 4 deletions engine/src/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ void Scene::processValue(MasterTimer *timer, QList<Universe*> ua, uint fadeIn, S
}

FadeChannel *fc = fader->getChannelFader(doc(), ua[universe], scv.fxi, scv.channel);
int chIndex = fc->channelIndex(scv.channel);

/** If a blend Function has been set, check if this channel needs to
* be blended from a previous value. If so, mark it for crossfade
Expand All @@ -738,7 +739,6 @@ void Scene::processValue(MasterTimer *timer, QList<Universe*> ua, uint fadeIn, S
Scene *blendScene = qobject_cast<Scene *>(doc()->function(blendFunctionID()));
if (blendScene != NULL && blendScene->checkValue(scv))
{
int chIndex = fc->channelIndex(scv.channel);
fc->addFlag(FadeChannel::CrossFade);
fc->setCurrent(blendScene->value(scv.fxi, scv.channel), chIndex);
qDebug() << "----- BLEND from Scene" << blendScene->name()
Expand All @@ -747,11 +747,11 @@ void Scene::processValue(MasterTimer *timer, QList<Universe*> ua, uint fadeIn, S
}
else
{
qDebug() << "Scene" << name() << "add channel" << scv.channel << "from" << fc->current() << "to" << scv.value;
qDebug() << "Scene" << name() << "add channel" << scv.channel << "from" << fc->current(chIndex) << "to" << scv.value;
}

fc->setStart(fc->current());
fc->setTarget(scv.value);
fc->setStart(fc->current(chIndex), chIndex);
fc->setTarget(scv.value, chIndex);

if (fc->canFade() == false)
{
Expand Down

0 comments on commit ceec55d

Please sign in to comment.