aboutsummaryrefslogtreecommitdiff
path: root/moc_library.h
diff options
context:
space:
mode:
authorCalvin Morrison <calvin@pobox.com>2026-06-22 14:43:39 -0400
committerCalvin Morrison <calvin@pobox.com>2026-06-22 14:43:39 -0400
commitc7e71230f74415c3f56220d29701780e6f1a9fdd (patch)
tree7f8869fe64d3fd63c06df8ffc76b9ab1b0a58035 /moc_library.h
parentcbc81ba76807acefecaa7cc60853fd7b35853266 (diff)
Add libmoc playback commands and Athena widget UIHEADmaster
Extends moc_library with playlist tracking and thread-safe playback commands (play/pause/stop/next/prev/playlist add/remove/clear), and adds moc_xaw.c, an Athena widget UI with a directory browser and live playlist view. Also taller default window and playlist rendering in moc_x11. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'moc_library.h')
-rw-r--r--moc_library.h39
1 files changed, 37 insertions, 2 deletions
diff --git a/moc_library.h b/moc_library.h
index c545927..d97d8be 100644
--- a/moc_library.h
+++ b/moc_library.h
@@ -25,10 +25,23 @@ enum moc_status {
INITIALIZING,
CONNECTED,
FAILED_TO_CONNECT,
- ERROR
+ ERROR,
+ RECONNECTING
};
-struct moc {
+/* One entry in the server's playlist or queue. A singly-linked list hangs
+ * off struct moc's playlist/queue fields. */
+struct moc_plist_item {
+ char *file;
+ char *title;
+ char *artist;
+ char *album;
+ int track;
+ int time;
+ struct moc_plist_item *next;
+};
+
+struct moc {
pthread_mutex_t lock;
enum moc_status status;
enum moc_state state;
@@ -41,9 +54,31 @@ struct moc {
int time;
int filled;
int length;
+
+ struct moc_plist_item *playlist;
+ struct moc_plist_item *queue;
+
+ /* The background thread owns the actual reads; sock/sock_lock let any
+ * other thread send commands without racing/interleaving with it or with
+ * the background thread's own internal requests. */
+ int sock;
+ pthread_mutex_t sock_lock;
};
extern const char * moc_str_status(enum moc_status s);
extern const char * moc_str_state(enum moc_state s);
extern struct moc * moc_init();
+/* Commands a UI can call from any thread to control playback or modify the
+ * playlist. Safe to call concurrently with each other and with the
+ * background thread; each is a single atomic request to the server. */
+extern void moc_play(struct moc *mh, const char *file);
+extern void moc_pause(struct moc *mh);
+extern void moc_unpause(struct moc *mh);
+extern void moc_stop(struct moc *mh);
+extern void moc_next(struct moc *mh);
+extern void moc_prev(struct moc *mh);
+extern void moc_playlist_add(struct moc *mh, const char *file);
+extern void moc_playlist_remove(struct moc *mh, const char *file);
+extern void moc_playlist_clear(struct moc *mh);
+