mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-23 04:25:42 +02:00
tag: add a new variant of int tags, with a realtime unit property
The idea is, consumers of a tag, can check the realtime property, and if set to something other than TAG_REALTIME_NONE, schedule a realtime update. For example, it could be used to track song progress.
This commit is contained in:
parent
9a94c9c1f7
commit
025c6991a3
2 changed files with 34 additions and 0 deletions
26
tag.c
26
tag.c
|
@ -11,6 +11,7 @@ struct private {
|
||||||
long value;
|
long value;
|
||||||
long min;
|
long min;
|
||||||
long max;
|
long max;
|
||||||
|
enum tag_realtime_unit realtime_unit;
|
||||||
} value_as_int;
|
} value_as_int;
|
||||||
bool value_as_bool;
|
bool value_as_bool;
|
||||||
double value_as_float;
|
double value_as_float;
|
||||||
|
@ -31,6 +32,12 @@ unimpl_min_max(const struct tag *tag)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static enum tag_realtime_unit
|
||||||
|
no_realtime(const struct tag *tag)
|
||||||
|
{
|
||||||
|
return TAG_REALTIME_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
destroy_int_and_float(struct tag *tag)
|
destroy_int_and_float(struct tag *tag)
|
||||||
{
|
{
|
||||||
|
@ -62,6 +69,13 @@ int_max(const struct tag *tag)
|
||||||
return priv->value_as_int.max;
|
return priv->value_as_int.max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static enum tag_realtime_unit
|
||||||
|
int_realtime(const struct tag *tag)
|
||||||
|
{
|
||||||
|
const struct private *priv = tag->private;
|
||||||
|
return priv->value_as_int.realtime_unit;
|
||||||
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
int_as_string(const struct tag *tag)
|
int_as_string(const struct tag *tag)
|
||||||
{
|
{
|
||||||
|
@ -197,12 +211,20 @@ tag_new_int(const char *name, long value)
|
||||||
|
|
||||||
struct tag *
|
struct tag *
|
||||||
tag_new_int_range(const char *name, long value, long min, long max)
|
tag_new_int_range(const char *name, long value, long min, long max)
|
||||||
|
{
|
||||||
|
return tag_new_int_realtime(name, value, min, max, TAG_REALTIME_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct tag *
|
||||||
|
tag_new_int_realtime(const char *name, long value, long min, long max,
|
||||||
|
enum tag_realtime_unit unit)
|
||||||
{
|
{
|
||||||
struct private *priv = malloc(sizeof(*priv));
|
struct private *priv = malloc(sizeof(*priv));
|
||||||
priv->name = strdup(name);
|
priv->name = strdup(name);
|
||||||
priv->value_as_int.value = value;
|
priv->value_as_int.value = value;
|
||||||
priv->value_as_int.min = min;
|
priv->value_as_int.min = min;
|
||||||
priv->value_as_int.max = max;
|
priv->value_as_int.max = max;
|
||||||
|
priv->value_as_int.realtime_unit = unit;
|
||||||
|
|
||||||
struct tag *tag = malloc(sizeof(*tag));
|
struct tag *tag = malloc(sizeof(*tag));
|
||||||
tag->private = priv;
|
tag->private = priv;
|
||||||
|
@ -210,6 +232,7 @@ tag_new_int_range(const char *name, long value, long min, long max)
|
||||||
tag->name = &tag_name;
|
tag->name = &tag_name;
|
||||||
tag->min = &int_min;
|
tag->min = &int_min;
|
||||||
tag->max = &int_max;
|
tag->max = &int_max;
|
||||||
|
tag->realtime = &int_realtime;
|
||||||
tag->as_string = &int_as_string;
|
tag->as_string = &int_as_string;
|
||||||
tag->as_int = &int_as_int;
|
tag->as_int = &int_as_int;
|
||||||
tag->as_bool = &int_as_bool;
|
tag->as_bool = &int_as_bool;
|
||||||
|
@ -230,6 +253,7 @@ tag_new_bool(const char *name, bool value)
|
||||||
tag->name = &tag_name;
|
tag->name = &tag_name;
|
||||||
tag->min = &unimpl_min_max;
|
tag->min = &unimpl_min_max;
|
||||||
tag->max = &unimpl_min_max;
|
tag->max = &unimpl_min_max;
|
||||||
|
tag->realtime = &no_realtime;
|
||||||
tag->as_string = &bool_as_string;
|
tag->as_string = &bool_as_string;
|
||||||
tag->as_int = &bool_as_int;
|
tag->as_int = &bool_as_int;
|
||||||
tag->as_bool = &bool_as_bool;
|
tag->as_bool = &bool_as_bool;
|
||||||
|
@ -250,6 +274,7 @@ tag_new_float(const char *name, double value)
|
||||||
tag->name = &tag_name;
|
tag->name = &tag_name;
|
||||||
tag->min = &unimpl_min_max;
|
tag->min = &unimpl_min_max;
|
||||||
tag->max = &unimpl_min_max;
|
tag->max = &unimpl_min_max;
|
||||||
|
tag->realtime = &no_realtime;
|
||||||
tag->as_string = &float_as_string;
|
tag->as_string = &float_as_string;
|
||||||
tag->as_int = &float_as_int;
|
tag->as_int = &float_as_int;
|
||||||
tag->as_bool = &float_as_bool;
|
tag->as_bool = &float_as_bool;
|
||||||
|
@ -270,6 +295,7 @@ tag_new_string(const char *name, const char *value)
|
||||||
tag->name = &tag_name;
|
tag->name = &tag_name;
|
||||||
tag->min = &unimpl_min_max;
|
tag->min = &unimpl_min_max;
|
||||||
tag->max = &unimpl_min_max;
|
tag->max = &unimpl_min_max;
|
||||||
|
tag->realtime = &no_realtime;
|
||||||
tag->as_string = &string_as_string;
|
tag->as_string = &string_as_string;
|
||||||
tag->as_int = &string_as_int;
|
tag->as_int = &string_as_int;
|
||||||
tag->as_bool = &string_as_bool;
|
tag->as_bool = &string_as_bool;
|
||||||
|
|
8
tag.h
8
tag.h
|
@ -4,6 +4,11 @@
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
enum tag_realtime_unit {
|
||||||
|
TAG_REALTIME_NONE,
|
||||||
|
TAG_REALTIME_SECONDS
|
||||||
|
};
|
||||||
|
|
||||||
struct tag {
|
struct tag {
|
||||||
void *private;
|
void *private;
|
||||||
|
|
||||||
|
@ -16,6 +21,7 @@ struct tag {
|
||||||
|
|
||||||
long (*min)(const struct tag *tag);
|
long (*min)(const struct tag *tag);
|
||||||
long (*max)(const struct tag *tag);
|
long (*max)(const struct tag *tag);
|
||||||
|
enum tag_realtime_unit (*realtime)(const struct tag *tag);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tag_set {
|
struct tag_set {
|
||||||
|
@ -25,6 +31,8 @@ struct tag_set {
|
||||||
|
|
||||||
struct tag *tag_new_int(const char *name, long value);
|
struct tag *tag_new_int(const char *name, long value);
|
||||||
struct tag *tag_new_int_range(const char *name, long value, long min, long max);
|
struct tag *tag_new_int_range(const char *name, long value, long min, long max);
|
||||||
|
struct tag *tag_new_int_realtime(const char *name, long value, long min,
|
||||||
|
long max, enum tag_realtime_unit unit);
|
||||||
struct tag *tag_new_bool(const char *name, bool value);
|
struct tag *tag_new_bool(const char *name, bool value);
|
||||||
struct tag *tag_new_float(const char *name, double value);
|
struct tag *tag_new_float(const char *name, double value);
|
||||||
struct tag *tag_new_string(const char *name, const char *value);
|
struct tag *tag_new_string(const char *name, const char *value);
|
||||||
|
|
Loading…
Add table
Reference in a new issue