1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-21 11:54:15 +01:00

Updates to Notify plugin, now works fine on Linux too. Should still be OK on Windows, please confirm...

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2290 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2010-12-26 22:14:56 +00:00 committed by edouard
parent c364f45fb7
commit 284a1ebd2c
3 changed files with 26 additions and 23 deletions

View File

@ -38,17 +38,18 @@
#include <iostream> #include <iostream>
#include "qxttimer.h" #include "qxttimer.h"
#define DEBUG_NOTIFIES //#define DEBUG_NOTIFIES
SoundNotifyPlugin::SoundNotifyPlugin() SoundNotifyPlugin::SoundNotifyPlugin()
{ {
phonon.mo = NULL; phonon.mo = NULL;
phonon.ms = NULL;
// Do nothing // Do nothing
} }
SoundNotifyPlugin::~SoundNotifyPlugin() SoundNotifyPlugin::~SoundNotifyPlugin()
{ {
if (phonon.mo != NULL)
delete phonon.mo;
// Do nothing // Do nothing
} }
@ -135,6 +136,7 @@ void SoundNotifyPlugin::resetNotification(void)
void SoundNotifyPlugin::updateNotificationList(QList<NotifyPluginConfiguration*> list) void SoundNotifyPlugin::updateNotificationList(QList<NotifyPluginConfiguration*> list)
{ {
removedNotifies.clear(); removedNotifies.clear();
resetNotification();
lstNotifications.clear(); lstNotifications.clear();
lstNotifications=list; lstNotifications=list;
connectNotifications(); connectNotifications();
@ -148,8 +150,6 @@ void SoundNotifyPlugin::connectNotifications()
} }
if(phonon.mo != NULL) if(phonon.mo != NULL)
delete phonon.mo; delete phonon.mo;
if(phonon.ms != NULL)
delete phonon.ms;
if(!enableSound) return; if(!enableSound) return;
@ -193,10 +193,8 @@ void SoundNotifyPlugin::connectNotifications()
if(lstNotifications.isEmpty()) return; if(lstNotifications.isEmpty()) return;
// set notification message to current event // set notification message to current event
//phonon.mo = new Phonon::MediaObject;
phonon.mo = Phonon::createPlayer(Phonon::NotificationCategory); phonon.mo = Phonon::createPlayer(Phonon::NotificationCategory);
phonon.ms = new QList<Phonon::MediaSource>; phonon.mo->clearQueue();
phonon.mo->clear();
phonon.firstPlay = true; phonon.firstPlay = true;
#ifdef DEBUG_NOTIFIES #ifdef DEBUG_NOTIFIES
QList<Phonon::AudioOutputDevice> audioOutputDevices = QList<Phonon::AudioOutputDevice> audioOutputDevices =
@ -316,7 +314,7 @@ bool SoundNotifyPlugin::playNotification(NotifyPluginConfiguration* notification
int pos = rxlen.indexIn(notification->getRepeatFlag()); int pos = rxlen.indexIn(notification->getRepeatFlag());
if (pos > -1) { if (pos > -1) {
value = rxlen.cap(1); // "189" value = rxlen.cap(1); // "189"
timer_value = (value.toInt()+8)*1000; //ms*1000 + average duration of meassage timer_value = (value.toInt()+8)*1000; //ms*1000 + average duration of meassage
} }
if(!notification->timer) if(!notification->timer)
@ -332,15 +330,16 @@ bool SoundNotifyPlugin::playNotification(NotifyPluginConfiguration* notification
} }
} }
notification->firstStart=false; notification->firstStart=false;
phonon.mo->clear(); phonon.mo->clear();
phonon.ms->clear();
QString str = notification->parseNotifyMessage(); QString str = notification->parseNotifyMessage();
#ifdef DEBUG_NOTIFIES #ifdef DEBUG_NOTIFIES
qDebug() << "play notification - " << str; qDebug() << "play notification - " << str;
#endif #endif
foreach(QString item, notification->getNotifyMessageList()) foreach(QString item, notification->getNotifyMessageList()) {
phonon.ms->append(Phonon::MediaSource(item)); Phonon::MediaSource *ms = new Phonon::MediaSource(item);
phonon.mo->setQueue(*phonon.ms); ms->setAutoDelete(true);
phonon.mo->enqueue(*ms);
}
phonon.mo->play(); phonon.mo->play();
phonon.firstPlay = false; // On Linux, you sometimes have to nudge Phonon to play 1 time before phonon.firstPlay = false; // On Linux, you sometimes have to nudge Phonon to play 1 time before
// the state is not "Loading" anymore. // the state is not "Loading" anymore.
@ -396,7 +395,14 @@ void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldst
#ifdef DEBUG_NOTIFIES #ifdef DEBUG_NOTIFIES
qDebug() << "File length (ms): " << phonon.mo->totalTime(); qDebug() << "File length (ms): " << phonon.mo->totalTime();
qDebug() << "New State: " << newstate;
#endif #endif
// This is a hack to force Linux to wait until the end of the
// wav file before moving to the next in the queue
if (phonon.mo->totalTime()>0)
phonon.mo->setTransitionTime(phonon.mo->totalTime());
if((newstate == Phonon::PausedState) || if((newstate == Phonon::PausedState) ||
(newstate == Phonon::StoppedState)) (newstate == Phonon::StoppedState))
{ {
@ -408,13 +414,12 @@ void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldst
qDebug() << "play audioFree - " << notification->parseNotifyMessage(); qDebug() << "play audioFree - " << notification->parseNotifyMessage();
#endif #endif
playNotification(notification); playNotification(notification);
} }
} } else if (newstate == Phonon::ErrorState)
if(newstate == Phonon::ErrorState)
{ {
if(phonon.mo->errorType()==0) { if(phonon.mo->errorType()==0) {
qDebug() << "Phonon::ErrorState: ErrorType = " << phonon.mo->errorType(); qDebug() << "Phonon::ErrorState: ErrorType = " << phonon.mo->errorType();
phonon.mo->clear(); phonon.mo->clearQueue();
} }
} }
// if(newstate == Phonon::BufferingState) // if(newstate == Phonon::BufferingState)

