Skip to content

Commit

Permalink
plugins/dmxusb: no need to rescan widgets on frequency change
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Aug 11, 2018
1 parent 4cbacdd commit f081a6f
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 21 deletions.
10 changes: 7 additions & 3 deletions plugins/dmxusb/src/dmxusbconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define COL_TYPE 2
#define COL_FREQ 3
#define PROP_SERIAL "serial"
#define PROP_WIDGET "widget"

DMXUSBConfig::DMXUSBConfig(DMXUSB* plugin, QWidget* parent)
: QDialog(parent)
Expand All @@ -55,10 +56,10 @@ DMXUSBConfig::DMXUSBConfig(DMXUSB* plugin, QWidget* parent)
m_tree->setHeaderLabels(header);
m_tree->setSelectionMode(QAbstractItemView::NoSelection);

QVBoxLayout* vbox = new QVBoxLayout(this);
QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->addWidget(m_tree);

QHBoxLayout* hbox = new QHBoxLayout;
QHBoxLayout *hbox = new QHBoxLayout;
hbox->addWidget(m_refreshButton);
hbox->addStretch();
hbox->addWidget(m_closeButton);
Expand Down Expand Up @@ -111,7 +112,9 @@ void DMXUSBConfig::slotFrequencyValueChanged(int value)
DMXInterface::storeFrequencyMap(frequencyMap);
}

QTimer::singleShot(0, this, SLOT(slotRefresh()));
var = spin->property(PROP_WIDGET);
DMXUSBWidget *widget = (DMXUSBWidget *) var.value<void *>();
widget->setOutputFrequency(value);
}

