Loading...
Searching...
No Matches
UDPWidget.hpp
1#pragma once
2#include <Device/Protocol/ProtocolSettingsWidget.hpp>
3
4#include <score/widgets/HelpInteraction.hpp>
5
6#include <ossia/network/sockets/configuration.hpp>
7
8#include <QCheckBox>
9#include <QFormLayout>
10#include <QLineEdit>
11#include <QSpinBox>
12namespace Protocols
13{
14
15class UDPWidget : public QWidget
16{
17public:
18 UDPWidget(Device::ProtocolSettingsWidget& proto, QWidget* parent)
19 : QWidget{parent}
20 {
21 auto layout = new QFormLayout{this};
22 layout->setContentsMargins(0, 0, 0, 0);
23
24 m_remotePort = new QSpinBox(this);
25 m_remotePort->setRange(0, 65535);
26 m_remotePort->setValue(9996);
27 score::setHelp(m_remotePort,
28 tr("This is where the other software listens from incoming messages. Score will "
29 "send packets to this port."));
30 proto.checkForChanges(m_remotePort);
31
32 m_localPort = new QSpinBox(this);
33 m_localPort->setRange(0, 65535);
34 m_localPort->setValue(9997);
35 score::setHelp(m_localPort,
36 tr("This is where the other software sends feedback messages to. Score will "
37 "listen for incoming OSC messages on this port."));
38 proto.checkForChanges(m_localPort);
39
40 m_broadcast = new QCheckBox{this};
41 m_broadcast->setCheckState(Qt::Unchecked);
42 score::setHelp(m_broadcast, tr("Broadcast to every device in the IP broadcast range"));
43
44 m_host = new QLineEdit(this);
45 m_host->setText("127.0.0.1");
46 score::setHelp(m_host,
47 tr("This is the IP address of the computer the OSC-compatible software is "
48 "located on. You can use 127.0.0.1 if the software runs on the same machine "
49 "than score."));
50
51 layout->addRow(tr("Device listening port"), m_remotePort);
52 layout->addRow(tr("Broadcast"), m_broadcast);
53 layout->addRow(tr("Device host"), m_host);
54 layout->addRow(tr("score listening port"), m_localPort);
55 }
56
57 ossia::net::udp_configuration settings() const noexcept
58 {
59 ossia::net::udp_configuration conf;
60 conf.local = ossia::net::inbound_socket_configuration{
61 "0.0.0.0", (uint16_t)m_localPort->value()};
62 conf.remote = ossia::net::outbound_socket_configuration{
63 m_host->text().toStdString(), (uint16_t)m_remotePort->value(),
64 m_broadcast->isChecked()};
65 return conf;
66 }
67
68 void setSettings(const ossia::net::udp_configuration& conf)
69 {
70 if(conf.remote)
71 {
72 m_remotePort->setValue(conf.remote->port);
73 m_host->setText(QString::fromStdString(conf.remote->host));
74 m_broadcast->setChecked(conf.remote->broadcast);
75 }
76 if(conf.local)
77 {
78 m_localPort->setValue(conf.local->port);
79 }
80 }
81
82private:
83 QSpinBox* m_localPort{};
84 QSpinBox* m_remotePort{};
85 QCheckBox* m_broadcast{};
86 QLineEdit* m_host{};
87};
88
89}
Definition ProtocolSettingsWidget.hpp:22
Definition UDPWidget.hpp:16