Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions src/core/Show.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,19 @@ void Show::setName(const QString& name) {
}
}

bool Show::isModified() const { return toJson() != m_originalState; }
bool Show::isModified() const { return m_isDirty; }

void Show::setModified(bool modified) {
if (!modified) {
m_originalState = toJson();
if (m_lastEmittedModified) {
m_lastEmittedModified = false;
emit modifiedChanged(false);
}
} else {
checkModifiedState();
}
if (m_isDirty == modified)
return;
m_isDirty = modified;
emit modifiedChanged(modified);
}

void Show::checkModifiedState() {
bool nowModified = isModified();
if (nowModified != m_lastEmittedModified) {
m_lastEmittedModified = nowModified;
emit modifiedChanged(nowModified);
if (!m_isDirty) {
m_isDirty = true;
emit modifiedChanged(true);
}
}

Expand All @@ -79,8 +73,7 @@ void Show::newShow() {
m_mixerConfig.port = 10023;
m_cueList.clear();
m_dcaMapping.clear();
m_originalState = toJson();
m_lastEmittedModified = false;
m_isDirty = false;
}

QJsonObject Show::toJson() const {
Expand Down Expand Up @@ -108,8 +101,7 @@ void Show::fromJson(const QJsonObject& json) {
m_dcaMapping.clear();
}

m_originalState = toJson();
m_lastEmittedModified = false;
m_isDirty = false;
emit nameChanged(m_name);
}

Expand Down
9 changes: 4 additions & 5 deletions src/core/Show.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class Show : public QObject {
void setName(const QString& name);

[[nodiscard]] QString author() const { return m_author; }
void setAuthor(const QString& author) { m_author = author; }
void setAuthor(const QString& author) { m_author = author; checkModifiedState(); }

[[nodiscard]] QString notes() const { return m_notes; }
void setNotes(const QString& notes) { m_notes = notes; }
void setNotes(const QString& notes) { m_notes = notes; checkModifiedState(); }

[[nodiscard]] QString filePath() const { return m_filePath; }
void setFilePath(const QString& path) { m_filePath = path; }
Expand All @@ -50,7 +50,7 @@ class Show : public QObject {
[[nodiscard]] const DCAMapping* dcaMapping() const { return &m_dcaMapping; }

[[nodiscard]] MixerConfig mixerConfig() const { return m_mixerConfig; }
void setMixerConfig(const MixerConfig& config) { m_mixerConfig = config; }
void setMixerConfig(const MixerConfig& config) { m_mixerConfig = config; checkModifiedState(); }

QJsonObject toJson() const;
void fromJson(const QJsonObject& json);
Expand All @@ -72,8 +72,7 @@ class Show : public QObject {
CueList m_cueList;
MixerConfig m_mixerConfig;
DCAMapping m_dcaMapping;
QJsonObject m_originalState;
bool m_lastEmittedModified = false;
bool m_isDirty = false;
};

} // namespace OpenMix
4 changes: 3 additions & 1 deletion src/core/UndoCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ AddCueCommand::AddCueCommand(CueList* cueList, const Cue& cue, int index, QUndoC
void AddCueCommand::undo() {
if (m_cueList) {
int idx = m_index >= 0 ? m_index : m_cueList->count() - 1;
m_cueList->removeCue(idx);
if (idx >= 0)
m_cueList->removeCue(idx);
}
}

Expand Down Expand Up @@ -129,6 +130,7 @@ BatchEditCommand::BatchEditCommand(CueList* cueList, const QVector<int>& indices
const QString& text, QUndoCommand* parent)
: QUndoCommand(parent), m_cueList(cueList), m_indices(indices), m_oldCues(oldCues),
m_newCues(newCues) {
Q_ASSERT(indices.size() == oldCues.size() && oldCues.size() == newCues.size());
setText(text);
}

Expand Down
37 changes: 16 additions & 21 deletions src/protocol/allenheath/AllenHeathTcpProtocol.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "AllenHeathTcpProtocol.h"
#include "../../core/Cue.h"
#include <QtEndian>
#include <cstring>

namespace OpenMix {

Expand Down Expand Up @@ -143,12 +144,10 @@ QByteArray AllenHeathTcpProtocol::buildDCAFaderMessage(int dca, float level) {
msg.append(static_cast<char>(dca - 1)); // 0-indexed

// float in big-endian
union {
float f;
quint32 i;
} val;
val.f = qBound(0.0f, level, 1.0f);
quint32 be = qToBigEndian(val.i);
float clamped = qBound(0.0f, level, 1.0f);
quint32 i;
std::memcpy(&i, &clamped, 4);
quint32 be = qToBigEndian(i);
msg.append(reinterpret_cast<const char*>(&be), 4);

return msg;
Expand Down Expand Up @@ -231,13 +230,11 @@ void AllenHeathTcpProtocol::parseProtocolData(const QByteArray& data) {
if (valueType == 0x01 && frame.size() >= valueOffset + 4) {
// float value
quint32 be;
memcpy(&be, frame.constData() + valueOffset, 4);
union {
float f;
quint32 i;
} fval;
fval.i = qFromBigEndian(be);
value = fval.f;
std::memcpy(&be, frame.constData() + valueOffset, 4);
quint32 hostBits = qFromBigEndian(be);
float f;
std::memcpy(&f, &hostBits, 4);
value = f;
} else if (valueType == 0x02 && frame.size() >= valueOffset + 4) {
quint32 be;
memcpy(&be, frame.constData() + valueOffset, 4);
Expand Down Expand Up @@ -275,15 +272,13 @@ void AllenHeathTcpProtocol::parseProtocolData(const QByteArray& data) {
emit parameterChanged(path, muted);
} else if (frame.size() >= 6) {
quint32 be;
memcpy(&be, frame.constData() + 2, 4);
union {
float f;
quint32 i;
} val;
val.i = qFromBigEndian(be);
std::memcpy(&be, frame.constData() + 2, 4);
quint32 hostBits = qFromBigEndian(be);
float f;
std::memcpy(&f, &hostBits, 4);
QString path = QString("/dca/%1/fader").arg(dcaIndex + 1);
m_parameterCache[path] = val.f;
emit parameterChanged(path, val.f);
m_parameterCache[path] = f;
emit parameterChanged(path, f);
}
}
break;
Expand Down
9 changes: 6 additions & 3 deletions src/protocol/behringer/WingProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ void WingProtocol::onTransportError(const QString& error) {
setStatus("Reconnection failed - max attempts reached");
setConnectionState(ConnectionState::Disconnected);
} else {
int delay = m_reconnectDelayMs * (1 << m_reconnectAttempts);
int shift = std::min(m_reconnectAttempts, 10);
int delay = std::min(m_reconnectDelayMs * (1 << shift), 30000);
m_reconnectTimer.start(delay);
}
}
Expand Down Expand Up @@ -292,7 +293,8 @@ void WingProtocol::onConnectionTimeout() {
setConnectionState(ConnectionState::Disconnected);
emit connectionError("Failed to reconnect after maximum attempts");
} else {
int delay = m_reconnectDelayMs * (1 << m_reconnectAttempts);
int shift = std::min(m_reconnectAttempts, 10);
int delay = std::min(m_reconnectDelayMs * (1 << shift), 30000);
m_reconnectTimer.start(delay);
}
}
Expand Down Expand Up @@ -336,7 +338,8 @@ void WingProtocol::onReconnectAttempt() {
m_transport.disconnect();

if (!m_transport.connect(m_host, m_port)) {
int delay = m_reconnectDelayMs * (1 << (m_reconnectAttempts - 1));
int shift = std::min(m_reconnectAttempts - 1, 10);
int delay = std::min(m_reconnectDelayMs * (1 << shift), 30000);
m_reconnectTimer.start(delay);
return;
}
Expand Down
9 changes: 6 additions & 3 deletions src/protocol/behringer/X32Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ void X32Protocol::onTransportError(const QString& error) {
setStatus("Reconnection failed - max attempts reached");
setConnectionState(ConnectionState::Disconnected);
} else {
int delay = m_reconnectDelayMs * (1 << m_reconnectAttempts);
int shift = std::min(m_reconnectAttempts, 10);
int delay = std::min(m_reconnectDelayMs * (1 << shift), 30000);
m_reconnectTimer.start(delay);
}
}
Expand Down Expand Up @@ -291,7 +292,8 @@ void X32Protocol::onConnectionTimeout() {
setConnectionState(ConnectionState::Disconnected);
emit connectionError("Failed to reconnect after maximum attempts");
} else {
int delay = m_reconnectDelayMs * (1 << m_reconnectAttempts);
int shift = std::min(m_reconnectAttempts, 10);
int delay = std::min(m_reconnectDelayMs * (1 << shift), 30000);
m_reconnectTimer.start(delay);
}
}
Expand Down Expand Up @@ -335,7 +337,8 @@ void X32Protocol::onReconnectAttempt() {
m_transport.disconnect();

if (!m_transport.connect(m_host, m_port)) {
int delay = m_reconnectDelayMs * (1 << (m_reconnectAttempts - 1));
int shift = std::min(m_reconnectAttempts - 1, 10);
int delay = std::min(m_reconnectDelayMs * (1 << shift), 30000);
m_reconnectTimer.start(delay);
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/protocol/transport/OscTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ QVariant OscTransport::parseOscArgument(const QByteArray& data, int& offset, cha
(static_cast<quint8>(data[offset + 1]) << 16) |
(static_cast<quint8>(data[offset + 2]) << 8) |
static_cast<quint8>(data[offset + 3]);
if (size < 0)
break;
offset += 4;
if (offset + size <= data.size()) {
QByteArray blob = data.mid(offset, size);
Expand Down
4 changes: 3 additions & 1 deletion src/protocol/transport/TcpTransport.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "TcpTransport.h"
#include <algorithm>

namespace OpenMix {

Expand Down Expand Up @@ -147,7 +148,8 @@ void TcpTransport::startReconnection() {
return;

// exponential backoff
int delay = m_reconnectDelayMs * (1 << m_reconnectAttempts);
int shift = std::min(m_reconnectAttempts, 10);
int delay = std::min(m_reconnectDelayMs * (1 << shift), 30000);
m_reconnectTimer.start(delay);
}

Expand Down
11 changes: 8 additions & 3 deletions src/protocol/yamaha/YamahaProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ void YamahaProtocol::onConnectionTimeout() {
setConnectionState(ConnectionState::Disconnected);
emit connectionError("Failed to reconnect after maximum attempts");
} else {
int delay = m_reconnectDelayMs * (1 << m_reconnectAttempts);
int shift = std::min(m_reconnectAttempts, 10);
int delay = std::min(m_reconnectDelayMs * (1 << shift), 30000);
m_reconnectTimer.start(delay);
}
}
Expand Down Expand Up @@ -328,15 +329,17 @@ void YamahaProtocol::onReconnectAttempt() {
m_oscAddress = lo_address_new(m_host.toUtf8().constData(),
QString::number(m_transmitPort).toUtf8().constData());
if (!m_oscAddress) {
int delay = m_reconnectDelayMs * (1 << (m_reconnectAttempts - 1));
int shift = std::min(m_reconnectAttempts - 1, 10);
int delay = std::min(m_reconnectDelayMs * (1 << shift), 30000);
m_reconnectTimer.start(delay);
return;
}

if (!m_receiveSocket.bind(QHostAddress::Any, m_port)) {
lo_address_free(m_oscAddress);
m_oscAddress = nullptr;
int delay = m_reconnectDelayMs * (1 << (m_reconnectAttempts - 1));
int shift = std::min(m_reconnectAttempts - 1, 10);
int delay = std::min(m_reconnectDelayMs * (1 << shift), 30000);
m_reconnectTimer.start(delay);
return;
}
Expand Down Expand Up @@ -456,6 +459,8 @@ QVariant YamahaProtocol::parseOscArgument(const QByteArray& data, int& offset, c
(static_cast<quint8>(data[offset + 1]) << 16) |
(static_cast<quint8>(data[offset + 2]) << 8) |
static_cast<quint8>(data[offset + 3]);
if (size < 0)
break;
offset += 4;
if (offset + size <= data.size()) {
QByteArray blob = data.mid(offset, size);
Expand Down
4 changes: 3 additions & 1 deletion src/protocol/yamaha/YamahaProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ class YamahaProtocol : public MixerProtocol {
void onRequestTimeoutCheck();
void onReconnectAttempt();

protected:
void parseOscMessage(const QByteArray& data);

private:
void sendOscMessage(const QString& path);
void sendOscMessage(const QString& path, float value);
void sendOscMessage(const QString& path, int value);
void sendOscMessage(const QString& path, const QString& value);
void parseOscMessage(const QByteArray& data);
QVariant parseOscArgument(const QByteArray& data, int& offset, char type);

void processResponse(const QString& path, const QVariant& value);
Expand Down
Loading
Loading