/*
* Asynchronous Interface to PulseAudio
*
- * (c) 2014 Martin Mares <mj@ucw.cz>
+ * (c) 2014--2018 Martin Mares <mj@ucw.cz>
*/
#undef LOCAL_DEBUG
msg(L_DEBUG, "## Client #%d: %s host=%s", c->idx, c->name, c->host);
CLIST_FOR_EACH(struct pulse_sink *, s, pulse_sink_list)
- msg(L_DEBUG, "## Sink #%d: %s channels=%u volume=%u base_vol=%u mute=%u suspended=%u",
- s->idx, s->name, s->channels, s->volume, s->base_volume, s->mute, s->suspended);
+ msg(L_DEBUG, "## Sink #%d: %s channels=%u volume=%u base_vol=%u mute=%u suspended=%u port=%s",
+ s->idx, s->name, s->channels, s->volume, s->base_volume, s->mute, s->suspended, s->active_port);
CLIST_FOR_EACH(struct pulse_sink_input *, s, pulse_sink_input_list)
msg(L_DEBUG, "## Sink input #%d: %s client=%d sink=%d channels=%u volume=%u mute=%u",
return;
}
- DBG("Pulse: SINK #%u: %s (%s) flags=%08x channels=%u volume=%u mute=%d base_vol=%u state=%u",
- i->index, i->name, i->description, i->flags, i->channel_map.channels, i->volume.values[0], i->mute, i->base_volume, i->state);
+ DBG("Pulse: SINK #%u: %s (%s) flags=%08x channels=%u volume=%u mute=%d base_vol=%u state=%u port=%s",
+ i->index, i->name, i->description, i->flags, i->channel_map.channels, i->volume.values[0], i->mute, i->base_volume, i->state,
+ (i->active_port ? i->active_port->name : "none"));
pulse_dump_proplist(i->proplist);
struct pulse_sink *s = pulse_sink_lookup(i->index);
s->base_volume = i->base_volume;
s->mute = i->mute;
s->suspended = (i->state == PA_SINK_SUSPENDED);
+ SET_STRING(s->active_port, (i->active_port ? i->active_port->name : "none"));
schedule_update();
}
PULSE_ASYNC_RUN(pa_context_set_sink_mute_by_index, idx, mute, pulse_success_cb);
}
+void pulse_sink_set_port(int idx, const char *port)
+{
+ PULSE_ASYNC_RUN(pa_context_set_sink_port_by_index, idx, port, pulse_success_cb);
+}
+
/*** Clients ***/
#define HASH_NODE struct pulse_client
/*
* The Ursary Audio Controls
*
- * (c) 2014 Martin Mares <mj@ucw.cz>
+ * (c) 2014--2018 Martin Mares <mj@ucw.cz>
*/
#undef LOCAL_DEBUG
noct_set_button(ring, 0);
}
+static void update_button_from_port(int button, const char *sink_name, const char *port_name)
+{
+ struct pulse_sink *s = pulse_sink_by_name(sink_name);
+ if (!s)
+ {
+ noct_set_button(button, 0);
+ return;
+ }
+
+ noct_set_button(button, !strcmp(s->active_port, port_name));
+}
+
static void update_sink_from_rotary(int delta, const char *sink_name)
{
struct pulse_sink *s = pulse_sink_by_name(sink_name);
pulse_sink_set_mute(s->idx, !s->mute);
}
+static void update_port_from_button(int on, const char *sink_name, const char *port1, const char *port2)
+{
+ if (!on)
+ return;
+
+ struct pulse_sink *s = pulse_sink_by_name(sink_name);
+ if (!s)
+ return;
+
+ const char *port = port1;
+ if (!strcmp(s->active_port, port1))
+ port = port2;
+
+ DBG("## Setting port of sink %s to %s", s->name, port);
+ pulse_sink_set_port(s->idx, port);
+}
+
/*** Client controls ***/
struct client_map {
// Everything normal
update_ring_from_sink(0, "alsa_output.brum.analog-stereo");
+ update_button_from_port(8, "alsa_output.brum.analog-stereo", "analog-output-headphones");
update_groups();
#if 0
update_default_sink();
case 0:
update_sink_mute_from_button(on, "alsa_output.brum.analog-stereo");
break;
-#if 0
case 8:
+ update_port_from_button(on, "alsa_output.brum.analog-stereo", "analog-output-lineout", "analog-output-headphones");
+ break;
+#if 0
case 9:
case 10:
update_default_sink_from_button(button, on);
uint base_volume;
bool mute;
bool suspended;
+ char *active_port;
};
struct pulse_sink_input {
struct pulse_sink *pulse_sink_by_idx(int idx);
void pulse_sink_set_volume(int idx, pa_cvolume *cvol);
void pulse_sink_set_mute(int idx, bool mute);
+void pulse_sink_set_port(int idx, const char *port);
void pulse_sink_input_set_volume(int idx, pa_cvolume *cvol);
void pulse_sink_input_set_mute(int idx, bool mute);
void pulse_sink_input_move(int input_idx, int sink_idx);