/* * Radio UI: everything that is the same in the window and on the real panel. * The frontends supply a way to show pixels and feed in key presses. */ #ifndef RADIO_APP_H #define RADIO_APP_H #include #include #include #include enum radio_key { RK_ESC, RK_NEXT, RK_STOP, RK_MENU, RK_LIST, RK_UP, RK_PREV, RK_RIGHT, RK_DOWN, RK_PAUSE, RK_OK, RK_LEFT, RK_PLAY, RK_COUNT }; enum play_state { PLAY_UNKNOWN, PLAY_PLAYING, PLAY_PAUSED, PLAY_STOPPED }; #define LOG_ROWS 8 #define LOG_COLS 44 #define TITLE_MAX 512 struct radio_state { bool connected; char server[128]; enum play_state state; char title[TITLE_MAX]; int song_pos; /* -1: none */ unsigned int queue_len; unsigned int elapsed_ms; gint64 elapsed_stamp_us; /* monotonic time elapsed_ms was read */ unsigned int total_ms; /* 0: unknown, e.g. a stream */ int volume; /* -1: unknown */ bool repeat, random; char log[LOG_ROWS][LOG_COLS * 4 + 1]; /* UTF-8, wrapped */ }; /* Current position, advanced locally between MPD updates while playing */ unsigned int radio_state_elapsed_ms(const struct radio_state *s); /* ---- rendering ---------------------------------------------------------- */ void ui_render(cairo_t *cr, const struct radio_state *s, int width, int height); /* ---- app ---------------------------------------------------------------- */ struct app_frontend { void *ctx; /* pixels is the whole frame; (x, y, w, h) bounds what changed */ void (*present)(void *ctx, const uint32_t *pixels, int stride, int x, int y, int w, int h); void (*backlight)(void *ctx, bool on); }; struct app_options { const char *host; unsigned int port; int width, height; bool kmsg; /* show this machine's kernel log */ }; struct app; struct app *app_new(const struct app_options *opt, const struct app_frontend *fe); void app_free(struct app *app); void app_key(struct app *app, enum radio_key key); void app_log(struct app *app, const char *text); /* ---- MPD client --------------------------------------------------------- */ struct mpdc; enum mpdc_command { MPDC_PLAY, MPDC_TOGGLE, MPDC_STOP, MPDC_NEXT, MPDC_PREV, MPDC_VOLUME_UP, MPDC_VOLUME_DOWN, MPDC_REFRESH, }; /* Called on the GLib main loop whenever *state may have changed */ typedef void (*mpdc_changed_fn)(void *user); typedef void (*mpdc_log_fn)(void *user, const char *text); struct mpdc *mpdc_new(const char *host, unsigned int port, struct radio_state *state, mpdc_changed_fn changed, mpdc_log_fn log, void *user); void mpdc_free(struct mpdc *m); void mpdc_command(struct mpdc *m, enum mpdc_command cmd); /* ---- kernel log --------------------------------------------------------- */ struct log_kmsg; struct log_kmsg *log_kmsg_new(mpdc_log_fn log, void *user); void log_kmsg_free(struct log_kmsg *k); #endif /* RADIO_APP_H */