}
}
+static int find_touched_client(void)
+{
+ int touched = -1;
+
+ for (uns i=0; i < NUM_CLIENTS; i++)
+ if (noct_rotary_touched[client_map[i].rotary])
+ {
+ if (touched >= 0)
+ return -1;
+ touched = i;
+ }
+ return touched;
+}
+
/*** Default sink controls ***/
+static const char *get_client_sink(int i)
+{
+ const char *sink = NULL;
+
+ CLIST_FOR_EACH(struct pulse_sink_input *, s, pulse_sink_input_list)
+ if (s->noct_client_idx == i)
+ {
+ struct pulse_sink *sk = (s->sink_idx >= 0) ? pulse_sink_by_idx(s->sink_idx) : NULL;
+ const char *ss = sk ? sk->name : NULL;
+ if (!sink)
+ sink = ss;
+ else if (strcmp(sink, ss))
+ sink = "?";
+ }
+ return sink ? : "?";
+}
+
static void update_default_sink(void)
{
- const char *def = pulse_default_sink_name ? : "?";
- if (!strcmp(def, "ursarium"))
+ int i = find_touched_client();
+ const char *sink;
+ if (i >= 0)
+ sink = get_client_sink(i);
+ else
+ sink = pulse_default_sink_name ? : "?";
+
+ if (!strcmp(sink, "ursarium"))
{
noct_set_button(8, 1);
noct_set_button(9, 0);
}
- else if (!strcmp(def, "catarium"))
+ else if (!strcmp(sink, "catarium"))
{
noct_set_button(8, 0);
noct_set_button(9, 1);
if (!on)
return;
- const char *def = pulse_default_sink_name ? : "?";
+ int i = find_touched_client();
+ const char *sink;
+ if (i >= 0)
+ sink = get_client_sink(i);
+ else
+ sink = pulse_default_sink_name ? : "?";
+
const char *switch_to = NULL;
if (button == 8)
{
- if (!strcmp(def, "ursarium"))
+ if (!strcmp(sink, "ursarium"))
switch_to = "burrow";
else
switch_to = "ursarium";
}
else if (button == 9)
{
- if (!strcmp(def, "catarium"))
+ if (!strcmp(sink, "catarium"))
switch_to = "burrow";
else
switch_to = "catarium";
if (!switch_to)
return;
- DBG("Switching default sink to %s", switch_to);
- pulse_server_set_default_sink(switch_to);
+ if (i >= 0)
+ {
+ struct pulse_sink *sk = pulse_sink_by_name(switch_to);
+ if (!sk)
+ return;
+
+ CLIST_FOR_EACH(struct pulse_sink_input *, s, pulse_sink_input_list)
+ if (s->noct_client_idx == i)
+ {
+ DBG("Moving input #%d to sink #%d", s->idx, sk->idx);
+ pulse_sink_input_move(s->idx, sk->idx);
+ }
+ }
+ else
+ {
+ DBG("Switching default sink to %s", switch_to);
+ pulse_server_set_default_sink(switch_to);
+ }
}
/*** Main update routines ***/
}
}
+void notify_touch(int rotary, int on UNUSED)
+{
+ if (pulse_state != PS_ONLINE)
+ {
+ DBG("## NOTIFY: Pulse is not online");
+ return;
+ }
+
+ // Rotary touches switch meaning of LEDs, this is handled inside display updates
+ if (rotary >= 4 && rotary < 8)
+ schedule_update();
+}
+
/*** Main entry point ***/
int main(int argc UNUSED, char **argv)