Skip to content

Commit

Permalink
qmlui: whole shutter timing calculation is now in FixtureUtils
Browse files Browse the repository at this point in the history
Added also precise frequency and frequency range presets
Preview shutter in 2D view as well
  • Loading branch information
mcallegari committed May 3, 2018
1 parent 1fe4148 commit daa8076
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 69 deletions.
69 changes: 62 additions & 7 deletions qmlui/fixtureutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "qlcfixturemode.h"
#include "qlccapability.h"
#include "fixtureutils.h"
#include "qlcmacros.h"
#include "fixture.h"
#include "doc.h"

Expand Down Expand Up @@ -316,20 +317,74 @@ QColor FixtureUtils::headColor(Doc *doc, Fixture *fixture, int headIndex)
return finalColor;
}

void FixtureUtils::shutterTimings(int capPreset, uchar value, int &highTime, int &lowTime)
int FixtureUtils::shutterTimings(const QLCChannel *ch, uchar value, int &highTime, int &lowTime)
{
int capPreset = QLCCapability::ShutterOpen;
float freq = 1.0;

switch (ch->preset())
{
case QLCChannel::ShutterStrobeSlowFast:
if (value)
capPreset = QLCCapability::StrobeSlowToFast;
break;
case QLCChannel::ShutterStrobeFastSlow:
if (value)
{
capPreset = QLCCapability::StrobeFastToSlow;
value = 255 - value;
}
break;
default:
{
QLCCapability *cap = ch->searchCapability(value);
capPreset = cap->preset();
switch (capPreset)
{
case QLCCapability::StrobeSlowToFast:
case QLCCapability::PulseInSlowToFast:
case QLCCapability::PulseOutSlowToFast:
value = SCALE(value, cap->min(), cap->max(), 1, 255);
break;
case QLCCapability::StrobeFastToSlow:
case QLCCapability::PulseInFastToSlow:
case QLCCapability::PulseOutFastToSlow:
value = 255 - SCALE(value, cap->min(), cap->max(), 1, 255);
break;
case QLCCapability::StrobeFrequency:
case QLCCapability::PulseInFrequency:
case QLCCapability::PulseOutFrequency:
freq = cap->resource(0).toFloat();
break;
case QLCCapability::StrobeFreqRange:
case QLCCapability::PulseInFreqRange:
case QLCCapability::PulseOutFreqRange:
freq = SCALE(value, cap->min(), cap->max(),
cap->resource(0).toFloat(), cap->resource(1).toFloat());
break;
default:
// invalidate any other preset, to avoid messing up the preview
capPreset = QLCCapability::Custom;
break;
}
}
break;
}

switch (capPreset)
{
case QLCCapability::StrobeSlowToFast:
case QLCCapability::StrobeFastToSlow:
case QLCCapability::PulseInSlowToFast:
case QLCCapability::PulseInFastToSlow:
{
float freq = qMax(((float)value * MAX_STROBE_FREQ_HZ) / 255.0, MIN_STROBE_FREQ_HZ);
//qDebug() << "Frequency:" << freq << "Hz";
highTime = qBound(50.0, 500.0 / freq, 200.0);
lowTime = (1000.0 / freq) - highTime;
}
freq = qMax(((float)value * MAX_STROBE_FREQ_HZ) / 255.0, MIN_STROBE_FREQ_HZ);
break;
}

//qDebug() << "Frequency:" << freq << "Hz";
highTime = qBound(50.0, 500.0 / freq, 200.0);
lowTime = (1000.0 / freq) - highTime;

return capPreset;
}

3 changes: 2 additions & 1 deletion qmlui/fixtureutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class FixtureUtils
* This considers: RGB / CMY / WAUVLI channels, dimmers and gel color */
static QColor headColor(Doc *doc, Fixture *fixture, int headIndex = 0);

static void shutterTimings(int capPreset, uchar value, int &highTime, int &lowTime);
/** Calculate the rise/fall periods for a shutter channel $ch, considering presets */
static int shutterTimings(const QLCChannel *ch, uchar value, int &highTime, int &lowTime);

private:
/** Perform a linear blending of $b over $a with the given $mix amount */
Expand Down
32 changes: 23 additions & 9 deletions qmlui/mainview2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ void MainView2D::updateFixture(Fixture *fixture)
return;

