--- qsampler/trunk/src/qsamplerMainForm.cpp 2010/03/31 09:07:30 2077 +++ qsampler/trunk/src/qsamplerMainForm.cpp 2010/07/22 08:12:12 2113 @@ -93,6 +93,36 @@ #endif +//------------------------------------------------------------------------- +// LADISH Level 1 support stuff. + +#ifdef HAVE_SIGNAL_H + +#include + +#include +#include + +#include + +// File descriptor for SIGUSR1 notifier. +static int g_fdUsr1[2]; + +// Unix SIGUSR1 signal handler. +static void qsampler_sigusr1_handler ( int /* signo */ ) +{ + char c = 1; + + (::write(g_fdUsr1[0], &c, sizeof(c)) > 0); +} + +#endif // HAVE_SIGNAL_H + + +//------------------------------------------------------------------------- +// qsampler -- namespace + + namespace QSampler { // Timer constant stuff. @@ -107,7 +137,6 @@ // Specialties for thread-callback comunication. #define QSAMPLER_LSCP_EVENT QEvent::Type(QEvent::User + 1) -#define QSAMPLER_SAVE_EVENT QEvent::Type(QEvent::User + 2) //------------------------------------------------------------------------- @@ -140,17 +169,6 @@ //------------------------------------------------------------------------- -// LADISH Level 1 support stuff. - -void qsampler_on_sigusr1 ( int /*signo*/ ) -{ - QApplication::postEvent( - MainForm::getInstance(), - new QEvent(QSAMPLER_SAVE_EVENT)); -} - - -//------------------------------------------------------------------------- // qsamplerMainForm -- Main window form implementation. // Kind of singleton reference. @@ -185,11 +203,34 @@ m_iTimerSlot = 0; #ifdef HAVE_SIGNAL_H + // Set to ignore any fatal "Broken pipe" signals. ::signal(SIGPIPE, SIG_IGN); + // LADISH Level 1 suport. - ::signal(SIGUSR1, qsampler_on_sigusr1); -#endif + + // Initialize file descriptors for SIGUSR1 socket notifier. + ::socketpair(AF_UNIX, SOCK_STREAM, 0, g_fdUsr1); + m_pUsr1Notifier + = new QSocketNotifier(g_fdUsr1[1], QSocketNotifier::Read, this); + + QObject::connect(m_pUsr1Notifier, + SIGNAL(activated(int)), + SLOT(handle_sigusr1())); + + // Install SIGUSR1 signal handler. + struct sigaction usr1; + usr1.sa_handler = qsampler_sigusr1_handler; + ::sigemptyset(&usr1.sa_mask); + usr1.sa_flags = 0; + usr1.sa_flags |= SA_RESTART; + ::sigaction(SIGUSR1, &usr1, NULL); + +#else // HAVE_SIGNAL_H + + m_pUsr1Notifier = NULL; + +#endif // !HAVE_SIGNAL_H #ifdef CONFIG_VOLUME // Make some extras into the toolbar... @@ -362,6 +403,11 @@ WSACleanup(); #endif +#ifdef HAVE_SIGNAL_H + if (m_pUsr1Notifier) + delete m_pUsr1Notifier; +#endif + // Finally drop any widgets around... if (m_pDeviceForm) delete m_pDeviceForm; @@ -545,7 +591,8 @@ QListIterator iter(pMimeData->urls()); while (iter.hasNext()) { const QString& sPath = iter.next().toLocalFile(); - if (Channel::isInstrumentFile(sPath)) { + // if (Channel::isDlsInstrumentFile(sPath)) { + if (QFileInfo(sPath).exists()) { // Try to create a new channel from instrument file... Channel *pChannel = new Channel(); if (pChannel == NULL) @@ -637,9 +684,21 @@ .arg(::lscp_event_to_text(pLscpEvent->event())) .arg(pLscpEvent->data()), "#996699"); } - } // LADISH1 Level 1 support... - else if (pEvent->type() == QSAMPLER_SAVE_EVENT) + } +} + + +// LADISH Level 1 -- SIGUSR1 signal handler. +void MainForm::handle_sigusr1 (void) +{ +#ifdef HAVE_SIGNAL_H + + char c; + + if (::read(g_fdUsr1[1], &c, sizeof(c)) > 0) saveSession(false); + +#endif }