Skip to content

Commit

Permalink
engine: fix LTP fading casting issue and add test unit
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Jun 5, 2024
1 parent aeab64e commit abeec90
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 4 deletions.
7 changes: 5 additions & 2 deletions engine/src/genericfader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,18 @@ void GenericFader::write(Universe *universe)
if ((flags & FadeChannel::CrossFade) && fc.fadeTime() == 0)
{
// morph start <-> target depending on intensities
value = quint32(((qreal(fc.target() - fc.start()) * intensity()) + fc.start()) * parentIntensity());
bool rampUp = fc.target() > fc.start() ? true : false;
value = rampUp ? fc.target() - fc.start() : fc.start() - fc.target();
value = qreal(value) * intensity();
value = qreal(rampUp ? fc.start() + value : fc.start() - value) * parentIntensity();
}
else if (flags & FadeChannel::Intensity)
{
value = fc.current(compIntensity);
}
}

//qDebug() << "[GenericFader] >>> uni:" << universe->id() << ", address:" << (address + i) << ", value:" << value << "int:" << compIntensity;
//qDebug() << "[GenericFader] >>> uni:" << universe->id() << ", address:" << address << ", value:" << value << "int:" << compIntensity;
if (flags & FadeChannel::Override)
{
universe->write(address, value, true);
Expand Down
90 changes: 89 additions & 1 deletion engine/test/chaser/chaser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ void Chaser_Test::cleanupTestCase()
void Chaser_Test::init()
{
m_doc = new Doc(this);

QDir dir(INTERNAL_FIXTUREDIR);
dir.setFilter(QDir::Files);
dir.setNameFilters(QStringList() << QString("*%1").arg(KExtFixture));
QVERIFY(m_doc->fixtureDefCache()->loadMap(dir) == true);
}

void Chaser_Test::cleanup()
Expand Down Expand Up @@ -878,7 +883,7 @@ void Chaser_Test::preRun()
c->postRun(&timer, ua);
}

void Chaser_Test::write()
void Chaser_Test::writeHTP()
{
Fixture* fxi = new Fixture(m_doc);
fxi->setAddress(0);
Expand Down Expand Up @@ -907,22 +912,105 @@ void Chaser_Test::write()
c->start(&timer, FunctionParent::master());

timer.timerTick();

// check step 1
for (uint i = MasterTimer::tick(); i < c->duration(); i += MasterTimer::tick())
{
timer.timerTick();
QVERIFY(c->isRunning() == true);
QVERIFY(c->stopped() == false);
QVERIFY(s1->isRunning() == true);
QVERIFY(s2->isRunning() == false);
}

// check step 2
for (uint i = 0; i < c->duration(); i += MasterTimer::tick())
{
timer.timerTick();
QVERIFY(c->isRunning() == true);
QVERIFY(c->stopped() == false);
QVERIFY(s1->isRunning() == false);
QVERIFY(s2->isRunning() == true);
}
}

void Chaser_Test::writeLTP()
{
QLCFixtureDef* def = m_doc->fixtureDefCache()->fixtureDef("Clay Paky", "Sharpy");
QVERIFY(def != NULL);

QLCFixtureMode* mode = def->mode("Standard");
QVERIFY(mode != NULL);

Fixture* fxi = new Fixture(m_doc);
fxi->setFixtureDefinition(def, mode);
QCOMPARE(fxi->channels(), quint32(16));
m_doc->addFixture(fxi);

Chaser* c = new Chaser(m_doc);
c->setDuration(MasterTimer::tick() * 10);
m_doc->addFunction(c);

Scene* s1 = new Scene(m_doc);
s1->setValue(fxi->id(), 0, 20);
m_doc->addFunction(s1);
c->addStep(s1->id());

Scene* s2 = new Scene(m_doc);
s2->setValue(fxi->id(), 0, 142);
m_doc->addFunction(s2);
c->addStep(s2->id());

MasterTimer timer(m_doc);
QList<Universe*> ua;
ua.append(new Universe(0, new GrandMaster()));

QVERIFY(c->isRunning() == false);
QVERIFY(c->stopped() == true);
c->start(&timer, FunctionParent::master());

timer.timerTick();

// check step 1
for (uint i = MasterTimer::tick(); i < c->duration(); i += MasterTimer::tick())
{
timer.timerTick();
QVERIFY(c->isRunning() == true);
QVERIFY(c->stopped() == false);
QVERIFY(s1->isRunning() == true);
QVERIFY(s2->isRunning() == false);
ua = m_doc->inputOutputMap()->claimUniverses();
ua[0]->processFaders();
QVERIFY(ua[0]->preGMValues()[0] == (char)20);
m_doc->inputOutputMap()->releaseUniverses(false);
}

// check step 2
for (uint i = 0; i < c->duration(); i += MasterTimer::tick())
{
timer.timerTick();
QVERIFY(c->isRunning() == true);
QVERIFY(c->stopped() == false);
QVERIFY(s1->isRunning() == false);
QVERIFY(s2->isRunning() == true);
ua = m_doc->inputOutputMap()->claimUniverses();
ua[0]->processFaders();
QVERIFY(ua[0]->preGMValues()[0] == (char)142);
m_doc->inputOutputMap()->releaseUniverses(false);
}

// check step 1 again
for (uint i = 0; i < c->duration(); i += MasterTimer::tick())
{
timer.timerTick();
QVERIFY(c->isRunning() == true);
QVERIFY(c->stopped() == false);
QVERIFY(s1->isRunning() == true);
QVERIFY(s2->isRunning() == false);
ua = m_doc->inputOutputMap()->claimUniverses();
ua[0]->processFaders();
QVERIFY(ua[0]->preGMValues()[0] == (char)20);
m_doc->inputOutputMap()->releaseUniverses(false);
}
}

Expand Down
3 changes: 2 additions & 1 deletion engine/test/chaser/chaser_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ private slots:

void tap();
void preRun();
void write();
void writeHTP();
void writeLTP();
void postRun();
void adjustIntensity();

Expand Down

0 comments on commit abeec90

Please sign in to comment.