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 |
966 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
967 |
const QList<QMdiSubWindow *>& wlist |
const QList<QMdiSubWindow *>& wlist |
968 |
= m_pWorkspace->subWindowList(); |
= m_pWorkspace->subWindowList(); |
969 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
970 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
971 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
972 |
if (pChannelStrip) { |
if (pChannelStrip) { |
973 |
Channel *pChannel = pChannelStrip->channel(); |
Channel *pChannel = pChannelStrip->channel(); |
974 |
if (bForce && pChannel) |
if (bForce && pChannel) |
975 |
pChannel->removeChannel(); |
pChannel->removeChannel(); |
976 |
delete pChannelStrip; |
delete pChannelStrip; |
977 |
} |
} |
978 |
if (pMdiSubWindow) |
delete pMdiSubWindow; |
|
delete pMdiSubWindow; |
|
979 |
} |
} |
980 |
m_pWorkspace->setUpdatesEnabled(true); |
m_pWorkspace->setUpdatesEnabled(true); |
981 |
// We're now clean, for sure. |
// We're now clean, for sure. |
1273 |
int iChannelID = 0; |
int iChannelID = 0; |
1274 |
const QList<QMdiSubWindow *>& wlist |
const QList<QMdiSubWindow *>& wlist |
1275 |
= m_pWorkspace->subWindowList(); |
= m_pWorkspace->subWindowList(); |
1276 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
1277 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
1278 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
1279 |
if (pChannelStrip) { |
if (pChannelStrip) { |
1280 |
Channel *pChannel = pChannelStrip->channel(); |
Channel *pChannel = pChannelStrip->channel(); |
1281 |
if (pChannel) { |
if (pChannel) { |
1755 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
1756 |
const QList<QMdiSubWindow *>& wlist |
const QList<QMdiSubWindow *>& wlist |
1757 |
= m_pWorkspace->subWindowList(); |
= m_pWorkspace->subWindowList(); |
1758 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
1759 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
1760 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
1761 |
if (pChannelStrip) |
if (pChannelStrip) |
1762 |
pChannelStrip->channelReset(); |
pChannelStrip->channelReset(); |
1763 |
} |
} |
1960 |
|
|
1961 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
1962 |
int y = 0; |
int y = 0; |
1963 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
1964 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
pMdiSubWindow->adjustSize(); |
1965 |
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
const QRect& frameRect |
1966 |
if (pMdiSubWindow) { |
= pMdiSubWindow->frameGeometry(); |
1967 |
pMdiSubWindow->adjustSize(); |
int w = m_pWorkspace->width(); |
1968 |
int iWidth = m_pWorkspace->width(); |
if (w < frameRect.width()) |
1969 |
if (iWidth < pMdiSubWindow->width()) |
w = frameRect.width(); |
1970 |
iWidth = pMdiSubWindow->width(); |
const int h = frameRect.height(); |
1971 |
const int iHeight = pMdiSubWindow->frameGeometry().height(); |
pMdiSubWindow->setGeometry(0, y, w, h); |
1972 |
pMdiSubWindow->setGeometry(0, y, iWidth, iHeight); |
y += h; |
|
y += iHeight; |
|
|
} |
|
1973 |
} |
} |
1974 |
m_pWorkspace->setUpdatesEnabled(true); |
m_pWorkspace->setUpdatesEnabled(true); |
1975 |
|
|
2279 |
if (bRemoveDeadStrips) { |
if (bRemoveDeadStrips) { |
2280 |
const QList<QMdiSubWindow *>& wlist |
const QList<QMdiSubWindow *>& wlist |
2281 |
= m_pWorkspace->subWindowList(); |
= m_pWorkspace->subWindowList(); |
2282 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2283 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2284 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2285 |
if (pChannelStrip) { |
if (pChannelStrip) { |
2286 |
bool bExists = false; |
bool bExists = false; |
2287 |
for (int iChannel = 0; piChannelIDs[iChannel] >= 0; ++iChannel) { |
for (int iChannel = 0; piChannelIDs[iChannel] >= 0; ++iChannel) { |
2358 |
return; |
return; |
2359 |
|
|
2360 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
2361 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2362 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2363 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2364 |
if (pChannelStrip) |
if (pChannelStrip) |
2365 |
pChannelStrip->updateInstrumentName(true); |
pChannelStrip->updateInstrumentName(true); |
2366 |
} |
} |
2390 |
return; |
return; |
2391 |
|
|
2392 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
2393 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2394 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2395 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2396 |
if (pChannelStrip) |
if (pChannelStrip) |
2397 |
pChannelStrip->setDisplayFont(font); |
pChannelStrip->setDisplayFont(font); |
2398 |
} |
} |
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->setDisplayEffect(m_pOptions->bDisplayEffect); |
pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect); |
2418 |
} |
} |
2440 |
return; |
return; |
2441 |
|
|
2442 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
2443 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2444 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2445 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2446 |
if (pChannelStrip) |
if (pChannelStrip) |
2447 |
pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume); |
pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume); |
2448 |
} |
} |
2590 |
} |
} |
2591 |
|
|
2592 |
// Add it to workspace... |
// Add it to workspace... |
2593 |
m_pWorkspace->addSubWindow(pChannelStrip, |
QMdiSubWindow *pMdiSubWindow |
2594 |
Qt::SubWindow | Qt::FramelessWindowHint); |
= m_pWorkspace->addSubWindow(pChannelStrip, |
2595 |
|
Qt::SubWindow | Qt::FramelessWindowHint); |
2596 |
|
pMdiSubWindow->setAttribute(Qt::WA_DeleteOnClose); |
2597 |
|
|
2598 |
// Actual channel strip setup... |
// Actual channel strip setup... |
2599 |
pChannelStrip->setup(pChannel); |
pChannelStrip->setup(pChannel); |
2669 |
if (wlist.isEmpty()) |
if (wlist.isEmpty()) |
2670 |
return nullptr; |
return nullptr; |
2671 |
|
|
2672 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2673 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2674 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2675 |
if (pChannelStrip) { |
if (pChannelStrip) { |
2676 |
Channel *pChannel = pChannelStrip->channel(); |
Channel *pChannel = pChannelStrip->channel(); |
2677 |
if (pChannel && pChannel->channelID() == iChannelID) |
if (pChannel && pChannel->channelID() == iChannelID) |
2695 |
= m_pWorkspace->subWindowList(); |
= m_pWorkspace->subWindowList(); |
2696 |
if (!wlist.isEmpty()) { |
if (!wlist.isEmpty()) { |
2697 |
m_ui.channelsMenu->addSeparator(); |
m_ui.channelsMenu->addSeparator(); |
2698 |
const int iStripCount = wlist.count(); |
int iStrip = 0; |
2699 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2700 |
ChannelStrip *pChannelStrip = nullptr; |
ChannelStrip *pChannelStrip |
2701 |
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2702 |
if (pChannelStrip) { |
if (pChannelStrip) { |
2703 |
QAction *pAction = m_ui.channelsMenu->addAction( |
QAction *pAction = m_ui.channelsMenu->addAction( |
2704 |
pChannelStrip->windowTitle(), |
pChannelStrip->windowTitle(), |
2707 |
pAction->setChecked(activeChannelStrip() == pChannelStrip); |
pAction->setChecked(activeChannelStrip() == pChannelStrip); |
2708 |
pAction->setData(iStrip); |
pAction->setData(iStrip); |
2709 |
} |
} |
2710 |
|
++iStrip; |
2711 |
} |
} |
2712 |
} |
} |
2713 |
} |
} |
2784 |
// Update the channel stream usage for each strip... |
// Update the channel stream usage for each strip... |
2785 |
const QList<QMdiSubWindow *>& wlist |
const QList<QMdiSubWindow *>& wlist |
2786 |
= m_pWorkspace->subWindowList(); |
= m_pWorkspace->subWindowList(); |
2787 |
const int iStripCount = wlist.count(); |
foreach (QMdiSubWindow *pMdiSubWindow, wlist) { |
2788 |
for (int iStrip = 0; iStrip < iStripCount; ++iStrip) { |
ChannelStrip *pChannelStrip |
2789 |
ChannelStrip *pChannelStrip = nullptr; |
= static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip); |
|
|
if (pMdiSubWindow) |
|
|
pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget()); |
|
2790 |
if (pChannelStrip && pChannelStrip->isVisible()) |
if (pChannelStrip && pChannelStrip->isVisible()) |
2791 |
pChannelStrip->updateChannelUsage(); |
pChannelStrip->updateChannelUsage(); |
2792 |
} |
} |
2793 |
} |
} |
2794 |
} |
} |
2795 |
|
|
2796 |
|
#if CONFIG_LSCP_CLIENT_CONNECTION_LOST |
2797 |
|
// If we lost connection to server: Try to automatically reconnect if we |
2798 |
|
// did not start the server. |
2799 |
|
// |
2800 |
|
// TODO: If we started the server, then we might inform the user that |
2801 |
|
// the server probably crashed and asking user ONCE whether we should |
2802 |
|
// restart the server. |
2803 |
|
if (lscp_client_connection_lost(m_pClient) && !m_pServer) |
2804 |
|
startAutoReconnectClient(); |
2805 |
|
#endif // CONFIG_LSCP_CLIENT_CONNECTION_LOST |
2806 |
} |
} |
2807 |
|
|
2808 |
// Register the next timer slot. |
// Register the next timer slot. |
3001 |
|
|
3002 |
|
|
3003 |
// Start our almighty client... |
// Start our almighty client... |
3004 |
bool MainForm::startClient (void) |
bool MainForm::startClient (bool bReconnectOnly) |
3005 |
{ |
{ |
3006 |
// Have it a setup? |
// Have it a setup? |
3007 |
if (m_pOptions == nullptr) |
if (m_pOptions == nullptr) |
3022 |
// Is this the first try? |
// Is this the first try? |
3023 |
// maybe we need to start a local server... |
// maybe we need to start a local server... |
3024 |
if ((m_pServer && m_pServer->state() == QProcess::Running) |
if ((m_pServer && m_pServer->state() == QProcess::Running) |
3025 |
|| !m_pOptions->bServerStart) { |
|| !m_pOptions->bServerStart || bReconnectOnly) |
3026 |
appendMessagesError( |
{ |
3027 |
tr("Could not connect to server as client.\n\nSorry.")); |
// if this method is called from autoReconnectClient() |
3028 |
|
// then don't bother user with an error message... |
3029 |
|
if (!bReconnectOnly) { |
3030 |
|
appendMessagesError( |
3031 |
|
tr("Could not connect to server as client.\n\nSorry.") |
3032 |
|
); |
3033 |
|
} |
3034 |
} else { |
} else { |
3035 |
startServer(); |
startServer(); |
3036 |
} |
} |
3159 |
} |
} |
3160 |
|
|
3161 |
|
|
3162 |
|
void MainForm::startAutoReconnectClient (void) |
3163 |
|
{ |
3164 |
|
stopClient(); |
3165 |
|
appendMessages(tr("Trying to reconnect...")); |
3166 |
|
QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient())); |
3167 |
|
} |
3168 |
|
|
3169 |
|
|
3170 |
|
void MainForm::autoReconnectClient (void) |
3171 |
|
{ |
3172 |
|
const bool bSuccess = startClient(true); |
3173 |
|
if (!bSuccess) |
3174 |
|
QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient())); |
3175 |
|
} |
3176 |
|
|
3177 |
|
|
3178 |
// Channel strip activation/selection. |
// Channel strip activation/selection. |
3179 |
void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow ) |
void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow ) |
3180 |
{ |
{ |