QQuickItem *fxItem = m_itemsMap[fixture->id()];
bool setColor = false;
bool setGobo = false;
bool colorSet = false;
bool goboSet = false;
bool setPosition = false;
int panDegrees = 0;
int tiltDegrees = 0;
Expand All @@ -298,7 +298,7 @@ void MainView2D::updateFixture(Fixture *fixture)
QMetaObject::invokeMethod(fxItem, "setHeadRGBColor",
Q_ARG(QVariant, headIdx),
Q_ARG(QVariant, FixtureUtils::headColor(m_doc, fixture, headIdx)));
setColor = true;
colorSet = true;
} // for heads

// now scan all the channels for "common" capabilities
Expand All @@ -307,6 +307,7 @@ void MainView2D::updateFixture(Fixture *fixture)
const QLCChannel *ch = fixture->channel(i);
if (ch == NULL)
continue;

uchar value = fixture->channelValueAt(i);

switch (ch->group())
Expand All @@ -331,7 +332,7 @@ void MainView2D::updateFixture(Fixture *fixture)
break;
case QLCChannel::Colour:
{
if (setColor && value == 0)
if (colorSet && value == 0)
break;

QLCCapability *cap = ch->searchCapability(value);
Expand Down Expand Up @@ -359,13 +360,13 @@ void MainView2D::updateFixture(Fixture *fixture)
Q_ARG(QVariant, 0),
Q_ARG(QVariant, wheelColor1));
}
setColor = true;
colorSet = true;
}
}
break;
case QLCChannel::Gobo:
{
if (setGobo)
if (goboSet)
break;

foreach(QLCCapability *cap, ch->capabilities())
Expand All @@ -383,18 +384,31 @@ void MainView2D::updateFixture(Fixture *fixture)
// fixture has more than one gobo wheel, the second
// one will be skipped if the first one has been set
// to a non-open gobo
setGobo = true;
goboSet = true;
}
}
}
}
break;
// ... more preset channels to be added here (Shutter ?)
case QLCChannel::Shutter:
{
int high = 200, low = 800;
int capPreset = FixtureUtils::shutterTimings(ch, value, high, low);

if (capPreset != QLCCapability::Custom)
{
QMetaObject::invokeMethod(fxItem, "setShutter",
Q_ARG(QVariant, capPreset),
Q_ARG(QVariant, low), Q_ARG(QVariant, high));
}
}
break;
default:
break;
}
}
if (setPosition == true)

