Skip to content

Commit

Permalink
ffmemless: Implement modifier haptic.repeat.
Browse files Browse the repository at this point in the history
If haptic.repeat key is not found revert to old behaviour
of using sound.repeat for determining effect looping.

[ffmemless] Implement modifier haptic.repeat. JB#59349
  • Loading branch information
jusa committed Nov 17, 2022
1 parent d0b1084 commit efd2121
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion data/plugins.d/50-ffmemless.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ supported_effects = touch;touch_weak;touch_strong;release;release_weak;release_s
# _DELAY = [0,65535], milliseconds before starting playback, defaults to 0
#
# _REPEAT = [1,4294967295], how many times to repeat effect, defaults to 1
# Please note that if the event has "sound.repeat" enabled,
# Please note that if the event has "haptic.repeat" enabled,
# the effect is repeated until stop signal regardless of _REPEAT
# value.
#
Expand Down
17 changes: 14 additions & 3 deletions src/plugins/ffmemless/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ static int ffm_sink_prepare(NSinkInterface *iface, NRequest *request)
const NProplist *props = n_request_get_properties (request);
const struct ffm_effect_data *data;
struct ffm_effect_data *copy;
gboolean repeat;
gint repeat = -1; /* -1 not set, 1 TRUE, 0 FALSE */
guint playback_time;
const gchar *key;

Expand All @@ -679,9 +679,20 @@ static int ffm_sink_prepare(NSinkInterface *iface, NRequest *request)
copy->request = request;
copy->iface = iface;

repeat = n_proplist_get_bool (props, FFM_SOUND_REPEAT_KEY);
/* If new haptic.repeat key is defined use that, otherwise revert to
* following sound.repeat to determine looping. */
if (n_proplist_has_key (props, N_HAPTIC_REPEAT_KEY))
repeat = n_proplist_get_bool (props, N_HAPTIC_REPEAT_KEY) ? 1 : 0;
else
repeat = n_proplist_get_bool (props, FFM_SOUND_REPEAT_KEY) ? 1 : 0;

playback_time = n_proplist_get_uint (props, FFM_HAPTIC_DURATION_KEY);
if (repeat || playback_time) {

/* If haptic.repeat is explicitly set to false either play change
* infinite repeats to 1. */
if (repeat == 0) {
copy->repeat = data->repeat == INT32_MAX ? 1 : data->repeat;
} else if (repeat == 1 || playback_time > 0) {
/*
* If duration was not defined, it's zero and we don't report playback
* done. Otherwise, as effects are already stored by the kernel we just
Expand Down

0 comments on commit efd2121

Please sign in to comment.