feat(cpn): Play radio-generated audio in global/special function editor (#3910)

* enh(cpn): play sounds in model functions editor

* add recorded radio sounds
This commit is contained in:
Neil Horne
2023-09-04 19:52:12 +10:00
committed by GitHub
parent 8d8a50ce74
commit d3ed7c12e6
19 changed files with 45 additions and 18 deletions
+16
View File
@@ -1273,6 +1273,22 @@
<file>themes/yerico/48/stop.png</file> <file>themes/yerico/48/stop.png</file>
<file>themes/yerico/48/write_eeprom.png</file> <file>themes/yerico/48/write_eeprom.png</file>
<file>themes/yerico/48/sdsync.png</file> <file>themes/yerico/48/sdsync.png</file>
<file>sounds/0.wav</file>
<file>sounds/1.wav</file>
<file>sounds/2.wav</file>
<file>sounds/3.wav</file>
<file>sounds/4.wav</file>
<file>sounds/5.wav</file>
<file>sounds/6.wav</file>
<file>sounds/7.wav</file>
<file>sounds/8.wav</file>
<file>sounds/9.wav</file>
<file>sounds/10.wav</file>
<file>sounds/11.wav</file>
<file>sounds/12.wav</file>
<file>sounds/13.wav</file>
<file>sounds/14.wav</file>
<file>sounds/15.wav</file>
</qresource> </qresource>
<qresource prefix="/layouts/"> <qresource prefix="/layouts/">
<file alias="mask_layout1p2.png">images/layouts/mask_layout1+2.png</file> <file alias="mask_layout1p2.png">images/layouts/mask_layout1+2.png</file>
+2 -2
View File
@@ -260,7 +260,7 @@ bool displayT16ImportWarning()
void Helpers::populateFileComboBox(QComboBox * b, const QSet<QString> & set, const QString & current) void Helpers::populateFileComboBox(QComboBox * b, const QSet<QString> & set, const QString & current)
{ {
b->clear(); b->clear();
b->addItem("----"); b->addItem(CPN_STR_NONE_ITEM);
bool added = false; bool added = false;
// Convert set into list and sort it alphabetically case insensitive // Convert set into list and sort it alphabetically case insensitive
@@ -283,7 +283,7 @@ void Helpers::populateFileComboBox(QComboBox * b, const QSet<QString> & set, con
void Helpers::getFileComboBoxValue(QComboBox * b, char * dest, int length) void Helpers::getFileComboBoxValue(QComboBox * b, char * dest, int length)
{ {
memset(dest, 0, length+1); memset(dest, 0, length+1);
if (b->currentText() != "----") { if (b->currentText() != CPN_STR_NONE_ITEM) {
strncpy(dest, b->currentText().toLatin1(), length); strncpy(dest, b->currentText().toLatin1(), length);
} }
} }
+27 -16
View File
@@ -242,29 +242,40 @@ void CustomFunctionsPanel::onMediaPlayerError(QMediaPlayer::Error error)
bool CustomFunctionsPanel::playSound(int index) bool CustomFunctionsPanel::playSound(int index)
{ {
QString path = g.profile[g.id()].sdPath(); QString path;
if (!QDir(path).exists())
return false; // unlikely
if (mediaPlayer) if (functions[index].func == FuncPlaySound) {
stopSound(mediaPlayerCurrent); path = QString(":/sounds/%1.wav").arg(functions[index].param);
if (firmware->getCapability(VoicesAsNumbers)) { // AVR
path.append(QString("/%1.wav").arg(int(fswtchParam[index]->value()), 4, 10, QChar('0')));
} }
else { else {
QString lang(generalSettings.ttsLanguage); path = g.profile[g.id()].sdPath();
if (lang.isEmpty()) if (!QDir(path).exists())
lang = "en"; return false; // unlikely
path.append(QString("/SOUNDS/%1/%2.wav").arg(lang).arg(fswtchParamArmT[index]->currentText()));
if (firmware->getCapability(VoicesAsNumbers)) { // AVR
path.append(QString("/%1.wav").arg(int(fswtchParam[index]->value()), 4, 10, QChar('0')));
}
else {
QString lang(generalSettings.ttsLanguage);
if (lang.isEmpty())
lang = "en";
path.append(QString("/SOUNDS/%1/%2.wav").arg(lang).arg(fswtchParamArmT[index]->currentText()));
}
} }
if (!QFileInfo::exists(path) || !QFileInfo(path).isReadable()) { if (!QFileInfo::exists(path) || !QFileInfo(path).isReadable()) {
QMessageBox::critical(this, CPN_STR_TTL_ERROR, tr("Unable to find or open sound file:\n%1").arg(path)); QMessageBox::critical(this, CPN_STR_TTL_ERROR, tr("Unable to find or open sound file:\n%1").arg(path));
return false; return false;
} }
if (mediaPlayer)
stopSound(mediaPlayerCurrent);
mediaPlayer = new QMediaPlayer(this, QMediaPlayer::LowLatency); mediaPlayer = new QMediaPlayer(this, QMediaPlayer::LowLatency);
mediaPlayer->setMedia(QUrl::fromLocalFile(path)); if (functions[index].func == FuncPlaySound)
mediaPlayer->setMedia(QUrl(path.prepend("qrc")));
else
mediaPlayer->setMedia(QUrl::fromLocalFile(path));
connect(mediaPlayer, &QMediaPlayer::stateChanged, this, &CustomFunctionsPanel::onMediaPlayerStateChanged); connect(mediaPlayer, &QMediaPlayer::stateChanged, this, &CustomFunctionsPanel::onMediaPlayerStateChanged);
connect(mediaPlayer, static_cast<void(QMediaPlayer::*)(QMediaPlayer::Error)>(&QMediaPlayer::error), this, &CustomFunctionsPanel::onMediaPlayerError); connect(mediaPlayer, static_cast<void(QMediaPlayer::*)(QMediaPlayer::Error)>(&QMediaPlayer::error), this, &CustomFunctionsPanel::onMediaPlayerError);
mediaPlayerCurrent = index; mediaPlayerCurrent = index;
@@ -489,7 +500,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
Helpers::getFileComboBoxValue(fswtchParamArmT[i], cfn.paramarm, firmware->getCapability(VoicesMaxLength)); Helpers::getFileComboBoxValue(fswtchParamArmT[i], cfn.paramarm, firmware->getCapability(VoicesMaxLength));
} }
Helpers::populateFileComboBox(fswtchParamArmT[i], tracksSet, cfn.paramarm); Helpers::populateFileComboBox(fswtchParamArmT[i], tracksSet, cfn.paramarm);
if (fswtchParamArmT[i]->currentText() != "----") { if (fswtchParamArmT[i]->currentText() != CPN_STR_NONE_ITEM) {
widgetsMask |= CUSTOM_FUNCTION_PLAY; widgetsMask |= CUSTOM_FUNCTION_PLAY;
} }
} }
@@ -500,7 +511,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
Helpers::getFileComboBoxValue(fswtchParamArmT[i], cfn.paramarm, firmware->getCapability(VoicesMaxLength)); Helpers::getFileComboBoxValue(fswtchParamArmT[i], cfn.paramarm, firmware->getCapability(VoicesMaxLength));
} }
Helpers::populateFileComboBox(fswtchParamArmT[i], tracksSet, cfn.paramarm); Helpers::populateFileComboBox(fswtchParamArmT[i], tracksSet, cfn.paramarm);
if (fswtchParamArmT[i]->currentText() != "----") { if (fswtchParamArmT[i]->currentText() != CPN_STR_NONE_ITEM) {
widgetsMask |= CUSTOM_FUNCTION_PLAY; widgetsMask |= CUSTOM_FUNCTION_PLAY;
} }
} }
@@ -508,7 +519,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
if (modified) if (modified)
cfn.param = (uint8_t)fswtchParamT[i]->currentIndex(); cfn.param = (uint8_t)fswtchParamT[i]->currentIndex();
populateFuncParamCB(fswtchParamT[i], func, cfn.param); populateFuncParamCB(fswtchParamT[i], func, cfn.param);
widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM; widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM | CUSTOM_FUNCTION_PLAY;
} }
else if (func == FuncPlayHaptic) { else if (func == FuncPlayHaptic) {
if (modified) if (modified)
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.