Commit 9cfd481d authored by minus's avatar minus

Make siso name match on the end of the name

And thus support mpv
parent 5aa82d41
......@@ -66,7 +66,8 @@ struct siso_watch *siso_add_name(struct siso_watch_list *wl, const char* name) {
struct siso_watch *siso_get(struct siso_watch_list *wl, const char *name) {
for (size_t i = 0; i < wl->len; i++) {
if (strcmp(wl->items[i].name, name) == 0) {
int offset = strlen(name) - strlen(wl->items[i].name);
if (strcmp(wl->items[i].name, name + offset) == 0) {
return &wl->items[i];
}
}
......
......@@ -13,13 +13,20 @@ struct seq_port {
int port;
};
struct show_mute_and_speakers_config {
struct seq_port *sp;
enum button button_mute;
enum button button_speakers;
};
void show_mute_and_speakers(struct siso_watch *w) {
struct seq_port *sp = w->userdata;
midi_button_led(sp->seq, sp->port, TOP1, w->mute ? BUTTON_LED_ON : BUTTON_LED_OFF);
struct show_mute_and_speakers_config *c = w->userdata;
midi_button_led(c->sp->seq, c->sp->port, c->button_mute, w->mute ? BUTTON_LED_ON : BUTTON_LED_OFF);
uint32_t speakers = siso_watch_get_first_or_default(siso_get(&sinks, "speakers"), -1);
midi_button_led(sp->seq, sp->port, BOTTOM1, w->target == speakers ? BUTTON_LED_ON : BUTTON_LED_OFF);
midi_button_led(c->sp->seq, c->sp->port, c->button_speakers,
w->target == speakers ? BUTTON_LED_ON : BUTTON_LED_OFF);
}
void button_mute(enum button button, enum button_direction direction, void *userdata) {
......@@ -61,14 +68,30 @@ int main(int argc, char *argv[]) {
alsa(source, &sp.seq, &sp.port);
struct siso_watch *mpd = siso_add_name(&sink_inputs, "mpd pulse");
mpd->userdata = &sp;
mpd->userdata = &(struct show_mute_and_speakers_config){
.sp = &sp,
.button_mute = TOP1,
.button_speakers = BOTTOM1,
};
mpd->volume_changed = show_mute_and_speakers;
button_callback_add(TOP1, button_mute, mpd);
button_callback_add(BOTTOM1, button_sink, mpd);
encoder_callback_add(ENC1, encoder_volume, mpd);
struct siso_watch *mpv = siso_add_name(&sink_inputs, " - mpv");
mpv->userdata = &(struct show_mute_and_speakers_config){
.sp = &sp,
.button_mute = TOP2,
.button_speakers = BOTTOM2,
};
mpv->volume_changed = show_mute_and_speakers;
button_callback_add(TOP2, button_mute, mpv);
button_callback_add(BOTTOM2, button_sink, mpv);
encoder_callback_add(ENC2, encoder_volume, mpv);
pa();
// create PA watch object for sink name "mpd pulse"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment