From a14301b235d7b3dfe2af59f94906a7dc146a6b1d Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 11 Aug 2012 14:33:28 +0200 Subject: [PATCH] scide: display server status in status bar Signed-off-by: Tim Blechmann --- editors/sc-ide/core/main.hpp | 4 +++- editors/sc-ide/core/sc_server.cpp | 5 +++-- editors/sc-ide/widgets/main_window.cpp | 41 ++++++++++++++++++++++++++++++---- editors/sc-ide/widgets/main_window.hpp | 4 +++- 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/editors/sc-ide/core/main.hpp b/editors/sc-ide/core/main.hpp index d7d9aa3d1..a40f292b9 100644 --- a/editors/sc-ide/core/main.hpp +++ b/editors/sc-ide/core/main.hpp @@ -48,7 +48,9 @@ public: Settings::Manager *settings() { return mSettings; } DocumentManager * documentManager() { return mDocManager; } SessionManager * sessionManager() { return mSessionManager; } - SCProcess * scProcess(void) { return mSCProcess; } + SCProcess * scProcess() { return mSCProcess; } + ScServer * scServer() { return mSCServer; } + ScResponder * scResponder() { return mSCResponder; } public Q_SLOTS: void storeSettings() { diff --git a/editors/sc-ide/core/sc_server.cpp b/editors/sc-ide/core/sc_server.cpp index f91a586f7..dbec25beb 100644 --- a/editors/sc-ide/core/sc_server.cpp +++ b/editors/sc-ide/core/sc_server.cpp @@ -46,6 +46,9 @@ void ScServer::timerEvent(QTimerEvent * event) QByteArray array(datagramSize, 0); mUdpSocket->readDatagram(array.data(), datagramSize); + if (!mPort) + return; + if (array[0]) { char *addr = array.data(); const char * data = OSCstrskip(array.data()); @@ -63,8 +66,6 @@ void ScServer::timerEvent(QTimerEvent * event) double srNom = reply.getd(); double srAct = reply.getd(); - qDebug() << "Server status:" << ugenCount << synthCount << groupCount << defCount << avgCPU << peakCPU; - emit updateServerStatus(ugenCount, synthCount, groupCount, defCount, avgCPU, peakCPU); } } diff --git a/editors/sc-ide/widgets/main_window.cpp b/editors/sc-ide/widgets/main_window.cpp index 3995ce714..782ecb158 100644 --- a/editors/sc-ide/widgets/main_window.cpp +++ b/editors/sc-ide/widgets/main_window.cpp @@ -65,14 +65,16 @@ MainWindow::MainWindow(Main * main) : mLangStatus = new StatusLabel(); mLangStatus->setText("Inactive"); - mSynthStatus = new StatusLabel(); - mSynthStatus->setText("Inactive"); + mServerStatus = new StatusLabel(); + onServerStatusReply(0, 0, 0, 0, 0, 0); QStatusBar *status = statusBar(); status->addPermanentWidget( new QLabel("Interpreter:") ); status->addPermanentWidget( mLangStatus ); - status->addPermanentWidget( new QLabel("Synth:") ); - status->addPermanentWidget( mSynthStatus ); + status->addPermanentWidget( new QLabel("Server:") ); + status->addPermanentWidget( mServerStatus ); + + onServerRunningChanged(false, "", 0); // Code editor mEditors = new MultiEditor(main); @@ -155,6 +157,9 @@ MainWindow::MainWindow(Main * main) : // ToolBox connect(mToolBox->closeButton(), SIGNAL(clicked()), this, SLOT(hideToolBox())); + connect(main->scResponder(), SIGNAL(serverRunningChanged(bool,QString,int)), this, SLOT(onServerRunningChanged(bool,QString,int))); + connect(main->scServer(), SIGNAL(updateServerStatus(int,int,int,int,float,float)), this, SLOT(onServerStatusReply(int,int,int,int,float,float))); + createActions(); createMenus(); @@ -627,6 +632,29 @@ void MainWindow::onInterpreterStateChanged( QProcess::ProcessState state ) mLangStatus->setTextColor(color); } + +void MainWindow::onServerStatusReply(int ugens, int synths, int groups, int synthDefs, float avgCPU, float peakCPU) +{ + QString statusString = + QString("%1% %2% %3u %4s %5g %6d") + .arg(avgCPU, 5, 'f', 2) + .arg(peakCPU, 5, 'f', 2) + .arg(ugens, 4) + .arg(synths, 4) + .arg(groups, 4) + .arg(synthDefs, 4); + + mServerStatus->setText(statusString); +} + +void MainWindow::onServerRunningChanged(bool running, const QString &, int) +{ + mServerStatus->setBackgroundRole( running ? QPalette::Window : QPalette::Button ); + mServerStatus->setTextColor( running ? Qt::green : Qt::white); + if (!running) + onServerStatusReply(0, 0, 0, 0, 0, 0); +} + void MainWindow::closeEvent(QCloseEvent *event) { if(!quit()) event->ignore(); @@ -983,6 +1011,11 @@ StatusLabel::StatusLabel(QWidget *parent) : QLabel(parent) setAlignment(Qt::AlignCenter); setBackground(Qt::black); setTextColor(Qt::white); + + QFont font("Monospace"); + font.setStyleHint(QFont::Monospace); + font.setBold(true); + setFont(font); } void StatusLabel::setBackground(const QBrush & brush) diff --git a/editors/sc-ide/widgets/main_window.hpp b/editors/sc-ide/widgets/main_window.hpp index c837eae8e..27217ef8a 100644 --- a/editors/sc-ide/widgets/main_window.hpp +++ b/editors/sc-ide/widgets/main_window.hpp @@ -132,6 +132,8 @@ private Q_SLOTS: void evaluateCurrentFile(); void helpForSelection(); void onInterpreterStateChanged( QProcess::ProcessState ); + void onServerStatusReply(int ugens, int synths, int groups, int synthDefs, float avgCPU, float peakCPU); + void onServerRunningChanged( bool running, QString const & hostName, int port ); void onQuit(); void onCurrentDocumentChanged( Document * ); void onDocumentChangedExternally( Document * ); @@ -167,7 +169,7 @@ private: // Status bar StatusLabel *mLangStatus; - StatusLabel *mSynthStatus; + StatusLabel *mServerStatus; // Docks PostDock * mPostDock; -- 2.11.4.GIT