Skip to content

Commit 08dea76

Browse files
committed
IanniX 0.9.14 alpha 1
- websockets for remote control
1 parent 5ecb4d2 commit 08dea76

28 files changed

+3918
-180
lines changed

IanniX.pro

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,34 @@ SOURCES += items/uitreeview.cpp items/uitreeviewwidget.cpp items/uitreedelegate
7272
HEADERS += items/uitreeview.h items/uitreeviewwidget.h items/uitreedelegate.h items/uifileitem.h items/uicoloritem.h items/uipathpointsitem.h items/uitextureitem.h
7373
FORMS += items/uitreeview.ui
7474

75-
HEADERS += interfaces/interfacehttp.h interfaces/interfacemidi.h interfaces/interfaceosc.h interfaces/interfaceserial.h interfaces/interfacetcp.h interfaces/interfaceudp.h interfaces/interfacedirect.h interfaces/interfacesyphon.h
76-
SOURCES += interfaces/interfacehttp.cpp interfaces/interfacemidi.cpp interfaces/interfaceosc.cpp interfaces/interfaceserial.cpp interfaces/interfacetcp.cpp interfaces/interfaceudp.cpp interfaces/interfacedirect.cpp
77-
FORMS += interfaces/interfacehttp.ui interfaces/interfacemidi.ui interfaces/interfaceosc.ui interfaces/interfaceserial.ui interfaces/interfacetcp.ui interfaces/interfaceudp.ui interfaces/interfacedirect.ui interfaces/interfacesyphon.ui
7875
HEADERS += interfaces/extscriptvariableask.h interfaces/extoscpatternask.h interfaces/extoscpatterneditor.h
7976
SOURCES += interfaces/extscriptvariableask.cpp interfaces/extoscpatternask.cpp interfaces/extoscpatterneditor.cpp
8077
FORMS += interfaces/extscriptvariableask.ui interfaces/extoscpatternask.ui interfaces/extoscpatterneditor.ui
8178

79+
80+
#Native interfaces
81+
HEADERS += interfaces/interfacehttp.h interfaces/interfacemidi.h interfaces/interfaceosc.h interfaces/interfaceserial.h interfaces/interfacetcp.h interfaces/interfaceudp.h interfaces/interfacedirect.h interfaces/interfacesyphon.h
82+
SOURCES += interfaces/interfacehttp.cpp interfaces/interfacemidi.cpp interfaces/interfaceosc.cpp interfaces/interfaceserial.cpp interfaces/interfacetcp.cpp interfaces/interfaceudp.cpp interfaces/interfacedirect.cpp
83+
FORMS += interfaces/interfacehttp.ui interfaces/interfacemidi.ui interfaces/interfaceosc.ui interfaces/interfaceserial.ui interfaces/interfacetcp.ui interfaces/interfaceudp.ui interfaces/interfacedirect.ui interfaces/interfacesyphon.ui
84+
85+
#Serial
8286
HEADERS += interfaces/qextserialport/qextserialport.h interfaces/qextserialport/qextserialenumerator.h interfaces/qextserialport/qextserialport_global.h interfaces/qextserialport/qextserialport_p.h interfaces/qextserialport/qextserialenumerator_p.h
8387
SOURCES += interfaces/qextserialport/qextserialport.cpp interfaces/qextserialport/qextserialenumerator.cpp
88+
89+
#MIDI
8490
HEADERS += interfaces/qrtmidi/RtMidi.h interfaces/qrtmidi/RtError.h
8591
SOURCES += interfaces/qrtmidi/RtMidi.cpp
8692
debug:DEFINES += __RTMIDI_DEBUG__
8793

94+
#Websockets
95+
SOURCES += interfaces/qwebsockets/websocket.cpp interfaces/qwebsockets/websocketserver.cpp interfaces/qwebsockets/websocketprotocol.cpp interfaces/qwebsockets/handshakerequest.cpp interfaces/qwebsockets/handshakeresponse.cpp interfaces/qwebsockets/dataprocessor.cpp
96+
HEADERS += interfaces/qwebsockets/websocket.h interfaces/qwebsockets/websocketserver.h interfaces/qwebsockets/websocketprotocol.h interfaces/qwebsockets/handshakerequest.h interfaces/qwebsockets/handshakeresponse.h interfaces/qwebsockets/dataprocessor.h
97+
98+
99+
88100

