refactor(audio): remove sound_pack from PlaybackData and add verbose mode
This commit is contained in:
2 files changed
+20
-32
No files matched your search
+19
-13
@@ -36,7 +36,6 @@ typedef struct {
|
|||||||
} SoundPack;
|
} SoundPack;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int key_code;
|
int key_code;
|
||||||
SoundPack *sound_pack;
|
|
||||||
int thread_id;
|
int thread_id;
|
||||||
int is_pressed;
|
int is_pressed;
|
||||||
} PlaybackData;
|
} PlaybackData;
|
||||||
@@ -97,13 +96,16 @@ int load_sound_config(const char *config_path) {
|
|||||||
if (json_object_object_get_ex(root, "key_define_type", &obj))
|
if (json_object_object_get_ex(root, "key_define_type", &obj))
|
||||||
key_type = json_object_get_string(obj);
|
key_type = json_object_get_string(obj);
|
||||||
g_sound_pack.is_multi = strcmp(key_type, "multi") == 0;
|
g_sound_pack.is_multi = strcmp(key_type, "multi") == 0;
|
||||||
printf("Config loaded: Using %s mode\n",
|
if (g_verbose) {
|
||||||
g_sound_pack.is_multi ? "multi" : "single");
|
printf("Config loaded: Using %s mode\n",
|
||||||
|
g_sound_pack.is_multi ? "multi" : "single");
|
||||||
|
}
|
||||||
if (g_sound_pack.is_multi) {
|
if (g_sound_pack.is_multi) {
|
||||||
g_sound_pack.num_generic_press_files = 0;
|
g_sound_pack.num_generic_press_files = 0;
|
||||||
if (json_object_object_get_ex(root, "sound", &obj)) {
|
if (json_object_object_get_ex(root, "sound", &obj)) {
|
||||||
const char *pattern = json_object_get_string(obj);
|
const char *pattern = json_object_get_string(obj);
|
||||||
printf("Sound pattern: %s\n", pattern);
|
if (g_verbose)
|
||||||
|
printf("Sound pattern: %s\n", pattern);
|
||||||
if (strstr(pattern, "%d") || strstr(pattern, "{")) {
|
if (strstr(pattern, "%d") || strstr(pattern, "{")) {
|
||||||
for (int i = 0; i <= 4; i++) {
|
for (int i = 0; i <= 4; i++) {
|
||||||
char temp_filename[256];
|
char temp_filename[256];
|
||||||
@@ -129,8 +131,9 @@ int load_sound_config(const char *config_path) {
|
|||||||
if (access(g_sound_pack.generic_press_files[i], R_OK) == 0) {
|
if (access(g_sound_pack.generic_press_files[i], R_OK) == 0) {
|
||||||
g_sound_pack.num_generic_press_files = i + 1;
|
g_sound_pack.num_generic_press_files = i + 1;
|
||||||
} else {
|
} else {
|
||||||
printf("Generic sound file not found: %s\n",
|
if (g_verbose)
|
||||||
g_sound_pack.generic_press_files[i]);
|
printf("Generic sound file not found: %s\n",
|
||||||
|
g_sound_pack.generic_press_files[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,12 +143,14 @@ int load_sound_config(const char *config_path) {
|
|||||||
pattern);
|
pattern);
|
||||||
if (access(g_sound_pack.generic_press_files[0], R_OK) == 0) {
|
if (access(g_sound_pack.generic_press_files[0], R_OK) == 0) {
|
||||||
g_sound_pack.num_generic_press_files = 1;
|
g_sound_pack.num_generic_press_files = 1;
|
||||||
printf("Found single generic sound file: %s\n",
|
if (g_verbose)
|
||||||
g_sound_pack.generic_press_files[0]);
|
printf("Found single generic sound file: %s\n",
|
||||||
|
g_sound_pack.generic_press_files[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("Total generic press sound files: %d\n",
|
if (g_verbose)
|
||||||
g_sound_pack.num_generic_press_files);
|
printf("Total generic press sound files: %d\n",
|
||||||
|
g_sound_pack.num_generic_press_files);
|
||||||
}
|
}
|
||||||
if (json_object_object_get_ex(root, "soundup", &obj)) {
|
if (json_object_object_get_ex(root, "soundup", &obj)) {
|
||||||
char temp_release_file[256];
|
char temp_release_file[256];
|
||||||
@@ -155,7 +160,8 @@ int load_sound_config(const char *config_path) {
|
|||||||
get_full_path(g_sound_pack.release_file,
|
get_full_path(g_sound_pack.release_file,
|
||||||
sizeof(g_sound_pack.release_file), config_dir,
|
sizeof(g_sound_pack.release_file), config_dir,
|
||||||
temp_release_file);
|
temp_release_file);
|
||||||
printf("Release sound file: %s\n", g_sound_pack.release_file);
|
if (g_verbose)
|
||||||
|
printf("Release sound file: %s\n", g_sound_pack.release_file);
|
||||||
}
|
}
|
||||||
if (json_object_object_get_ex(root, "defines", &obj)) {
|
if (json_object_object_get_ex(root, "defines", &obj)) {
|
||||||
json_object_object_foreach(obj, key, val) {
|
json_object_object_foreach(obj, key, val) {
|
||||||
@@ -198,7 +204,8 @@ int load_sound_config(const char *config_path) {
|
|||||||
temp_sound_file[sizeof(temp_sound_file) - 1] = '\0';
|
temp_sound_file[sizeof(temp_sound_file) - 1] = '\0';
|
||||||
get_full_path(g_sound_pack.sound_file, sizeof(g_sound_pack.sound_file),
|
get_full_path(g_sound_pack.sound_file, sizeof(g_sound_pack.sound_file),
|
||||||
config_dir, temp_sound_file);
|
config_dir, temp_sound_file);
|
||||||
printf("Single mode sound file: %s\n", g_sound_pack.sound_file);
|
if (g_verbose)
|
||||||
|
printf("Single mode sound file: %s\n", g_sound_pack.sound_file);
|
||||||
}
|
}
|
||||||
if (json_object_object_get_ex(root, "defines", &obj)) {
|
if (json_object_object_get_ex(root, "defines", &obj)) {
|
||||||
json_object_object_foreach(obj, key, val) {
|
json_object_object_foreach(obj, key, val) {
|
||||||
@@ -416,7 +423,6 @@ void play_sound_segment(int key_code, int is_pressed) {
|
|||||||
if (!data)
|
if (!data)
|
||||||
return;
|
return;
|
||||||
data->key_code = key_code;
|
data->key_code = key_code;
|
||||||
data->sound_pack = &g_sound_pack;
|
|
||||||
data->thread_id = slot;
|
data->thread_id = slot;
|
||||||
data->is_pressed = is_pressed;
|
data->is_pressed = is_pressed;
|
||||||
pthread_mutex_lock(&thread_mutex);
|
pthread_mutex_lock(&thread_mutex);
|
||||||
|
|||||||
+1
-19
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
#define _POSIX_C_SOURCE 200809L
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@@ -211,25 +212,6 @@ void cleanup_processes(int sig) {
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_sudo_cached() {
|
|
||||||
int status = system("sudo -n true 2>/dev/null");
|
|
||||||
return WEXITSTATUS(status) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ensure_sudo_access() {
|
|
||||||
if (check_sudo_cached()) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
printf("This program requires sudo access to monitor keyboard events.\n");
|
|
||||||
printf("Please enter your password when prompted:\n");
|
|
||||||
int status = system("sudo -v");
|
|
||||||
if (WEXITSTATUS(status) != 0) {
|
|
||||||
fprintf(stderr, "Error: Failed to obtain sudo access\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *get_user_config_path(char *buffer, size_t buflen) {
|
static char *get_user_config_path(char *buffer, size_t buflen) {
|
||||||
const char *home = getenv("HOME");
|
const char *home = getenv("HOME");
|
||||||
if (!home || strlen(home) == 0) {
|
if (!home || strlen(home) == 0) {
|
||||||
|
|||||||
Reference in new issue
Block a user