View File

@ -40,7 +40,6 @@ class NotifyPluginConfiguration;
typedef struct { typedef struct {
Phonon::MediaObject* mo; Phonon::MediaObject* mo;
QList<Phonon::MediaSource>* ms;
NotifyPluginConfiguration* notify; NotifyPluginConfiguration* notify;
bool firstPlay; bool firstPlay;
} PhononObject, *pPhononObject; } PhononObject, *pPhononObject;

View File

@ -323,17 +323,16 @@ void NotifyPluginOptionsPage::changeButtonText(Phonon::State newstate, Phonon::
void NotifyPluginOptionsPage::on_buttonTestSoundNotification_clicked() void NotifyPluginOptionsPage::on_buttonTestSoundNotification_clicked()
{ {
QList <Phonon::MediaSource> messageNotify; // QList <Phonon::MediaSource> messageNotify;
NotifyPluginConfiguration* notification = new NotifyPluginConfiguration; NotifyPluginConfiguration *notification;
if(notifyRulesSelection->currentIndex().row()==-1) return; if(notifyRulesSelection->currentIndex().row()==-1) return;
notifySound->clearQueue();
notification = privListNotifications.at(notifyRulesSelection->currentIndex().row()); notification = privListNotifications.at(notifyRulesSelection->currentIndex().row());
notification->parseNotifyMessage(); notification->parseNotifyMessage();
foreach(QString item, notification->getNotifyMessageList()) foreach(QString item, notification->getNotifyMessageList())
messageNotify.append(Phonon::MediaSource(item)); notifySound->enqueue(Phonon::MediaSource(item));
notifySound->clear();
notifySound->setQueue(messageNotify);
notifySound->play(); notifySound->play();
} }