void RGBMatrix::setAlgorithm(RGBAlgorithm* algo) { { QMutexLocker algorithmLocker(&m_algorithmMutex); delete m_algorithm; m_algorithm = algo; /** If there's been a change of Script algorithm "on the fly", * then re-apply the properties currently set in this RGBMatrix */ if (m_algorithm != NULL && m_algorithm->type() == RGBAlgorithm::Script) { RGBScript *script = static_cast<RGBScript*> (m_algorithm); QHashIterator<QString, QString> it(m_properties); while(it.hasNext()) { it.next(); if (script->setProperty(it.key(), it.value()) == false) { /** If the new algorithm doesn't expose a property, * then remove it from the cached list, otherwise * it would be carried around forever (and saved on XML) */ m_properties.take(it.key()); } } } } m_stepsCount = stepsCount(); emit changed(id()); }
void RGBMatrix::preRun(MasterTimer* timer) { Q_UNUSED(timer); { QMutexLocker algorithmLocker(&m_algorithmMutex); m_group = doc()->fixtureGroup(m_fixtureGroupID); if (m_group == NULL) { // No fixture group to control stop(); return; } if (m_algorithm != NULL) { Q_ASSERT(m_fader == NULL); m_fader = new GenericFader(doc()); m_fader->adjustIntensity(getAttributeValue(Intensity)); m_fader->setBlendMode(blendMode()); // Copy direction from parent class direction m_direction = direction(); if (m_direction == Forward) { m_step = 0; m_stepColor = m_startColor.rgb(); } else { m_step = m_algorithm->rgbMapStepCount(m_group->size()) - 1; if (m_endColor.isValid()) { m_stepColor = m_endColor.rgb(); } else { m_stepColor = m_startColor.rgb(); } } calculateColorDelta(); if (m_algorithm->type() == RGBAlgorithm::Script) { RGBScript *script = static_cast<RGBScript*> (m_algorithm); QHashIterator<QString, QString> it(m_properties); while(it.hasNext()) { it.next(); script->setProperty(it.key(), it.value()); } } } } m_roundTime->start(); Function::preRun(timer); }
void RGBMatrix::setProperty(QString propName, QString value) { QMutexLocker algoLocker(&m_algorithmMutex); m_properties[propName] = value; if (m_algorithm != NULL && m_algorithm->type() == RGBAlgorithm::Script) { RGBScript *script = static_cast<RGBScript*> (m_algorithm); script->setProperty(propName, value); } m_stepsCount = stepsCount(); }
void RGBMatrix::preRun(MasterTimer* timer) { { QMutexLocker algorithmLocker(&m_algorithmMutex); m_group = doc()->fixtureGroup(m_fixtureGroupID); if (m_group == NULL) { // No fixture group to control stop(FunctionParent::master()); return; } if (m_algorithm != NULL) { Q_ASSERT(m_fader == NULL); m_fader = new GenericFader(doc()); m_fader->adjustIntensity(getAttributeValue(Intensity)); m_fader->setBlendMode(blendMode()); // Copy direction from parent class direction m_stepHandler->initializeDirection(direction(), m_startColor, m_endColor, m_stepsCount); if (m_algorithm->type() == RGBAlgorithm::Script) { RGBScript *script = static_cast<RGBScript*> (m_algorithm); QHashIterator<QString, QString> it(m_properties); while(it.hasNext()) { it.next(); script->setProperty(it.key(), it.value()); } } } } m_roundTime->restart(); Function::preRun(timer); }
void RGBScript_Test::rgbMap() { RGBScript s = m_doc->rgbScriptsCache()->script("Stripes"); QVERIFY(s.rgbMap(QSize(3, 4), 0, 0).isEmpty() == false); s.setProperty("orientation", "Vertical"); QVERIFY(s.property("orientation") == "Vertical"); for (int z = 0; z < 5; z++) { RGBMap map = s.rgbMap(QSize(5, 5), QColor(Qt::red).rgb(), z); for (int y = 0; y < 5; y++) { for (int x = 0; x < 5; x++) { if (y == z) QCOMPARE(map[y][x], QColor(Qt::red).rgb()); else QCOMPARE(map[y][x], uint(0)); } } } }
void VCMatrix::slotCustomControlClicked() { QPushButton *btn = qobject_cast<QPushButton*>(sender()); VCMatrixControl *control = m_controls[btn]; if (control != NULL) { RGBMatrix* matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID)); if (matrix == NULL || mode() == Doc::Design) return; if (control->m_type == VCMatrixControl::StartColor) { QPixmap px(42, 42); px.fill(control->m_color); m_startColorButton->setIcon(px); matrix->setStartColor(control->m_color); matrix->calculateColorDelta(); } else if (control->m_type == VCMatrixControl::EndColor) { QPixmap px(42, 42); px.fill(control->m_color); m_endColorButton->setIcon(px); matrix->setEndColor(control->m_color); matrix->calculateColorDelta(); } else if (control->m_type == VCMatrixControl::Animation) { RGBAlgorithm* algo = RGBAlgorithm::algorithm(m_doc, control->m_resource); if (!control->m_properties.isEmpty()) { RGBScript *script = static_cast<RGBScript*> (algo); QHashIterator<QString, QString> it(control->m_properties); while(it.hasNext()) { it.next(); script->setProperty(it.key(), it.value()); } } matrix->setAlgorithm(algo); if (instantChanges() == true) matrix->calculateColorDelta(); m_presetCombo->blockSignals(true); #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) m_presetCombo->setCurrentText(control->m_resource); #else m_presetCombo->setCurrentIndex(m_presetCombo->findText(control->m_resource)); #endif m_presetCombo->blockSignals(false); } else if (control->m_type == VCMatrixControl::Text) { RGBAlgorithm* algo = RGBAlgorithm::algorithm(m_doc, "Text"); RGBText* text = static_cast<RGBText*> (algo); text->setText(control->m_resource); matrix->setAlgorithm(algo); if (instantChanges() == true) matrix->calculateColorDelta(); } } }