applying keymap files if found. Fixed sound regression due to pclose

This commit is contained in:
Vincent-FK 2021-04-19 18:39:13 +02:00
parent 152bae7693
commit 4e9b31baff
5 changed files with 101 additions and 37 deletions

View File

@ -120,6 +120,44 @@ bool Launcher::run(std::string collection, Item *collectionItem)
selectedItemsDirectory,
collection);
/* Apply key mapping for selected item's directory if found */
std::string selectedItemDirnameKeyfile = Utils::getDirectory(selectedItemsPath) + "/default_config.key";
if (!access(selectedItemDirnameKeyfile.c_str(), R_OK)) {
/* Create shell cmd */
std::string cmd = SHELL_CMD_MAPPING_SET;
cmd += " " + selectedItemDirnameKeyfile;
/* Log shell cmd */
Logger::write(Logger::ZONE_INFO, "Launcher", "Applying keymap file: " + selectedItemDirnameKeyfile);
printf("Applying keymap file cmd: \"%s\"\n", cmd.c_str());
/* Launch shell cmd */
fp = popen(cmd.c_str(), "r");
if (fp != NULL) {
pclose(fp);
}
}
/* Apply specific key mapping for selected item if found */
std::string selectedItemBasenameKeyfile = Utils::removeExtension(selectedItemsPath) + ".key";
if (!access(selectedItemBasenameKeyfile.c_str(), R_OK)) {
/* Create shell cmd */
std::string cmd = SHELL_CMD_MAPPING_SET;
cmd += " " + selectedItemBasenameKeyfile;
/* Log shell cmd */
Logger::write(Logger::ZONE_INFO, "Launcher", "Applying keymap file: " + selectedItemBasenameKeyfile);
printf("Applying keymap file cmd: \"%s\"\n", cmd.c_str());
/* Launch shell cmd */
fp = popen(cmd.c_str(), "r");
if (fp != NULL) {
pclose(fp);
}
}
/* Restart audio amp */
fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
if (fp != NULL) {
@ -139,6 +177,12 @@ bool Launcher::run(std::string collection, Item *collectionItem)
pclose(fp);
}
/* Reset default key mapping */
fp = popen(SHELL_CMD_MAPPING_RESET, "r");
if (fp != NULL) {
pclose(fp);
}
/* Restore stored PID */
char shellCmd[20];
sprintf(shellCmd, "%s %d", SHELL_CMD_RECORD_PID, getpid());

View File

@ -56,7 +56,7 @@ void Sound::play()
fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
if (fp != NULL) {
ampliStarted = 1;
pclose(fp);
//pclose(fp); // --> regression, to investigate
}
}
@ -75,7 +75,7 @@ uint32_t Sound::turnOffAmpli(uint32_t interval, void *param)
fp = popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
if (fp != NULL) {
ampliStarted = 0;
pclose(fp);
//pclose(fp); // --> regression, to investigate
}
return 0;
}

View File

@ -255,6 +255,23 @@ std::string Utils::getFileName(std::string filePath)
}
std::string Utils::removeExtension(std::string filePath)
{
/** Declared static to be kept in memory even after this function's scope */
static std::string filename;
filename = filePath;
const size_t lastPoint = filename.find_last_of(".");
if (std::string::npos != lastPoint)
{
filename = filePath.substr(0, lastPoint);
}
return filename;
}
std::string Utils::trimEnds(std::string str)
{
// strip off any initial tabs or spaces

View File

@ -25,6 +25,8 @@
#define SHELL_CMD_RECORD_PID "record_pid"
#define SHELL_CMD_TURN_AMPLI_ON "start_audio_amp 1"
#define SHELL_CMD_TURN_AMPLI_OFF "start_audio_amp 0"
#define SHELL_CMD_MAPPING_SET "keymap"
#define SHELL_CMD_MAPPING_RESET "keymap reset"
class Utils
{
@ -38,6 +40,7 @@ public:
static std::string getDirectory(std::string filePath);
static std::string getParentDirectory(std::string filePath);
static std::string getFileName(std::string filePath);
static std::string removeExtension(std::string filePath);
static bool findMatchingFile(std::string prefix, std::vector<std::string> &extensions, std::string &file);
static std::string toLower(std::string str);
static std::string uppercaseFirst(std::string str);