2 |
// |
// |
3 |
// ui.h extension file, included from the uic-generated form implementation. |
// ui.h extension file, included from the uic-generated form implementation. |
4 |
/**************************************************************************** |
/**************************************************************************** |
5 |
Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2005, rncbc aka Rui Nuno Capela. All rights reserved. |
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 |
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> |
45 |
|
|
46 |
#include "config.h" |
#include "config.h" |
47 |
|
|
48 |
|
#ifdef HAVE_SIGNAL_H |
49 |
|
#include <signal.h> |
50 |
|
#endif |
51 |
|
|
52 |
// Timer constant stuff. |
// Timer constant stuff. |
53 |
#define QSAMPLER_TIMER_MSECS 200 |
#define QSAMPLER_TIMER_MSECS 200 |
120 |
|
|
121 |
m_iTimerSlot = 0; |
m_iTimerSlot = 0; |
122 |
|
|
123 |
|
#ifdef HAVE_SIGNAL_H |
124 |
|
// Set to ignore any fatal "Broken pipe" signals. |
125 |
|
::signal(SIGPIPE, SIG_IGN); |
126 |
|
#endif |
127 |
|
|
128 |
// Make it an MDI workspace. |
// Make it an MDI workspace. |
129 |
m_pWorkspace = new QWorkspace(this); |
m_pWorkspace = new QWorkspace(this); |
130 |
m_pWorkspace->setScrollBarsEnabled(true); |
m_pWorkspace->setScrollBarsEnabled(true); |
295 |
} |
} |
296 |
|
|
297 |
|
|
298 |
// Window drag-n-drop event handlers. |
// Drag'n'drop file handler. |
299 |
void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) |
bool qsamplerMainForm::decodeDragFiles ( const QMimeSource *pEvent, QStringList& files ) |
300 |
{ |
{ |
301 |
bool bAccept = false; |
bool bDecode = false; |
302 |
|
|
303 |
if (QTextDrag::canDecode(pDragEnterEvent)) { |
if (QTextDrag::canDecode(pEvent)) { |
304 |
QString sUrl; |
QString sText; |
305 |
if (QTextDrag::decode(pDragEnterEvent, sUrl) && m_pClient) |
bDecode = QTextDrag::decode(pEvent, sText); |
306 |
bAccept = QFileInfo(QUrl(sUrl).path()).exists(); |
if (bDecode) { |
307 |
|
files = QStringList::split('\n', sText); |
308 |
|
for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) |
309 |
|
*iter = (*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null); |
310 |
|
} |
311 |
} |
} |
312 |
|
|
313 |
pDragEnterEvent->accept(bAccept); |
return bDecode; |
314 |
|
} |
315 |
|
|
316 |
|
|
317 |
|
// Window drag-n-drop event handlers. |
318 |
|
void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) |
319 |
|
{ |
320 |
|
QStringList files; |
321 |
|
pDragEnterEvent->accept(decodeDragFiles(pDragEnterEvent, files)); |
322 |
} |
} |
323 |
|
|
324 |
|
|
325 |
void qsamplerMainForm::dropEvent ( QDropEvent* pDropEvent ) |
void qsamplerMainForm::dropEvent ( QDropEvent* pDropEvent ) |
326 |
{ |
{ |
327 |
if (QTextDrag::canDecode(pDropEvent)) { |
QStringList files; |
328 |
QString sUrl; |
|
329 |
if (QTextDrag::decode(pDropEvent, sUrl) && closeSession(true)) |
if (!decodeDragFiles(pDropEvent, files)) |
330 |
loadSessionFile(QUrl(sUrl).path()); |
return; |
331 |
} |
|
332 |
|
for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) { |
333 |
|
const QString& sPath = QUrl(*iter).path(); |
334 |
|
if (qsamplerChannel::isInstrumentFile(sPath)) { |
335 |
|
// Try to create a new channel from instrument file... |
336 |
|
qsamplerChannel *pChannel = new qsamplerChannel(this); |
337 |
|
if (pChannel == NULL) |
338 |
|
return; |
339 |
|
// Start setting the instrument filename... |
340 |
|
pChannel->setInstrument(sPath, 0); |
341 |
|
// Before we show it up, may be we'll |
342 |
|
// better ask for some initial values? |
343 |
|
if (!pChannel->channelSetup(this)) { |
344 |
|
delete pChannel; |
345 |
|
return; |
346 |
|
} |
347 |
|
// Finally, give it to a new channel strip... |
348 |
|
if (!createChannelStrip(pChannel)) { |
349 |
|
delete pChannel; |
350 |
|
return; |
351 |
|
} |
352 |
|
// Make that an overall update. |
353 |
|
m_iDirtyCount++; |
354 |
|
m_iChangeCount++; |
355 |
|
stabilizeForm(); |
356 |
|
} // Otherwise, load an usual session file (LSCP script)... |
357 |
|
else if (closeSession(true)) |
358 |
|
loadSessionFile(sPath); |
359 |
|
// Make it look responsive...:) |
360 |
|
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
361 |
|
} |
362 |
} |
} |
363 |
|
|
364 |
|
|
423 |
if (!closeSession(true)) |
if (!closeSession(true)) |
424 |
return false; |
return false; |
425 |
|
|
426 |
|
// Give us what the server has, right now... |
427 |
|
updateSession(); |
428 |
|
|
429 |
// Ok increment untitled count. |
// Ok increment untitled count. |
430 |
m_iUntitled++; |
m_iUntitled++; |
431 |
|
|
584 |
if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) { |
if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) { |
585 |
appendMessagesClient("lscp_client_query"); |
appendMessagesClient("lscp_client_query"); |
586 |
iErrors++; |
iErrors++; |
587 |
|
break; |
588 |
} |
} |
589 |
} |
} |
590 |
// Try to make it snappy :) |
// Try to make it snappy :) |
596 |
|
|
597 |
// Have we any errors? |
// Have we any errors? |
598 |
if (iErrors > 0) |
if (iErrors > 0) |
599 |
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)); |
600 |
|
|
601 |
// Now we'll try to create the whole GUI session. |
// Now we'll try to create (update) the whole GUI session. |
602 |
int iChannels = ::lscp_get_channels(m_pClient); |
updateSession(); |
|
if (iChannels < 0) { |
|
|
appendMessagesClient("lscp_get_channels"); |
|
|
appendMessagesError(tr("Could not get current number of channels.\n\nSorry.")); |
|
|
} |
|
|
|
|
|
// Try to (re)create each channel. |
|
|
m_pWorkspace->setUpdatesEnabled(false); |
|
|
for (int iChannelID = 0; iChannelID < iChannels; iChannelID++) { |
|
|
createChannelStrip(iChannelID); |
|
|
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
|
|
} |
|
|
m_pWorkspace->setUpdatesEnabled(true); |
|
603 |
|
|
604 |
// Save as default session directory. |
// Save as default session directory. |
605 |
if (m_pOptions) |
if (m_pOptions) |
610 |
m_sFilename = sFilename; |
m_sFilename = sFilename; |
611 |
updateRecentFiles(sFilename); |
updateRecentFiles(sFilename); |
612 |
appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename))); |
appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename))); |
613 |
|
|
614 |
|
// Make that an overall update. |
615 |
|
m_iChangeCount++; |
616 |
stabilizeForm(); |
stabilizeForm(); |
617 |
return true; |
return true; |
618 |
} |
} |
657 |
ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannelID << " " << pChannel->midiDriver() << endl; |
ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannelID << " " << pChannel->midiDriver() << endl; |
658 |
ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannelID << " " << pChannel->midiPort() << endl; |
ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannelID << " " << pChannel->midiPort() << endl; |
659 |
ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannelID << " "; |
ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannelID << " "; |
660 |
if (pChannel->midiChannel() > 0) |
if (pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) |
|
ts << pChannel->midiChannel(); |
|
|
else |
|
661 |
ts << "ALL"; |
ts << "ALL"; |
662 |
|
else |
663 |
|
ts << pChannel->midiChannel(); |
664 |
ts << endl; |
ts << endl; |
665 |
ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannelID << endl; |
ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannelID << endl; |
666 |
ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' " << pChannel->instrumentNr() << " " << iChannelID << endl; |
ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' " << pChannel->instrumentNr() << " " << iChannelID << endl; |
764 |
|
|
765 |
// Log this. |
// Log this. |
766 |
appendMessages(tr("Sampler reset.")); |
appendMessages(tr("Sampler reset.")); |
767 |
|
|
768 |
|
// Make it a new session... |
769 |
|
newSession(); |
770 |
} |
} |
771 |
|
|
772 |
|
|
817 |
if (m_pClient == NULL) |
if (m_pClient == NULL) |
818 |
return; |
return; |
819 |
|
|
820 |
// Just create the channel strip, |
// Just create the channel instance... |
821 |
// by giving an invalid channel id. |
qsamplerChannel *pChannel = new qsamplerChannel(this); |
822 |
createChannelStrip(-1); |
if (pChannel == NULL) |
823 |
|
return; |
824 |
|
|
825 |
|
// Before we show it up, may be we'll |
826 |
|
// better ask for some initial values? |
827 |
|
if (!pChannel->channelSetup(this)) { |
828 |
|
delete pChannel; |
829 |
|
return; |
830 |
|
} |
831 |
|
|
832 |
|
// And give it to the strip (will own the channel instance, if successful). |
833 |
|
if (!createChannelStrip(pChannel)) { |
834 |
|
delete pChannel; |
835 |
|
return; |
836 |
|
} |
837 |
|
|
838 |
|
// Make that an overall update. |
839 |
|
m_iDirtyCount++; |
840 |
|
m_iChangeCount++; |
841 |
|
stabilizeForm(); |
842 |
} |
} |
843 |
|
|
844 |
|
|
916 |
// Reset the existing sampler channel. |
// Reset the existing sampler channel. |
917 |
pChannel->resetChannel(); |
pChannel->resetChannel(); |
918 |
|
|
|
// Refresh channel strip info. |
|
|
pChannelStrip->updateChannelInfo(); |
|
919 |
// And force a deferred update. |
// And force a deferred update. |
920 |
m_iChangeCount++; |
m_iChangeCount++; |
921 |
} |
} |
997 |
int bOldMessagesLimit = m_pOptions->bMessagesLimit; |
int bOldMessagesLimit = m_pOptions->bMessagesLimit; |
998 |
int iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines; |
int iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines; |
999 |
bool bOldCompletePath = m_pOptions->bCompletePath; |
bool bOldCompletePath = m_pOptions->bCompletePath; |
1000 |
|
bool bOldInstrumentNames = m_pOptions->bInstrumentNames; |
1001 |
int iOldMaxRecentFiles = m_pOptions->iMaxRecentFiles; |
int iOldMaxRecentFiles = m_pOptions->iMaxRecentFiles; |
1002 |
// Load the current setup settings. |
// Load the current setup settings. |
1003 |
pOptionsForm->setup(m_pOptions); |
pOptionsForm->setup(m_pOptions); |
1016 |
(!bOldCompletePath && m_pOptions->bCompletePath) || |
(!bOldCompletePath && m_pOptions->bCompletePath) || |
1017 |
(iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles)) |
(iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles)) |
1018 |
updateRecentFilesMenu(); |
updateRecentFilesMenu(); |
1019 |
|
if (( bOldInstrumentNames && !m_pOptions->bInstrumentNames) || |
1020 |
|
(!bOldInstrumentNames && m_pOptions->bInstrumentNames)) |
1021 |
|
updateInstrumentNames(); |
1022 |
if (( bOldDisplayEffect && !m_pOptions->bDisplayEffect) || |
if (( bOldDisplayEffect && !m_pOptions->bDisplayEffect) || |
1023 |
(!bOldDisplayEffect && m_pOptions->bDisplayEffect)) |
(!bOldDisplayEffect && m_pOptions->bDisplayEffect)) |
1024 |
updateDisplayEffect(); |
updateDisplayEffect(); |
1129 |
sText += tr("GIG (libgig) file support disabled."); |
sText += tr("GIG (libgig) file support disabled."); |
1130 |
sText += "</font></small><br />"; |
sText += "</font></small><br />"; |
1131 |
#endif |
#endif |
1132 |
|
#ifndef CONFIG_INSTRUMENT_NAME |
1133 |
|
sText += "<small><font color=\"red\">"; |
1134 |
|
sText += tr("LSCP (liblscp) instrument_name support disabled."); |
1135 |
|
sText += "</font></small><br />"; |
1136 |
|
#endif |
1137 |
sText += "<br />\n"; |
sText += "<br />\n"; |
1138 |
sText += tr("Using") + ": "; |
sText += tr("Using") + ": "; |
1139 |
sText += ::lscp_client_package(); |
sText += ::lscp_client_package(); |
1223 |
} |
} |
1224 |
|
|
1225 |
|
|
1226 |
|
// Grab and restore current sampler channels session. |
1227 |
|
void qsamplerMainForm::updateSession (void) |
1228 |
|
{ |
1229 |
|
// Retrieve the current channel list. |
1230 |
|
int *piChannelIDs = ::lscp_list_channels(m_pClient); |
1231 |
|
if (piChannelIDs == NULL) { |
1232 |
|
if (::lscp_client_get_errno(m_pClient)) { |
1233 |
|
appendMessagesClient("lscp_list_channels"); |
1234 |
|
appendMessagesError(tr("Could not get current list of channels.\n\nSorry.")); |
1235 |
|
} |
1236 |
|
return; |
1237 |
|
} |
1238 |
|
|
1239 |
|
// Try to (re)create each channel. |
1240 |
|
m_pWorkspace->setUpdatesEnabled(false); |
1241 |
|
for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) { |
1242 |
|
// Check if theres already a channel strip for this one... |
1243 |
|
if (!channelStrip(piChannelIDs[iChannel])) |
1244 |
|
createChannelStrip(new qsamplerChannel(this, piChannelIDs[iChannel])); |
1245 |
|
// Make it visibly responsive... |
1246 |
|
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
1247 |
|
} |
1248 |
|
m_pWorkspace->setUpdatesEnabled(true); |
1249 |
|
} |
1250 |
|
|
1251 |
|
|
1252 |
// Update the recent files list and menu. |
// Update the recent files list and menu. |
1253 |
void qsamplerMainForm::updateRecentFiles ( const QString& sFilename ) |
void qsamplerMainForm::updateRecentFiles ( const QString& sFilename ) |
1254 |
{ |
{ |
1293 |
} |
} |
1294 |
|
|
1295 |
|
|
1296 |
|
// Force update of the channels instrument names mode. |
1297 |
|
void qsamplerMainForm::updateInstrumentNames (void) |
1298 |
|
{ |
1299 |
|
// Full channel list update... |
1300 |
|
QWidgetList wlist = m_pWorkspace->windowList(); |
1301 |
|
if (wlist.isEmpty()) |
1302 |
|
return; |
1303 |
|
|
1304 |
|
m_pWorkspace->setUpdatesEnabled(false); |
1305 |
|
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
1306 |
|
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
1307 |
|
if (pChannelStrip) |
1308 |
|
pChannelStrip->updateInstrumentName(true); |
1309 |
|
} |
1310 |
|
m_pWorkspace->setUpdatesEnabled(true); |
1311 |
|
} |
1312 |
|
|
1313 |
|
|
1314 |
// Force update of the channels display font. |
// Force update of the channels display font. |
1315 |
void qsamplerMainForm::updateDisplayFont (void) |
void qsamplerMainForm::updateDisplayFont (void) |
1316 |
{ |
{ |
1476 |
// qsamplerMainForm -- MDI channel strip management. |
// qsamplerMainForm -- MDI channel strip management. |
1477 |
|
|
1478 |
// The channel strip creation executive. |
// The channel strip creation executive. |
1479 |
qsamplerChannelStrip *qsamplerMainForm::createChannelStrip ( int iChannelID ) |
qsamplerChannelStrip *qsamplerMainForm::createChannelStrip ( qsamplerChannel *pChannel ) |
1480 |
{ |
{ |
1481 |
if (m_pClient == NULL) |
if (m_pClient == NULL || pChannel == NULL) |
1482 |
return NULL; |
return NULL; |
1483 |
|
|
1484 |
// Prepare for auto-arrange? |
// Prepare for auto-arrange? |
1488 |
QWidgetList wlist = m_pWorkspace->windowList(); |
QWidgetList wlist = m_pWorkspace->windowList(); |
1489 |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
1490 |
pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
1491 |
// y += pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height(); |
if (pChannelStrip) { |
1492 |
y += pChannelStrip->parentWidget()->frameGeometry().height(); |
// y += pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height(); |
1493 |
|
y += pChannelStrip->parentWidget()->frameGeometry().height(); |
1494 |
|
} |
1495 |
} |
} |
1496 |
} |
} |
1497 |
|
|
1498 |
// Add a new channel itema... |
// Add a new channel itema... |
1499 |
WFlags wflags = Qt::WStyle_Customize | Qt::WStyle_Tool | Qt::WStyle_Title | Qt::WStyle_NoBorder; |
WFlags wflags = Qt::WStyle_Customize | Qt::WStyle_Tool | Qt::WStyle_Title | Qt::WStyle_NoBorder; |
1500 |
pChannelStrip = new qsamplerChannelStrip(m_pWorkspace, 0, wflags); |
pChannelStrip = new qsamplerChannelStrip(m_pWorkspace, 0, wflags); |
1501 |
// Actual channel setup. |
if (pChannelStrip == NULL) |
|
pChannelStrip->setup(this, iChannelID); |
|
|
QObject::connect(pChannelStrip, SIGNAL(channelChanged(qsamplerChannelStrip *)), this, SLOT(channelStripChanged(qsamplerChannelStrip *))); |
|
|
// Before we show it up, may be we'll |
|
|
// better ask for some initial values? |
|
|
if (iChannelID < 0 && !pChannelStrip->channelSetup()) { |
|
|
// No luck, bail out... |
|
|
delete pChannelStrip; |
|
1502 |
return NULL; |
return NULL; |
1503 |
} |
|
1504 |
|
// Actual channel strip setup... |
1505 |
|
pChannelStrip->setup(pChannel); |
1506 |
|
QObject::connect(pChannelStrip, SIGNAL(channelChanged(qsamplerChannelStrip *)), this, SLOT(channelStripChanged(qsamplerChannelStrip *))); |
1507 |
// Set some initial aesthetic options... |
// Set some initial aesthetic options... |
1508 |
if (m_pOptions) { |
if (m_pOptions) { |
1509 |
// Background display effect... |
// Background display effect... |
1543 |
{ |
{ |
1544 |
QWidgetList wlist = m_pWorkspace->windowList(); |
QWidgetList wlist = m_pWorkspace->windowList(); |
1545 |
if (wlist.isEmpty()) |
if (wlist.isEmpty()) |
1546 |
return 0; |
return NULL; |
1547 |
|
|
1548 |
return (qsamplerChannelStrip *) wlist.at(iChannel); |
return (qsamplerChannelStrip *) wlist.at(iChannel); |
1549 |
} |
} |
1550 |
|
|
1551 |
|
|
1552 |
|
// Retrieve a channel strip by sampler channel id. |
1553 |
|
qsamplerChannelStrip *qsamplerMainForm::channelStrip ( int iChannelID ) |
1554 |
|
{ |
1555 |
|
QWidgetList wlist = m_pWorkspace->windowList(); |
1556 |
|
if (wlist.isEmpty()) |
1557 |
|
return NULL; |
1558 |
|
|
1559 |
|
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
1560 |
|
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
1561 |
|
if (pChannelStrip) { |
1562 |
|
qsamplerChannel *pChannel = pChannelStrip->channel(); |
1563 |
|
if (pChannel && pChannel->channelID() == iChannelID) |
1564 |
|
return pChannelStrip; |
1565 |
|
} |
1566 |
|
} |
1567 |
|
|
1568 |
|
// Not found. |
1569 |
|
return NULL; |
1570 |
|
} |
1571 |
|
|
1572 |
|
|
1573 |
// Construct the windows menu. |
// Construct the windows menu. |
1574 |
void qsamplerMainForm::channelsMenuAboutToShow (void) |
void qsamplerMainForm::channelsMenuAboutToShow (void) |
1575 |
{ |
{ |