mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
Update from Daniel of the notify plugin. Play with this, it is very cool, it looks at UAVObjects and based on their values it has rules to play sounds. It is flexible and a much better approach than text to speech which was originally considered but still sounds bad and hard to do cross platform.
Sound collection path if you are building in a build directory would be: ../../share/openpilotgcs/sounds Select default as the language. There is one issue remaining which Daniel is working on, 0.0x values do not play, these are rare ut will be fixed shortly. It is now mature enough to test with however. Additionally as part of this commit, typeo correct of a sound file. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@849 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
20535abf53
commit
b2840b41ef
Binary file not shown.
Binary file not shown.
@ -28,6 +28,7 @@
|
||||
|
||||
#include "notifyplugin.h"
|
||||
#include "notifypluginconfiguration.h"
|
||||
#include "notifypluginoptionspage.h"
|
||||
#include <coreplugin/icore.h>
|
||||
#include <QDebug>
|
||||
#include <QtPlugin>
|
||||
@ -94,6 +95,11 @@ void SoundNotifyPlugin::connectNotifications()
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
|
||||
QList<Phonon::MediaObject*> deleteList = mapMediaObjects.values();
|
||||
if(!deleteList.isEmpty())
|
||||
foreach(Phonon::MediaObject* mediaObj,deleteList)
|
||||
delete mediaObj;
|
||||
|
||||
// Check validity of arguments first, reject empty args and unknown fields.
|
||||
foreach(NotifyPluginConfiguration* notify,lstNotifications) {
|
||||
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(notify->getDataObject()) );
|
||||
|
@ -29,8 +29,13 @@
|
||||
#define SOUNDNOTIFYPLUGIN_H
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
#include "notifypluginoptionspage.h"
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
#include "uavobjects/uavobject.h"
|
||||
#include <QSettings>
|
||||
#include <Phonon>
|
||||
|
||||
class NotifyPluginOptionsPage;
|
||||
class NotifyPluginConfiguration;
|
||||
|
||||
class SoundNotifyPlugin : public ExtensionSystem::IPlugin
|
||||
{
|
||||
|
@ -131,11 +131,61 @@ QString NotifyPluginConfiguration::parseNotifyMessage()
|
||||
|
||||
if(position!=0xFF)
|
||||
{
|
||||
if(QFile::exists(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+QString("%L1 ").arg(getSpinBoxValue())+".wav"))
|
||||
notifyMessageList.insert(position,getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+QString("%L1 ").arg(getSpinBoxValue())+".wav");
|
||||
else
|
||||
if(QFile::exists(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+QString("%L1 ").arg(getSpinBoxValue())+".wav"))
|
||||
notifyMessageList.insert(position,getSoundCollectionPath()+"\\default\\"+QString("%L1 ").arg(getSpinBoxValue())+".wav");
|
||||
QStringList numberParts = QString("%1").arg(getSpinBoxValue()).trimmed().split(".");
|
||||
QStringList numberFiles;
|
||||
|
||||
if((numberParts.at(0).size()==1) || (numberParts.at(0).toInt()<20))
|
||||
{
|
||||
if(numberParts.at(0)!="0")
|
||||
numberFiles.append(numberParts.at(0));
|
||||
} else {
|
||||
int i=0;
|
||||
if(numberParts.at(0).right(2).toInt()<20) {
|
||||
if(numberParts.at(0).right(2).toInt()<10)
|
||||
numberFiles.append(numberParts.at(0).right(1));
|
||||
else
|
||||
numberFiles.append(numberParts.at(0).right(2));
|
||||
i=2;
|
||||
}
|
||||
for(;i<numberParts.at(0).size();i++)
|
||||
{
|
||||
numberFiles.prepend(numberParts.at(0).at(numberParts.at(0).size()-i-1));
|
||||
if(numberFiles.first()==QString("0")) {
|
||||
numberFiles.removeFirst();
|
||||
continue;
|
||||
}
|
||||
if(i==1)
|
||||
numberFiles.replace(0,numberFiles.first()+'0');
|
||||
if(i==2)
|
||||
numberFiles.insert(1,"100");
|
||||
if(i==3)
|
||||
numberFiles.insert(1,"1000");
|
||||
}
|
||||
}
|
||||
|
||||
if(numberParts.size()>1) {
|
||||
numberFiles.append("point");
|
||||
if((numberParts.at(1).size()==1) || (numberParts.at(1).toInt()<20))
|
||||
numberFiles.append(numberParts.at(1));
|
||||
else {
|
||||
numberFiles.append(numberParts.at(1).left(1)+'0');
|
||||
numberFiles.append(numberParts.at(1).right(1));
|
||||
}
|
||||
}
|
||||
foreach(QString fileName,numberFiles) {
|
||||
fileName+=".wav";
|
||||
QString filePath = getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+fileName;
|
||||
if(QFile::exists(filePath))
|
||||
notifyMessageList.insert(position++,getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+fileName);
|
||||
else {
|
||||
if(QFile::exists(getSoundCollectionPath()+"\\default\\"+fileName))
|
||||
notifyMessageList.insert(position++,getSoundCollectionPath()+"\\default\\"+fileName);
|
||||
else {
|
||||
notifyMessageList.clear();
|
||||
break; // if no some of *.wav files, then don't play number!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//str.replace(QString(".wav | .mp3"), QString(""));
|
||||
|
@ -125,6 +125,7 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
|
||||
}
|
||||
options_page->buttonModify->setEnabled(false);
|
||||
options_page->buttonDelete->setEnabled(false);
|
||||
options_page->buttonPlayNotification->setEnabled(false);
|
||||
|
||||
sound1 = Phonon::createPlayer(Phonon::NotificationCategory);
|
||||
sound2 = Phonon::createPlayer(Phonon::NotificationCategory);
|
||||
@ -189,7 +190,7 @@ void NotifyPluginOptionsPage::apply()
|
||||
settings->setValue(QLatin1String("EnableSound"), options_page->chkEnableSound->isChecked());
|
||||
settings->endGroup();
|
||||
|
||||
emit updateNotifications();
|
||||
//emit updateNotifications();
|
||||
}
|
||||
|
||||
void NotifyPluginOptionsPage::finish()
|
||||
@ -318,6 +319,7 @@ void NotifyPluginOptionsPage::on_buttonTestSoundNotification_clicked()
|
||||
{
|
||||
QList <Phonon::MediaSource> messageNotify;
|
||||
//getOptionsPageValues();
|
||||
if(options_page->tableNotifications->currentRow()==-1) return;
|
||||
notify = privListNotifications.at(options_page->tableNotifications->currentRow());
|
||||
notify->parseNotifyMessage();
|
||||
QStringList stringList = notify->getNotifyMessageList();
|
||||
@ -424,6 +426,7 @@ void NotifyPluginOptionsPage::on_tableNotification_changeSelection()
|
||||
updateConfigView(privListNotifications.at(item->row()));
|
||||
options_page->buttonModify->setEnabled(item->isSelected());
|
||||
options_page->buttonDelete->setEnabled(item->isSelected());
|
||||
options_page->buttonPlayNotification->setEnabled(item->isSelected());
|
||||
}
|
||||
|
||||
void NotifyPluginOptionsPage::on_buttonAddNotification_clicked()
|
||||
@ -437,8 +440,6 @@ void NotifyPluginOptionsPage::on_buttonAddNotification_clicked()
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
notify->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path());
|
||||
notify->setCurrentLanguage(options_page->SoundCollectionList->currentText());
|
||||
notify->setDataObject(options_page->UAVObject->currentText());
|
||||
@ -476,12 +477,18 @@ void NotifyPluginOptionsPage::on_buttonDeleteNotification_clicked()
|
||||
// if(!privListNotifications.size())
|
||||
// notify = new NotifyPluginConfiguration;
|
||||
|
||||
if(options_page->tableNotifications->rowCount()>1 && row < options_page->tableNotifications->rowCount()-1
|
||||
/*&& row*/)
|
||||
if(item->isSelected())
|
||||
item->setSelected(false);
|
||||
|
||||
options_page->tableNotifications->removeRow(row);
|
||||
|
||||
if(!options_page->tableNotifications->rowCount())
|
||||
{
|
||||
options_page->buttonDelete->setEnabled(false);
|
||||
options_page->buttonModify->setEnabled(false);
|
||||
options_page->buttonPlayNotification->setEnabled(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>140</y>
|
||||
<y>150</y>
|
||||
<width>501</width>
|
||||
<height>71</height>
|
||||
</rect>
|
||||
@ -58,6 +58,12 @@
|
||||
</item>
|
||||
<item row="1" column="7" colspan="3">
|
||||
<widget class="QDoubleSpinBox" name="ValueSpinBox">
|
||||
<property name="decimals">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>9999.899999999999636</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
@ -448,7 +454,7 @@ p, li { white-space: pre-wrap; }
|
||||
<rect>
|
||||
<x>7</x>
|
||||
<y>130</y>
|
||||
<width>481</width>
|
||||
<width>501</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
Loading…
Reference in New Issue
Block a user