1 |
// qsamplerMainForm.cpp |
// qsamplerMainForm.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2019, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2022, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007,2008,2015 Christian Schoenebeck |
Copyright (C) 2007-2019 Christian Schoenebeck |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
35 |
#include "qsamplerOptionsForm.h" |
#include "qsamplerOptionsForm.h" |
36 |
#include "qsamplerDeviceStatusForm.h" |
#include "qsamplerDeviceStatusForm.h" |
37 |
|
|
38 |
|
#include "qsamplerPaletteForm.h" |
39 |
|
|
40 |
|
#include <QStyleFactory> |
41 |
|
|
42 |
#include <QMdiArea> |
#include <QMdiArea> |
43 |
#include <QMdiSubWindow> |
#include <QMdiSubWindow> |
44 |
|
|
46 |
#include <QProcess> |
#include <QProcess> |
47 |
#include <QMessageBox> |
#include <QMessageBox> |
48 |
|
|
|
#include <QRegExp> |
|
49 |
#include <QTextStream> |
#include <QTextStream> |
50 |
#include <QFileDialog> |
#include <QFileDialog> |
51 |
#include <QFileInfo> |
#include <QFileInfo> |
61 |
#include <QTimer> |
#include <QTimer> |
62 |
#include <QDateTime> |
#include <QDateTime> |
63 |
|
|
64 |
|
#include <QElapsedTimer> |
65 |
|
|
66 |
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
67 |
#include <QMimeData> |
#include <QMimeData> |
68 |
#endif |
#endif |
74 |
#endif |
#endif |
75 |
|
|
76 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
77 |
|
#if defined(Q_CC_GNU) || defined(Q_CC_MINGW) |
78 |
|
#pragma GCC diagnostic push |
79 |
|
#pragma GCC diagnostic ignored "-Wunused-parameter" |
80 |
|
#endif |
81 |
#include <gig.h> |
#include <gig.h> |
82 |
|
#if defined(Q_CC_GNU) || defined(Q_CC_MINGW) |
83 |
|
#pragma GCC diagnostic pop |
84 |
|
#endif |
85 |
#endif |
#endif |
86 |
|
|
87 |
// Needed for lroundf() |
// Deprecated QTextStreamFunctions/Qt namespaces workaround. |
88 |
#include <math.h> |
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) |
89 |
|
#define endl Qt::endl |
90 |
|
#endif |
91 |
|
|
92 |
#ifndef CONFIG_ROUND |
// Needed for lroundf() |
93 |
|
#ifdef CONFIG_ROUND |
94 |
|
#include <cmath> |
95 |
|
#else |
96 |
static inline long lroundf ( float x ) |
static inline long lroundf ( float x ) |
97 |
{ |
{ |
98 |
if (x >= 0.0f) |
if (x >= 0.0f) |
130 |
{ |
{ |
131 |
char c = 1; |
char c = 1; |
132 |
|
|
133 |
(::write(g_fdSigusr1[0], &c, sizeof(c)) > 0); |
(void) (::write(g_fdSigusr1[0], &c, sizeof(c)) > 0); |
134 |
} |
} |
135 |
|
|
136 |
// File descriptor for SIGTERM notifier. |
// File descriptor for SIGTERM notifier. |
141 |
{ |
{ |
142 |
char c = 1; |
char c = 1; |
143 |
|
|
144 |
(::write(g_fdSigterm[0], &c, sizeof(c)) > 0); |
(void) (::write(g_fdSigterm[0], &c, sizeof(c)) > 0); |
145 |
} |
} |
146 |
|
|
147 |
#endif // HAVE_SIGNAL_H |
#endif // HAVE_SIGNAL_H |
225 |
: QMainWindow(pParent) |
: QMainWindow(pParent) |
226 |
{ |
{ |
227 |
m_ui.setupUi(this); |
m_ui.setupUi(this); |
228 |
|
#if QT_VERSION < QT_VERSION_CHECK(6, 1, 0) |
229 |
|
QMainWindow::setWindowIcon(QIcon(":/images/qsampler.png")); |
230 |
|
#endif |
231 |
// Pseudo-singleton reference setup. |
// Pseudo-singleton reference setup. |
232 |
g_pMainForm = this; |
g_pMainForm = this; |
233 |
|
|
985 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
986 |
const QList<QMdiSubWindow *>& wlist |
const QList<QMdiSubWindow *>& wlist |
987 |
= m_pWorkspace->subWindowList(); |
= m_pWorkspace->subWindowList(); |
988 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
989 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
990 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
991 |
if (pChannelStrip) { |
if (pChannelStrip) { |
992 |
Channel *pChannel = pChannelStrip->channel(); |
Channel *pChannel = pChannelStrip->channel(); |
993 |
if (bForce && pChannel) |
if (bForce && pChannel) |
994 |
pChannel->removeChannel(); |
pChannel->removeChannel(); |
995 |
delete pChannelStrip; |
delete pChannelStrip; |
996 |
} |
} |
997 |
if (pMdiSubWindow) |
delete pMdiSubWindow; |
|
delete pMdiSubWindow; |
|
998 |
} |
} |
999 |
m_pWorkspace->setUpdatesEnabled(true); |
m_pWorkspace->setUpdatesEnabled(true); |
1000 |
// We're now clean, for sure. |
// We're now clean, for sure. |
1292 |
int iChannelID = 0; |
int iChannelID = 0; |
1293 |
const QList<QMdiSubWindow *>& wlist |
const QList<QMdiSubWindow *>& wlist |
1294 |
= m_pWorkspace->subWindowList(); |
= m_pWorkspace->subWindowList(); |
1295 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
1296 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
1297 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
1298 |
if (pChannelStrip) { |
if (pChannelStrip) { |
1299 |
Channel *pChannel = pChannelStrip->channel(); |
Channel *pChannel = pChannelStrip->channel(); |
1300 |
if (pChannel) { |
if (pChannel) { |
1774 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
1775 |
const QList<QMdiSubWindow *>& wlist |
const QList<QMdiSubWindow *>& wlist |
1776 |
= m_pWorkspace->subWindowList(); |
= m_pWorkspace->subWindowList(); |
1777 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
1778 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
1779 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
1780 |
if (pChannelStrip) |
if (pChannelStrip) |
1781 |
pChannelStrip->channelReset(); |
pChannelStrip->channelReset(); |
1782 |
} |
} |
1885 |
if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages) |
if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages) |
1886 |
m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString(); |
m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString(); |
1887 |
// To track down deferred or immediate changes. |
// To track down deferred or immediate changes. |
1888 |
const QString sOldServerHost = m_pOptions->sServerHost; |
const QString sOldServerHost = m_pOptions->sServerHost; |
1889 |
const int iOldServerPort = m_pOptions->iServerPort; |
const int iOldServerPort = m_pOptions->iServerPort; |
1890 |
const int iOldServerTimeout = m_pOptions->iServerTimeout; |
const int iOldServerTimeout = m_pOptions->iServerTimeout; |
1891 |
const bool bOldServerStart = m_pOptions->bServerStart; |
const bool bOldServerStart = m_pOptions->bServerStart; |
1892 |
const QString sOldServerCmdLine = m_pOptions->sServerCmdLine; |
const QString sOldServerCmdLine = m_pOptions->sServerCmdLine; |
1893 |
const bool bOldMessagesLog = m_pOptions->bMessagesLog; |
const bool bOldMessagesLog = m_pOptions->bMessagesLog; |
1894 |
const QString sOldMessagesLogPath = m_pOptions->sMessagesLogPath; |
const QString sOldMessagesLogPath = m_pOptions->sMessagesLogPath; |
1895 |
const QString sOldDisplayFont = m_pOptions->sDisplayFont; |
const QString sOldDisplayFont = m_pOptions->sDisplayFont; |
1896 |
const bool bOldDisplayEffect = m_pOptions->bDisplayEffect; |
const bool bOldDisplayEffect = m_pOptions->bDisplayEffect; |
1897 |
const int iOldMaxVolume = m_pOptions->iMaxVolume; |
const int iOldMaxVolume = m_pOptions->iMaxVolume; |
1898 |
const QString sOldMessagesFont = m_pOptions->sMessagesFont; |
const QString sOldMessagesFont = m_pOptions->sMessagesFont; |
1899 |
const bool bOldKeepOnTop = m_pOptions->bKeepOnTop; |
const bool bOldKeepOnTop = m_pOptions->bKeepOnTop; |
1900 |
const bool bOldStdoutCapture = m_pOptions->bStdoutCapture; |
const bool bOldStdoutCapture = m_pOptions->bStdoutCapture; |
1901 |
const int bOldMessagesLimit = m_pOptions->bMessagesLimit; |
const int bOldMessagesLimit = m_pOptions->bMessagesLimit; |
1902 |
const int iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines; |
const int iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines; |
1903 |
const bool bOldCompletePath = m_pOptions->bCompletePath; |
const bool bOldCompletePath = m_pOptions->bCompletePath; |
1904 |
const bool bOldInstrumentNames = m_pOptions->bInstrumentNames; |
const bool bOldInstrumentNames = m_pOptions->bInstrumentNames; |
1905 |
const int iOldMaxRecentFiles = m_pOptions->iMaxRecentFiles; |
const int iOldMaxRecentFiles = m_pOptions->iMaxRecentFiles; |
1906 |
const int iOldBaseFontSize = m_pOptions->iBaseFontSize; |
const int iOldBaseFontSize = m_pOptions->iBaseFontSize; |
1907 |
|
const QString sOldCustomStyleTheme = m_pOptions->sCustomStyleTheme; |
1908 |
|
const QString sOldCustomColorTheme = m_pOptions->sCustomColorTheme; |
1909 |
// Load the current setup settings. |
// Load the current setup settings. |
1910 |
pOptionsForm->setup(m_pOptions); |
pOptionsForm->setup(m_pOptions); |
1911 |
// Show the setup dialog... |
// Show the setup dialog... |
1912 |
if (pOptionsForm->exec()) { |
if (pOptionsForm->exec()) { |
1913 |
// Warn if something will be only effective on next run. |
// Warn if something will be only effective on next run. |
1914 |
|
int iNeedRestart = 0; |
1915 |
if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) || |
if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) || |
1916 |
(!bOldStdoutCapture && m_pOptions->bStdoutCapture) || |
(!bOldStdoutCapture && m_pOptions->bStdoutCapture)) { |
1917 |
( bOldKeepOnTop && !m_pOptions->bKeepOnTop) || |
updateMessagesCapture(); |
1918 |
|
++iNeedRestart; |
1919 |
|
} |
1920 |
|
if (( bOldKeepOnTop && !m_pOptions->bKeepOnTop) || |
1921 |
(!bOldKeepOnTop && m_pOptions->bKeepOnTop) || |
(!bOldKeepOnTop && m_pOptions->bKeepOnTop) || |
1922 |
(iOldBaseFontSize != m_pOptions->iBaseFontSize)) { |
(iOldBaseFontSize != m_pOptions->iBaseFontSize)) { |
1923 |
QMessageBox::information(this, |
++iNeedRestart; |
1924 |
tr("Information"), |
} |
1925 |
tr("Some settings may be only effective\n" |
// Check whether restart is needed or whether |
1926 |
"next time you start this program.")); |
// custom options maybe set up immediately... |
1927 |
updateMessagesCapture(); |
if (m_pOptions->sCustomStyleTheme != sOldCustomStyleTheme) { |
1928 |
|
if (m_pOptions->sCustomStyleTheme.isEmpty()) { |
1929 |
|
++iNeedRestart; |
1930 |
|
} else { |
1931 |
|
QApplication::setStyle( |
1932 |
|
QStyleFactory::create(m_pOptions->sCustomStyleTheme)); |
1933 |
|
} |
1934 |
|
} |
1935 |
|
if (m_pOptions->sCustomColorTheme != sOldCustomColorTheme) { |
1936 |
|
if (m_pOptions->sCustomColorTheme.isEmpty()) { |
1937 |
|
++iNeedRestart; |
1938 |
|
} else { |
1939 |
|
QPalette pal; |
1940 |
|
if (PaletteForm::namedPalette( |
1941 |
|
&m_pOptions->settings(), m_pOptions->sCustomColorTheme, pal)) |
1942 |
|
QApplication::setPalette(pal); |
1943 |
|
} |
1944 |
} |
} |
1945 |
// Check wheather something immediate has changed. |
// Check wheather something immediate has changed. |
1946 |
if (( bOldMessagesLog && !m_pOptions->bMessagesLog) || |
if (( bOldMessagesLog && !m_pOptions->bMessagesLog) || |
1968 |
(!bOldMessagesLimit && m_pOptions->bMessagesLimit) || |
(!bOldMessagesLimit && m_pOptions->bMessagesLimit) || |
1969 |
(iOldMessagesLimitLines != m_pOptions->iMessagesLimitLines)) |
(iOldMessagesLimitLines != m_pOptions->iMessagesLimitLines)) |
1970 |
updateMessagesLimit(); |
updateMessagesLimit(); |
1971 |
|
// Show restart needed message... |
1972 |
|
if (iNeedRestart > 0) { |
1973 |
|
QMessageBox::information(this, |
1974 |
|
tr("Information"), |
1975 |
|
tr("Some settings may be only effective\n" |
1976 |
|
"next time you start this program.")); |
1977 |
|
} |
1978 |
// And now the main thing, whether we'll do client/server recycling? |
// And now the main thing, whether we'll do client/server recycling? |
1979 |
if ((sOldServerHost != m_pOptions->sServerHost) || |
if ((sOldServerHost != m_pOptions->sServerHost) || |
1980 |
(iOldServerPort != m_pOptions->iServerPort) || |
(iOldServerPort != m_pOptions->iServerPort) || |
2008 |
|
|
2009 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
2010 |
int y = 0; |
int y = 0; |
2011 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2012 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
pMdiSubWindow->adjustSize(); |
2013 |
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
const QRect& frameRect |
2014 |
if (pMdiSubWindow) { |
= pMdiSubWindow->frameGeometry(); |
2015 |
pMdiSubWindow->adjustSize(); |
int w = m_pWorkspace->width(); |
2016 |
int iWidth = m_pWorkspace->width(); |
if (w < frameRect.width()) |
2017 |
if (iWidth < pMdiSubWindow->width()) |
w = frameRect.width(); |
2018 |
iWidth = pMdiSubWindow->width(); |
const int h = frameRect.height(); |
2019 |
const int iHeight = pMdiSubWindow->frameGeometry().height(); |
pMdiSubWindow->setGeometry(0, y, w, h); |
2020 |
pMdiSubWindow->setGeometry(0, y, iWidth, iHeight); |
y += h; |
|
y += iHeight; |
|
|
} |
|
2021 |
} |
} |
2022 |
m_pWorkspace->setUpdatesEnabled(true); |
m_pWorkspace->setUpdatesEnabled(true); |
2023 |
|
|
2109 |
sText += "</font></small>"; |
sText += "</font></small>"; |
2110 |
} |
} |
2111 |
sText += "<br />\n"; |
sText += "<br />\n"; |
2112 |
sText += tr("Using") + ": "; |
sText += tr("Using: Qt %1").arg(qVersion()); |
2113 |
|
#if defined(QT_STATIC) |
2114 |
|
sText += "-static"; |
2115 |
|
#endif |
2116 |
|
sText += ", "; |
2117 |
sText += ::lscp_client_package(); |
sText += ::lscp_client_package(); |
2118 |
sText += " "; |
sText += " "; |
2119 |
sText += ::lscp_client_version(); |
sText += ::lscp_client_version(); |
2331 |
if (bRemoveDeadStrips) { |
if (bRemoveDeadStrips) { |
2332 |
const QList<QMdiSubWindow *>& wlist |
const QList<QMdiSubWindow *>& wlist |
2333 |
= m_pWorkspace->subWindowList(); |
= m_pWorkspace->subWindowList(); |
2334 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2335 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2336 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2337 |
if (pChannelStrip) { |
if (pChannelStrip) { |
2338 |
bool bExists = false; |
bool bExists = false; |
2339 |
for (int iChannel = 0; piChannelIDs[iChannel] >= 0; ++iChannel) { |
for (int iChannel = 0; piChannelIDs[iChannel] >= 0; ++iChannel) { |
2410 |
return; |
return; |
2411 |
|
|
2412 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
2413 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2414 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2415 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2416 |
if (pChannelStrip) |
if (pChannelStrip) |
2417 |
pChannelStrip->updateInstrumentName(true); |
pChannelStrip->updateInstrumentName(true); |
2418 |
} |
} |
2442 |
return; |
return; |
2443 |
|
|
2444 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
2445 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2446 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2447 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2448 |
if (pChannelStrip) |
if (pChannelStrip) |
2449 |
pChannelStrip->setDisplayFont(font); |
pChannelStrip->setDisplayFont(font); |
2450 |
} |
} |
2462 |
return; |
return; |
2463 |
|
|
2464 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
2465 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2466 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2467 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2468 |
if (pChannelStrip) |
if (pChannelStrip) |
2469 |
pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect); |
pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect); |
2470 |
} |
} |
2492 |
return; |
return; |
2493 |
|
|
2494 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
2495 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2496 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2497 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2498 |
if (pChannelStrip) |
if (pChannelStrip) |
2499 |
pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume); |
pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume); |
2500 |
} |
} |
2506 |
// QSampler::MainForm -- Messages window form handlers. |
// QSampler::MainForm -- Messages window form handlers. |
2507 |
|
|
2508 |
// Messages output methods. |
// Messages output methods. |
2509 |
void MainForm::appendMessages( const QString& s ) |
void MainForm::appendMessages ( const QString& s ) |
2510 |
{ |
{ |
2511 |
if (m_pMessages) |
if (m_pMessages) |
2512 |
m_pMessages->appendMessages(s); |
m_pMessages->appendMessages(s); |
2514 |
statusBar()->showMessage(s, 3000); |
statusBar()->showMessage(s, 3000); |
2515 |
} |
} |
2516 |
|
|
2517 |
void MainForm::appendMessagesColor( const QString& s, const QString& c ) |
void MainForm::appendMessagesColor ( const QString& s, const QColor& rgb ) |
2518 |
{ |
{ |
2519 |
if (m_pMessages) |
if (m_pMessages) |
2520 |
m_pMessages->appendMessagesColor(s, c); |
m_pMessages->appendMessagesColor(s, rgb); |
2521 |
|
|
2522 |
statusBar()->showMessage(s, 3000); |
statusBar()->showMessage(s, 3000); |
2523 |
} |
} |
2524 |
|
|
2525 |
void MainForm::appendMessagesText( const QString& s ) |
void MainForm::appendMessagesText ( const QString& s ) |
2526 |
{ |
{ |
2527 |
if (m_pMessages) |
if (m_pMessages) |
2528 |
m_pMessages->appendMessagesText(s); |
m_pMessages->appendMessagesText(s); |
2529 |
} |
} |
2530 |
|
|
2531 |
void MainForm::appendMessagesError( const QString& sText ) |
void MainForm::appendMessagesError ( const QString& s ) |
2532 |
{ |
{ |
2533 |
if (m_pMessages) |
if (m_pMessages) |
2534 |
m_pMessages->show(); |
m_pMessages->show(); |
2535 |
|
|
2536 |
appendMessagesColor(sText.simplified(), "#ff0000"); |
appendMessagesColor(s.simplified(), Qt::red); |
2537 |
|
|
2538 |
// Make it look responsive...:) |
// Make it look responsive...:) |
2539 |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
2546 |
QMessageBox mbox(this); |
QMessageBox mbox(this); |
2547 |
mbox.setIcon(QMessageBox::Critical); |
mbox.setIcon(QMessageBox::Critical); |
2548 |
mbox.setWindowTitle(sTitle); |
mbox.setWindowTitle(sTitle); |
2549 |
mbox.setText(sText); |
mbox.setText(s); |
2550 |
mbox.setStandardButtons(QMessageBox::Cancel); |
mbox.setStandardButtons(QMessageBox::Cancel); |
2551 |
QCheckBox cbox(tr("Don't show this again")); |
QCheckBox cbox(tr("Don't show this again")); |
2552 |
cbox.setChecked(false); |
cbox.setChecked(false); |
2642 |
} |
} |
2643 |
|
|
2644 |
// Add it to workspace... |
// Add it to workspace... |
2645 |
m_pWorkspace->addSubWindow(pChannelStrip, |
QMdiSubWindow *pMdiSubWindow |
2646 |
Qt::SubWindow | Qt::FramelessWindowHint); |
= m_pWorkspace->addSubWindow(pChannelStrip, |
2647 |
|
Qt::SubWindow | Qt::FramelessWindowHint); |
2648 |
|
pMdiSubWindow->setAttribute(Qt::WA_DeleteOnClose); |
2649 |
|
|
2650 |
// Actual channel strip setup... |
// Actual channel strip setup... |
2651 |
pChannelStrip->setup(pChannel); |
pChannelStrip->setup(pChannel); |
2721 |
if (wlist.isEmpty()) |
if (wlist.isEmpty()) |
2722 |
return nullptr; |
return nullptr; |
2723 |
|
|
2724 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2725 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2726 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2727 |
if (pChannelStrip) { |
if (pChannelStrip) { |
2728 |
Channel *pChannel = pChannelStrip->channel(); |
Channel *pChannel = pChannelStrip->channel(); |
2729 |
if (pChannel && pChannel->channelID() == iChannelID) |
if (pChannel && pChannel->channelID() == iChannelID) |
2747 |
= m_pWorkspace->subWindowList(); |
= m_pWorkspace->subWindowList(); |
2748 |
if (!wlist.isEmpty()) { |
if (!wlist.isEmpty()) { |
2749 |
m_ui.channelsMenu->addSeparator(); |
m_ui.channelsMenu->addSeparator(); |
2750 |
const int iStripCount = wlist.count(); |
int iStrip = 0; |
2751 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2752 |
ChannelStrip *pChannelStrip = nullptr; |
ChannelStrip *pChannelStrip |
2753 |
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2754 |
if (pChannelStrip) { |
if (pChannelStrip) { |
2755 |
QAction *pAction = m_ui.channelsMenu->addAction( |
QAction *pAction = m_ui.channelsMenu->addAction( |
2756 |
pChannelStrip->windowTitle(), |
pChannelStrip->windowTitle(), |
2759 |
pAction->setChecked(activeChannelStrip() == pChannelStrip); |
pAction->setChecked(activeChannelStrip() == pChannelStrip); |
2760 |
pAction->setData(iStrip); |
pAction->setData(iStrip); |
2761 |
} |
} |
2762 |
|
++iStrip; |
2763 |
} |
} |
2764 |
} |
} |
2765 |
} |
} |
2836 |
// Update the channel stream usage for each strip... |
// Update the channel stream usage for each strip... |
2837 |
const QList<QMdiSubWindow *>& wlist |
const QList<QMdiSubWindow *>& wlist |
2838 |
= m_pWorkspace->subWindowList(); |
= m_pWorkspace->subWindowList(); |
2839 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2840 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2841 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2842 |
if (pChannelStrip && pChannelStrip->isVisible()) |
if (pChannelStrip && pChannelStrip->isVisible()) |
2843 |
pChannelStrip->updateChannelUsage(); |
pChannelStrip->updateChannelUsage(); |
2844 |
} |
} |
2845 |
} |
} |
2846 |
} |
} |
2847 |
|
|
2848 |
|
#if CONFIG_LSCP_CLIENT_CONNECTION_LOST |
2849 |
|
// If we lost connection to server: Try to automatically reconnect if we |
2850 |
|
// did not start the server. |
2851 |
|
// |
2852 |
|
// TODO: If we started the server, then we might inform the user that |
2853 |
|
// the server probably crashed and asking user ONCE whether we should |
2854 |
|
// restart the server. |
2855 |
|
if (lscp_client_connection_lost(m_pClient) && !m_pServer) |
2856 |
|
startAutoReconnectClient(); |
2857 |
|
#endif // CONFIG_LSCP_CLIENT_CONNECTION_LOST |
2858 |
} |
} |
2859 |
|
|
2860 |
// Register the next timer slot. |
// Register the next timer slot. |
2931 |
|
|
2932 |
// Show startup results... |
// Show startup results... |
2933 |
appendMessages( |
appendMessages( |
2934 |
tr("Server was started with PID=%1.").arg((long) m_pServer->pid())); |
tr("Server was started with PID=%1.") |
2935 |
|
#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) |
2936 |
|
.arg(quint64(m_pServer->pid()))); |
2937 |
|
#else |
2938 |
|
.arg(quint64(m_pServer->processId()))); |
2939 |
|
#endif |
2940 |
|
|
2941 |
// Reset (yet again) the timer counters, |
// Reset (yet again) the timer counters, |
2942 |
// but this time is deferred as the user opted. |
// but this time is deferred as the user opted. |
2986 |
|
|
2987 |
// Give it some time to terminate gracefully and stabilize... |
// Give it some time to terminate gracefully and stabilize... |
2988 |
if (bGraceWait) { |
if (bGraceWait) { |
2989 |
QTime t; |
QElapsedTimer timer; |
2990 |
t.start(); |
timer.start(); |
2991 |
while (t.elapsed() < QSAMPLER_TIMER_MSECS) |
while (timer.elapsed() < QSAMPLER_TIMER_MSECS) |
2992 |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
2993 |
} |
} |
2994 |
} |
} |
3018 |
// Force final server shutdown... |
// Force final server shutdown... |
3019 |
m_pServer->kill(); |
m_pServer->kill(); |
3020 |
// Give it some time to terminate gracefully and stabilize... |
// Give it some time to terminate gracefully and stabilize... |
3021 |
QTime t; |
QElapsedTimer timer; |
3022 |
t.start(); |
timer.start(); |
3023 |
while (t.elapsed() < QSAMPLER_TIMER_MSECS) |
while (timer.elapsed() < QSAMPLER_TIMER_MSECS) |
3024 |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
3025 |
} |
} |
3026 |
// Force final server shutdown... |
// Force final server shutdown... |
3058 |
|
|
3059 |
|
|
3060 |
// Start our almighty client... |
// Start our almighty client... |
3061 |
bool MainForm::startClient (void) |
bool MainForm::startClient (bool bReconnectOnly) |
3062 |
{ |
{ |
3063 |
// Have it a setup? |
// Have it a setup? |
3064 |
if (m_pOptions == nullptr) |
if (m_pOptions == nullptr) |
3079 |
// Is this the first try? |
// Is this the first try? |
3080 |
// maybe we need to start a local server... |
// maybe we need to start a local server... |
3081 |
if ((m_pServer && m_pServer->state() == QProcess::Running) |
if ((m_pServer && m_pServer->state() == QProcess::Running) |
3082 |
|| !m_pOptions->bServerStart) { |
|| !m_pOptions->bServerStart || bReconnectOnly) |
3083 |
appendMessagesError( |
{ |
3084 |
tr("Could not connect to server as client.\n\nSorry.")); |
// if this method is called from autoReconnectClient() |
3085 |
|
// then don't bother user with an error message... |
3086 |
|
if (!bReconnectOnly) { |
3087 |
|
appendMessagesError( |
3088 |
|
tr("Could not connect to server as client.\n\nSorry.") |
3089 |
|
); |
3090 |
|
} |
3091 |
} else { |
} else { |
3092 |
startServer(); |
startServer(); |
3093 |
} |
} |
3216 |
} |
} |
3217 |
|
|
3218 |
|
|
3219 |
|
void MainForm::startAutoReconnectClient (void) |
3220 |
|
{ |
3221 |
|
stopClient(); |
3222 |
|
appendMessages(tr("Trying to reconnect...")); |
3223 |
|
QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient())); |
3224 |
|
} |
3225 |
|
|
3226 |
|
|
3227 |
|
void MainForm::autoReconnectClient (void) |
3228 |
|
{ |
3229 |
|
const bool bSuccess = startClient(true); |
3230 |
|
if (!bSuccess) |
3231 |
|
QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient())); |
3232 |
|
} |
3233 |
|
|
3234 |
|
|
3235 |
// Channel strip activation/selection. |
// Channel strip activation/selection. |
3236 |
void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow ) |
void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow ) |
3237 |
{ |
{ |