Skip to content

Commit

Permalink
qmlui: started to implement fanning curve maths
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Nov 17, 2019
1 parent ae4a948 commit c866a3f
Show file tree
Hide file tree
Showing 12 changed files with 336 additions and 55 deletions.
158 changes: 139 additions & 19 deletions engine/src/qlcpalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QtMath>
#include <QDebug>

#include "qlcpalette.h"
Expand Down Expand Up @@ -172,58 +173,96 @@ QList<SceneValue> QLCPalette::valuesFromFixtures(Doc *doc, QList<quint32> fixtur
{
QList<SceneValue> list;

int fxCount = fixtures.count();
// nomralized progress in [ 0.0, 1.0 ] range
qreal progress = 0.0;
int intFanValue = fanningValue().toInt();

foreach (quint32 id, fixtures)
{
Fixture *fixture = doc->fixture(id);
if (fixture == NULL)
continue;

qreal factor = valueFactor(progress);

switch(type())
{
case Dimmer:
{
int dValue = value().toInt();
quint32 intCh = fixture->masterIntensityChannel();

qDebug() << "dvalue" << dValue;

if (intCh != QLCChannel::invalid())
list << SceneValue(id, intCh, uchar(value().toUInt()));
{
if (fanningType() != Flat)
dValue = int((qreal(intFanValue - dValue) * factor) + dValue);

qDebug() << "progress" << progress << "factor" << factor << "value" << dValue;
list << SceneValue(id, intCh, uchar(dValue));
}
}
break;
case Color:
{
// TODO loop through heads
QColor col = value().value<QColor>();
QVector<quint32> rgbCh = fixture->rgbChannels();
if (rgbCh.size() == 3)
{
list << SceneValue(id, rgbCh.at(0), uchar(col.red()));
list << SceneValue(id, rgbCh.at(1), uchar(col.green()));
list << SceneValue(id, rgbCh.at(2), uchar(col.blue()));
break;
}
QVector<quint32> cmyCh = fixture->cmyChannels();
if (cmyCh.size() == 3)

for (int i = 0; i < fixture->heads(); i++)
{
list << SceneValue(id, cmyCh.at(0), uchar(col.cyan()));
list << SceneValue(id, cmyCh.at(1), uchar(col.magenta()));
list << SceneValue(id, cmyCh.at(2), uchar(col.yellow()));
QVector<quint32> rgbCh = fixture->rgbChannels(i);
if (rgbCh.size() == 3)
{
list << SceneValue(id, rgbCh.at(0), uchar(col.red()));
list << SceneValue(id, rgbCh.at(1), uchar(col.green()));
list << SceneValue(id, rgbCh.at(2), uchar(col.blue()));
}
QVector<quint32> cmyCh = fixture->cmyChannels(i);
if (cmyCh.size() == 3)
{
list << SceneValue(id, cmyCh.at(0), uchar(col.cyan()));
list << SceneValue(id, cmyCh.at(1), uchar(col.magenta()));
list << SceneValue(id, cmyCh.at(2), uchar(col.yellow()));
}
}
}
break;
case Pan:
{
list << fixture->positionToValues(QLCChannel::Pan, value().toInt());
int degrees = value().toInt();

if (fanningType() != Flat)
degrees = int((qreal(degrees) + qreal(intFanValue) * factor));

list << fixture->positionToValues(QLCChannel::Pan, degrees);
}
break;
case Tilt:
{
list << fixture->positionToValues(QLCChannel::Tilt, value().toInt());
int degrees = m_values.count() == 2 ? m_values.at(1).toInt() : value().toInt();

if (fanningType() != Flat)
degrees = int((qreal(degrees) + qreal(intFanValue) * factor));

list << fixture->positionToValues(QLCChannel::Tilt, degrees);
}
break;
case PanTilt:
{
if (m_values.count() == 2)
{
list << fixture->positionToValues(QLCChannel::Pan, m_values.at(0).toInt());
list << fixture->positionToValues(QLCChannel::Tilt, m_values.at(1).toInt());
int panDegrees = m_values.at(0).toInt();
int tiltDegrees = m_values.at(1).toInt();

if (fanningType() != Flat)
{
panDegrees = int((qreal(panDegrees) + qreal(intFanValue) * factor));
tiltDegrees = int((qreal(tiltDegrees) + qreal(intFanValue) * factor));
}

list << fixture->positionToValues(QLCChannel::Pan, panDegrees);
list << fixture->positionToValues(QLCChannel::Tilt, tiltDegrees);
}
}
break;
Expand All @@ -244,6 +283,8 @@ QList<SceneValue> QLCPalette::valuesFromFixtures(Doc *doc, QList<quint32> fixtur
case Undefined:
break;
}

progress += (1.0 / qreal(fxCount - 1));
}

return list;
Expand All @@ -265,6 +306,65 @@ QList<SceneValue> QLCPalette::valuesFromFixtureGroups(Doc *doc, QList<quint32> g
return list;
}

qreal QLCPalette::valueFactor(qreal progress)
{
qreal factor = 1.0;
qreal normalizedAmount = qreal(m_fanningAmount) / 100.0;

switch (m_fanningType)
{
case Flat:
// nothing to do. Factor is always 1.0
break;
case Linear:
{
if (normalizedAmount < 1.0)
{
if (progress > normalizedAmount)
factor = 1.0;
else
factor = progress * normalizedAmount;
}
else if (normalizedAmount > 1.0)
{
factor = progress / normalizedAmount;
}
else
{
factor = progress;
}
}
break;
case Sine:
{
//qreal degrees = (progress * 3.6) + 270;


}
break;
case Square:
{
if (normalizedAmount < 1.0)
{
factor = progress < normalizedAmount ? 0.0 : 1.0;
}
else if (normalizedAmount > 1.0)
{

}
else
{
factor = progress < 0.5 ? 0.0 : 1.0;
}
}
break;
case Saw:
break;
}

return factor;
}

/************************************************************************
* Fanning
************************************************************************/
Expand All @@ -276,7 +376,12 @@ QLCPalette::FanningType QLCPalette::fanningType() const

void QLCPalette::setFanningType(QLCPalette::FanningType type)
{
if (type == m_fanningType)
return;

m_fanningType = type;

emit fanningTypeChanged();
}

QString QLCPalette::fanningTypeToString(QLCPalette::FanningType type)
Expand Down Expand Up @@ -316,7 +421,12 @@ QLCPalette::FanningLayout QLCPalette::fanningLayout() const

void QLCPalette::setFanningLayout(QLCPalette::FanningLayout layout)
{
if (layout == m_fanningLayout)
return;

m_fanningLayout = layout;

emit fanningLayoutChanged();
}

QString QLCPalette::fanningLayoutToString(QLCPalette::FanningLayout layout)
Expand Down Expand Up @@ -356,7 +466,12 @@ int QLCPalette::fanningAmount() const

void QLCPalette::setFanningAmount(int amount)
{
if (amount == m_fanningAmount)
return;

m_fanningAmount = amount;

emit fanningAmountChanged();
}

QVariant QLCPalette::fanningValue() const
Expand All @@ -366,7 +481,12 @@ QVariant QLCPalette::fanningValue() const

void QLCPalette::setFanningValue(QVariant value)
{
if (value == m_fanningValue)
return;

m_fanningValue = value;

emit fanningValueChanged();
}

/************************************************************************
Expand Down
18 changes: 18 additions & 0 deletions engine/src/qlcpalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class QLCPalette : public QObject
Q_PROPERTY(quint32 id READ id CONSTANT)
Q_PROPERTY(int type READ type CONSTANT)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(FanningType fanningType READ fanningType WRITE setFanningType NOTIFY fanningTypeChanged)
Q_PROPERTY(FanningLayout fanningLayout READ fanningLayout WRITE setFanningLayout NOTIFY fanningLayoutChanged)
Q_PROPERTY(int fanningAmount READ fanningAmount WRITE setFanningAmount NOTIFY fanningAmountChanged)
Q_PROPERTY(QVariant fanningValue READ fanningValue WRITE setFanningValue NOTIFY fanningValueChanged)

public:
/**
Expand Down Expand Up @@ -110,6 +114,14 @@ class QLCPalette : public QObject
QList<SceneValue> valuesFromFixtures(Doc *doc, QList<quint32>fixtures);
QList<SceneValue> valuesFromFixtureGroups(Doc *doc, QList<quint32>groups);

protected:
/** This method returns a normalized factor between 0.0 and 1.0
* which will then be multiplied by a value to obtain the final
* DMX value.
* It considers the fanning algorithm and amount and with
* the provided progress it can calculate the X-axis value. */
qreal valueFactor(qreal progress);

signals:
void nameChanged();

Expand Down Expand Up @@ -171,6 +183,12 @@ class QLCPalette : public QObject
QVariant fanningValue() const;
void setFanningValue(QVariant value);

signals:
void fanningTypeChanged();
void fanningLayoutChanged();
void fanningAmountChanged();
void fanningValueChanged();

private:
FanningType m_fanningType;
FanningLayout m_fanningLayout;
Expand Down
2 changes: 1 addition & 1 deletion qmlui/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void App::startup()
m_fixtureGroupEditor = new FixtureGroupEditor(this, m_doc);
m_functionManager = new FunctionManager(this, m_doc);
m_contextManager = new ContextManager(this, m_doc, m_fixtureManager, m_functionManager);
m_paletteManager = new PaletteManager(this, m_doc);
m_paletteManager = new PaletteManager(this, m_doc, m_contextManager);

m_virtualConsole = new VirtualConsole(this, m_doc, m_contextManager);
m_showManager = new ShowManager(this, m_doc);
Expand Down
19 changes: 15 additions & 4 deletions qmlui/contextmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,9 +1185,9 @@ void ContextManager::slotFixtureFlagsChanged(quint32 itemID, quint32 flags)
void ContextManager::slotChannelValueChanged(quint32 fxID, quint32 channel, quint8 value)
{
if (m_editingEnabled == false)
setDumpValue(fxID, channel, (uchar)value);
setDumpValue(fxID, channel, uchar(value));
else
m_functionManager->setChannelValue(fxID, channel, (uchar)value);
m_functionManager->setChannelValue(fxID, channel, uchar(value));
}

void ContextManager::slotChannelTypeValueChanged(int type, quint8 value, quint32 channel)
Expand All @@ -1199,9 +1199,9 @@ void ContextManager::slotChannelTypeValueChanged(int type, quint8 value, quint32
if (channel == UINT_MAX || channel == sv.channel)
{
if (m_editingEnabled == false)
setDumpValue(sv.fxi, sv.channel, (uchar)value);
setDumpValue(sv.fxi, sv.channel, uchar(value));
else
m_functionManager->setChannelValue(sv.fxi, sv.channel, (uchar)value);
m_functionManager->setChannelValue(sv.fxi, sv.channel, uchar(value));
}
}
}
Expand Down Expand Up @@ -1246,6 +1246,17 @@ void ContextManager::setPositionValue(int type, int degrees)
}
}

