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 |
|
|
322 |
|
pDragEnterEvent->accept(decodeDragFiles(pDragEnterEvent, files)); |
323 |
} |
} |
324 |
|
|
325 |
|
|
326 |
void qsamplerMainForm::dropEvent ( QDropEvent* pDropEvent ) |
void qsamplerMainForm::dropEvent ( QDropEvent* pDropEvent ) |
327 |
{ |
{ |
328 |
if (QTextDrag::canDecode(pDropEvent)) { |
QStringList files; |
329 |
QString sUrl; |
if (decodeDragFiles(pDropEvent, files)) { |
330 |
if (QTextDrag::decode(pDropEvent, sUrl) && closeSession(true)) |
for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) { |
331 |
loadSessionFile(QUrl(sUrl).path()); |
const QString& sPath = QUrl(*iter).path(); |
332 |
|
if (qsamplerChannel::isInstrumentFile(sPath)) { |
333 |
|
// Try to create a new channel from instrument file... |
334 |
|
qsamplerChannel *pChannel = new qsamplerChannel(this); |
335 |
|
if (pChannel == NULL) |
336 |
|
return; |
337 |
|
// Start setting the instrument filename... |
338 |
|
pChannel->setInstrument(sPath, 0); |
339 |
|
// Before we show it up, may be we'll |
340 |
|
// better ask for some initial values? |
341 |
|
if (!pChannel->channelSetup(this)) { |
342 |
|
delete pChannel; |
343 |
|
return; |
344 |
|
} |
345 |
|
// Make that an overall update. |
346 |
|
m_iDirtyCount++; |
347 |
|
m_iChangeCount++; |
348 |
|
stabilizeForm(); |
349 |
|
} // Otherwise, load an usual session file (LSCP script)... |
350 |
|
else if (closeSession(true)) |
351 |
|
loadSessionFile(sPath); |
352 |
|
} |
353 |
} |
} |
354 |
} |
} |
355 |
|
|
573 |
if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) { |
if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) { |
574 |
appendMessagesClient("lscp_client_query"); |
appendMessagesClient("lscp_client_query"); |
575 |
iErrors++; |
iErrors++; |
576 |
|
break; |
577 |
} |
} |
578 |
} |
} |
579 |
// Try to make it snappy :) |
// Try to make it snappy :) |
585 |
|
|
586 |
// Have we any errors? |
// Have we any errors? |
587 |
if (iErrors > 0) |
if (iErrors > 0) |
588 |
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)); |
589 |
|
|
590 |
// Now we'll try to create the whole GUI session. |
// Now we'll try to create the whole GUI session. |
591 |
int iChannels = ::lscp_get_channels(m_pClient); |
int *piChannelIDs = ::lscp_list_channels(m_pClient); |
592 |
if (iChannels < 0) { |
if (piChannelIDs == NULL) { |
593 |
appendMessagesClient("lscp_get_channels"); |
appendMessagesClient("lscp_list_channels"); |
594 |
appendMessagesError(tr("Could not get current number of channels.\n\nSorry.")); |
appendMessagesError(tr("Could not get current list of channels.\n\nSorry.")); |
595 |
} |
} else { |
596 |
|
// Try to (re)create each channel. |
597 |
// Try to (re)create each channel. |
m_pWorkspace->setUpdatesEnabled(false); |
598 |
m_pWorkspace->setUpdatesEnabled(false); |
for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) { |
599 |
for (int iChannelID = 0; iChannelID < iChannels; iChannelID++) { |
createChannelStrip(new qsamplerChannel(this, piChannelIDs[iChannel])); |
600 |
createChannelStrip(iChannelID); |
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
601 |
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
} |
602 |
} |
m_pWorkspace->setUpdatesEnabled(true); |
603 |
m_pWorkspace->setUpdatesEnabled(true); |
} |
604 |
|
|
605 |
// Save as default session directory. |
// Save as default session directory. |
606 |
if (m_pOptions) |
if (m_pOptions) |
611 |
m_sFilename = sFilename; |
m_sFilename = sFilename; |
612 |
updateRecentFiles(sFilename); |
updateRecentFiles(sFilename); |
613 |
appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename))); |
appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename))); |
614 |
|
|
615 |
|
// Make that an overall update. |
616 |
|
m_iChangeCount++; |
617 |
stabilizeForm(); |
stabilizeForm(); |
618 |
return true; |
return true; |
619 |
} |
} |
658 |
ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannelID << " " << pChannel->midiDriver() << endl; |
ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannelID << " " << pChannel->midiDriver() << endl; |
659 |
ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannelID << " " << pChannel->midiPort() << endl; |
ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannelID << " " << pChannel->midiPort() << endl; |
660 |
ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannelID << " "; |
ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannelID << " "; |
661 |
if (pChannel->midiChannel() > 0) |
if (pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) |
|
ts << pChannel->midiChannel(); |
|
|
else |
|
662 |
ts << "ALL"; |
ts << "ALL"; |
663 |
|
else |
664 |
|
ts << pChannel->midiChannel(); |
665 |
ts << endl; |
ts << endl; |
666 |
ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannelID << endl; |
ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannelID << endl; |
667 |
ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' " << pChannel->instrumentNr() << " " << iChannelID << endl; |
ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' " << pChannel->instrumentNr() << " " << iChannelID << endl; |
815 |
if (m_pClient == NULL) |
if (m_pClient == NULL) |
816 |
return; |
return; |
817 |
|
|
818 |
// Just create the channel strip, |
// Just create the channel instance... |
819 |
// by giving an invalid channel id. |
qsamplerChannel *pChannel = new qsamplerChannel(this); |
820 |
createChannelStrip(-1); |
if (pChannel == NULL) |
821 |
|
return; |
822 |
|
|
823 |
|
// Before we show it up, may be we'll |
824 |
|
// better ask for some initial values? |
825 |
|
if (!pChannel->channelSetup(this)) { |
826 |
|
delete pChannel; |
827 |
|
return; |
828 |
|
} |
829 |
|
|
830 |
|
// And give it to the strip (will own the channel instance, if successful). |
831 |
|
if (!createChannelStrip(pChannel)) { |
832 |
|
delete pChannel; |
833 |
|
return; |
834 |
|
} |
835 |
|
|
836 |
|
// Make that an overall update. |
837 |
|
m_iDirtyCount++; |
838 |
|
m_iChangeCount++; |
839 |
|
stabilizeForm(); |
840 |
} |
} |
841 |
|
|
842 |
|
|
914 |
// Reset the existing sampler channel. |
// Reset the existing sampler channel. |
915 |
pChannel->resetChannel(); |
pChannel->resetChannel(); |
916 |
|
|
|
// Refresh channel strip info. |
|
|
pChannelStrip->updateChannelInfo(); |
|
917 |
// And force a deferred update. |
// And force a deferred update. |
918 |
m_iChangeCount++; |
m_iChangeCount++; |
919 |
} |
} |
995 |
int bOldMessagesLimit = m_pOptions->bMessagesLimit; |
int bOldMessagesLimit = m_pOptions->bMessagesLimit; |
996 |
int iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines; |
int iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines; |
997 |
bool bOldCompletePath = m_pOptions->bCompletePath; |
bool bOldCompletePath = m_pOptions->bCompletePath; |
998 |
|
bool bOldInstrumentNames = m_pOptions->bInstrumentNames; |
999 |
int iOldMaxRecentFiles = m_pOptions->iMaxRecentFiles; |
int iOldMaxRecentFiles = m_pOptions->iMaxRecentFiles; |
1000 |
// Load the current setup settings. |
// Load the current setup settings. |
1001 |
pOptionsForm->setup(m_pOptions); |
pOptionsForm->setup(m_pOptions); |
1014 |
(!bOldCompletePath && m_pOptions->bCompletePath) || |
(!bOldCompletePath && m_pOptions->bCompletePath) || |
1015 |
(iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles)) |
(iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles)) |
1016 |
updateRecentFilesMenu(); |
updateRecentFilesMenu(); |
1017 |
|
if (( bOldInstrumentNames && !m_pOptions->bInstrumentNames) || |
1018 |
|
(!bOldInstrumentNames && m_pOptions->bInstrumentNames)) |
1019 |
|
updateInstrumentNames(); |
1020 |
if (( bOldDisplayEffect && !m_pOptions->bDisplayEffect) || |
if (( bOldDisplayEffect && !m_pOptions->bDisplayEffect) || |
1021 |
(!bOldDisplayEffect && m_pOptions->bDisplayEffect)) |
(!bOldDisplayEffect && m_pOptions->bDisplayEffect)) |
1022 |
updateDisplayEffect(); |
updateDisplayEffect(); |
1127 |
sText += tr("GIG (libgig) file support disabled."); |
sText += tr("GIG (libgig) file support disabled."); |
1128 |
sText += "</font></small><br />"; |
sText += "</font></small><br />"; |
1129 |
#endif |
#endif |
1130 |
|
#ifndef CONFIG_INSTRUMENT_NAME |
1131 |
|
sText += "<small><font color=\"red\">"; |
1132 |
|
sText += tr("LSCP (liblscp) instrument_name support disabled."); |
1133 |
|
sText += "</font></small><br />"; |
1134 |
|
#endif |
1135 |
sText += "<br />\n"; |
sText += "<br />\n"; |
1136 |
sText += tr("Using") + ": "; |
sText += tr("Using") + ": "; |
1137 |
sText += ::lscp_client_package(); |
sText += ::lscp_client_package(); |
1265 |
} |
} |
1266 |
|
|
1267 |
|
|
1268 |
|
// Force update of the channels instrument names mode. |
1269 |
|
void qsamplerMainForm::updateInstrumentNames (void) |
1270 |
|
{ |
1271 |
|
// Full channel list update... |
1272 |
|
QWidgetList wlist = m_pWorkspace->windowList(); |
1273 |
|
if (wlist.isEmpty()) |
1274 |
|
return; |
1275 |
|
|
1276 |
|
m_pWorkspace->setUpdatesEnabled(false); |
1277 |
|
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
1278 |
|
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
1279 |
|
if (pChannelStrip) |
1280 |
|
pChannelStrip->updateInstrumentName(true); |
1281 |
|
} |
1282 |
|
m_pWorkspace->setUpdatesEnabled(true); |
1283 |
|
} |
1284 |
|
|
1285 |
|
|
1286 |
// Force update of the channels display font. |
// Force update of the channels display font. |
1287 |
void qsamplerMainForm::updateDisplayFont (void) |
void qsamplerMainForm::updateDisplayFont (void) |
1288 |
{ |
{ |
1448 |
// qsamplerMainForm -- MDI channel strip management. |
// qsamplerMainForm -- MDI channel strip management. |
1449 |
|
|
1450 |
// The channel strip creation executive. |
// The channel strip creation executive. |
1451 |
qsamplerChannelStrip *qsamplerMainForm::createChannelStrip ( int iChannelID ) |
qsamplerChannelStrip *qsamplerMainForm::createChannelStrip ( qsamplerChannel *pChannel ) |
1452 |
{ |
{ |
1453 |
if (m_pClient == NULL) |
if (m_pClient == NULL || pChannel == NULL) |
1454 |
return NULL; |
return NULL; |
1455 |
|
|
1456 |
// Prepare for auto-arrange? |
// Prepare for auto-arrange? |
1468 |
// Add a new channel itema... |
// Add a new channel itema... |
1469 |
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; |
1470 |
pChannelStrip = new qsamplerChannelStrip(m_pWorkspace, 0, wflags); |
pChannelStrip = new qsamplerChannelStrip(m_pWorkspace, 0, wflags); |
1471 |
// 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; |
|
1472 |
return NULL; |
return NULL; |
1473 |
} |
|
1474 |
|
// Actual channel strip setup... |
1475 |
|
pChannelStrip->setup(pChannel); |
1476 |
|
QObject::connect(pChannelStrip, SIGNAL(channelChanged(qsamplerChannelStrip *)), this, SLOT(channelStripChanged(qsamplerChannelStrip *))); |
1477 |
// Set some initial aesthetic options... |
// Set some initial aesthetic options... |
1478 |
if (m_pOptions) { |
if (m_pOptions) { |
1479 |
// Background display effect... |
// Background display effect... |