89101
#Zeroconf
90102
macx {
91-
DEFINES += ZEROCONF_INSTALLED
92103
#DEFINES += ZEROCONF_AS_SERVICE
93104
INCLUDEPATH += interfaces/zeroconf
94105
SOURCES += interfaces/zeroconf/bonjourserviceregister.cpp interfaces/zeroconf/bonjourserviceresolver.cpp interfaces/zeroconf/bonjourservicebrowser.cpp

IanniX.pro.user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE QtCreatorProject>
3-
<!-- Written by QtCreator 2.7.1, 2013-08-14T06:44:44. -->
3+
<!-- Written by QtCreator 2.7.1, 2013-08-20T16:18:50. -->
44
<qtcreator>
55
<data>
66
<variable>ProjectExplorer.Project.ActiveTarget</variable>

Patches/Max/Max Sound Example.maxpat

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"numoutlets" : 1,
5252
"outlettype" : [ "" ],
5353
"patching_rect" : [ 513.520386, 105.0, 92.387787, 18.0 ],
54-
"text" : "000:00.000"
54+
"text" : "000:00:000"
5555
}
5656

5757
}
@@ -211,7 +211,7 @@
211211
"numoutlets" : 1,
212212
"outlettype" : [ "" ],
213213
"patching_rect" : [ 82.36731, 376.0, 71.040863, 18.0 ],
214-
"text" : "cue 4"
214+
"text" : "cue 8"
215215
}
216216

217217
}
@@ -581,7 +581,7 @@
581581
"numoutlets" : 1,
582582
"outlettype" : [ "" ],
583583
"patching_rect" : [ 435.908173, 398.5, 170.0, 18.0 ],
584-
"text" : "0.585983 562.986572"
584+
"text" : "0.006006 519.044312"
585585
}
586586

587587
}
@@ -855,11 +855,11 @@
855855
"fontsize" : 12.0,
856856
"id" : "obj-50",
857857
"maxclass" : "newobj",
858-
"numinlets" : 5,
858+
"numinlets" : 6,
859859
"numoutlets" : 1,
860860
"outlettype" : [ "" ],
861-
"patching_rect" : [ 548.928589, 326.0, 142.5, 20.0 ],
862-
"text" : "zmap 0. 1. 0. 1."
861+
"patching_rect" : [ 548.928589, 326.0, 142.734619, 20.0 ],
862+
"text" : "scale 0. 1. 0. 1."
863863
}
864864

865865
}
@@ -869,11 +869,11 @@
869869
"fontsize" : 12.0,
870870
"id" : "obj-48",
871871
"maxclass" : "newobj",
872-
"numinlets" : 5,
872+
"numinlets" : 6,
873873
"numoutlets" : 1,
874874
"outlettype" : [ "" ],
875-
"patching_rect" : [ 397.928589, 296.0, 142.5, 20.0 ],
876-
"text" : "zmap 0. 1. -1. 1."
875+
"patching_rect" : [ 397.928589, 296.0, 96.0, 20.0 ],
876+
"text" : "scale 0. 1. -1. 1."
877877
}
878878

879879
}

Tools/HTML Template.html

Lines changed: 150 additions & 125 deletions
Large diffs are not rendered by default.

gui/uiview.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>1094</width>
10-
<height>700</height>
10+
<height>740</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">

iannix.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,18 +1135,21 @@ void IanniX::send(const Message &message, QStringList *sentMessage) {
11351135
MessageManager::logReceive(message, sentMessage);
11361136
}
11371137

1138-
QString IanniX::incomingMessage(const MessageIncomming &source, bool needOutput) {
1138+
QString IanniX::incomingMessage(const MessageIncomming &source, bool needOutput, bool needToScript) {
11391139
if(needOutput) {
11401140
QString retour;
11411141
retour += execute(source, false, true).toString();
1142-
QString retourScript = getCurrentDocument()->incomingMessage(source, true);
1143-
if(retourScript != "undefined")
1144-
retourScript += retourScript;
1142+
if(needToScript) {
1143+
QString retourScript = getCurrentDocument()->incomingMessage(source, true);
1144+
if(retourScript != "undefined")
1145+
retour += retourScript;
1146+
}
11451147
return retour;
11461148
}
11471149
else {
11481150
execute(source, ExecuteSourceNetwork);
1149-
getCurrentDocument()->incomingMessage(source);
1151+
if(needToScript)
1152+
getCurrentDocument()->incomingMessage(source);
11501153
}
11511154
return QString();
11521155
}

iannix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public slots:
151151
if(index < argv.count()) return argv.at(index).toDouble();
152152
else return 0;
153153
}
154-
QString incomingMessage(const MessageIncomming &source, bool needOutput = false);
154+
QString incomingMessage(const MessageIncomming &source, bool needOutput = false, bool needToScript = true);
155155
void openMessageEditor();
156156
void send(const Message &message, QStringList *sentMessage = 0);
157157
QMainWindow* getMainWindow() { return view; }

