108 |
m_pMessages = NULL; |
m_pMessages = NULL; |
109 |
|
|
110 |
// We'll start clean. |
// We'll start clean. |
111 |
m_iUntitled = 0; |
m_iUntitled = 0; |
112 |
m_iDirtyCount = 0; |
m_iDirtyCount = 0; |
|
m_iChangeCount = 0; |
|
113 |
|
|
114 |
m_pServer = NULL; |
m_pServer = NULL; |
115 |
m_pClient = NULL; |
m_pClient = NULL; |
173 |
{ |
{ |
174 |
// Do final processing anyway. |
// Do final processing anyway. |
175 |
processServerExit(); |
processServerExit(); |
176 |
|
|
177 |
// Delete recentfiles menu. |
#if defined(WIN32) |
178 |
if (m_pRecentFilesMenu) |
WSACleanup(); |
179 |
delete m_pRecentFilesMenu; |
#endif |
180 |
|
|
181 |
|
// Finally drop any widgets around... |
182 |
|
if (m_pMessages) |
183 |
|
delete m_pMessages; |
184 |
|
if (m_pWorkspace) |
185 |
|
delete m_pWorkspace; |
186 |
|
|
187 |
// Delete status item labels one by one. |
// Delete status item labels one by one. |
188 |
if (m_status[QSAMPLER_STATUS_CLIENT]) |
if (m_status[QSAMPLER_STATUS_CLIENT]) |
189 |
delete m_status[QSAMPLER_STATUS_CLIENT]; |
delete m_status[QSAMPLER_STATUS_CLIENT]; |
194 |
if (m_status[QSAMPLER_STATUS_SESSION]) |
if (m_status[QSAMPLER_STATUS_SESSION]) |
195 |
delete m_status[QSAMPLER_STATUS_SESSION]; |
delete m_status[QSAMPLER_STATUS_SESSION]; |
196 |
|
|
197 |
// Finally drop any widgets around... |
// Delete recentfiles menu. |
198 |
if (m_pMessages) |
if (m_pRecentFilesMenu) |
199 |
delete m_pMessages; |
delete m_pRecentFilesMenu; |
|
if (m_pWorkspace) |
|
|
delete m_pWorkspace; |
|
|
|
|
|
#if defined(WIN32) |
|
|
WSACleanup(); |
|
|
#endif |
|
200 |
} |
} |
201 |
|
|
202 |
|
|
306 |
if (bDecode) { |
if (bDecode) { |
307 |
files = QStringList::split('\n', sText); |
files = QStringList::split('\n', sText); |
308 |
for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) |
for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) |
309 |
*iter = (*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null); |
*iter = QUrl((*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null)).path(); |
310 |
} |
} |
311 |
} |
} |
312 |
|
|
317 |
// Window drag-n-drop event handlers. |
// Window drag-n-drop event handlers. |
318 |
void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) |
void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) |
319 |
{ |
{ |
320 |
QStringList files; |
QStringList files; |
321 |
|
pDragEnterEvent->accept(decodeDragFiles(pDragEnterEvent, files)); |
|
pDragEnterEvent->accept(decodeDragFiles(pDragEnterEvent, files)); |
|
322 |
} |
} |
323 |
|
|
324 |
|
|
330 |
return; |
return; |
331 |
|
|
332 |
for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) { |
for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) { |
333 |
const QString& sPath = QUrl(*iter).path(); |
const QString& sPath = *iter; |
334 |
if (qsamplerChannel::isInstrumentFile(sPath)) { |
if (qsamplerChannel::isInstrumentFile(sPath)) { |
335 |
// Try to create a new channel from instrument file... |
// Try to create a new channel from instrument file... |
336 |
qsamplerChannel *pChannel = new qsamplerChannel(this); |
qsamplerChannel *pChannel = new qsamplerChannel(this); |
351 |
} |
} |
352 |
// Make that an overall update. |
// Make that an overall update. |
353 |
m_iDirtyCount++; |
m_iDirtyCount++; |
|
m_iChangeCount++; |
|
354 |
stabilizeForm(); |
stabilizeForm(); |
355 |
} // Otherwise, load an usual session file (LSCP script)... |
} // Otherwise, load an usual session file (LSCP script)... |
356 |
else if (closeSession(true)) |
else if (closeSession(true)) |
422 |
if (!closeSession(true)) |
if (!closeSession(true)) |
423 |
return false; |
return false; |
424 |
|
|
425 |
|
// Give us what the server has, right now... |
426 |
|
updateSession(); |
427 |
|
|
428 |
// Ok increment untitled count. |
// Ok increment untitled count. |
429 |
m_iUntitled++; |
m_iUntitled++; |
430 |
|
|
597 |
if (iErrors > 0) |
if (iErrors > 0) |
598 |
appendMessagesError(tr("Session could not be loaded\nfrom \"%1\".\n\nSorry.").arg(sFilename)); |
appendMessagesError(tr("Session could not be loaded\nfrom \"%1\".\n\nSorry.").arg(sFilename)); |
599 |
|
|
600 |
// Now we'll try to create the whole GUI session. |
// Now we'll try to create (update) the whole GUI session. |
601 |
int *piChannelIDs = ::lscp_list_channels(m_pClient); |
updateSession(); |
|
if (piChannelIDs == NULL) { |
|
|
appendMessagesClient("lscp_list_channels"); |
|
|
appendMessagesError(tr("Could not get current list of channels.\n\nSorry.")); |
|
|
} else { |
|
|
// Try to (re)create each channel. |
|
|
m_pWorkspace->setUpdatesEnabled(false); |
|
|
for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) { |
|
|
createChannelStrip(new qsamplerChannel(this, piChannelIDs[iChannel])); |
|
|
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
|
|
} |
|
|
m_pWorkspace->setUpdatesEnabled(true); |
|
|
} |
|
602 |
|
|
603 |
// Save as default session directory. |
// Save as default session directory. |
604 |
if (m_pOptions) |
if (m_pOptions) |
611 |
appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename))); |
appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename))); |
612 |
|
|
613 |
// Make that an overall update. |
// Make that an overall update. |
|
m_iChangeCount++; |
|
614 |
stabilizeForm(); |
stabilizeForm(); |
615 |
return true; |
return true; |
616 |
} |
} |
648 |
if (pChannelStrip) { |
if (pChannelStrip) { |
649 |
qsamplerChannel *pChannel = pChannelStrip->channel(); |
qsamplerChannel *pChannel = pChannelStrip->channel(); |
650 |
if (pChannel) { |
if (pChannel) { |
651 |
int iChannelID = pChannel->channelID(); |
ts << "# Channel " << iChannel << endl; |
|
ts << "# " << pChannelStrip->caption() << endl; |
|
652 |
ts << "ADD CHANNEL" << endl; |
ts << "ADD CHANNEL" << endl; |
653 |
ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannelID << " " << pChannel->audioDriver() << endl; |
ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannel << " " << pChannel->audioDriver() << endl; |
654 |
ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannelID << " " << pChannel->midiDriver() << endl; |
ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannel << " " << pChannel->midiDriver() << endl; |
655 |
ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannelID << " " << pChannel->midiPort() << endl; |
// ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannel << " " << pChannel->midiPort() << endl; |
656 |
ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannelID << " "; |
ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannel << " "; |
657 |
if (pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) |
if (pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) |
658 |
ts << "ALL"; |
ts << "ALL"; |
659 |
else |
else |
660 |
ts << pChannel->midiChannel(); |
ts << pChannel->midiChannel(); |
661 |
ts << endl; |
ts << endl; |
662 |
ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannelID << endl; |
ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannel << endl; |
663 |
ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' " << pChannel->instrumentNr() << " " << iChannelID << endl; |
ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' " << pChannel->instrumentNr() << " " << iChannel << endl; |
664 |
ts << "SET CHANNEL VOLUME " << iChannelID << " " << pChannel->volume() << endl; |
ts << "SET CHANNEL VOLUME " << iChannel << " " << pChannel->volume() << endl; |
665 |
ts << endl; |
ts << endl; |
666 |
} |
} |
667 |
} |
} |
761 |
|
|
762 |
// Log this. |
// Log this. |
763 |
appendMessages(tr("Sampler reset.")); |
appendMessages(tr("Sampler reset.")); |
764 |
|
|
765 |
|
// Make it a new session... |
766 |
|
newSession(); |
767 |
} |
} |
768 |
|
|
769 |
|
|
834 |
|
|
835 |
// Make that an overall update. |
// Make that an overall update. |
836 |
m_iDirtyCount++; |
m_iDirtyCount++; |
|
m_iChangeCount++; |
|
837 |
stabilizeForm(); |
stabilizeForm(); |
838 |
} |
} |
839 |
|
|
905 |
if (pChannelStrip == NULL) |
if (pChannelStrip == NULL) |
906 |
return; |
return; |
907 |
|
|
908 |
qsamplerChannel *pChannel = pChannelStrip->channel(); |
// Just invoque the channel strip procedure. |
909 |
if (pChannel == NULL) |
pChannelStrip->channelReset(); |
910 |
return; |
} |
911 |
|
|
|
// Reset the existing sampler channel. |
|
|
pChannel->resetChannel(); |
|
912 |
|
|
913 |
// And force a deferred update. |
// Reset all sampler channels. |
914 |
m_iChangeCount++; |
void qsamplerMainForm::editResetAllChannels (void) |
915 |
|
{ |
916 |
|
if (m_pClient == NULL) |
917 |
|
return; |
918 |
|
|
919 |
|
// Invoque the channel strip procedure, |
920 |
|
// for all channels out there... |
921 |
|
m_pWorkspace->setUpdatesEnabled(false); |
922 |
|
QWidgetList wlist = m_pWorkspace->windowList(); |
923 |
|
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
924 |
|
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
925 |
|
if (pChannelStrip) |
926 |
|
pChannelStrip->channelReset(); |
927 |
|
} |
928 |
|
m_pWorkspace->setUpdatesEnabled(true); |
929 |
} |
} |
930 |
|
|
931 |
|
|
1169 |
void qsamplerMainForm::stabilizeForm (void) |
void qsamplerMainForm::stabilizeForm (void) |
1170 |
{ |
{ |
1171 |
// Update the main application caption... |
// Update the main application caption... |
1172 |
QString sSessioName = sessionName(m_sFilename); |
QString sSessionName = sessionName(m_sFilename); |
1173 |
if (m_iDirtyCount > 0) |
if (m_iDirtyCount > 0) |
1174 |
sSessioName += '*'; |
sSessionName += '*'; |
1175 |
setCaption(tr(QSAMPLER_TITLE " - [%1]").arg(sSessioName)); |
setCaption(tr(QSAMPLER_TITLE " - [%1]").arg(sSessionName)); |
1176 |
|
|
1177 |
// Update the main menu state... |
// Update the main menu state... |
1178 |
qsamplerChannelStrip *pChannelStrip = activeChannelStrip(); |
qsamplerChannelStrip *pChannelStrip = activeChannelStrip(); |
1188 |
editRemoveChannelAction->setEnabled(bHasChannel); |
editRemoveChannelAction->setEnabled(bHasChannel); |
1189 |
editSetupChannelAction->setEnabled(bHasChannel); |
editSetupChannelAction->setEnabled(bHasChannel); |
1190 |
editResetChannelAction->setEnabled(bHasChannel); |
editResetChannelAction->setEnabled(bHasChannel); |
1191 |
|
editResetAllChannelsAction->setEnabled(bHasChannel); |
1192 |
channelsArrangeAction->setEnabled(bHasChannel); |
channelsArrangeAction->setEnabled(bHasChannel); |
1193 |
viewMessagesAction->setOn(m_pMessages && m_pMessages->isVisible()); |
viewMessagesAction->setOn(m_pMessages && m_pMessages->isVisible()); |
1194 |
|
|
1221 |
|
|
1222 |
|
|
1223 |
// Channel change receiver slot. |
// Channel change receiver slot. |
1224 |
void qsamplerMainForm::channelStripChanged( qsamplerChannelStrip * ) |
void qsamplerMainForm::channelStripChanged( qsamplerChannelStrip *pChannelStrip ) |
1225 |
{ |
{ |
1226 |
// Flag that we're update those channel strips. |
// Add this strip to the changed list... |
1227 |
m_iChangeCount++; |
if (m_changedStrips.containsRef(pChannelStrip) == 0) |
1228 |
|
m_changedStrips.append(pChannelStrip); |
1229 |
|
|
1230 |
// Just mark the dirty form. |
// Just mark the dirty form. |
1231 |
m_iDirtyCount++; |
m_iDirtyCount++; |
1232 |
// and update the form status... |
// and update the form status... |
1234 |
} |
} |
1235 |
|
|
1236 |
|
|
1237 |
|
// Grab and restore current sampler channels session. |
1238 |
|
void qsamplerMainForm::updateSession (void) |
1239 |
|
{ |
1240 |
|
// Retrieve the current channel list. |
1241 |
|
int *piChannelIDs = ::lscp_list_channels(m_pClient); |
1242 |
|
if (piChannelIDs == NULL) { |
1243 |
|
if (::lscp_client_get_errno(m_pClient)) { |
1244 |
|
appendMessagesClient("lscp_list_channels"); |
1245 |
|
appendMessagesError(tr("Could not get current list of channels.\n\nSorry.")); |
1246 |
|
} |
1247 |
|
return; |
1248 |
|
} |
1249 |
|
|
1250 |
|
// Try to (re)create each channel. |
1251 |
|
m_pWorkspace->setUpdatesEnabled(false); |
1252 |
|
for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) { |
1253 |
|
// Check if theres already a channel strip for this one... |
1254 |
|
if (!channelStrip(piChannelIDs[iChannel])) |
1255 |
|
createChannelStrip(new qsamplerChannel(this, piChannelIDs[iChannel])); |
1256 |
|
// Make it visibly responsive... |
1257 |
|
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
1258 |
|
} |
1259 |
|
m_pWorkspace->setUpdatesEnabled(true); |
1260 |
|
} |
1261 |
|
|
1262 |
|
|
1263 |
// Update the recent files list and menu. |
// Update the recent files list and menu. |
1264 |
void qsamplerMainForm::updateRecentFiles ( const QString& sFilename ) |
void qsamplerMainForm::updateRecentFiles ( const QString& sFilename ) |
1265 |
{ |
{ |
1499 |
QWidgetList wlist = m_pWorkspace->windowList(); |
QWidgetList wlist = m_pWorkspace->windowList(); |
1500 |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
1501 |
pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
1502 |
// y += pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height(); |
if (pChannelStrip) { |
1503 |
y += pChannelStrip->parentWidget()->frameGeometry().height(); |
// y += pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height(); |
1504 |
|
y += pChannelStrip->parentWidget()->frameGeometry().height(); |
1505 |
|
} |
1506 |
} |
} |
1507 |
} |
} |
1508 |
|
|
1536 |
int iHeight = pChannelStrip->parentWidget()->frameGeometry().height(); |
int iHeight = pChannelStrip->parentWidget()->frameGeometry().height(); |
1537 |
pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight); |
pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight); |
1538 |
} |
} |
1539 |
|
|
1540 |
|
// This is pretty new, so we'll watch for it closely. |
1541 |
|
channelStripChanged(pChannelStrip); |
1542 |
|
|
1543 |
// Return our successful reference... |
// Return our successful reference... |
1544 |
return pChannelStrip; |
return pChannelStrip; |
1545 |
} |
} |
1557 |
{ |
{ |
1558 |
QWidgetList wlist = m_pWorkspace->windowList(); |
QWidgetList wlist = m_pWorkspace->windowList(); |
1559 |
if (wlist.isEmpty()) |
if (wlist.isEmpty()) |
1560 |
return 0; |
return NULL; |
1561 |
|
|
1562 |
return (qsamplerChannelStrip *) wlist.at(iChannel); |
return (qsamplerChannelStrip *) wlist.at(iChannel); |
1563 |
} |
} |
1564 |
|
|
1565 |
|
|
1566 |
|
// Retrieve a channel strip by sampler channel id. |
1567 |
|
qsamplerChannelStrip *qsamplerMainForm::channelStrip ( int iChannelID ) |
1568 |
|
{ |
1569 |
|
QWidgetList wlist = m_pWorkspace->windowList(); |
1570 |
|
if (wlist.isEmpty()) |
1571 |
|
return NULL; |
1572 |
|
|
1573 |
|
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
1574 |
|
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
1575 |
|
if (pChannelStrip) { |
1576 |
|
qsamplerChannel *pChannel = pChannelStrip->channel(); |
1577 |
|
if (pChannel && pChannel->channelID() == iChannelID) |
1578 |
|
return pChannelStrip; |
1579 |
|
} |
1580 |
|
} |
1581 |
|
|
1582 |
|
// Not found. |
1583 |
|
return NULL; |
1584 |
|
} |
1585 |
|
|
1586 |
|
|
1587 |
// Construct the windows menu. |
// Construct the windows menu. |
1588 |
void qsamplerMainForm::channelsMenuAboutToShow (void) |
void qsamplerMainForm::channelsMenuAboutToShow (void) |
1589 |
{ |
{ |
1652 |
} |
} |
1653 |
|
|
1654 |
// Refresh each channel usage, on each period... |
// Refresh each channel usage, on each period... |
1655 |
if (m_pClient && (m_iChangeCount > 0 || m_pOptions->bAutoRefresh)) { |
if (m_pClient && (m_changedStrips.count() > 0 || m_pOptions->bAutoRefresh)) { |
1656 |
m_iTimerSlot += QSAMPLER_TIMER_MSECS; |
m_iTimerSlot += QSAMPLER_TIMER_MSECS; |
1657 |
if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime && m_pWorkspace->isUpdatesEnabled()) { |
if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime && m_pWorkspace->isUpdatesEnabled()) { |
1658 |
m_iTimerSlot = 0; |
m_iTimerSlot = 0; |
1659 |
m_iChangeCount = 0; |
// Update the channel information for each pending strip... |
1660 |
|
for (qsamplerChannelStrip *pChannelStrip = m_changedStrips.first(); |
1661 |
|
pChannelStrip; |
1662 |
|
pChannelStrip = m_changedStrips.next()) { |
1663 |
|
// If successfull, remove from pending list... |
1664 |
|
if (pChannelStrip->updateChannelInfo()) |
1665 |
|
m_changedStrips.remove(pChannelStrip); |
1666 |
|
} |
1667 |
|
// Update the channel stream usage for each strip... |
1668 |
QWidgetList wlist = m_pWorkspace->windowList(); |
QWidgetList wlist = m_pWorkspace->windowList(); |
1669 |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
1670 |
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
1671 |
if (pChannelStrip && pChannelStrip->isVisible()) { |
if (pChannelStrip && pChannelStrip->isVisible()) |
1672 |
// If we can't make it clean, try next time. |
pChannelStrip->updateChannelUsage(); |
|
if (!pChannelStrip->updateChannelUsage()) |
|
|
m_iChangeCount++; |
|
|
} |
|
1673 |
} |
} |
1674 |
} |
} |
1675 |
} |
} |