if (setPosition)
{
QMetaObject::invokeMethod(fxItem, "setPosition",
Q_ARG(QVariant, panDegrees),
Expand Down
46 changes: 1 addition & 45 deletions qmlui/mainview3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "doc.h"
#include "tardis.h"
#include "qlcfile.h"
#include "qlcmacros.h"
#include "qlcconfig.h"
#include "mainview3d.h"
#include "fixtureutils.h"
Expand Down Expand Up @@ -759,50 +758,7 @@ void MainView3D::updateFixture(Fixture *fixture)
case QLCChannel::Shutter:
{
int high = 200, low = 800;
int capPreset = QLCCapability::ShutterOpen;

switch (ch->preset())
{
case QLCChannel::ShutterStrobeSlowFast:
if (value)
{
capPreset = QLCCapability::StrobeSlowToFast;
FixtureUtils::shutterTimings(capPreset, value, high, low);
}
break;
case QLCChannel::ShutterStrobeFastSlow:
if (value)
{
capPreset = QLCCapability::StrobeFastToSlow;
FixtureUtils::shutterTimings(capPreset, 255 - value, high, low);
}
break;
default:
{
QLCCapability *cap = ch->searchCapability(value);
capPreset = cap->preset();
switch (capPreset)
{
case QLCCapability::StrobeSlowToFast:
case QLCCapability::PulseInSlowToFast:
case QLCCapability::PulseOutSlowToFast:
FixtureUtils::shutterTimings(capPreset,
SCALE(value, cap->min(), cap->max(), 1, 255),
high, low);
break;
case QLCCapability::StrobeFastToSlow:
case QLCCapability::PulseInFastToSlow:
case QLCCapability::PulseOutFastToSlow:
FixtureUtils::shutterTimings(capPreset,
255 - SCALE(value, cap->min(), cap->max(), 1, 255),
high, low);
break;
default:
break;
}
}
break;
}
int capPreset = FixtureUtils::shutterTimings(ch, value, high, low);

QMetaObject::invokeMethod(fixtureItem, "setShutter",
Q_ARG(QVariant, capPreset),
Expand Down
8 changes: 4 additions & 4 deletions qmlui/qml/fixturesfunctions/3DView/Fixture3DItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ Entity
QQ2.SequentialAnimation on intensity
{
id: shutterAnim
running: true
running: false
loops: QQ2.Animation.Infinite
QQ2.NumberAnimation { id: inPhase; from: 0; to: 1.0; duration: 0; easing.type: Easing.Linear }
QQ2.NumberAnimation { id: highPhase; from: 1.0; to: 1.0; duration: 200; easing.type: Easing.Linear }
QQ2.NumberAnimation { id: outPhase; from: 1.0; to: 0; duration: 0; easing.type: Easing.Linear }
QQ2.NumberAnimation { id: inPhase; from: 0; to: intensityOrigValue; duration: 0; easing.type: Easing.Linear }
QQ2.NumberAnimation { id: highPhase; from: intensityOrigValue; to: intensityOrigValue; duration: 200; easing.type: Easing.Linear }
QQ2.NumberAnimation { id: outPhase; from: intensityOrigValue; to: 0; duration: 0; easing.type: Easing.Linear }
QQ2.NumberAnimation { id: lowPhase; from: 0; to: 0; duration: 800; easing.type: Easing.Linear }
}

Expand Down
62 changes: 59 additions & 3 deletions qmlui/qml/fixturesfunctions/Fixture2DItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Rectangle
function setHeadIntensity(headIndex, intensity)
{
//console.log("headIdx: " + headIndex + ", int: " + intensity)
headsRepeater.itemAt(headIndex).headLevel = intensity
headsRepeater.itemAt(headIndex).intensity = intensity
}

function setHeadRGBColor(headIndex, color)
Expand All @@ -101,6 +101,13 @@ Rectangle
headItem.headColor1 = color
}

function setShutter(type, low, high)
{
for (var i = 0; i < headsRepeater.count; i++)
headsRepeater.itemAt(i).setShutter(type, low, high);
}


function setPosition(pan, tilt)
{
if (panMaxDegrees)
Expand Down Expand Up @@ -146,7 +153,8 @@ Rectangle
Rectangle
{
id: headDelegate
property real headLevel: 0.0
property real intensity: 0.0
property real intensityOrigValue: intensity
property bool isWheelColor: false
property color headColor1: "black"
property color headColor2: "black"
Expand All @@ -159,14 +167,50 @@ Rectangle
border.width: 1
border.color: "#AAA"

function setShutter(type, low, high)
{
console.log("Shutter " + low + ", " + high)
shutterAnim.stop()
inPhase.duration = 0
highPhase.duration = 0
outPhase.duration = 0
lowPhase.duration = low

switch(type)
{
case QLCCapability.ShutterOpen:
intensity = intensityOrigValue
break;
case QLCCapability.ShutterClose:
intensityOrigValue = intensity
intensity = 0
break;
case QLCCapability.StrobeFastToSlow:
case QLCCapability.StrobeSlowToFast:
highPhase.duration = high
shutterAnim.start()
break;
case QLCCapability.PulseInFastToSlow:
case QLCCapability.PulseInSlowToFast:
inPhase.duration = high
shutterAnim.start()
break;
case QLCCapability.PulseOutSlowToFast:
case QLCCapability.PulseOutFastToSlow:
outPhase.duration = high
shutterAnim.start()
break;
}
}

MultiColorBox
{
x: 1
y: 1
width: parent.width - 2
height: parent.height - 2
radius: parent.radius - 2
opacity: headDelegate.headLevel
opacity: headDelegate.intensity
biColor: headDelegate.isWheelColor
primary: headDelegate.headColor1
secondary: headDelegate.headColor2
Expand All @@ -178,6 +222,18 @@ Rectangle
sourceSize: Qt.size(parent.width, parent.height)
source: headDelegate.goboSource
}

// strobe/pulse effect
SequentialAnimation on intensity
{
id: shutterAnim
running: false
loops: Animation.Infinite
NumberAnimation { id: inPhase; from: 0; to: intensityOrigValue; duration: 0; easing.type: Easing.Linear }
NumberAnimation { id: highPhase; from: intensityOrigValue; to: intensityOrigValue; duration: 200; easing.type: Easing.Linear }
NumberAnimation { id: outPhase; from: intensityOrigValue; to: 0; duration: 0; easing.type: Easing.Linear }
NumberAnimation { id: lowPhase; from: 0; to: 0; duration: 800; easing.type: Easing.Linear }
}
}
}
}
Expand Down

0 comments on commit daa8076

Please sign in to comment.