interfaces/interfacehttp.cpp

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ InterfaceHttp::InterfaceHttp(QWidget *parent) :
55
NetworkInterface(parent),
66
ui(new Ui::InterfaceHttp) {
77
ui->setupUi(this);
8+
89
connect(ui->examples, SIGNAL(released()), SLOT(openExamples()));
910

11+
//HTTP server
1012
httpServer = new InterfaceHttpServer(this);
1113
connect(httpServer, SIGNAL(parseRequest(QNetworkReply*)), SLOT(parseRequest(QNetworkReply*)));
1214
connect(httpServer, SIGNAL(parseSocket(QTcpSocket*)), SLOT(parseSocket(QTcpSocket*)));
1315

16+
//Websockets server
17+
webSocketServer = new WebSocketServer(this);
18+
connect(webSocketServer, SIGNAL(newConnection()), SLOT(webSocketsNewConnection()));
19+
1420
//Html template
1521
QFile htmlTemplateFile("Tools/HTML Template.html");
1622
if(htmlTemplateFile.open(QFile::ReadOnly)) {
@@ -23,6 +29,9 @@ InterfaceHttp::InterfaceHttp(QWidget *parent) :
2329
port.setAction(ui->port, "interfaceHttpPort");
2430
connect(&port, SIGNAL(triggered(qreal)), SLOT(portChanged()));
2531
port = 1236;
32+
webSocketsPort.setAction(ui->portWebSockets, "interfaceHttpWebSocketsPort");
33+
connect(&webSocketsPort, SIGNAL(triggered(qreal)), SLOT(portWebSocketsChanged()));
34+
webSocketsPort = 1237;
2635
}
2736

2837
InterfaceHttpServer::InterfaceHttpServer(QObject *parent) :
@@ -35,7 +44,11 @@ InterfaceHttpServer::InterfaceHttpServer(QObject *parent) :
3544
void InterfaceHttp::portChanged() {
3645
if(httpServer->portChanged(port.val())) ui->port->setStyleSheet(ihmFeedbackOk);
3746
else ui->port->setStyleSheet(ihmFeedbackNok);
38-
47+
}
48+
void InterfaceHttp::portWebSocketsChanged() {
49+
webSocketServer->close();
50+
if(webSocketServer->listen(QHostAddress::Any, webSocketsPort.val())) ui->portWebSockets->setStyleSheet(ihmFeedbackOk);
51+
else ui->portWebSockets->setStyleSheet(ihmFeedbackNok);
3952
}
4053
bool InterfaceHttpServer::portChanged(quint16 port) {
4154
//Initialization
@@ -44,9 +57,55 @@ bool InterfaceHttpServer::portChanged(quint16 port) {
4457
}
4558

4659

60+
void InterfaceHttp::webSocketsNewConnection() {
61+
WebSocket *webSocket = webSocketServer->nextPendingConnection();
62+
connect(webSocket, SIGNAL(textMessageReceived(QString)), SLOT(webSocketsProcessMessage(QString)));
63+
connect(webSocket, SIGNAL(binaryMessageReceived(QByteArray)), SLOT(webSocketsProcessBinaryMessage(QByteArray)));
64+
connect(webSocket, SIGNAL(disconnected()), SLOT(webSocketsSocketDisconnected()));
65+
webSocketClients << webSocket;
66+
webSocketsUpdateConnectedClients();
67+
}
68+
void InterfaceHttp::webSocketsProcessMessage(const QString &message) {
69+
WebSocket *webSocket = qobject_cast<WebSocket *>(sender());
70+
if(webSocket) {
71+
QStringList commandItems = message.split(COMMAND_END, QString::SkipEmptyParts);;
72+
QString response;
73+
foreach(const QString & command, commandItems)
74+
response += MessageManager::incomingMessage(MessageIncomming("http", webSocket->peerAddress().toString(), webSocket->peerPort(), "", command, command.split(" ", QString::SkipEmptyParts)), true, (command != "goto"));
75+
if(!response.isEmpty())
76+
webSocket->send(response);
77+
}
78+
}
79+
void InterfaceHttp::webSocketsProcessBinaryMessage(const QByteArray &message) {
80+
WebSocket *webSocket = qobject_cast<WebSocket *>(sender());
81+
if(webSocket) {
82+
}
83+
}
84+
void InterfaceHttp::webSocketsSocketDisconnected() {
85+
WebSocket *webSocket = qobject_cast<WebSocket *>(sender());
86+
if(webSocket) {
87+
webSocketClients.removeAll(webSocket);
88+
webSocket->deleteLater();
89+
}
90+
webSocketsUpdateConnectedClients();
91+
}
92+
void InterfaceHttp::webSocketsUpdateConnectedClients() {
93+
QString clientsWebSockets;
94+
foreach(WebSocket *webSocket, webSocketClients)
95+
clientsWebSockets += QString("%1:%2\n").arg(webSocket->peerAddress().toString()).arg(webSocket->peerPort());
96+
clientsWebSockets.chop(1);
97+
if(webSocketClients.count() == 0) ui->clientsWebSockets->setText(tr("No websocket connected"));
98+
else if(webSocketClients.count() == 1) ui->clientsWebSockets->setText(tr("1 websocket connected\n(%1)").arg(clientsWebSockets));
99+
else ui->clientsWebSockets->setText(tr("%1 websockets connected").arg(webSocketClients.count()));
100+
ui->clientsWebSockets->setToolTip(clientsWebSockets);
101+
}
102+
103+
104+
47105
bool InterfaceHttp::send(const Message &message, QStringList *messageSent) {
48106
if(!enable)
49107
return false;
108+
50109
return httpServer->send(message, messageSent);
51110
}
52111
bool InterfaceHttpServer::send(const Message &message, QStringList *messageSent) {
@@ -73,7 +132,6 @@ void InterfaceHttp::parseRequest(QNetworkReply *reply) {
73132
}
74133

75134

76-
77135
//HTTP reception
78136
void InterfaceHttpServer::incomingConnection(int socketDescriptor) {
79137
QTcpSocket *socket = new QTcpSocket(this);
@@ -124,7 +182,7 @@ void InterfaceHttp::parseSocket(QTcpSocket *socket) {
124182

125183
QString response;
126184
foreach(const QString & command, commands)
127-
response += MessageManager::incomingMessage(MessageIncomming("http", socket->peerAddress().toString(), socket->peerPort(), url.path(), command, command.split(" ", QString::SkipEmptyParts)), true) + "\n";
185+
response += MessageManager::incomingMessage(MessageIncomming("http", socket->peerAddress().toString(), socket->peerPort(), url.path(), command, command.split(" ", QString::SkipEmptyParts)), true, (command != "goto")) + "\n";
128186

129187
os << response;
130188
}

interfaces/interfacehttp.h

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#include <QApplication>
1313
#include "misc/options.h"
1414
#include "messages/messagemanager.h"
15+
#include "qwebsockets/websocketserver.h"
16+
#include "qwebsockets/websocket.h"
17+
1518

1619
namespace Ui {
1720
class InterfaceHttp;
@@ -41,6 +44,8 @@ private slots:
4144
void parseSocket(QTcpSocket*);
4245
};
4346

47+
48+
4449
class InterfaceHttp : public NetworkInterface {
4550
Q_OBJECT
4651

@@ -50,20 +55,37 @@ class InterfaceHttp : public NetworkInterface {
5055

5156
private:
5257
InterfaceHttpServer *httpServer;
53-
UiReal port;
54-
UiBool enable;
55-
QString htmlTemplate;
5658
private slots:
5759
void portChanged();
5860
void parseRequest(QNetworkReply*);
5961
void parseSocket(QTcpSocket*);
62+
63+
private:
64+
WebSocketServer* webSocketServer;
65+
QList<WebSocket*> webSocketClients;
66+
private slots:
67+
void portWebSocketsChanged();
68+
void webSocketsNewConnection();
69+
void webSocketsProcessMessage(const QString &message);
70+
void webSocketsProcessBinaryMessage(const QByteArray &message);
71+
void webSocketsSocketDisconnected();
72+
void webSocketsUpdateConnectedClients();
73+
74+
75+
private:
76+
UiReal port, webSocketsPort;
77+
UiBool enable;
78+
QString htmlTemplate;
79+
private slots:
6080
void openExamples() {
6181
QDesktopServices::openUrl(QUrl("http://127.0.0.1:" + QString::number(port) + "/"));
6282
}
6383

84+
6485
public:
6586
bool send(const Message &message, QStringList *messageSent = 0);
6687

88+
6789
private:
6890
Ui::InterfaceHttp *ui;
6991
};

0 commit comments

Comments
 (0)