Blob


1 /*
2 * Copyright (c) 2022 Omar Polo <op@openbsd.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 #ifndef AMUSED_H
18 #define AMUSED_H
20 extern char *csock;
21 extern int debug;
22 extern int verbose;
23 extern int playing;
24 extern struct imsgev *iev_player;
26 #define IMSG_DATA_SIZE(imsg) ((imsg).hdr.len - IMSG_HEADER_SIZE)
28 enum imsg_type {
29 IMSG_PLAY, /* fd + filename */
30 IMSG_RESUME,
31 IMSG_PAUSE,
32 IMSG_STOP,
33 IMSG_POS,
34 IMSG_LEN,
35 IMSG_EOF,
36 IMSG_ERR, /* error string */
38 IMSG_CTL_PLAY, /* with optional filename */
39 IMSG_CTL_TOGGLE_PLAY,
40 IMSG_CTL_PAUSE,
41 IMSG_CTL_STOP,
42 IMSG_CTL_RESTART,
43 IMSG_CTL_FLUSH,
44 IMSG_CTL_SHOW,
45 IMSG_CTL_STATUS,
46 IMSG_CTL_NEXT,
47 IMSG_CTL_PREV,
48 IMSG_CTL_JUMP,
49 IMSG_CTL_REPEAT, /* struct player_repeat */
51 IMSG_CTL_BEGIN,
52 IMSG_CTL_ADD, /* path to a file */
53 IMSG_CTL_COMMIT, /* offset of the track to jump to */
55 IMSG_CTL_MONITOR,
57 IMSG_CTL_ERR,
58 IMSG__LAST,
59 };
61 struct imsgev {
62 struct imsgbuf ibuf;
63 void (*handler)(int, short, void *);
64 struct event ev;
65 short events;
66 };
68 enum actions {
69 NONE,
70 PLAY,
71 PAUSE,
72 TOGGLE,
73 STOP,
74 RESTART,
75 ADD,
76 FLUSH,
77 SHOW,
78 STATUS,
79 PREV,
80 NEXT,
81 LOAD,
82 JUMP,
83 REPEAT,
84 MONITOR,
85 };
87 struct ctl_command;
89 struct player_repeat {
90 int repeat_one;
91 int repeat_all;
92 };
94 struct player_status {
95 char path[PATH_MAX];
96 int status;
97 int64_t position;
98 int64_t duration;
99 struct player_repeat rp;
100 };
102 struct parse_result {
103 enum actions action;
104 char **files;
105 const char *file;
106 int pretty;
107 int monitor[IMSG__LAST];
108 struct player_repeat rep;
109 struct ctl_command *ctl;
110 };
112 struct ctl_command {
113 const char *name;
114 enum actions action;
115 int (*main)(struct parse_result *, int, char **);
116 const char *usage;
117 int has_pledge;
118 };
120 struct playlist;
122 /* amused.c */
123 void spawn_daemon(void);
124 void imsg_event_add(struct imsgev *iev);
125 int imsg_compose_event(struct imsgev *, uint16_t, uint32_t,
126 pid_t, int, const void *, uint16_t);
127 int main_send_player(uint16_t, int);
128 int main_play_song(const char *);
129 void main_playlist_jump(struct imsgev *, struct imsg *);
130 void main_playlist_resume(void);
131 void main_playlist_advance(void);
132 void main_playlist_previous(void);
133 void main_restart_track(void);
134 void main_senderr(struct imsgev *, const char *);
135 void main_enqueue(int, struct playlist *, struct imsgev *, struct imsg *);
136 void main_send_playlist(struct imsgev *);
137 void main_send_status(struct imsgev *);
139 /* ctl.c */
140 __dead void usage(void);
141 __dead void ctl(int, char **);
143 /* player.c */
144 int player_setup(int, int, int);
145 void player_setduration(int64_t);
146 int play(const void *, size_t);
147 int player(int, int);
149 int play_oggvorbis(int, const char **);
150 int play_mp3(int, const char **);
151 int play_flac(int, const char **);
152 int play_opus(int, const char **);
154 #endif