diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2023-05-09 21:03:16 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2023-05-11 15:19:25 -0700 |
commit | daf765c1351e551266682a48e148812195d97905 (patch) | |
tree | e07296f6bf65511eb7a0ad4e5b2330cc94888af4 | |
parent | ce5d4d8bf226ec2fd7177427f490893e5d262419 (diff) |
modules/rtv: add basic log_channels= setting
This introduces a boolean style log_channels= setting for
enabling logging of channel settings on channel switch.
It might be nice to change this to accept stdout/stderr/fdnum as
the setting instead of always directing at stderr.
This also doesn't capture the seed state so it's not exactly
logging everything needed to reproduce wholly what is being
shown. Some compositions depend more on rand than others, so
it matters at varying degrees.
It'd be nice for settings syntax to have some global syntax
supported where a seed can always be embedded to be loaded.
Introducing such things as global settings to the settings syntax
is a pending TODO item... right now the only way to load seed
state is at startup passed to main as --seed=. That's not gonna
cut it long-term.
This is an easy big step in the right direction though. Trying
to make sense of what's on-screen from the truncated captions is
impossible. Even if the captions wrapped the settings, it would
be tricky to catch the settings without recording the output or
screenshotting.
This also immediately makes me wonder about the voting system for
rtv where we log settings of favorites... then roll those into
playlists.
-rw-r--r-- | src/modules/rtv/rtv.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/modules/rtv/rtv.c b/src/modules/rtv/rtv.c index 1984f30..82720b6 100644 --- a/src/modules/rtv/rtv.c +++ b/src/modules/rtv/rtv.c @@ -1,4 +1,6 @@ +#include <stdio.h> #include <stdlib.h> +#include <string.h> #include <time.h> #include "til.h" @@ -22,6 +24,7 @@ #define RTV_CONTEXT_DURATION_SECS 4 #define RTV_CAPTION_DURATION_SECS 2 #define RTV_DEFAULT_SNOW_MODULE "none" +#define RTV_DEFAULT_LOG_SETTINGS 0 typedef struct rtv_channel_t { const til_module_t *module; @@ -43,6 +46,7 @@ typedef struct rtv_context_t { unsigned context_duration; unsigned snow_duration; unsigned caption_duration; + unsigned log_channels:1; rtv_channel_t snow_channel; @@ -57,6 +61,7 @@ typedef struct rtv_setup_t { unsigned snow_duration; unsigned caption_duration; char *snow_module; + unsigned log_channels:1; char *channels[]; } rtv_setup_t; @@ -181,6 +186,9 @@ static void setup_next_channel(rtv_context_t *ctxt, unsigned ticks) ctxt->caption = ctxt->channel->caption = caption; ctxt->channel->settings_as_arg = settings_as_arg ? settings_as_arg : strdup(""); + + if (ctxt->log_channels) /* TODO: we need to capture seed state too, a general solution capturing such global state would be nice */ + fprintf(stderr, "rtv channel settings: \'%s\'\n", ctxt->channel->settings_as_arg); } ctxt->next_switch = now + ctxt->duration; @@ -252,6 +260,8 @@ static til_module_context_t * rtv_create_context(const til_module_t *module, til (void) til_module_create_context(ctxt->snow_channel.module, stream, rand_r(&seed), ticks, 0, path, NULL, &ctxt->snow_channel.module_ctxt); } + ctxt->log_channels = ((rtv_setup_t *)setup)->log_channels; + for (size_t i = 0; i < n_modules; i++) { if (!rtv_should_skip_module((rtv_setup_t *)setup, modules[i])) ctxt->channels[ctxt->n_channels++].module = modules[i]; @@ -319,6 +329,12 @@ static int rtv_setup(const til_settings_t *settings, til_setting_t **res_setting const char *caption_duration; const char *snow_duration; const char *snow_module; + const char *log_channels; + const char *log_channels_values[] = { + "no", + "yes", + NULL + }; int r; r = til_settings_get_and_describe_value(settings, @@ -403,6 +419,20 @@ static int rtv_setup(const til_settings_t *settings, til_setting_t **res_setting if (r) return r; + r = til_settings_get_and_describe_value(settings, + &(til_setting_spec_t){ + .name = "Log channel settings to stderr", + .key = "log_channels", + .preferred = log_channels_values[RTV_DEFAULT_LOG_SETTINGS], + .values = log_channels_values, + .annotations = NULL + }, + &log_channels, + res_setting, + res_desc); + if (r) + return r; + if (res_setup) { rtv_setup_t *setup; @@ -467,6 +497,9 @@ static int rtv_setup(const til_settings_t *settings, til_setting_t **res_setting sscanf(caption_duration, "%u", &setup->caption_duration); sscanf(snow_duration, "%u", &setup->snow_duration); + if (!strcasecmp(log_channels, log_channels_values[1])) + setup->log_channels = 1; + *res_setup = &setup->til_setup; } |