Skip to content

Commit

Permalink
feat(cpn): Play radio-generated audio in global/special function edit…
Browse files Browse the repository at this point in the history
…or (#3910)

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

* add recorded radio sounds
  • Loading branch information
Neil Horne authored Sep 4, 2023
1 parent 8d8a50c commit d3ed7c1
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 18 deletions.
16 changes: 16 additions & 0 deletions companion/src/companion.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,22 @@
<file>themes/yerico/48/stop.png</file>
<file>themes/yerico/48/write_eeprom.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 prefix="/layouts/">
<file alias="mask_layout1p2.png">images/layouts/mask_layout1+2.png</file>
Expand Down
4 changes: 2 additions & 2 deletions companion/src/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ bool displayT16ImportWarning()
void Helpers::populateFileComboBox(QComboBox * b, const QSet<QString> & set, const QString & current)
{
b->clear();
b->addItem("----");
b->addItem(CPN_STR_NONE_ITEM);

bool added = false;
// Convert set into list and sort it alphabetically case insensitive
Expand All @@ -283,7 +283,7 @@ void Helpers::populateFileComboBox(QComboBox * b, const QSet<QString> & set, con
void Helpers::getFileComboBoxValue(QComboBox * b, char * dest, int length)
{
memset(dest, 0, length+1);
if (b->currentText() != "----") {
if (b->currentText() != CPN_STR_NONE_ITEM) {
strncpy(dest, b->currentText().toLatin1(), length);
}
}
Expand Down
43 changes: 27 additions & 16 deletions companion/src/modeledit/customfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,29 +242,40 @@ void CustomFunctionsPanel::onMediaPlayerError(QMediaPlayer::Error error)

bool CustomFunctionsPanel::playSound(int index)
{
QString path = g.profile[g.id()].sdPath();
if (!QDir(path).exists())
return false; // unlikely
QString path;

if (mediaPlayer)
stopSound(mediaPlayerCurrent);

if (firmware->getCapability(VoicesAsNumbers)) { // AVR
path.append(QString("/%1.wav").arg(int(fswtchParam[index]->value()), 4, 10, QChar('0')));
if (functions[index].func == FuncPlaySound) {
path = QString(":/sounds/%1.wav").arg(functions[index].param);
}
else {
QString lang(generalSettings.ttsLanguage);
if (lang.isEmpty())
lang = "en";
path.append(QString("/SOUNDS/%1/%2.wav").arg(lang).arg(fswtchParamArmT[index]->currentText()));
path = g.profile[g.id()].sdPath();
if (!QDir(path).exists())
return false; // unlikely

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()) {
QMessageBox::critical(this, CPN_STR_TTL_ERROR, tr("Unable to find or open sound file:\n%1").arg(path));
return false;
}

if (mediaPlayer)
stopSound(mediaPlayerCurrent);

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, static_cast<void(QMediaPlayer::*)(QMediaPlayer::Error)>(&QMediaPlayer::error), this, &CustomFunctionsPanel::onMediaPlayerError);
mediaPlayerCurrent = index;
Expand Down Expand Up @@ -489,7 +500,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
Helpers::getFileComboBoxValue(fswtchParamArmT[i], cfn.paramarm, firmware->getCapability(VoicesMaxLength));
}
Helpers::populateFileComboBox(fswtchParamArmT[i], tracksSet, cfn.paramarm);
if (fswtchParamArmT[i]->currentText() != "----") {
if (fswtchParamArmT[i]->currentText() != CPN_STR_NONE_ITEM) {
widgetsMask |= CUSTOM_FUNCTION_PLAY;
}
}
Expand All @@ -500,15 +511,15 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
Helpers::getFileComboBoxValue(fswtchParamArmT[i], cfn.paramarm, firmware->getCapability(VoicesMaxLength));
}
Helpers::populateFileComboBox(fswtchParamArmT[i], tracksSet, cfn.paramarm);
if (fswtchParamArmT[i]->currentText() != "----") {
if (fswtchParamArmT[i]->currentText() != CPN_STR_NONE_ITEM) {
widgetsMask |= CUSTOM_FUNCTION_PLAY;
}
}
else if (func == FuncPlaySound) {
if (modified)
cfn.param = (uint8_t)fswtchParamT[i]->currentIndex();
populateFuncParamCB(fswtchParamT[i], func, cfn.param);
widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM;
widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM | CUSTOM_FUNCTION_PLAY;
}
else if (func == FuncPlayHaptic) {
if (modified)
Expand Down
Binary file added companion/src/sounds/0.wav
Binary file not shown.
Binary file added companion/src/sounds/1.wav
Binary file not shown.
Binary file added companion/src/sounds/10.wav
Binary file not shown.
Binary file added companion/src/sounds/11.wav
Binary file not shown.
Binary file added companion/src/sounds/12.wav
Binary file not shown.
Binary file added companion/src/sounds/13.wav
Binary file not shown.
Binary file added companion/src/sounds/14.wav
Binary file not shown.
Binary file added companion/src/sounds/15.wav
Binary file not shown.
Binary file added companion/src/sounds/2.wav
Binary file not shown.
Binary file added companion/src/sounds/3.wav
Binary file not shown.
Binary file added companion/src/sounds/4.wav
Binary file not shown.
Binary file added companion/src/sounds/5.wav
Binary file not shown.
Binary file added companion/src/sounds/6.wav
Binary file not shown.
Binary file added companion/src/sounds/7.wav
Binary file not shown.
Binary file added companion/src/sounds/8.wav
Binary file not shown.
Binary file added companion/src/sounds/9.wav
Binary file not shown.

0 comments on commit d3ed7c1

Please sign in to comment.