Cleanup dbindex.c a bit.
[playerz] / audio-cmd.c
1 /* audio-cmd.c: Sends commands to music player.
2
3    Copyright (C) 2019 Michael Zucchi
4
5    This program is free software: you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation, either version 3 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program. If not, see
17    <http://www.gnu.org/licenses/>.
18 */
19
20 #include <string.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <stdint.h>
24
25 #include "dbindex.h"
26 #include "notify.h"
27
28 int main(int argc, char **argv) {
29         if (argc > 1) {
30                 char *cmd = argv[1];
31                 notify_t player = notify_writer_new(NOTIFY_PLAYER);
32
33                 if (strcmp(cmd, "pause") == 0)
34                         notify_msg_send(player, NOTIFY_PLAY_PAUSE, 1, NULL);
35                 else if (strcmp(cmd, "play") == 0)
36                         notify_msg_send(player, NOTIFY_PLAY_PLAY, 0, NULL);
37                 else if (strcmp(cmd, "seek") == 0 || strcmp(cmd, "skip") == 0) {
38                         if (argc == 3) {
39                                 struct notify_play_seek msg;
40
41                                 msg.mode = strcmp(cmd, "skip") == 0;
42                                 msg.stamp = strtod(argv[2], NULL);
43
44                                 notify_msg_send(player, NOTIFY_PLAY_SEEK, 0, &msg);
45                         }
46                 } else if (strcmp(cmd, "next") == 0) {
47                         notify_msg_send(player, NOTIFY_PLAY_NEXT, 0, NULL);
48                 } else if (strcmp(cmd, "prev") == 0) {
49                         notify_msg_send(player, NOTIFY_PLAY_PREV, 0, NULL);
50                 } else if (strcmp(cmd, "goto") == 0) {
51                         if (argc == 4) {
52                                 struct notify_goto msg = {
53                                         .info.listid = atoi(argv[2]),
54                                         .info.fileid = atoi(argv[3])
55                                 };
56                                 notify_msg_send(player, NOTIFY_PLAY_GOTO, 0, &msg);
57                         }
58                 } else if (strcmp(cmd, "playnow") == 0) {
59                         if (argc == 3) {
60                                 struct notify_goto msg = {
61                                         .info.fileid = atoi(argv[2])
62                                 };
63                                 notify_msg_send(player, NOTIFY_PLAY_NOW, 0, &msg);
64                         }
65                 } else if (strcmp(cmd, "enqueue") == 0) {
66                         if (argc == 3) {
67                                 struct notify_goto msg = {
68                                         .info.fileid = atoi(argv[2])
69                                 };
70                                 notify_msg_send(player, NOTIFY_PLAY_ENQUEUE, 0, &msg);
71                         }
72                 } else if (strcmp(cmd, "vol+") == 0) {
73                         notify_msg_send(player, NOTIFY_VOLUME_UP, 0, NULL);
74                 } else if (strcmp(cmd, "vol-") == 0) {
75                         notify_msg_send(player, NOTIFY_VOLUME_DOWN, 0, NULL);
76                 } else if (strcmp(cmd, "mute") == 0) {
77                         notify_msg_send(player, NOTIFY_VOLUME_MUTE, 0, NULL);
78                 } else if (strcmp(cmd, "quit") == 0) {
79                         notify_msg_send(player, NOTIFY_QUIT, 0, NULL);
80                 } else if (strcmp(cmd, "debug") == 0) {
81                         if (argc == 3) {
82                                 struct notify_debug msg;
83
84                                 msg.func = atoi(argv[2]);
85
86                                 notify_msg_send(player, NOTIFY_DEBUG, 0, &msg);
87                         }
88                 }
89
90                 notify_close(player);
91
92         }
93 }