Loading...
Searching...
No Matches
TCPWidget.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#include <ossia/protocols/osc/osc_factory.hpp>
8
9#include <QComboBox>
10#include <QFormLayout>
11#include <QLineEdit>
12#include <QSpinBox>
13namespace Protocols
14{
15
16using framing_type = decltype(ossia::net::osc_protocol_configuration::framing);
17class BasicTCPWidget : public QWidget
18{
19public:
20 BasicTCPWidget(Device::ProtocolSettingsWidget& proto, QWidget* parent)
21 : QWidget{parent}
22 {
23 auto layout = new QFormLayout{this};
24 layout->setContentsMargins(0, 0, 0, 0);
25
26 m_remotePort = new QSpinBox(this);
27 m_remotePort->setRange(0, 65535);
28 m_remotePort->setValue(9996);
29 score::setHelp(m_remotePort,
30 tr("This is the communication port used for the TCP connection."));
31 proto.checkForChanges(m_remotePort);
32
33 m_host = new QLineEdit(this);
34 m_host->setText("127.0.0.1");
35 score::setHelp(m_host,
36 tr("This is the IP address of the computer the OSC-compatible software is "
37 "located on. You can use 127.0.0.1 if the software runs on the same machine "
38 "than score."));
39
40 layout->addRow(tr("Port"), m_remotePort);
41 layout->addRow(tr("Host"), m_host);
42 }
43
44 ossia::net::tcp_client_configuration settings() const noexcept
45 {
46 ossia::net::tcp_client_configuration conf;
47 conf.port = m_remotePort->value();
48 conf.host = m_host->text().toStdString();
49 return conf;
50 }
51
52 void setSettings(const ossia::net::tcp_client_configuration& conf)
53 {
54 m_remotePort->setValue(conf.port);
55 m_host->setText(QString::fromStdString(conf.host));
56 }
57
58private:
59 QSpinBox* m_remotePort{};
60 QLineEdit* m_host{};
61};
62
63class TCPWidget : public QWidget
64{
65public:
66 TCPWidget(Device::ProtocolSettingsWidget& proto, QWidget* parent)
67 : QWidget{parent}
68 {
69 auto layout = new QFormLayout{this};
70 layout->setContentsMargins(0, 0, 0, 0);
71
72 m_remotePort = new QSpinBox(this);
73 m_remotePort->setRange(0, 65535);
74 m_remotePort->setValue(9996);
75 score::setHelp(m_remotePort,
76 tr("This is the communication port used for the TCP connection."));
77 proto.checkForChanges(m_remotePort);
78
79 m_host = new QLineEdit(this);
80 m_host->setText("127.0.0.1");
81 score::setHelp(m_host,
82 tr("This is the IP address of the computer the OSC-compatible software is "
83 "located on. You can use 127.0.0.1 if the software runs on the same machine "
84 "than score."));
85
86 m_framing = new QComboBox{this};
87 m_framing->addItems({"Size prefixing", "SLIP"});
88 m_framing->setCurrentIndex(1);
89
90 layout->addRow(tr("Port"), m_remotePort);
91 layout->addRow(tr("Host"), m_host);
92 layout->addRow(tr("Framing"), m_framing);
93 }
94
95 framing_type framing() const noexcept
96 {
97 return (framing_type)m_framing->currentIndex();
98 }
99
100 ossia::net::tcp_client_configuration settings() const noexcept
101 {
102 ossia::net::tcp_client_configuration conf;
103 conf.port = m_remotePort->value();
104 conf.host = m_host->text().toStdString();
105 return conf;
106 }
107
108 void setSettings(
109 const ossia::net::osc_protocol_configuration& c,
110 const ossia::net::tcp_client_configuration& conf)
111 {
112 m_remotePort->setValue(conf.port);
113 m_framing->setCurrentIndex(c.framing);
114 m_host->setText(QString::fromStdString(conf.host));
115 }
116
117private:
118 QSpinBox* m_remotePort{};
119 QComboBox* m_framing{};
120 QLineEdit* m_host{};
121};
122}
Definition ProtocolSettingsWidget.hpp:22
Definition TCPWidget.hpp:18
Definition TCPWidget.hpp:64