scide: implement selectionLength for openDocument
[supercollider.git] / editors / sc-ide / core / sc_server.cpp
blob0f7edc69bd3de6d42aac19811c9ef7d279128978
1 /*
2 SuperCollider Qt IDE
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
21 #include <QDebug>
23 #include "sc_server.hpp"
24 #include "sc_process.hpp"
25 #include "main.hpp"
27 #include "scsynthsend.h"
28 #include "sc_msg_iter.h"
30 namespace ScIDE {
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);
38 if (success)
39 break;
41 startTimer(333);
44 void ScServer::boot()
46 if (isRunning())
47 return;
49 Main::scProcess()->evaluateCode( "ScIDE.defaultServer.boot" );
52 void ScServer::quit()
55 if (!isRunning())
56 return;
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);
68 if (!mPort)
69 return;
71 if (array[0]) {
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);
93 if (mPort) {
94 small_scpacket packet;
95 packet.BeginMsg();
96 packet.adds_slpre("status");
97 packet.maketags(1);
98 packet.addtag(',');
99 packet.EndMsg();
101 mUdpSocket->writeDatagram(packet.data(), packet.size(), mServerAddress, mPort);