Skip to content

Commit

Permalink
Snapshot cleanup
Browse files Browse the repository at this point in the history
Ready for logic fix and new features (docsteer#163)
  • Loading branch information
marcusbirkin committed Dec 1, 2018
1 parent 1c4f487 commit 7a789b4
Show file tree
Hide file tree
Showing 12 changed files with 3,147 additions and 2,750 deletions.
6 changes: 4 additions & 2 deletions sACNView.pro
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ SOURCES += src/main.cpp\
src/theme/darkstyle.cpp \
src/ipc.cpp \
src/sacn/sacndiscovery.cpp \
src/sacn/sacndiscoveredsourcelistmodel.cpp
src/sacn/sacndiscoveredsourcelistmodel.cpp \
src/clssnapshot.cpp

HEADERS += src/mdimainwindow.h \
src/scopewindow.h \
Expand Down Expand Up @@ -167,7 +168,8 @@ HEADERS += src/mdimainwindow.h \
src/ipc.h \
src/qt56.h \
src/sacn/sacndiscovery.h \
src/sacn/sacndiscoveredsourcelistmodel.h
src/sacn/sacndiscoveredsourcelistmodel.h \
src/clssnapshot.h

FORMS += ui/mdimainwindow.ui \
ui/scopewindow.ui \
Expand Down
91 changes: 91 additions & 0 deletions src/clssnapshot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include "clssnapshot.h"

clsSnapshot::clsSnapshot(quint16 universe, CID cid, QString name, QWidget *parent) : QWidget(parent),
m_universe(universe),
m_priority(DEFAULT_SACN_PRIORITY),
m_cid(cid),
m_sbUniverse(new QSpinBox(this)),
m_sbPriority(new QSpinBox(this)),
m_btnEnable(new QToolButton(this)),
m_sender(Q_NULLPTR),
m_listener(Q_NULLPTR)
{
m_sbUniverse->setMinimum(MIN_SACN_UNIVERSE);
m_sbUniverse->setMaximum(MAX_SACN_UNIVERSE);
m_sbUniverse->setValue(m_universe);
connect(m_sbUniverse, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, [this](int value) { setUniverse(value); } );

m_sbPriority->setMinimum(MIN_SACN_PRIORITY);
m_sbPriority->setMaximum(MAX_SACN_PRIORITY);
m_sbPriority->setValue(m_priority);
connect(m_sbPriority, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, [this](int value) { setPriority(value); } );

connect(m_btnEnable, SIGNAL(clicked(bool)), this, SLOT(btnEnableClicked(bool)));

m_sender = sACNManager::getInstance()->getSender(m_universe, m_cid);
m_sender->setName(name);
connect(m_sender.data(), &sACNSentUniverse::sendingTimeout, [this]() { emit senderTimedOut();} );

m_listener = sACNManager::getInstance()->getListener(m_universe);
}

clsSnapshot::~clsSnapshot() {
}

void clsSnapshot::setUniverse(quint16 universe) {
Q_ASSERT(universe >= MIN_SACN_UNIVERSE);
Q_ASSERT(universe <= MAX_SACN_UNIVERSE);

m_universe = universe;

m_sbUniverse->setValue(m_universe);

m_listener->deleteLater();
m_listener = sACNManager::getInstance()->getListener(m_universe);

m_sender->setUniverse(m_universe);
}

void clsSnapshot::setPriority(quint8 priority) {
Q_ASSERT(priority >= MIN_SACN_PRIORITY);
Q_ASSERT(priority <= MAX_SACN_PRIORITY);

m_priority = priority;

m_sbPriority->setValue(m_priority);

m_sender->setPerSourcePriority(m_priority);
}

void clsSnapshot::takeSnapshot() {
m_levelData.clear();

// Copy current merged universe
for(int addr=0; addr<MAX_DMX_ADDRESS; addr++)
{
m_levelData.append(m_listener->mergedLevels().at(addr).level);
}
}

void clsSnapshot::playSnapshot() {
m_sender->startSending();
m_sender->setLevel((const quint8*)m_levelData.constData(), std::min(m_levelData.count(), MAX_DMX_ADDRESS));
emit senderStarted();
}

void clsSnapshot::stopSnapshot() {
m_sender->stopSending();
emit senderStopped();
}

void clsSnapshot::btnEnableClicked(bool value) {
Q_UNUSED(value);
if (m_sender->isSending())
{
m_sender->stopSending();
emit senderStopped();
} else {
m_sender->startSending();
emit senderStarted();
}
}
57 changes: 57 additions & 0 deletions src/clssnapshot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef CLSSNAPSHOT_H
#define CLSSNAPSHOT_H

#include <QObject>
#include <QSpinBox>
#include <QToolButton>
#include "streamingacn.h"
#include "sacnlistener.h"
#include "sacnsender.h"

class clsSnapshot : public QWidget
{
Q_OBJECT
public:
explicit clsSnapshot(quint16 universe, CID cid, QString name, QWidget *parent = nullptr);
~clsSnapshot();

void takeSnapshot();
void playSnapshot();
void stopSnapshot();

bool hasData() { return !m_levelData.isEmpty(); }

quint16 getUniverse() {return m_universe;}
void setUniverse(quint16 universe);

quint8 getPriority() {return m_priority;}
void setPriority(quint8 priority);

QSpinBox *getSbUniverse() {return m_sbUniverse;}
QSpinBox *getSbPriority() {return m_sbPriority;}
QToolButton *getBtnEnable() {return m_btnEnable;}

signals:
void senderStarted();
void senderStopped();
void senderTimedOut();

public slots:

private slots:
void btnEnableClicked(bool value);

private:
quint16 m_universe;
quint8 m_priority;
CID m_cid;

QByteArray m_levelData;
QSpinBox* m_sbUniverse;
QSpinBox* m_sbPriority;
QToolButton* m_btnEnable;
sACNManager::tSender m_sender;
sACNManager::tListener m_listener;
};

#endif // CLSSNAPSHOT_H
4 changes: 3 additions & 1 deletion src/sacn/sacnsender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ void sACNSentUniverse::setHorizontalBar(quint16 index, quint8 level)

void sACNSentUniverse::setName(const QString &name)
{
m_name = name;
auto tmpStr = name.trimmed();
tmpStr.truncate(MAX_SOURCE_NAME_LEN);
m_name = tmpStr;
if(isSending())
{
QByteArray arr = name.toUtf8();
Expand Down
Loading

0 comments on commit 7a789b4

Please sign in to comment.