--- qsampler/trunk/src/qsamplerMainForm.cpp 2010/10/06 18:49:54 2144 +++ qsampler/trunk/src/qsamplerMainForm.cpp 2013/04/10 09:11:37 2441 @@ -1,7 +1,7 @@ // qsamplerMainForm.cpp // /**************************************************************************** - Copyright (C) 2004-2010, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2004-2013, rncbc aka Rui Nuno Capela. All rights reserved. Copyright (C) 2007, 2008 Christian Schoenebeck This program is free software; you can redistribute it and/or @@ -35,8 +35,10 @@ #include "qsamplerOptionsForm.h" #include "qsamplerDeviceStatusForm.h" +#include +#include + #include -#include #include #include @@ -56,6 +58,10 @@ #include #include +#if QT_VERSION >= 0x050000 +#include +#endif + #if QT_VERSION < 0x040500 namespace Qt { const WindowFlags WindowCloseButtonHint = WindowFlags(0x08000000); @@ -221,7 +227,7 @@ // Install SIGUSR1 signal handler. struct sigaction usr1; usr1.sa_handler = qsampler_sigusr1_handler; - ::sigemptyset(&usr1.sa_mask); + sigemptyset(&usr1.sa_mask); usr1.sa_flags = 0; usr1.sa_flags |= SA_RESTART; ::sigaction(SIGUSR1, &usr1, NULL); @@ -269,12 +275,13 @@ #endif // Make it an MDI workspace. - m_pWorkspace = new QWorkspace(this); - m_pWorkspace->setScrollBarsEnabled(true); + m_pWorkspace = new QMdiArea(this); + m_pWorkspace->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + m_pWorkspace->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); // Set the activation connection. QObject::connect(m_pWorkspace, - SIGNAL(windowActivated(QWidget *)), - SLOT(activateStrip(QWidget *))); + SIGNAL(subWindowActivated(QMdiSubWindow *)), + SLOT(activateStrip(QMdiSubWindow *))); // Make it shine :-) setCentralWidget(m_pWorkspace); @@ -890,15 +897,20 @@ if (bClose) { // Remove all channel strips from sight... m_pWorkspace->setUpdatesEnabled(false); - QWidgetList wlist = m_pWorkspace->windowList(); - for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { - ChannelStrip *pChannelStrip = (ChannelStrip*) wlist.at(iChannel); + QList wlist = m_pWorkspace->subWindowList(); + for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) { + ChannelStrip *pChannelStrip = NULL; + QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel); + if (pMdiSubWindow) + pChannelStrip = static_cast (pMdiSubWindow->widget()); if (pChannelStrip) { Channel *pChannel = pChannelStrip->channel(); if (bForce && pChannel) pChannel->removeChannel(); delete pChannelStrip; } + if (pMdiSubWindow) + delete pMdiSubWindow; } m_pWorkspace->setUpdatesEnabled(true); // We're now clean, for sure. @@ -1189,10 +1201,12 @@ #endif // CONFIG_MIDI_INSTRUMENT // Sampler channel mapping. - QWidgetList wlist = m_pWorkspace->windowList(); - for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { - ChannelStrip* pChannelStrip - = static_cast (wlist.at(iChannel)); + QList wlist = m_pWorkspace->subWindowList(); + for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) { + ChannelStrip *pChannelStrip = NULL; + QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel); + if (pMdiSubWindow) + pChannelStrip = static_cast (pMdiSubWindow->widget()); if (pChannelStrip) { Channel *pChannel = pChannelStrip->channel(); if (pChannel) { @@ -1240,13 +1254,13 @@ ts << "SET CHANNEL MUTE " << iChannel << " 1" << endl; if (pChannel->channelSolo()) ts << "SET CHANNEL SOLO " << iChannel << " 1" << endl; -#ifdef CONFIG_MIDI_INSTRUMENT + #ifdef CONFIG_MIDI_INSTRUMENT if (pChannel->midiMap() >= 0) { ts << "SET CHANNEL MIDI_INSTRUMENT_MAP " << iChannel << " " << midiInstrumentMap[pChannel->midiMap()] << endl; } -#endif -#ifdef CONFIG_FXSEND + #endif + #ifdef CONFIG_FXSEND int iChannelID = pChannel->channelID(); int *piFxSends = ::lscp_list_fxsends(m_pClient, iChannelID); for (int iFxSend = 0; @@ -1270,18 +1284,18 @@ << " " << iAudioSrc << " " << piRouting[iAudioSrc] << endl; } -#ifdef CONFIG_FXSEND_LEVEL + #ifdef CONFIG_FXSEND_LEVEL ts << "SET FX_SEND LEVEL " << iChannel << " " << iFxSend << " " << pFxSendInfo->level << endl; -#endif + #endif } // Check for errors... else if (::lscp_client_get_errno(m_pClient)) { appendMessagesClient("lscp_get_fxsend_info"); iErrors++; } } -#endif + #endif ts << endl; } } @@ -1506,7 +1520,7 @@ if (m_pClient == NULL) return; - ChannelStrip* pChannelStrip = activeChannelStrip(); + ChannelStrip *pChannelStrip = activeChannelStrip(); if (pChannelStrip == NULL) return; @@ -1531,16 +1545,11 @@ if (!pChannel->removeChannel()) return; - // Just delete the channel strip. - delete pChannelStrip; - - // Do we auto-arrange? - if (m_pOptions && m_pOptions->bAutoArrange) - channelsArrange(); - // We'll be dirty, for sure... m_iDirtyCount++; - stabilizeForm(); + + // Just delete the channel strip. + destroyChannelStrip(pChannelStrip); } @@ -1550,7 +1559,7 @@ if (m_pClient == NULL) return; - ChannelStrip* pChannelStrip = activeChannelStrip(); + ChannelStrip *pChannelStrip = activeChannelStrip(); if (pChannelStrip == NULL) return; @@ -1565,7 +1574,7 @@ if (m_pClient == NULL) return; - ChannelStrip* pChannelStrip = activeChannelStrip(); + ChannelStrip *pChannelStrip = activeChannelStrip(); if (pChannelStrip == NULL) return; @@ -1580,7 +1589,7 @@ if (m_pClient == NULL) return; - ChannelStrip* pChannelStrip = activeChannelStrip(); + ChannelStrip *pChannelStrip = activeChannelStrip(); if (pChannelStrip == NULL) return; @@ -1598,9 +1607,12 @@ // Invoque the channel strip procedure, // for all channels out there... m_pWorkspace->setUpdatesEnabled(false); - QWidgetList wlist = m_pWorkspace->windowList(); - for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { - ChannelStrip* pChannelStrip = (ChannelStrip*) wlist.at(iChannel); + QList wlist = m_pWorkspace->subWindowList(); + for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) { + ChannelStrip *pChannelStrip = NULL; + QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel); + if (pMdiSubWindow) + pChannelStrip = static_cast (pMdiSubWindow->widget()); if (pChannelStrip) pChannelStrip->channelReset(); } @@ -1703,7 +1715,7 @@ OptionsForm* pOptionsForm = new OptionsForm(this); if (pOptionsForm) { // Check out some initial nullities(tm)... - ChannelStrip* pChannelStrip = activeChannelStrip(); + ChannelStrip *pChannelStrip = activeChannelStrip(); if (m_pOptions->sDisplayFont.isEmpty() && pChannelStrip) m_pOptions->sDisplayFont = pChannelStrip->displayFont().toString(); if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages) @@ -1796,28 +1808,33 @@ void MainForm::channelsArrange (void) { // Full width vertical tiling - QWidgetList wlist = m_pWorkspace->windowList(); + QList wlist = m_pWorkspace->subWindowList(); if (wlist.isEmpty()) return; m_pWorkspace->setUpdatesEnabled(false); int y = 0; - for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { - ChannelStrip* pChannelStrip = (ChannelStrip*) wlist.at(iChannel); - /* if (pChannelStrip->testWState(WState_Maximized | WState_Minimized)) { - // Prevent flicker... - pChannelStrip->hide(); - pChannelStrip->showNormal(); - } */ - pChannelStrip->adjustSize(); - int iWidth = m_pWorkspace->width(); - if (iWidth < pChannelStrip->width()) - iWidth = pChannelStrip->width(); - // int iHeight = pChannelStrip->height() - // + pChannelStrip->parentWidget()->baseSize().height(); - int iHeight = pChannelStrip->parentWidget()->frameGeometry().height(); - pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight); - y += iHeight; + for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) { + ChannelStrip *pChannelStrip = NULL; + QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel); + if (pMdiSubWindow) + pChannelStrip = static_cast (pMdiSubWindow->widget()); + if (pChannelStrip) { + /* if (pChannelStrip->testWState(WState_Maximized | WState_Minimized)) { + // Prevent flicker... + pChannelStrip->hide(); + pChannelStrip->showNormal(); + } */ + pChannelStrip->adjustSize(); + int iWidth = m_pWorkspace->width(); + if (iWidth < pChannelStrip->width()) + iWidth = pChannelStrip->width(); + // int iHeight = pChannelStrip->height() + // + pChannelStrip->parentWidget()->baseSize().height(); + int iHeight = pChannelStrip->parentWidget()->frameGeometry().height(); + pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight); + y += iHeight; + } } m_pWorkspace->setUpdatesEnabled(true); @@ -1962,7 +1979,7 @@ ChannelStrip *pChannelStrip = activeChannelStrip(); bool bHasClient = (m_pOptions != NULL && m_pClient != NULL); bool bHasChannel = (bHasClient && pChannelStrip != NULL); - bool bHasChannels = (bHasClient && m_pWorkspace->windowList().count() > 0); + bool bHasChannels = (bHasClient && m_pWorkspace->subWindowList().count() > 0); m_ui.fileNewAction->setEnabled(bHasClient); m_ui.fileOpenAction->setEnabled(bHasClient); m_ui.fileSaveAction->setEnabled(bHasClient && m_iDirtyCount > 0); @@ -2058,7 +2075,7 @@ // Channel change receiver slot. -void MainForm::channelStripChanged(ChannelStrip* pChannelStrip) +void MainForm::channelStripChanged ( ChannelStrip *pChannelStrip ) { // Add this strip to the changed list... if (!m_changedStrips.contains(pChannelStrip)) { @@ -2109,7 +2126,9 @@ m_pDeviceForm->refreshDevices(); } -void MainForm::updateAllChannelStrips(bool bRemoveDeadStrips) { + +void MainForm::updateAllChannelStrips ( bool bRemoveDeadStrips ) +{ // Retrieve the current channel list. int *piChannelIDs = ::lscp_list_channels(m_pClient); if (piChannelIDs == NULL) { @@ -2121,38 +2140,45 @@ } else { // Try to (re)create each channel. m_pWorkspace->setUpdatesEnabled(false); - for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) { + for (int iChannel = 0; piChannelIDs[iChannel] >= 0; ++iChannel) { // Check if theres already a channel strip for this one... if (!channelStrip(piChannelIDs[iChannel])) createChannelStrip(new Channel(piChannelIDs[iChannel])); } - // Do we auto-arrange? if (m_pOptions && m_pOptions->bAutoArrange) channelsArrange(); - - stabilizeForm(); - // remove dead channel strips if (bRemoveDeadStrips) { - for (int i = 0; channelStripAt(i); ++i) { - ChannelStrip* pChannelStrip = channelStripAt(i); - bool bExists = false; - for (int j = 0; piChannelIDs[j] >= 0; ++j) { - if (!pChannelStrip->channel()) break; - if (piChannelIDs[j] == pChannelStrip->channel()->channelID()) { - // strip exists, don't touch it - bExists = true; - break; + QList wlist = m_pWorkspace->subWindowList(); + for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) { + ChannelStrip *pChannelStrip = NULL; + QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel); + if (pMdiSubWindow) + pChannelStrip = static_cast (pMdiSubWindow->widget()); + if (pChannelStrip) { + bool bExists = false; + for (int j = 0; piChannelIDs[j] >= 0; ++j) { + if (!pChannelStrip->channel()) + break; + if (piChannelIDs[j] == pChannelStrip->channel()->channelID()) { + // strip exists, don't touch it + bExists = true; + break; + } } + if (!bExists) + destroyChannelStrip(pChannelStrip); } - if (!bExists) destroyChannelStrip(pChannelStrip); } } m_pWorkspace->setUpdatesEnabled(true); } + + stabilizeForm(); } + // Update the recent files list and menu. void MainForm::updateRecentFiles ( const QString& sFilename ) { @@ -2199,12 +2225,12 @@ void MainForm::updateInstrumentNames (void) { // Full channel list update... - QWidgetList wlist = m_pWorkspace->windowList(); + QList wlist = m_pWorkspace->subWindowList(); if (wlist.isEmpty()) return; m_pWorkspace->setUpdatesEnabled(false); - for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { + for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) { ChannelStrip *pChannelStrip = (ChannelStrip *) wlist.at(iChannel); if (pChannelStrip) pChannelStrip->updateInstrumentName(true); @@ -2228,13 +2254,16 @@ return; // Full channel list update... - QWidgetList wlist = m_pWorkspace->windowList(); + QList wlist = m_pWorkspace->subWindowList(); if (wlist.isEmpty()) return; m_pWorkspace->setUpdatesEnabled(false); - for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { - ChannelStrip* pChannelStrip = (ChannelStrip*) wlist.at(iChannel); + for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) { + ChannelStrip *pChannelStrip = NULL; + QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel); + if (pMdiSubWindow) + pChannelStrip = static_cast (pMdiSubWindow->widget()); if (pChannelStrip) pChannelStrip->setDisplayFont(font); } @@ -2246,13 +2275,16 @@ void MainForm::updateDisplayEffect (void) { // Full channel list update... - QWidgetList wlist = m_pWorkspace->windowList(); + QList wlist = m_pWorkspace->subWindowList(); if (wlist.isEmpty()) return; m_pWorkspace->setUpdatesEnabled(false); - for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { - ChannelStrip* pChannelStrip = (ChannelStrip*) wlist.at(iChannel); + for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) { + ChannelStrip *pChannelStrip = NULL; + QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel); + if (pMdiSubWindow) + pChannelStrip = static_cast (pMdiSubWindow->widget()); if (pChannelStrip) pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect); } @@ -2274,13 +2306,16 @@ #endif // Full channel list update... - QWidgetList wlist = m_pWorkspace->windowList(); + QList wlist = m_pWorkspace->subWindowList(); if (wlist.isEmpty()) return; m_pWorkspace->setUpdatesEnabled(false); - for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { - ChannelStrip* pChannelStrip = (ChannelStrip*) wlist.at(iChannel); + for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) { + ChannelStrip *pChannelStrip = NULL; + QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel); + if (pMdiSubWindow) + pChannelStrip = static_cast (pMdiSubWindow->widget()); if (pChannelStrip) pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume); } @@ -2388,7 +2423,7 @@ // qsamplerMainForm -- MDI channel strip management. // The channel strip creation executive. -ChannelStrip* MainForm::createChannelStrip ( Channel *pChannel ) +ChannelStrip *MainForm::createChannelStrip ( Channel *pChannel ) { if (m_pClient == NULL || pChannel == NULL) return NULL; @@ -2411,14 +2446,15 @@ } // Add it to workspace... - m_pWorkspace->addWindow(pChannelStrip, Qt::FramelessWindowHint); + m_pWorkspace->addSubWindow(pChannelStrip, + Qt::SubWindow | Qt::FramelessWindowHint); // Actual channel strip setup... pChannelStrip->setup(pChannel); QObject::connect(pChannelStrip, - SIGNAL(channelChanged(ChannelStrip*)), - SLOT(channelStripChanged(ChannelStrip*))); + SIGNAL(channelChanged(ChannelStrip *)), + SLOT(channelStripChanged(ChannelStrip *))); // Now we show up us to the world. pChannelStrip->show(); @@ -2430,9 +2466,17 @@ return pChannelStrip; } -void MainForm::destroyChannelStrip(ChannelStrip* pChannelStrip) { + +void MainForm::destroyChannelStrip ( ChannelStrip *pChannelStrip ) +{ + QMdiSubWindow *pMdiSubWindow + = static_cast (pChannelStrip->parentWidget()); + if (pMdiSubWindow == NULL) + return; + // Just delete the channel strip. delete pChannelStrip; + delete pMdiSubWindow; // Do we auto-arrange? if (m_pOptions && m_pOptions->bAutoArrange) @@ -2441,39 +2485,50 @@ stabilizeForm(); } + // Retrieve the active channel strip. -ChannelStrip* MainForm::activeChannelStrip (void) +ChannelStrip *MainForm::activeChannelStrip (void) { - return static_cast (m_pWorkspace->activeWindow()); + QMdiSubWindow *pMdiSubWindow = m_pWorkspace->activeSubWindow(); + if (pMdiSubWindow) + return static_cast (pMdiSubWindow->widget()); + else + return NULL; } // Retrieve a channel strip by index. -ChannelStrip* MainForm::channelStripAt ( int iChannel ) +ChannelStrip *MainForm::channelStripAt ( int iChannel ) { if (!m_pWorkspace) return NULL; - QWidgetList wlist = m_pWorkspace->windowList(); + QList wlist = m_pWorkspace->subWindowList(); if (wlist.isEmpty()) return NULL; if (iChannel < 0 || iChannel >= wlist.size()) return NULL; - return dynamic_cast (wlist.at(iChannel)); + QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel); + if (pMdiSubWindow) + return static_cast (pMdiSubWindow->widget()); + else + return NULL; } // Retrieve a channel strip by sampler channel id. -ChannelStrip* MainForm::channelStrip ( int iChannelID ) +ChannelStrip *MainForm::channelStrip ( int iChannelID ) { - QWidgetList wlist = m_pWorkspace->windowList(); + QList wlist = m_pWorkspace->subWindowList(); if (wlist.isEmpty()) return NULL; - for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { - ChannelStrip* pChannelStrip - = static_cast (wlist.at(iChannel)); + for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) { + ChannelStrip *pChannelStrip = NULL; + QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel); + if (pMdiSubWindow) + pChannelStrip = static_cast (pMdiSubWindow->widget()); if (pChannelStrip) { Channel *pChannel = pChannelStrip->channel(); if (pChannel && pChannel->channelID() == iChannelID) @@ -2493,12 +2548,14 @@ m_ui.channelsMenu->addAction(m_ui.channelsArrangeAction); m_ui.channelsMenu->addAction(m_ui.channelsAutoArrangeAction); - QWidgetList wlist = m_pWorkspace->windowList(); + QList wlist = m_pWorkspace->subWindowList(); if (!wlist.isEmpty()) { m_ui.channelsMenu->addSeparator(); - for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { - ChannelStrip* pChannelStrip - = static_cast (wlist.at(iChannel)); + for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) { + ChannelStrip *pChannelStrip = NULL; + QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel); + if (pMdiSubWindow) + pChannelStrip = static_cast (pMdiSubWindow->widget()); if (pChannelStrip) { QAction *pAction = m_ui.channelsMenu->addAction( pChannelStrip->windowTitle(), @@ -2520,7 +2577,7 @@ if (pAction == NULL) return; - ChannelStrip* pChannelStrip = channelStripAt(pAction->data().toInt()); + ChannelStrip *pChannelStrip = channelStripAt(pAction->data().toInt()); if (pChannelStrip) { pChannelStrip->showNormal(); pChannelStrip->setFocus(); @@ -2581,11 +2638,12 @@ if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime) { m_iTimerSlot = 0; // Update the channel stream usage for each strip... - QWidgetList wlist = m_pWorkspace->windowList(); - for (int iChannel = 0; - iChannel < (int) wlist.count(); iChannel++) { - ChannelStrip* pChannelStrip - = (ChannelStrip*) wlist.at(iChannel); + QList wlist = m_pWorkspace->subWindowList(); + for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) { + ChannelStrip *pChannelStrip = NULL; + QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel); + if (pMdiSubWindow) + pChannelStrip = static_cast (pMdiSubWindow->widget()); if (pChannelStrip && pChannelStrip->isVisible()) pChannelStrip->updateChannelUsage(); } @@ -2637,9 +2695,9 @@ // Setup stdout/stderr capture... // if (m_pOptions->bStdoutCapture) { -#if QT_VERSION >= 0x040200 + #if QT_VERSION >= 0x040200 m_pServer->setProcessChannelMode(QProcess::ForwardedChannels); -#endif + #endif QObject::connect(m_pServer, SIGNAL(readyReadStandardOutput()), SLOT(readServerStdout())); @@ -2704,13 +2762,13 @@ if (m_pServer && bForceServerStop) { appendMessages(tr("Server is stopping...")); if (m_pServer->state() == QProcess::Running) { -#if defined(WIN32) + #if defined(WIN32) // Try harder... m_pServer->kill(); -#else + #else // Try softly... m_pServer->terminate(); -#endif + #endif } } // Do final processing anyway. else processServerExit(); @@ -2939,10 +2997,11 @@ // Channel strip activation/selection. -void MainForm::activateStrip ( QWidget *pWidget ) +void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow ) { - ChannelStrip *pChannelStrip - = static_cast (pWidget); + ChannelStrip *pChannelStrip = NULL; + if (pMdiSubWindow) + pChannelStrip = static_cast (pMdiSubWindow->widget()); if (pChannelStrip) pChannelStrip->setSelected(true);