26 |
#include <qprocess.h> |
#include <qprocess.h> |
27 |
#include <qmessagebox.h> |
#include <qmessagebox.h> |
28 |
#include <qdragobject.h> |
#include <qdragobject.h> |
29 |
|
#include <qregexp.h> |
30 |
#include <qfiledialog.h> |
#include <qfiledialog.h> |
31 |
#include <qfileinfo.h> |
#include <qfileinfo.h> |
32 |
#include <qfile.h> |
#include <qfile.h> |
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; |
294 |
} |
} |
295 |
|
|
296 |
|
|
297 |
// Window drag-n-drop event handlers. |
// Drag'n'drop file handler. |
298 |
void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) |
bool qsamplerMainForm::decodeDragFiles ( const QMimeSource *pEvent, QStringList& files ) |
299 |
{ |
{ |
300 |
bool bAccept = false; |
bool bDecode = false; |
301 |
|
|
302 |
if (QTextDrag::canDecode(pDragEnterEvent)) { |
if (QTextDrag::canDecode(pEvent)) { |
303 |
QString sUrl; |
QString sText; |
304 |
if (QTextDrag::decode(pDragEnterEvent, sUrl) && m_pClient) |
bDecode = QTextDrag::decode(pEvent, sText); |
305 |
bAccept = QFileInfo(QUrl(sUrl).path()).exists(); |
if (bDecode) { |
306 |
|
files = QStringList::split('\n', sText); |
307 |
|
for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) |
308 |
|
*iter = QUrl((*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null)).path(); |
309 |
|
} |
310 |
} |
} |
311 |
|
|
312 |
pDragEnterEvent->accept(bAccept); |
return bDecode; |
313 |
|
} |
314 |
|
|
315 |
|
|
316 |
|
// Window drag-n-drop event handlers. |
317 |
|
void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) |
318 |
|
{ |
319 |
|
QStringList files; |
320 |
|
pDragEnterEvent->accept(decodeDragFiles(pDragEnterEvent, files)); |
321 |
} |
} |
322 |
|
|
323 |
|
|
324 |
void qsamplerMainForm::dropEvent ( QDropEvent* pDropEvent ) |
void qsamplerMainForm::dropEvent ( QDropEvent* pDropEvent ) |
325 |
{ |
{ |
326 |
if (QTextDrag::canDecode(pDropEvent)) { |
QStringList files; |
327 |
QString sUrl; |
|
328 |
if (QTextDrag::decode(pDropEvent, sUrl) && closeSession(true)) |
if (!decodeDragFiles(pDropEvent, files)) |
329 |
loadSessionFile(QUrl(sUrl).path()); |
return; |
330 |
} |
|
331 |
|
for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) { |
332 |
|
const QString& sPath = *iter; |
333 |
|
if (qsamplerChannel::isInstrumentFile(sPath)) { |
334 |
|
// Try to create a new channel from instrument file... |
335 |
|
qsamplerChannel *pChannel = new qsamplerChannel(this); |
336 |
|
if (pChannel == NULL) |
337 |
|
return; |
338 |
|
// Start setting the instrument filename... |
339 |
|
pChannel->setInstrument(sPath, 0); |
340 |
|
// Before we show it up, may be we'll |
341 |
|
// better ask for some initial values? |
342 |
|
if (!pChannel->channelSetup(this)) { |
343 |
|
delete pChannel; |
344 |
|
return; |
345 |
|
} |
346 |
|
// Finally, give it to a new channel strip... |
347 |
|
if (!createChannelStrip(pChannel)) { |
348 |
|
delete pChannel; |
349 |
|
return; |
350 |
|
} |
351 |
|
// Make that an overall update. |
352 |
|
m_iDirtyCount++; |
353 |
|
stabilizeForm(); |
354 |
|
} // Otherwise, load an usual session file (LSCP script)... |
355 |
|
else if (closeSession(true)) |
356 |
|
loadSessionFile(sPath); |
357 |
|
// Make it look responsive...:) |
358 |
|
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
359 |
|
} |
360 |
} |
} |
361 |
|
|
362 |
|
|
421 |
if (!closeSession(true)) |
if (!closeSession(true)) |
422 |
return false; |
return false; |
423 |
|
|
424 |
|
// Give us what the server has, right now... |
425 |
|
updateSession(); |
426 |
|
|
427 |
// Ok increment untitled count. |
// Ok increment untitled count. |
428 |
m_iUntitled++; |
m_iUntitled++; |
429 |
|
|
582 |
if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) { |
if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) { |
583 |
appendMessagesClient("lscp_client_query"); |
appendMessagesClient("lscp_client_query"); |
584 |
iErrors++; |
iErrors++; |
585 |
|
break; |
586 |
} |
} |
587 |
} |
} |
588 |
// Try to make it snappy :) |
// Try to make it snappy :) |
594 |
|
|
595 |
// Have we any errors? |
// Have we any errors? |
596 |
if (iErrors > 0) |
if (iErrors > 0) |
597 |
appendMessagesError(tr("Some setttings could not be loaded\nfrom \"%1\" session file.\n\nSorry.").arg(sFilename)); |
appendMessagesError(tr("Session could not be loaded\nfrom \"%1\".\n\nSorry.").arg(sFilename)); |
598 |
|
|
599 |
// Now we'll try to create the whole GUI session. |
// Now we'll try to create (update) the whole GUI session. |
600 |
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); |
|
|
} |
|
601 |
|
|
602 |
// Save as default session directory. |
// Save as default session directory. |
603 |
if (m_pOptions) |
if (m_pOptions) |
610 |
appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename))); |
appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename))); |
611 |
|
|
612 |
// Make that an overall update. |
// Make that an overall update. |
|
m_iChangeCount++; |
|
613 |
stabilizeForm(); |
stabilizeForm(); |
614 |
return true; |
return true; |
615 |
} |
} |
647 |
if (pChannelStrip) { |
if (pChannelStrip) { |
648 |
qsamplerChannel *pChannel = pChannelStrip->channel(); |
qsamplerChannel *pChannel = pChannelStrip->channel(); |
649 |
if (pChannel) { |
if (pChannel) { |
650 |
int iChannelID = pChannel->channelID(); |
ts << "# Channel " << iChannel << endl; |
|
ts << "# " << pChannelStrip->caption() << endl; |
|
651 |
ts << "ADD CHANNEL" << endl; |
ts << "ADD CHANNEL" << endl; |
652 |
ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannelID << " " << pChannel->audioDriver() << endl; |
ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannel << " " << pChannel->audioDriver() << endl; |
653 |
ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannelID << " " << pChannel->midiDriver() << endl; |
ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannel << " " << pChannel->midiDriver() << endl; |
654 |
ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannelID << " " << pChannel->midiPort() << endl; |
// ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannel << " " << pChannel->midiPort() << endl; |
655 |
ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannelID << " "; |
ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannel << " "; |
656 |
if (pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) |
if (pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) |
657 |
ts << "ALL"; |
ts << "ALL"; |
658 |
else |
else |
659 |
ts << pChannel->midiChannel(); |
ts << pChannel->midiChannel(); |
660 |
ts << endl; |
ts << endl; |
661 |
ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannelID << endl; |
ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannel << endl; |
662 |
ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' " << pChannel->instrumentNr() << " " << iChannelID << endl; |
ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' " << pChannel->instrumentNr() << " " << iChannel << endl; |
663 |
ts << "SET CHANNEL VOLUME " << iChannelID << " " << pChannel->volume() << endl; |
ts << "SET CHANNEL VOLUME " << iChannel << " " << pChannel->volume() << endl; |
664 |
ts << endl; |
ts << endl; |
665 |
} |
} |
666 |
} |
} |
760 |
|
|
761 |
// Log this. |
// Log this. |
762 |
appendMessages(tr("Sampler reset.")); |
appendMessages(tr("Sampler reset.")); |
763 |
|
|
764 |
|
// Make it a new session... |
765 |
|
newSession(); |
766 |
} |
} |
767 |
|
|
768 |
|
|
833 |
|
|
834 |
// Make that an overall update. |
// Make that an overall update. |
835 |
m_iDirtyCount++; |
m_iDirtyCount++; |
|
m_iChangeCount++; |
|
836 |
stabilizeForm(); |
stabilizeForm(); |
837 |
} |
} |
838 |
|
|
904 |
if (pChannelStrip == NULL) |
if (pChannelStrip == NULL) |
905 |
return; |
return; |
906 |
|
|
907 |
qsamplerChannel *pChannel = pChannelStrip->channel(); |
// Just invoque the channel strip procedure. |
908 |
if (pChannel == NULL) |
pChannelStrip->channelReset(); |
909 |
return; |
} |
910 |
|
|
|
// Reset the existing sampler channel. |
|
|
pChannel->resetChannel(); |
|
911 |
|
|
912 |
// And force a deferred update. |
// Reset all sampler channels. |
913 |
m_iChangeCount++; |
void qsamplerMainForm::editResetAllChannels (void) |
914 |
|
{ |
915 |
|
if (m_pClient == NULL) |
916 |
|
return; |
917 |
|
|
918 |
|
// Invoque the channel strip procedure, |
919 |
|
// for all channels out there... |
920 |
|
m_pWorkspace->setUpdatesEnabled(false); |
921 |
|
QWidgetList wlist = m_pWorkspace->windowList(); |
922 |
|
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
923 |
|
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
924 |
|
if (pChannelStrip) |
925 |
|
pChannelStrip->channelReset(); |
926 |
|
} |
927 |
|
m_pWorkspace->setUpdatesEnabled(true); |
928 |
} |
} |
929 |
|
|
930 |
|
|
1187 |
editRemoveChannelAction->setEnabled(bHasChannel); |
editRemoveChannelAction->setEnabled(bHasChannel); |
1188 |
editSetupChannelAction->setEnabled(bHasChannel); |
editSetupChannelAction->setEnabled(bHasChannel); |
1189 |
editResetChannelAction->setEnabled(bHasChannel); |
editResetChannelAction->setEnabled(bHasChannel); |
1190 |
|
editResetAllChannelsAction->setEnabled(bHasChannel); |
1191 |
channelsArrangeAction->setEnabled(bHasChannel); |
channelsArrangeAction->setEnabled(bHasChannel); |
1192 |
viewMessagesAction->setOn(m_pMessages && m_pMessages->isVisible()); |
viewMessagesAction->setOn(m_pMessages && m_pMessages->isVisible()); |
1193 |
|
|
1220 |
|
|
1221 |
|
|
1222 |
// Channel change receiver slot. |
// Channel change receiver slot. |
1223 |
void qsamplerMainForm::channelStripChanged( qsamplerChannelStrip * ) |
void qsamplerMainForm::channelStripChanged( qsamplerChannelStrip *pChannelStrip ) |
1224 |
{ |
{ |
1225 |
// Flag that we're update those channel strips. |
// Add this strip to the changed list... |
1226 |
m_iChangeCount++; |
if (m_changedStrips.containsRef(pChannelStrip) == 0) |
1227 |
|
m_changedStrips.append(pChannelStrip); |
1228 |
|
|
1229 |
// Just mark the dirty form. |
// Just mark the dirty form. |
1230 |
m_iDirtyCount++; |
m_iDirtyCount++; |
1231 |
// and update the form status... |
// and update the form status... |
1233 |
} |
} |
1234 |
|
|
1235 |
|
|
1236 |
|
// Grab and restore current sampler channels session. |
1237 |
|
void qsamplerMainForm::updateSession (void) |
1238 |
|
{ |
1239 |
|
// Retrieve the current channel list. |
1240 |
|
int *piChannelIDs = ::lscp_list_channels(m_pClient); |
1241 |
|
if (piChannelIDs == NULL) { |
1242 |
|
if (::lscp_client_get_errno(m_pClient)) { |
1243 |
|
appendMessagesClient("lscp_list_channels"); |
1244 |
|
appendMessagesError(tr("Could not get current list of channels.\n\nSorry.")); |
1245 |
|
} |
1246 |
|
return; |
1247 |
|
} |
1248 |
|
|
1249 |
|
// Try to (re)create each channel. |
1250 |
|
m_pWorkspace->setUpdatesEnabled(false); |
1251 |
|
for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) { |
1252 |
|
// Check if theres already a channel strip for this one... |
1253 |
|
if (!channelStrip(piChannelIDs[iChannel])) |
1254 |
|
createChannelStrip(new qsamplerChannel(this, piChannelIDs[iChannel])); |
1255 |
|
// Make it visibly responsive... |
1256 |
|
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
1257 |
|
} |
1258 |
|
m_pWorkspace->setUpdatesEnabled(true); |
1259 |
|
} |
1260 |
|
|
1261 |
|
|
1262 |
// Update the recent files list and menu. |
// Update the recent files list and menu. |
1263 |
void qsamplerMainForm::updateRecentFiles ( const QString& sFilename ) |
void qsamplerMainForm::updateRecentFiles ( const QString& sFilename ) |
1264 |
{ |
{ |
1498 |
QWidgetList wlist = m_pWorkspace->windowList(); |
QWidgetList wlist = m_pWorkspace->windowList(); |
1499 |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
1500 |
pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
1501 |
// y += pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height(); |
if (pChannelStrip) { |
1502 |
y += pChannelStrip->parentWidget()->frameGeometry().height(); |
// y += pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height(); |
1503 |
|
y += pChannelStrip->parentWidget()->frameGeometry().height(); |
1504 |
|
} |
1505 |
} |
} |
1506 |
} |
} |
1507 |
|
|
1535 |
int iHeight = pChannelStrip->parentWidget()->frameGeometry().height(); |
int iHeight = pChannelStrip->parentWidget()->frameGeometry().height(); |
1536 |
pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight); |
pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight); |
1537 |
} |
} |
1538 |
|
|
1539 |
|
// This is pretty new, so we'll watch for it closely. |
1540 |
|
channelStripChanged(pChannelStrip); |
1541 |
|
|
1542 |
// Return our successful reference... |
// Return our successful reference... |
1543 |
return pChannelStrip; |
return pChannelStrip; |
1544 |
} |
} |
1556 |
{ |
{ |
1557 |
QWidgetList wlist = m_pWorkspace->windowList(); |
QWidgetList wlist = m_pWorkspace->windowList(); |
1558 |
if (wlist.isEmpty()) |
if (wlist.isEmpty()) |
1559 |
return 0; |
return NULL; |
1560 |
|
|
1561 |
return (qsamplerChannelStrip *) wlist.at(iChannel); |
return (qsamplerChannelStrip *) wlist.at(iChannel); |
1562 |
} |
} |
1563 |
|
|
1564 |
|
|
1565 |
|
// Retrieve a channel strip by sampler channel id. |
1566 |
|
qsamplerChannelStrip *qsamplerMainForm::channelStrip ( int iChannelID ) |
1567 |
|
{ |
1568 |
|
QWidgetList wlist = m_pWorkspace->windowList(); |
1569 |
|
if (wlist.isEmpty()) |
1570 |
|
return NULL; |
1571 |
|
|
1572 |
|
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
1573 |
|
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
1574 |
|
if (pChannelStrip) { |
1575 |
|
qsamplerChannel *pChannel = pChannelStrip->channel(); |
1576 |
|
if (pChannel && pChannel->channelID() == iChannelID) |
1577 |
|
return pChannelStrip; |
1578 |
|
} |
1579 |
|
} |
1580 |
|
|
1581 |
|
// Not found. |
1582 |
|
return NULL; |
1583 |
|
} |
1584 |
|
|
1585 |
|
|
1586 |
// Construct the windows menu. |
// Construct the windows menu. |
1587 |
void qsamplerMainForm::channelsMenuAboutToShow (void) |
void qsamplerMainForm::channelsMenuAboutToShow (void) |
1588 |
{ |
{ |
1651 |
} |
} |
1652 |
|
|
1653 |
// Refresh each channel usage, on each period... |
// Refresh each channel usage, on each period... |
1654 |
if (m_pClient && (m_iChangeCount > 0 || m_pOptions->bAutoRefresh)) { |
if (m_pClient && (m_changedStrips.count() > 0 || m_pOptions->bAutoRefresh)) { |
1655 |
m_iTimerSlot += QSAMPLER_TIMER_MSECS; |
m_iTimerSlot += QSAMPLER_TIMER_MSECS; |
1656 |
if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime && m_pWorkspace->isUpdatesEnabled()) { |
if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime && m_pWorkspace->isUpdatesEnabled()) { |
1657 |
m_iTimerSlot = 0; |
m_iTimerSlot = 0; |
1658 |
m_iChangeCount = 0; |
// Update the channel information for each pending strip... |
1659 |
|
for (qsamplerChannelStrip *pChannelStrip = m_changedStrips.first(); |
1660 |
|
pChannelStrip; |
1661 |
|
pChannelStrip = m_changedStrips.next()) { |
1662 |
|
// If successfull, remove from pending list... |
1663 |
|
if (pChannelStrip->updateChannelInfo()) |
1664 |
|
m_changedStrips.remove(pChannelStrip); |
1665 |
|
} |
1666 |
|
// Update the channel stream usage for each strip... |
1667 |
QWidgetList wlist = m_pWorkspace->windowList(); |
QWidgetList wlist = m_pWorkspace->windowList(); |
1668 |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
1669 |
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
1670 |
if (pChannelStrip && pChannelStrip->isVisible()) { |
if (pChannelStrip && pChannelStrip->isVisible()) |
1671 |
// If we can't make it clean, try next time. |
pChannelStrip->updateChannelUsage(); |
|
if (!pChannelStrip->updateChannelUsage()) |
|
|
m_iChangeCount++; |
|
|
} |
|
1672 |
} |
} |
1673 |
} |
} |
1674 |
} |
} |