3 Copyright (c) 2012 Jakob Leben & Tim Blechmann
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "sc_server.hpp"
24 #include "sc_process.hpp"
27 #include "scsynthsend.h"
28 #include "sc_msg_iter.h"
32 ScServer::ScServer(QObject
* parent
):
33 QObject(parent
), mPort(0)
35 mUdpSocket
= new QUdpSocket(this);
36 for (int port
= 57140; port
!= 57150; ++port
) {
37 bool success
= mUdpSocket
->bind(port
);
49 Main::scProcess()->evaluateCode( "ScIDE.defaultServer.boot", true );
57 Main::scProcess()->evaluateCode( "ScIDE.defaultServer.quit", true );
60 void ScServer::reboot()
62 Main::scProcess()->evaluateCode( "ScIDE.defaultServer.reboot", true );
65 void ScServer::queryAllNodes(bool dumpControls
)
67 QString arg
= dumpControls
? QString("true") : QString("false");
69 Main::scProcess()->evaluateCode( QString("ScIDE.defaultServer.queryAllNodes(%1)").arg(arg
), true );
72 void ScServer::timerEvent(QTimerEvent
* event
)
74 if (mUdpSocket
->hasPendingDatagrams()) {
75 size_t datagramSize
= mUdpSocket
->pendingDatagramSize();
76 QByteArray
array(datagramSize
, 0);
77 mUdpSocket
->readDatagram(array
.data(), datagramSize
);
83 char *addr
= array
.data();
84 const char * data
= OSCstrskip(array
.data());
85 int size
= datagramSize
- (data
- addr
);
87 if (strcmp(addr
, "/status.reply") == 0) {
88 sc_msg_iter
reply(size
, data
);
89 int unused
= reply
.geti();
90 int ugenCount
= reply
.geti();
91 int synthCount
= reply
.geti();
92 int groupCount
= reply
.geti();
93 int defCount
= reply
.geti();
94 float avgCPU
= reply
.getf();
95 float peakCPU
= reply
.getf();
96 double srNom
= reply
.getd();
97 double srAct
= reply
.getd();
99 emit
updateServerStatus(ugenCount
, synthCount
, groupCount
, defCount
, avgCPU
, peakCPU
);
105 small_scpacket packet
;
107 packet
.adds_slpre("status");
112 mUdpSocket
->writeDatagram(packet
.data(), packet
.size(), mServerAddress
, mPort
);