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