Check whether we need to reload the config file in regular intervals, even if the focus doesn't change and no MIDI input is being processed.
This commit is contained in:
parent
a462bccc12
commit
465a16cee6
21
midizap.c
21
midizap.c
|
@ -494,11 +494,17 @@ void quitter()
|
|||
quit = 1;
|
||||
}
|
||||
|
||||
// poll interval in microsec (this shouldn't be too large to avoid jitter)
|
||||
#define POLL_INTERVAL 1000
|
||||
// how often we check the config file per sec (> 0, < 1000000/POLL_INTERVAL)
|
||||
#define CONF_FREQ 1
|
||||
#define MAX_COUNT (1000000/CONF_FREQ/POLL_INTERVAL)
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
uint8_t msg[3];
|
||||
int opt;
|
||||
int opt, count = 0;
|
||||
|
||||
while ((opt = getopt(argc, argv, "htd::r:")) != -1) {
|
||||
switch (opt) {
|
||||
|
@ -559,11 +565,22 @@ main(int argc, char **argv)
|
|||
}
|
||||
|
||||
signal(SIGINT, quitter);
|
||||
// force the config file to be loaded initially
|
||||
count = MAX_COUNT;
|
||||
while (!quit) {
|
||||
while (pop_midi(&seq, msg)) {
|
||||
handle_event(msg);
|
||||
count = 0;
|
||||
}
|
||||
usleep(POLL_INTERVAL);
|
||||
if (++count >= MAX_COUNT) {
|
||||
// Check whether to reload the config file if we haven't seen any MIDI
|
||||
// input in a while. Note that if the file *is* reloaded, then we also
|
||||
// need to reset last_focused_window here, so that the translations of
|
||||
// the focused window are recomputed the next time we handle an event.
|
||||
if (read_config_file()) last_focused_window = 0;
|
||||
count = 0;
|
||||
}
|
||||
usleep(1000);
|
||||
}
|
||||
printf(" [exiting]\n");
|
||||
close_jack(&seq);
|
||||
|
|
|
@ -81,6 +81,7 @@ typedef struct _translation {
|
|||
int step[NUM_CHAN][2]; // step size for pitch bends (1 by default)
|
||||
} translation;
|
||||
|
||||
extern int read_config_file(void);
|
||||
extern translation *get_translation(char *win_title, char *win_class);
|
||||
extern void print_stroke_sequence(char *name, char *up_or_down, stroke *s);
|
||||
extern int debug_regex, debug_strokes, debug_keys;
|
||||
|
|
21
readconfig.c
21
readconfig.c
|
@ -967,7 +967,7 @@ finish_translation(void)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
read_config_file(void)
|
||||
{
|
||||
struct stat buf;
|
||||
|
@ -983,6 +983,7 @@ read_config_file(void)
|
|||
translation *tr = NULL;
|
||||
FILE *f;
|
||||
int config_file_default = 0;
|
||||
static int errors = 0;
|
||||
|
||||
if (config_file_name == NULL) {
|
||||
config_file_name = getenv("MIDIZAP_CONFIG_FILE");
|
||||
|
@ -997,13 +998,19 @@ read_config_file(void)
|
|||
}
|
||||
if (stat(config_file_name, &buf) < 0) {
|
||||
// AG: Fall back to the system-wide configuration file.
|
||||
if (!config_file_default) perror(config_file_name);
|
||||
if (!config_file_default && !errors) {
|
||||
perror(config_file_name);
|
||||
errors++;
|
||||
}
|
||||
config_file_name = "/etc/midizaprc";
|
||||
config_file_modification_time = 0;
|
||||
}
|
||||
if (stat(config_file_name, &buf) < 0) {
|
||||
if (!errors) {
|
||||
perror(config_file_name);
|
||||
return;
|
||||
errors++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (buf.st_mtime == 0) {
|
||||
buf.st_mtime = 1;
|
||||
|
@ -1016,8 +1023,11 @@ read_config_file(void)
|
|||
|
||||
f = fopen(config_file_name, "r");
|
||||
if (f == NULL) {
|
||||
if (!errors) {
|
||||
perror(config_file_name);
|
||||
return;
|
||||
errors++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
free_all_translations();
|
||||
|
@ -1126,7 +1136,10 @@ read_config_file(void)
|
|||
}
|
||||
|
||||
fclose(f);
|
||||
return 1;
|
||||
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue