diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 896ff2e98..127518ade 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -1023,3 +1023,29 @@ QString generateProcessUniqueTempFileName(const QString & fileName) sanitizedFileName.remove('/'); return QDir::tempPath() + QString("/%1-").arg(QCoreApplication::applicationPid()) + sanitizedFileName; } + +QString getSoundsPath(const GeneralSettings &generalSettings) +{ + QString path = g.profile[g.id()].sdPath() + "/SOUNDS/"; + QString lang = generalSettings.ttsLanguage; + if (lang.isEmpty()) + lang = "en"; + path.append(lang); + return path; +} + +QSet getFilesSet(const QString &path, const QStringList &filter, int maxLen) +{ + QSet result; + QDir dir(path); + if (dir.exists()) { + foreach (QString filename, dir.entryList(filter, QDir::Files)) { + QFileInfo file(filename); + QString name = file.completeBaseName(); + if (name.length() <= maxLen) { + result.insert(name); + } + } + } + return result; +} diff --git a/companion/src/helpers.h b/companion/src/helpers.h index f831f5190..02675f1f4 100644 --- a/companion/src/helpers.h +++ b/companion/src/helpers.h @@ -154,4 +154,7 @@ int qunlink(const QString & fileName); QString generateProcessUniqueTempFileName(const QString & fileName); +QString getSoundsPath(const GeneralSettings &generalSettings); +QSet getFilesSet(const QString &path, const QStringList &filter, int maxLen); + #endif // HELPERS_H diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp index bae50a3ac..8b5c98455 100644 --- a/companion/src/modeledit/customfunctions.cpp +++ b/companion/src/modeledit/customfunctions.cpp @@ -70,36 +70,29 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, int num_fsw = firmware->getCapability(CustomFunctions); if (!firmware->getCapability(VoicesAsNumbers)) { + tracksSet = getFilesSet(getSoundsPath(generalSettings), QStringList() << "*.wav" << "*.WAV", firmware->getCapability(VoicesMaxLength)); for (int i=0; igetCapability(VoicesMaxLength); - if (qd.exists()) { - QStringList filters; - filters << "*.wav" << "*.WAV"; - foreach ( QString file, qd.entryList(filters, QDir::Files) ) { - QFileInfo fi(file); - QString temp=fi.completeBaseName(); - if (!paramarmList.contains(temp) && temp.length()<=vml) { - paramarmList.append(temp); + if (IS_TARANIS(firmware->getBoard())) { + scriptsSet = getFilesSet(g.profile[g.id()].sdPath() + "/SCRIPTS", QStringList() << "*.lua", firmware->getCapability(VoicesMaxLength)); + for (int i=0; isetProperty("index", i); - connect(fswtchFunc[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited())); + connect(fswtchFunc[i], SIGNAL(currentIndexChanged(int)), this, SLOT(functionEdited())); gridLayout->addWidget(fswtchFunc[i], i+1, 2); QHBoxLayout *paramLayout = new QHBoxLayout(); @@ -297,10 +290,20 @@ void CustomFunctionsPanel::customFunctionEdited() { if (!lock) { lock = true; - int index = sender()->property("index").toInt(); refreshCustomFunction(index, true); + emit modified(); + lock = false; + } +} +void CustomFunctionsPanel::functionEdited() +{ + if (!lock) { + lock = true; + int index = sender()->property("index").toInt(); + fswtchParamArmT[index]->setCurrentIndex(0); + refreshCustomFunction(index, true); emit modified(); lock = false; } @@ -446,11 +449,9 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) } } } - else { - populateFuncParamArmTCB(fswtchParamArmT[i], cfn.paramarm, paramarmList); - if (fswtchParamArmT[i]->currentText() != "----") { - widgetsMask |= CUSTOM_FUNCTION_PLAY; - } + populateFuncParamArmTCB(fswtchParamArmT[i], cfn.paramarm, tracksSet); + if (fswtchParamArmT[i]->currentText() != "----") { + widgetsMask |= CUSTOM_FUNCTION_PLAY; } } } @@ -466,6 +467,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) } } } + populateFuncParamArmTCB(fswtchParamArmT[i], cfn.paramarm, tracksSet); } else if (func==FuncPlaySound) { if (modified) cfn.param = (uint8_t)fswtchParamT[i]->currentIndex(); @@ -478,6 +480,19 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM; } } + else if (func==FuncPlayScript) { + widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM; + if (modified) { + memset(cfn.paramarm, 0, sizeof(cfn.paramarm)); + int vml = 8/*TODO*/; + if (fswtchParamArmT[i]->currentText() != "----") { + for (int j=0; jcurrentText().length(), vml); j++) { + cfn.paramarm[j] = fswtchParamArmT[i]->currentText().toAscii().at(j); + } + } + } + populateFuncParamArmTCB(fswtchParamArmT[i], cfn.paramarm, scriptsSet); + } else if (func==FuncPlayScript) { widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM; if (modified) { @@ -531,7 +546,6 @@ void CustomFunctionsPanel::update() populateFuncCB(fswtchFunc[i], functions[i].func); populateGVmodeCB(fswtchGVmode[i], functions[i].adjustMode); populateFuncParamCB(fswtchParamT[i], functions[i].func, functions[i].param, functions[i].adjustMode); - populateFuncParamArmTCB(fswtchParamArmT[i], functions[i].paramarm, paramarmList); } refreshCustomFunction(i); } @@ -552,7 +566,6 @@ void CustomFunctionsPanel::fswPaste() populateFuncCB(fswtchFunc[selectedFunction], functions[selectedFunction].func); populateGVmodeCB(fswtchGVmode[selectedFunction], functions[selectedFunction].adjustMode); populateFuncParamCB(fswtchParamT[selectedFunction], functions[selectedFunction].func, functions[selectedFunction].param, functions[selectedFunction].adjustMode); - populateFuncParamArmTCB(fswtchParamArmT[selectedFunction], functions[selectedFunction].paramarm, paramarmList); refreshCustomFunction(selectedFunction); lock = false; emit modified(); @@ -643,14 +656,14 @@ void CustomFunctionsPanel::populateGVmodeCB(QComboBox *b, unsigned int value) b->setCurrentIndex(value); } -void CustomFunctionsPanel::populateFuncParamArmTCB(QComboBox *b, char * value, QStringList & paramsList) +void CustomFunctionsPanel::populateFuncParamArmTCB(QComboBox *b, char * value, const QSet ¶msList) { b->clear(); b->addItem("----"); bool added = false; QString currentvalue(value); - foreach ( QString entry, paramsList ) { + foreach (QString entry, paramsList) { b->addItem(entry); if (entry==currentvalue) { b->setCurrentIndex(b->count()-1); diff --git a/companion/src/modeledit/customfunctions.h b/companion/src/modeledit/customfunctions.h index 699a6312e..95f7400cd 100644 --- a/companion/src/modeledit/customfunctions.h +++ b/companion/src/modeledit/customfunctions.h @@ -47,6 +47,7 @@ class CustomFunctionsPanel : public GenericPanel private slots: void customFunctionEdited(); + void functionEdited(); void fsw_customContextMenuRequested(QPoint pos); void refreshCustomFunction(int index, bool modified=false); void onChildModified(); @@ -63,10 +64,11 @@ class CustomFunctionsPanel : public GenericPanel void populateFuncCB(QComboBox *b, unsigned int value); void populateGVmodeCB(QComboBox *b, unsigned int value); void populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode=0); - void populateFuncParamArmTCB(QComboBox *b, char * value, QStringList & paramsList); + void populateFuncParamArmTCB(QComboBox *b, char * value, const QSet & paramsList); bool initialized; - QStringList paramarmList; + QSet tracksSet; + QSet scriptsSet; int phononCurrent; QComboBox * fswtchSwtch[C9X_MAX_CUSTOM_FUNCTIONS]; QComboBox * fswtchFunc[C9X_MAX_CUSTOM_FUNCTIONS];