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" );
58 Main::scProcess()->evaluateCode( "ScIDE.defaultServer.quit" );
61 void ScServer::timerEvent(QTimerEvent
* event
)
63 if (mUdpSocket
->hasPendingDatagrams()) {
64 size_t datagramSize
= mUdpSocket
->pendingDatagramSize();
65 QByteArray
array(datagramSize
, 0);
66 mUdpSocket
->readDatagram(array
.data(), datagramSize
);
72 char *addr
= array
.data();
73 const char * data
= OSCstrskip(array
.data());
74 int size
= datagramSize
- (data
- addr
);
76 if (strcmp(addr
, "/status.reply") == 0) {
77 sc_msg_iter
reply(size
, data
);
78 int unused
= reply
.geti();
79 int ugenCount
= reply
.geti();
80 int synthCount
= reply
.geti();
81 int groupCount
= reply
.geti();
82 int defCount
= reply
.geti();
83 float avgCPU
= reply
.getf();
84 float peakCPU
= reply
.getf();
85 double srNom
= reply
.getd();
86 double srAct
= reply
.getd();
88 emit
updateServerStatus(ugenCount
, synthCount
, groupCount
, defCount
, avgCPU
, peakCPU
);
94 small_scpacket packet
;
96 packet
.adds_slpre("status");
101 mUdpSocket
->writeDatagram(packet
.data(), packet
.size(), mServerAddress
, mPort
);