void DMXUSBConfig::slotRefresh()
Expand Down Expand Up @@ -158,6 +161,7 @@ QSpinBox *DMXUSBConfig::createFrequencySpin(DMXUSBWidget *widget)
Q_ASSERT(widget != NULL);
QSpinBox *spin = new QSpinBox;
spin->setProperty(PROP_SERIAL, widget->serial());
spin->setProperty(PROP_WIDGET, qVariantFromValue((void *)widget));
spin->setRange(1, 60);
spin->setValue(widget->outputFrequency());
spin->setSuffix("Hz");
Expand Down
5 changes: 4 additions & 1 deletion plugins/dmxusb/src/dmxusbwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@
DMXUSBWidget::DMXUSBWidget(DMXInterface *interface, quint32 outputLine)
: m_interface(interface)
, m_outputBaseLine(outputLine)
, m_frequency(DEFAULT_OUTPUT_FREQUENCY)
, m_inputBaseLine(0)
{
Q_ASSERT(interface != NULL);

QMap <QString, QVariant> freqMap(DMXInterface::frequencyMap());
if (freqMap.contains(m_interface->serial()))
setOutputFrequency(freqMap[m_interface->serial()].toInt());
else
setOutputFrequency(DEFAULT_OUTPUT_FREQUENCY);

setOutputsNumber(1);
setInputsNumber(0);
Expand Down Expand Up @@ -395,6 +396,8 @@ int DMXUSBWidget::outputFrequency()
void DMXUSBWidget::setOutputFrequency(int frequency)
{
m_frequency = frequency;
// One "official" DMX frame can take (1s/44Hz) = 23ms
m_frameTimeUs = (int) (floor(((double)1000 / m_frequency) + (double)0.5)) * 1000;
}

/********************************************************************
Expand Down
1 change: 1 addition & 0 deletions plugins/dmxusb/src/dmxusbwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class DMXUSBWidget

/** The output frequency in Hertz */
int m_frequency;
int m_frameTimeUs;

/** Array of output lines supported by the device. This is resized on setOutputsNumber */
QVector<DMXUSBLineInfo> m_outputLines;
Expand Down
4 changes: 1 addition & 3 deletions plugins/dmxusb/src/enttecdmxusbopen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ void EnttecDMXUSBOpen::stop()
void EnttecDMXUSBOpen::run()
{
QElapsedTimer timer;
// One "official" DMX frame can take (1s/44Hz) = 23ms
int frameTimeUs = (int) (floor(((double)1000 / m_frequency) + (double)0.5)) * 1000;

// Wait for device to settle in case the device was opened just recently
usleep(1000);
Expand Down Expand Up @@ -210,7 +208,7 @@ void EnttecDMXUSBOpen::run()
framesleep:
// Sleep for the remainder of the DMX frame time
// and set granularity accordingly
int timetoSleep = frameTimeUs - (timer.nsecsElapsed() / 1000);
int timetoSleep = m_frameTimeUs - (timer.nsecsElapsed() / 1000);
if (timetoSleep < 0)
{
qWarning() << "DMX output is running late !";
Expand Down
5 changes: 1 addition & 4 deletions plugins/dmxusb/src/enttecdmxusbpro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,6 @@ void EnttecDMXUSBPro::run()
qDebug() << "OUTPUT thread started";
QElapsedTimer timer;

// One "official" DMX frame can take (1s/44Hz) = 23ms
int frameTimeUs = (int) (floor(((double)1000 / m_frequency) + (double)0.5)) * 1000;

m_outputRunning = true;
while (m_outputRunning == true)
{
Expand Down Expand Up @@ -505,7 +502,7 @@ void EnttecDMXUSBPro::run()
}
}
framesleep:
int timetoSleep = frameTimeUs - (timer.nsecsElapsed() / 1000);
int timetoSleep = m_frameTimeUs - (timer.nsecsElapsed() / 1000);
if (timetoSleep < 0)
qWarning() << "DMX output is running late !";
else
Expand Down
5 changes: 1 addition & 4 deletions plugins/dmxusb/src/euroliteusbdmxpro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,6 @@ void EuroliteUSBDMXPro::run()
QElapsedTimer timer;
QByteArray request;

// One "official" DMX frame can take (1s/44Hz) = 23ms
int frameTimeUs = (int) (floor(((double)1000 / m_frequency) + (double)0.5)) * 1000;

m_running = true;
while (m_running == true)
{
Expand Down Expand Up @@ -255,7 +252,7 @@ void EuroliteUSBDMXPro::run()
#endif
}
framesleep:
int timetoSleep = frameTimeUs - (timer.nsecsElapsed() / 1000);
int timetoSleep = m_frameTimeUs - (timer.nsecsElapsed() / 1000);
if (timetoSleep < 0)
qWarning() << "DMX output is running late !";
else
Expand Down
4 changes: 1 addition & 3 deletions plugins/dmxusb/src/nanodmx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,6 @@ void NanoDMX::run()
qDebug() << "OUTPUT thread started";

QElapsedTimer timer;
// One "official" DMX frame can take (1s/44Hz) = 23ms
int frameTimeUs = (int) (floor(((double)1000 / m_frequency) + (double)0.5)) * 1000;

m_running = true;

Expand Down Expand Up @@ -345,7 +343,7 @@ void NanoDMX::run()
}
}

int timetoSleep = frameTimeUs - (timer.nsecsElapsed() / 1000);
int timetoSleep = m_frameTimeUs - (timer.nsecsElapsed() / 1000);
if (timetoSleep < 0)
qWarning() << "DMX output is running late !";
else
Expand Down
4 changes: 1 addition & 3 deletions plugins/dmxusb/src/stageprofi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ void Stageprofi::run()
qDebug() << "OUTPUT thread started";

QElapsedTimer timer;
// One "official" DMX frame can take (1s/44Hz) = 23ms
int frameTimeUs = (int) (floor(((double)1000 / m_frequency) + (double)0.5)) * 1000;

m_running = true;

Expand Down Expand Up @@ -235,7 +233,7 @@ void Stageprofi::run()
}
}

int timetoSleep = frameTimeUs - (timer.nsecsElapsed() / 1000);
int timetoSleep = m_frameTimeUs - (timer.nsecsElapsed() / 1000);
if (timetoSleep < 0)
qWarning() << "DMX output is running late !";
else
Expand Down

0 comments on commit f081a6f

Please sign in to comment.