1 |
// qsamplerMainForm.cpp |
// qsamplerMainForm.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2019, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2020, 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 |
77 |
#include <gig.h> |
#include <gig.h> |
78 |
#endif |
#endif |
79 |
|
|
80 |
|
// Deprecated QTextStreamFunctions/Qt namespaces workaround. |
81 |
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) |
82 |
|
#define endl Qt::endl |
83 |
|
#endif |
84 |
|
|
85 |
// Needed for lroundf() |
// Needed for lroundf() |
86 |
#include <math.h> |
#include <math.h> |
87 |
|
|
879 |
|
|
880 |
// Ask for the filename to open... |
// Ask for the filename to open... |
881 |
QString sFilename = QFileDialog::getOpenFileName(this, |
QString sFilename = QFileDialog::getOpenFileName(this, |
882 |
QSAMPLER_TITLE ": " + tr("Open Session"), // Caption. |
tr("Open Session"), // Caption. |
883 |
m_pOptions->sSessionDir, // Start here. |
m_pOptions->sSessionDir, // Start here. |
884 |
tr("LSCP Session files") + " (*.lscp)" // Filter (LSCP files) |
tr("LSCP Session files") + " (*.lscp)" // Filter (LSCP files) |
885 |
); |
); |
912 |
sFilename = m_pOptions->sSessionDir; |
sFilename = m_pOptions->sSessionDir; |
913 |
// Prompt the guy... |
// Prompt the guy... |
914 |
sFilename = QFileDialog::getSaveFileName(this, |
sFilename = QFileDialog::getSaveFileName(this, |
915 |
QSAMPLER_TITLE ": " + tr("Save Session"), // Caption. |
tr("Save Session"), // Caption. |
916 |
sFilename, // Start here. |
sFilename, // Start here. |
917 |
tr("LSCP Session files") + " (*.lscp)" // Filter (LSCP files) |
tr("LSCP Session files") + " (*.lscp)" // Filter (LSCP files) |
918 |
); |
); |
926 |
// Check if already exists... |
// Check if already exists... |
927 |
if (sFilename != m_sFilename && QFileInfo(sFilename).exists()) { |
if (sFilename != m_sFilename && QFileInfo(sFilename).exists()) { |
928 |
if (QMessageBox::warning(this, |
if (QMessageBox::warning(this, |
929 |
QSAMPLER_TITLE ": " + tr("Warning"), |
tr("Warning"), |
930 |
tr("The file already exists:\n\n" |
tr("The file already exists:\n\n" |
931 |
"\"%1\"\n\n" |
"\"%1\"\n\n" |
932 |
"Do you want to replace it?") |
"Do you want to replace it?") |
951 |
// Are we dirty enough to prompt it? |
// Are we dirty enough to prompt it? |
952 |
if (m_iDirtyCount > 0) { |
if (m_iDirtyCount > 0) { |
953 |
switch (QMessageBox::warning(this, |
switch (QMessageBox::warning(this, |
954 |
QSAMPLER_TITLE ": " + tr("Warning"), |
tr("Warning"), |
955 |
tr("The current session has been changed:\n\n" |
tr("The current session has been changed:\n\n" |
956 |
"\"%1\"\n\n" |
"\"%1\"\n\n" |
957 |
"Do you want to save the changes?") |
"Do you want to save the changes?") |
976 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
977 |
const QList<QMdiSubWindow *>& wlist |
const QList<QMdiSubWindow *>& wlist |
978 |
= m_pWorkspace->subWindowList(); |
= m_pWorkspace->subWindowList(); |
979 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
980 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
981 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
982 |
if (pChannelStrip) { |
if (pChannelStrip) { |
983 |
Channel *pChannel = pChannelStrip->channel(); |
Channel *pChannel = pChannelStrip->channel(); |
984 |
if (bForce && pChannel) |
if (bForce && pChannel) |
985 |
pChannel->removeChannel(); |
pChannel->removeChannel(); |
986 |
delete pChannelStrip; |
delete pChannelStrip; |
987 |
} |
} |
988 |
if (pMdiSubWindow) |
delete pMdiSubWindow; |
|
delete pMdiSubWindow; |
|
989 |
} |
} |
990 |
m_pWorkspace->setUpdatesEnabled(true); |
m_pWorkspace->setUpdatesEnabled(true); |
991 |
// We're now clean, for sure. |
// We're now clean, for sure. |
1283 |
int iChannelID = 0; |
int iChannelID = 0; |
1284 |
const QList<QMdiSubWindow *>& wlist |
const QList<QMdiSubWindow *>& wlist |
1285 |
= m_pWorkspace->subWindowList(); |
= m_pWorkspace->subWindowList(); |
1286 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
1287 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
1288 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
1289 |
if (pChannelStrip) { |
if (pChannelStrip) { |
1290 |
Channel *pChannel = pChannelStrip->channel(); |
Channel *pChannel = pChannelStrip->channel(); |
1291 |
if (pChannel) { |
if (pChannel) { |
1496 |
|
|
1497 |
// Ask user whether he/she want's an internal sampler reset... |
// Ask user whether he/she want's an internal sampler reset... |
1498 |
if (m_pOptions && m_pOptions->bConfirmReset) { |
if (m_pOptions && m_pOptions->bConfirmReset) { |
1499 |
const QString& sTitle = QSAMPLER_TITLE ": " + tr("Warning"); |
const QString& sTitle = tr("Warning"); |
1500 |
const QString& sText = tr( |
const QString& sText = tr( |
1501 |
"Resetting the sampler instance will close\n" |
"Resetting the sampler instance will close\n" |
1502 |
"all device and channel configurations.\n\n" |
"all device and channel configurations.\n\n" |
1555 |
// Ask user whether he/she want's a complete restart... |
// Ask user whether he/she want's a complete restart... |
1556 |
// (if we're currently up and running) |
// (if we're currently up and running) |
1557 |
if (m_pOptions && m_pOptions->bConfirmRestart) { |
if (m_pOptions && m_pOptions->bConfirmRestart) { |
1558 |
const QString& sTitle = QSAMPLER_TITLE ": " + tr("Warning"); |
const QString& sTitle = tr("Warning"); |
1559 |
const QString& sText = tr( |
const QString& sText = tr( |
1560 |
"New settings will be effective after\n" |
"New settings will be effective after\n" |
1561 |
"restarting the client/server connection.\n\n" |
"restarting the client/server connection.\n\n" |
1669 |
|
|
1670 |
// Prompt user if he/she's sure about this... |
// Prompt user if he/she's sure about this... |
1671 |
if (m_pOptions && m_pOptions->bConfirmRemove) { |
if (m_pOptions && m_pOptions->bConfirmRemove) { |
1672 |
const QString& sTitle = QSAMPLER_TITLE ": " + tr("Warning"); |
const QString& sTitle = tr("Warning"); |
1673 |
const QString& sText = tr( |
const QString& sText = tr( |
1674 |
"About to remove channel:\n\n" |
"About to remove channel:\n\n" |
1675 |
"%1\n\n" |
"%1\n\n" |
1765 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
1766 |
const QList<QMdiSubWindow *>& wlist |
const QList<QMdiSubWindow *>& wlist |
1767 |
= m_pWorkspace->subWindowList(); |
= m_pWorkspace->subWindowList(); |
1768 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
1769 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
1770 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
1771 |
if (pChannelStrip) |
if (pChannelStrip) |
1772 |
pChannelStrip->channelReset(); |
pChannelStrip->channelReset(); |
1773 |
} |
} |
1876 |
if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages) |
if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages) |
1877 |
m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString(); |
m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString(); |
1878 |
// To track down deferred or immediate changes. |
// To track down deferred or immediate changes. |
1879 |
const QString sOldServerHost = m_pOptions->sServerHost; |
const QString sOldServerHost = m_pOptions->sServerHost; |
1880 |
const int iOldServerPort = m_pOptions->iServerPort; |
const int iOldServerPort = m_pOptions->iServerPort; |
1881 |
const int iOldServerTimeout = m_pOptions->iServerTimeout; |
const int iOldServerTimeout = m_pOptions->iServerTimeout; |
1882 |
const bool bOldServerStart = m_pOptions->bServerStart; |
const bool bOldServerStart = m_pOptions->bServerStart; |
1883 |
const QString sOldServerCmdLine = m_pOptions->sServerCmdLine; |
const QString sOldServerCmdLine = m_pOptions->sServerCmdLine; |
1884 |
const bool bOldMessagesLog = m_pOptions->bMessagesLog; |
const bool bOldMessagesLog = m_pOptions->bMessagesLog; |
1885 |
const QString sOldMessagesLogPath = m_pOptions->sMessagesLogPath; |
const QString sOldMessagesLogPath = m_pOptions->sMessagesLogPath; |
1886 |
const QString sOldDisplayFont = m_pOptions->sDisplayFont; |
const QString sOldDisplayFont = m_pOptions->sDisplayFont; |
1887 |
const bool bOldDisplayEffect = m_pOptions->bDisplayEffect; |
const bool bOldDisplayEffect = m_pOptions->bDisplayEffect; |
1888 |
const int iOldMaxVolume = m_pOptions->iMaxVolume; |
const int iOldMaxVolume = m_pOptions->iMaxVolume; |
1889 |
const QString sOldMessagesFont = m_pOptions->sMessagesFont; |
const QString sOldMessagesFont = m_pOptions->sMessagesFont; |
1890 |
const bool bOldKeepOnTop = m_pOptions->bKeepOnTop; |
const bool bOldKeepOnTop = m_pOptions->bKeepOnTop; |
1891 |
const bool bOldStdoutCapture = m_pOptions->bStdoutCapture; |
const bool bOldStdoutCapture = m_pOptions->bStdoutCapture; |
1892 |
const int bOldMessagesLimit = m_pOptions->bMessagesLimit; |
const int bOldMessagesLimit = m_pOptions->bMessagesLimit; |
1893 |
const int iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines; |
const int iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines; |
1894 |
const bool bOldCompletePath = m_pOptions->bCompletePath; |
const bool bOldCompletePath = m_pOptions->bCompletePath; |
1895 |
const bool bOldInstrumentNames = m_pOptions->bInstrumentNames; |
const bool bOldInstrumentNames = m_pOptions->bInstrumentNames; |
1896 |
const int iOldMaxRecentFiles = m_pOptions->iMaxRecentFiles; |
const int iOldMaxRecentFiles = m_pOptions->iMaxRecentFiles; |
1897 |
const int iOldBaseFontSize = m_pOptions->iBaseFontSize; |
const int iOldBaseFontSize = m_pOptions->iBaseFontSize; |
1898 |
|
const QString sOldCustomStyleTheme = m_pOptions->sCustomStyleTheme; |
1899 |
|
const QString sOldCustomColorTheme = m_pOptions->sCustomColorTheme; |
1900 |
// Load the current setup settings. |
// Load the current setup settings. |
1901 |
pOptionsForm->setup(m_pOptions); |
pOptionsForm->setup(m_pOptions); |
1902 |
// Show the setup dialog... |
// Show the setup dialog... |
1903 |
if (pOptionsForm->exec()) { |
if (pOptionsForm->exec()) { |
1904 |
// Warn if something will be only effective on next run. |
// Warn if something will be only effective on next run. |
1905 |
|
int iNeedRestart = 0; |
1906 |
if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) || |
if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) || |
1907 |
(!bOldStdoutCapture && m_pOptions->bStdoutCapture) || |
(!bOldStdoutCapture && m_pOptions->bStdoutCapture)) { |
1908 |
( bOldKeepOnTop && !m_pOptions->bKeepOnTop) || |
updateMessagesCapture(); |
1909 |
|
++iNeedRestart; |
1910 |
|
} |
1911 |
|
if (( bOldKeepOnTop && !m_pOptions->bKeepOnTop) || |
1912 |
(!bOldKeepOnTop && m_pOptions->bKeepOnTop) || |
(!bOldKeepOnTop && m_pOptions->bKeepOnTop) || |
1913 |
(iOldBaseFontSize != m_pOptions->iBaseFontSize)) { |
(iOldBaseFontSize != m_pOptions->iBaseFontSize)) { |
1914 |
QMessageBox::information(this, |
++iNeedRestart; |
1915 |
QSAMPLER_TITLE ": " + tr("Information"), |
} |
1916 |
tr("Some settings may be only effective\n" |
// Check whether restart is needed or whether |
1917 |
"next time you start this program.")); |
// custom options maybe set up immediately... |
1918 |
updateMessagesCapture(); |
if (m_pOptions->sCustomStyleTheme != sOldCustomStyleTheme) { |
1919 |
|
if (m_pOptions->sCustomStyleTheme.isEmpty()) { |
1920 |
|
++iNeedRestart; |
1921 |
|
} else { |
1922 |
|
QApplication::setStyle( |
1923 |
|
QStyleFactory::create(m_pOptions->sCustomStyleTheme)); |
1924 |
|
} |
1925 |
|
} |
1926 |
|
if (m_pOptions->sCustomColorTheme != sOldCustomColorTheme) { |
1927 |
|
if (m_pOptions->sCustomColorTheme.isEmpty()) { |
1928 |
|
++iNeedRestart; |
1929 |
|
} else { |
1930 |
|
QPalette pal; |
1931 |
|
if (PaletteForm::namedPalette( |
1932 |
|
&m_pOptions->settings(), m_pOptions->sCustomColorTheme, pal)) |
1933 |
|
QApplication::setPalette(pal); |
1934 |
|
} |
1935 |
} |
} |
1936 |
// Check wheather something immediate has changed. |
// Check wheather something immediate has changed. |
1937 |
if (( bOldMessagesLog && !m_pOptions->bMessagesLog) || |
if (( bOldMessagesLog && !m_pOptions->bMessagesLog) || |
1959 |
(!bOldMessagesLimit && m_pOptions->bMessagesLimit) || |
(!bOldMessagesLimit && m_pOptions->bMessagesLimit) || |
1960 |
(iOldMessagesLimitLines != m_pOptions->iMessagesLimitLines)) |
(iOldMessagesLimitLines != m_pOptions->iMessagesLimitLines)) |
1961 |
updateMessagesLimit(); |
updateMessagesLimit(); |
1962 |
|
// Show restart needed message... |
1963 |
|
if (iNeedRestart > 0) { |
1964 |
|
QMessageBox::information(this, |
1965 |
|
tr("Information"), |
1966 |
|
tr("Some settings may be only effective\n" |
1967 |
|
"next time you start this program.")); |
1968 |
|
} |
1969 |
// And now the main thing, whether we'll do client/server recycling? |
// And now the main thing, whether we'll do client/server recycling? |
1970 |
if ((sOldServerHost != m_pOptions->sServerHost) || |
if ((sOldServerHost != m_pOptions->sServerHost) || |
1971 |
(iOldServerPort != m_pOptions->iServerPort) || |
(iOldServerPort != m_pOptions->iServerPort) || |
1999 |
|
|
2000 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
2001 |
int y = 0; |
int y = 0; |
2002 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2003 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
pMdiSubWindow->adjustSize(); |
2004 |
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
const QRect& frameRect |
2005 |
if (pMdiSubWindow) { |
= pMdiSubWindow->frameGeometry(); |
2006 |
pMdiSubWindow->adjustSize(); |
int w = m_pWorkspace->width(); |
2007 |
int iWidth = m_pWorkspace->width(); |
if (w < frameRect.width()) |
2008 |
if (iWidth < pMdiSubWindow->width()) |
w = frameRect.width(); |
2009 |
iWidth = pMdiSubWindow->width(); |
const int h = frameRect.height(); |
2010 |
const int iHeight = pMdiSubWindow->frameGeometry().height(); |
pMdiSubWindow->setGeometry(0, y, w, h); |
2011 |
pMdiSubWindow->setGeometry(0, y, iWidth, iHeight); |
y += h; |
|
y += iHeight; |
|
|
} |
|
2012 |
} |
} |
2013 |
m_pWorkspace->setUpdatesEnabled(true); |
m_pWorkspace->setUpdatesEnabled(true); |
2014 |
|
|
2123 |
sText += "</small>"; |
sText += "</small>"; |
2124 |
sText += "</p>\n"; |
sText += "</p>\n"; |
2125 |
|
|
2126 |
QMessageBox::about(this, tr("About") + " " QSAMPLER_TITLE, sText); |
QMessageBox::about(this, tr("About"), sText); |
2127 |
} |
} |
2128 |
|
|
2129 |
|
|
2136 |
QString sSessionName = sessionName(m_sFilename); |
QString sSessionName = sessionName(m_sFilename); |
2137 |
if (m_iDirtyCount > 0) |
if (m_iDirtyCount > 0) |
2138 |
sSessionName += " *"; |
sSessionName += " *"; |
2139 |
setWindowTitle(tr(QSAMPLER_TITLE " - [%1]").arg(sSessionName)); |
setWindowTitle(sSessionName); |
2140 |
|
|
2141 |
// Update the main menu state... |
// Update the main menu state... |
2142 |
ChannelStrip *pChannelStrip = activeChannelStrip(); |
ChannelStrip *pChannelStrip = activeChannelStrip(); |
2318 |
if (bRemoveDeadStrips) { |
if (bRemoveDeadStrips) { |
2319 |
const QList<QMdiSubWindow *>& wlist |
const QList<QMdiSubWindow *>& wlist |
2320 |
= m_pWorkspace->subWindowList(); |
= m_pWorkspace->subWindowList(); |
2321 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2322 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2323 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2324 |
if (pChannelStrip) { |
if (pChannelStrip) { |
2325 |
bool bExists = false; |
bool bExists = false; |
2326 |
for (int iChannel = 0; piChannelIDs[iChannel] >= 0; ++iChannel) { |
for (int iChannel = 0; piChannelIDs[iChannel] >= 0; ++iChannel) { |
2397 |
return; |
return; |
2398 |
|
|
2399 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
2400 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2401 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2402 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2403 |
if (pChannelStrip) |
if (pChannelStrip) |
2404 |
pChannelStrip->updateInstrumentName(true); |
pChannelStrip->updateInstrumentName(true); |
2405 |
} |
} |
2429 |
return; |
return; |
2430 |
|
|
2431 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
2432 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2433 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2434 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2435 |
if (pChannelStrip) |
if (pChannelStrip) |
2436 |
pChannelStrip->setDisplayFont(font); |
pChannelStrip->setDisplayFont(font); |
2437 |
} |
} |
2449 |
return; |
return; |
2450 |
|
|
2451 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
2452 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2453 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2454 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2455 |
if (pChannelStrip) |
if (pChannelStrip) |
2456 |
pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect); |
pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect); |
2457 |
} |
} |
2479 |
return; |
return; |
2480 |
|
|
2481 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
2482 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2483 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2484 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2485 |
if (pChannelStrip) |
if (pChannelStrip) |
2486 |
pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume); |
pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume); |
2487 |
} |
} |
2493 |
// QSampler::MainForm -- Messages window form handlers. |
// QSampler::MainForm -- Messages window form handlers. |
2494 |
|
|
2495 |
// Messages output methods. |
// Messages output methods. |
2496 |
void MainForm::appendMessages( const QString& s ) |
void MainForm::appendMessages ( const QString& s ) |
2497 |
{ |
{ |
2498 |
if (m_pMessages) |
if (m_pMessages) |
2499 |
m_pMessages->appendMessages(s); |
m_pMessages->appendMessages(s); |
2501 |
statusBar()->showMessage(s, 3000); |
statusBar()->showMessage(s, 3000); |
2502 |
} |
} |
2503 |
|
|
2504 |
void MainForm::appendMessagesColor( const QString& s, const QString& c ) |
void MainForm::appendMessagesColor ( const QString& s, const QColor& rgb ) |
2505 |
{ |
{ |
2506 |
if (m_pMessages) |
if (m_pMessages) |
2507 |
m_pMessages->appendMessagesColor(s, c); |
m_pMessages->appendMessagesColor(s, rgb); |
2508 |
|
|
2509 |
statusBar()->showMessage(s, 3000); |
statusBar()->showMessage(s, 3000); |
2510 |
} |
} |
2511 |
|
|
2512 |
void MainForm::appendMessagesText( const QString& s ) |
void MainForm::appendMessagesText ( const QString& s ) |
2513 |
{ |
{ |
2514 |
if (m_pMessages) |
if (m_pMessages) |
2515 |
m_pMessages->appendMessagesText(s); |
m_pMessages->appendMessagesText(s); |
2516 |
} |
} |
2517 |
|
|
2518 |
void MainForm::appendMessagesError( const QString& sText ) |
void MainForm::appendMessagesError ( const QString& s ) |
2519 |
{ |
{ |
2520 |
if (m_pMessages) |
if (m_pMessages) |
2521 |
m_pMessages->show(); |
m_pMessages->show(); |
2522 |
|
|
2523 |
appendMessagesColor(sText.simplified(), "#ff0000"); |
appendMessagesColor(s.simplified(), Qt::red); |
2524 |
|
|
2525 |
// Make it look responsive...:) |
// Make it look responsive...:) |
2526 |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
2527 |
|
|
2528 |
if (m_pOptions && m_pOptions->bConfirmError) { |
if (m_pOptions && m_pOptions->bConfirmError) { |
2529 |
const QString& sTitle = QSAMPLER_TITLE ": " + tr("Error"); |
const QString& sTitle = tr("Error"); |
2530 |
#if 0 |
#if 0 |
2531 |
QMessageBox::critical(this, sTitle, sText, QMessageBox::Cancel); |
QMessageBox::critical(this, sTitle, sText, QMessageBox::Cancel); |
2532 |
#else |
#else |
2533 |
QMessageBox mbox(this); |
QMessageBox mbox(this); |
2534 |
mbox.setIcon(QMessageBox::Critical); |
mbox.setIcon(QMessageBox::Critical); |
2535 |
mbox.setWindowTitle(sTitle); |
mbox.setWindowTitle(sTitle); |
2536 |
mbox.setText(sText); |
mbox.setText(s); |
2537 |
mbox.setStandardButtons(QMessageBox::Cancel); |
mbox.setStandardButtons(QMessageBox::Cancel); |
2538 |
QCheckBox cbox(tr("Don't show this again")); |
QCheckBox cbox(tr("Don't show this again")); |
2539 |
cbox.setChecked(false); |
cbox.setChecked(false); |
2629 |
} |
} |
2630 |
|
|
2631 |
// Add it to workspace... |
// Add it to workspace... |
2632 |
m_pWorkspace->addSubWindow(pChannelStrip, |
QMdiSubWindow *pMdiSubWindow |
2633 |
Qt::SubWindow | Qt::FramelessWindowHint); |
= m_pWorkspace->addSubWindow(pChannelStrip, |
2634 |
|
Qt::SubWindow | Qt::FramelessWindowHint); |
2635 |
|
pMdiSubWindow->setAttribute(Qt::WA_DeleteOnClose); |
2636 |
|
|
2637 |
// Actual channel strip setup... |
// Actual channel strip setup... |
2638 |
pChannelStrip->setup(pChannel); |
pChannelStrip->setup(pChannel); |
2708 |
if (wlist.isEmpty()) |
if (wlist.isEmpty()) |
2709 |
return nullptr; |
return nullptr; |
2710 |
|
|
2711 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2712 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2713 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2714 |
if (pChannelStrip) { |
if (pChannelStrip) { |
2715 |
Channel *pChannel = pChannelStrip->channel(); |
Channel *pChannel = pChannelStrip->channel(); |
2716 |
if (pChannel && pChannel->channelID() == iChannelID) |
if (pChannel && pChannel->channelID() == iChannelID) |
2734 |
= m_pWorkspace->subWindowList(); |
= m_pWorkspace->subWindowList(); |
2735 |
if (!wlist.isEmpty()) { |
if (!wlist.isEmpty()) { |
2736 |
m_ui.channelsMenu->addSeparator(); |
m_ui.channelsMenu->addSeparator(); |
2737 |
const int iStripCount = wlist.count(); |
int iStrip = 0; |
2738 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2739 |
ChannelStrip *pChannelStrip = nullptr; |
ChannelStrip *pChannelStrip |
2740 |
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2741 |
if (pChannelStrip) { |
if (pChannelStrip) { |
2742 |
QAction *pAction = m_ui.channelsMenu->addAction( |
QAction *pAction = m_ui.channelsMenu->addAction( |
2743 |
pChannelStrip->windowTitle(), |
pChannelStrip->windowTitle(), |
2746 |
pAction->setChecked(activeChannelStrip() == pChannelStrip); |
pAction->setChecked(activeChannelStrip() == pChannelStrip); |
2747 |
pAction->setData(iStrip); |
pAction->setData(iStrip); |
2748 |
} |
} |
2749 |
|
++iStrip; |
2750 |
} |
} |
2751 |
} |
} |
2752 |
} |
} |
2823 |
// Update the channel stream usage for each strip... |
// Update the channel stream usage for each strip... |
2824 |
const QList<QMdiSubWindow *>& wlist |
const QList<QMdiSubWindow *>& wlist |
2825 |
= m_pWorkspace->subWindowList(); |
= m_pWorkspace->subWindowList(); |
2826 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2827 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2828 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2829 |
if (pChannelStrip && pChannelStrip->isVisible()) |
if (pChannelStrip && pChannelStrip->isVisible()) |
2830 |
pChannelStrip->updateChannelUsage(); |
pChannelStrip->updateChannelUsage(); |
2831 |
} |
} |
2832 |
} |
} |
2833 |
} |
} |
2834 |
|
|
2835 |
|
#if CONFIG_LSCP_CLIENT_CONNECTION_LOST |
2836 |
|
// If we lost connection to server: Try to automatically reconnect if we |
2837 |
|
// did not start the server. |
2838 |
|
// |
2839 |
|
// TODO: If we started the server, then we might inform the user that |
2840 |
|
// the server probably crashed and asking user ONCE whether we should |
2841 |
|
// restart the server. |
2842 |
|
if (lscp_client_connection_lost(m_pClient) && !m_pServer) |
2843 |
|
startAutoReconnectClient(); |
2844 |
|
#endif // CONFIG_LSCP_CLIENT_CONNECTION_LOST |
2845 |
} |
} |
2846 |
|
|
2847 |
// Register the next timer slot. |
// Register the next timer slot. |
2865 |
// Is the server process instance still here? |
// Is the server process instance still here? |
2866 |
if (m_pServer) { |
if (m_pServer) { |
2867 |
if (QMessageBox::warning(this, |
if (QMessageBox::warning(this, |
2868 |
QSAMPLER_TITLE ": " + tr("Warning"), |
tr("Warning"), |
2869 |
tr("Could not start the LinuxSampler server.\n\n" |
tr("Could not start the LinuxSampler server.\n\n" |
2870 |
"Maybe it is already started."), |
"Maybe it is already started."), |
2871 |
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) { |
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) { |
2918 |
|
|
2919 |
// Show startup results... |
// Show startup results... |
2920 |
appendMessages( |
appendMessages( |
2921 |
tr("Server was started with PID=%1.").arg((long) m_pServer->pid())); |
tr("Server was started with PID=%1.") |
2922 |
|
#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) |
2923 |
|
.arg(quint64(m_pServer->pid()))); |
2924 |
|
#else |
2925 |
|
.arg(quint64(m_pServer->processId()))); |
2926 |
|
#endif |
2927 |
|
|
2928 |
// Reset (yet again) the timer counters, |
// Reset (yet again) the timer counters, |
2929 |
// but this time is deferred as the user opted. |
// but this time is deferred as the user opted. |
2940 |
|
|
2941 |
if (m_pServer && bInteractive) { |
if (m_pServer && bInteractive) { |
2942 |
if (QMessageBox::question(this, |
if (QMessageBox::question(this, |
2943 |
QSAMPLER_TITLE ": " + tr("The backend's fate ..."), |
tr("The backend's fate ..."), |
2944 |
tr("You have the option to keep the sampler backend (LinuxSampler)\n" |
tr("You have the option to keep the sampler backend (LinuxSampler)\n" |
2945 |
"running in the background. The sampler would continue to work\n" |
"running in the background. The sampler would continue to work\n" |
2946 |
"according to your current sampler session and you could alter the\n" |
"according to your current sampler session and you could alter the\n" |
2973 |
|
|
2974 |
// Give it some time to terminate gracefully and stabilize... |
// Give it some time to terminate gracefully and stabilize... |
2975 |
if (bGraceWait) { |
if (bGraceWait) { |
2976 |
QTime t; |
QElapsedTimer timer; |
2977 |
t.start(); |
timer.start(); |
2978 |
while (t.elapsed() < QSAMPLER_TIMER_MSECS) |
while (timer.elapsed() < QSAMPLER_TIMER_MSECS) |
2979 |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
2980 |
} |
} |
2981 |
} |
} |
3005 |
// Force final server shutdown... |
// Force final server shutdown... |
3006 |
m_pServer->kill(); |
m_pServer->kill(); |
3007 |
// Give it some time to terminate gracefully and stabilize... |
// Give it some time to terminate gracefully and stabilize... |
3008 |
QTime t; |
QElapsedTimer timer; |
3009 |
t.start(); |
timer.start(); |
3010 |
while (t.elapsed() < QSAMPLER_TIMER_MSECS) |
while (timer.elapsed() < QSAMPLER_TIMER_MSECS) |
3011 |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
3012 |
} |
} |
3013 |
// Force final server shutdown... |
// Force final server shutdown... |
3045 |
|
|
3046 |
|
|
3047 |
// Start our almighty client... |
// Start our almighty client... |
3048 |
bool MainForm::startClient (void) |
bool MainForm::startClient (bool bReconnectOnly) |
3049 |
{ |
{ |
3050 |
// Have it a setup? |
// Have it a setup? |
3051 |
if (m_pOptions == nullptr) |
if (m_pOptions == nullptr) |
3066 |
// Is this the first try? |
// Is this the first try? |
3067 |
// maybe we need to start a local server... |
// maybe we need to start a local server... |
3068 |
if ((m_pServer && m_pServer->state() == QProcess::Running) |
if ((m_pServer && m_pServer->state() == QProcess::Running) |
3069 |
|| !m_pOptions->bServerStart) { |
|| !m_pOptions->bServerStart || bReconnectOnly) |
3070 |
appendMessagesError( |
{ |
3071 |
tr("Could not connect to server as client.\n\nSorry.")); |
// if this method is called from autoReconnectClient() |
3072 |
|
// then don't bother user with an error message... |
3073 |
|
if (!bReconnectOnly) { |
3074 |
|
appendMessagesError( |
3075 |
|
tr("Could not connect to server as client.\n\nSorry.") |
3076 |
|
); |
3077 |
|
} |
3078 |
} else { |
} else { |
3079 |
startServer(); |
startServer(); |
3080 |
} |
} |
3203 |
} |
} |
3204 |
|
|
3205 |
|
|
3206 |
|
void MainForm::startAutoReconnectClient (void) |
3207 |
|
{ |
3208 |
|
stopClient(); |
3209 |
|
appendMessages(tr("Trying to reconnect...")); |
3210 |
|
QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient())); |
3211 |
|
} |
3212 |
|
|
3213 |
|
|
3214 |
|
void MainForm::autoReconnectClient (void) |
3215 |
|
{ |
3216 |
|
const bool bSuccess = startClient(true); |
3217 |
|
if (!bSuccess) |
3218 |
|
QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient())); |
3219 |
|
} |
3220 |
|
|
3221 |
|
|
3222 |
// Channel strip activation/selection. |
// Channel strip activation/selection. |
3223 |
void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow ) |
void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow ) |
3224 |
{ |
{ |