Commit 5a66e1d5 authored by minus's avatar minus

Stewdio faving & display

parent 0504b5d3
......@@ -19,6 +19,15 @@ struct show_mute_and_speakers_config {
enum button button_speakers;
};
struct fav_config {
struct seq_port *sp;
enum button button;
char *hash;
bool is_fav;
char *username;
int stdin;
};
void show_mute_and_speakers(struct siso_watch *w) {
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);
......@@ -53,6 +62,36 @@ void encoder_volume(enum encoder encoder, int delta, void *userdata) {
xpa_sink_input_set_volume(w, delta / 100.0f);
}
static gboolean on_fav_info(GIOChannel *source, GIOCondition condition, gpointer data) {
struct fav_config *fc = data;
char *line;
size_t len;
g_io_channel_read_line(source, &line, &len, NULL, NULL);
if (len < 13 || memcmp(line, "playing song", 12) == 0) {
char *hash = strtok(&line[13], " ");
if (fc->hash) free(fc->hash);
fc->hash = strdup(hash);
}
if (len < 20 || memcmp(line, "playing favorite", 16) == 0) {
fc->is_fav = strcmp(&line[17], "true\n") == 0;
midi_button_led(fc->sp->seq, fc->sp->port, fc->button, fc->is_fav ? BUTTON_LED_ON : BUTTON_LED_OFF);
}
g_free(line);
return TRUE;
}
void button_fav(enum button button, enum button_direction direction, void *userdata) {
fprintf(stdout, "button pressed: %i dir=%i\n", button, direction);
if (direction != BUTTON_PRESS) return;
struct fav_config *fc = userdata;
char buf[1024];
const char *verb = fc->is_fav ? "DELETE" : "PUT";
int n = snprintf(buf, sizeof(buf), "%s favorites/%s/%s\n", verb, fc->username, fc->hash);
fwrite(buf, n, 1, stderr);
write(fc->stdin, buf, n);
}
int main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(stderr, "usage: %s CLIENT_ID\n", argv[0]);
......@@ -92,6 +131,29 @@ int main(int argc, char *argv[]) {
button_callback_add(BOTTOM2, button_sink, mpv);
encoder_callback_add(ENC2, encoder_volume, mpv);
gchar *args[] = {"stewdio-textcmd", "https://radio.stew.moe/api/", "minus", NULL};
int child_stdout, child_stdin;
g_autoptr(GError) error = NULL;
g_spawn_async_with_pipes (NULL, args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &child_stdin, &child_stdout, NULL, &error);
if (error != NULL)
{
g_error ("Spawning child failed: %s", error->message);
return -1;
}
struct fav_config fc = {
.sp = &sp,
.button = BOTTOM7,
.username = "minus",
.stdin = child_stdin,
};
GIOChannel *ch = g_io_channel_unix_new(child_stdout);
guint evsrcid = g_io_add_watch(ch, G_IO_IN, &on_fav_info, &fc);
button_callback_add(BOTTOM7, button_fav, &fc);
pa();
GMainLoop *main_loop = g_main_loop_new(NULL, FALSE);
......
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