uns channels;
uns volume;
uns mute;
+ int noct_client_idx; // Used by the high-level logic below
};
#define HASH_NODE struct pulse_sink_input
return -1;
}
-static bool client_match_sink_input(struct client_map *cm, struct pulse_sink_input *s)
-{
- if (s->client_idx < 0 || s->sink_idx < 0)
- return 0;
-
- struct pulse_client *c = pulse_client_lookup(s->client_idx);
- if (!c)
- return 0;
-
- return ((!cm->client || !strcmp(cm->client, c->name)) &&
- (!cm->host || !strcmp(cm->host, c->host)));
-}
-
static void calc_clients(void)
{
bzero(client_state, sizeof(client_state));
HASH_FOR_ALL(pulse_sink_input, s)
{
+ s->noct_client_idx = -1;
+
+ if (s->client_idx < 0 || s->sink_idx < 0)
+ continue;
+
+ struct pulse_client *c = pulse_client_lookup(s->client_idx);
+ if (!c)
+ continue;
+
for (uns i=0; i < NUM_CLIENTS; i++)
{
struct client_map *cm = &client_map[i];
struct client_state *cs = &client_state[i];
- if (client_match_sink_input(cm, s))
+ if ((!cm->client || !strcmp(cm->client, c->name)) &&
+ (!cm->host || !strcmp(cm->host, c->host)))
{
- DBG("@@ Client #%d, sink input #%d -> rotary %d", s->client_idx, s->idx, cm->rotary);
+ // DBG("@@ Client #%d, sink input #%d -> rotary %d", s->client_idx, s->idx, cm->rotary);
+ s->noct_client_idx = i;
cs->volume = MAX(cs->volume, s->volume);
cs->have_muted[!!s->mute] = 1;
+ break;
}
}
}
HASH_FOR_ALL(pulse_sink_input, s)
{
- if (client_match_sink_input(cm, s) && s->volume != pavol)
+ if (s->noct_client_idx == i && s->volume != pavol)
{
DBG("@@ Client #%d, sink input #%d: setting volume=%u", s->client_idx, s->idx, pavol);
pa_cvolume cvol;
int i = find_client_by_rotary(button);
if (i < 0)
return;
- struct client_map *cm = &client_map[i];
struct client_state *cs = &client_state[i];
calc_clients();
HASH_FOR_ALL(pulse_sink_input, s)
{
- if (client_match_sink_input(cm, s))
+ if (s->noct_client_idx == i)
{
DBG("@@ Client #%d, sink input #%d: setting mute=%u", s->client_idx, s->idx, mute);
PULSE_ASYNC_RUN(pa_context_set_sink_input_mute, pulse_ctx, s->idx, mute, pulse_success_cb);