void ContextManager::setChannelValues(QList<SceneValue> values)
{
for (SceneValue sv : values)
{
if (m_editingEnabled == false)
setDumpValue(sv.fxi, sv.channel, sv.value);
else
m_functionManager->setChannelValue(sv.fxi, sv.channel, sv.value);
}
}

void ContextManager::slotPresetChanged(const QLCChannel *channel, quint8 value)
{
for (quint32 itemID : m_selectedFixtures)
Expand Down
3 changes: 2 additions & 1 deletion qmlui/contextmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ public slots:
/** Set a Pan/Tilt position in degrees */
Q_INVOKABLE void setPositionValue(int type, int degrees);

void setChannelValues(QList<SceneValue> values);

protected slots:
void slotNewFixtureCreated(quint32 fxID, qreal x, qreal y, qreal z = 0);
void slotFixtureDeleted(quint32 itemID);
Expand Down Expand Up @@ -293,7 +295,6 @@ protected slots:

GenericDMXSource *dmxSource() const;

private:
/** Return a list only of the fixture IDs from the selected preview items */
QList<quint32> selectedFixtureIDList() const;

Expand Down
6 changes: 3 additions & 3 deletions qmlui/efxeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ void EFXEditor::addGroup(QVariant reference)
{
Tardis::instance()->enqueueAction(Tardis::EFXAddFixture, m_efx->id(), QVariant(),
Tardis::instance()->actionToByteArray(Tardis::EFXAddFixture, m_efx->id(),
qVariantFromValue((void *)ef)));
QVariant::fromValue((void *)ef)));
listChanged = true;
}
}
Expand Down Expand Up @@ -477,7 +477,7 @@ void EFXEditor::addFixture(QVariant reference)
{
Tardis::instance()->enqueueAction(Tardis::EFXAddFixture, m_efx->id(), QVariant(),
Tardis::instance()->actionToByteArray(Tardis::EFXAddFixture, m_efx->id(),
qVariantFromValue((void *)ef)));
QVariant::fromValue((void *)ef)));
updateFixtureList();
}
}
Expand All @@ -501,7 +501,7 @@ void EFXEditor::addHead(int fixtureID, int headIndex)
{
Tardis::instance()->enqueueAction(Tardis::EFXAddFixture, m_efx->id(), QVariant(),
Tardis::instance()->actionToByteArray(Tardis::EFXAddFixture, m_efx->id(),
qVariantFromValue((void *)ef)));
QVariant::fromValue((void *)ef)));
updateFixtureList();
}
}
Expand Down

0 comments on commit c866a3f

Please sign in to comment.