Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/dll/xmms/xmms.c
1072 views
1
#if !defined(WINNT) && !defined(EMX)
2
/*
3
* xmms.c: This file handles all the XMMS routines, in BitchX
4
*
5
* Written by Andr� Camargo
6
* based on the code of Tom Zickel a.k.a. IceBreak on the IRC
7
* and Peter Alm, Mikael Alm, Olle Hallnas, Thomas Nilsson and
8
* 4Front Technologies
9
*
10
* Copyleft (1999) "CASSIUS IN THE HOUSE!" :)
11
*
12
* BitchX plugin v0.01 by DavidW2
13
* BitchX plugin v1.00 by caf
14
*/
15
16
#include "irc.h"
17
#include "struct.h"
18
#include "server.h"
19
#include "ircaux.h"
20
#include "output.h"
21
#include "misc.h"
22
#include "vars.h"
23
#include "status.h"
24
#include "hook.h"
25
#include "module.h"
26
#include "ctcp.h"
27
#ifndef INIT_MODULE
28
#define INIT_MODULE
29
#endif
30
#include "modval.h"
31
32
#include <xmms/xmmsctrl.h>
33
34
#define MODULE_NAME "Xmms"
35
#define _MODULE_VERSION "1.00"
36
37
static int check_xmms(void);
38
39
static char xmms_format[] = "%K[%G" MODULE_NAME " %g" _MODULE_VERSION
40
"%K] %n$*";
41
static char xmms_format2[] = "%K[%G" MODULE_NAME " %g" _MODULE_VERSION
42
" %K|%B $0 %K] %n$1-";
43
static char xmms_format_vol[] = "%K[%G" MODULE_NAME " %g" _MODULE_VERSION
44
" %K|%B $0 %K|%W$[10]1%K] %n$2%%";
45
static char xmms_format_track[] = "%K[%G" MODULE_NAME " %g" _MODULE_VERSION
46
" %K|%B $0 %K|%W$[-4]1%n/%W$[-4]2%K] %n$3-";
47
48
static char xmms_volbar[] = "==========";
49
#define VOLBAR(n) ((n)>9?(xmms_volbar + 10 - (n)/10):".")
50
51
static int xmms_session = 0;
52
53
BUILT_IN_DLL(xmms_cmd)
54
{
55
char *arg;
56
arg = next_arg(args, &args);
57
58
if (!arg)
59
arg = "HELP";
60
61
if (*arg == '-' || *arg == '/')
62
arg++;
63
64
if (!my_stricmp(arg, "PLAY"))
65
{
66
if (check_xmms())
67
{
68
if ((arg = next_arg(args, &args)))
69
if (atoi(arg) < xmms_remote_get_playlist_length(xmms_session))
70
xmms_remote_set_playlist_pos(xmms_session, atoi(args));
71
xmms_remote_play(xmms_session);
72
}
73
}
74
else if (!my_stricmp(arg, "PAUSE"))
75
{
76
if (check_xmms())
77
{
78
if (!xmms_remote_is_paused(xmms_session))
79
xmms_remote_pause(xmms_session);
80
}
81
}
82
else if (!my_stricmp(arg, "NEXT"))
83
{
84
if (check_xmms())
85
xmms_remote_playlist_next(xmms_session);
86
}
87
else if (!my_stricmp(arg, "PREV"))
88
{
89
if (check_xmms())
90
xmms_remote_playlist_prev(xmms_session);
91
}
92
else if (!my_stricmp(arg, "STOP"))
93
{
94
if (check_xmms())
95
xmms_remote_stop(xmms_session);
96
}
97
else if (!my_stricmp(arg, "LIST"))
98
{
99
int i;
100
101
if (check_xmms())
102
{
103
char *title;
104
int pl_len = xmms_remote_get_playlist_length(xmms_session);
105
for (i = 0; i < pl_len; i++) {
106
title = xmms_remote_get_playlist_title(xmms_session, i);
107
put_it("%s", convert_output_format(xmms_format_track,
108
"playlist %d %d %s", i + 1, pl_len, title));
109
}
110
}
111
}
112
else if (!my_stricmp(arg, "VOL"))
113
{
114
int v;
115
116
if (check_xmms())
117
{
118
if ((arg = next_arg(args, &args)))
119
{
120
v = atoi(arg);
121
if (v > 100)
122
v = 100;
123
if (v < 0)
124
v = 0;
125
xmms_remote_set_main_volume(xmms_session, v);
126
} else {
127
v = xmms_remote_get_main_volume(xmms_session);
128
}
129
put_it("%s", convert_output_format(xmms_format_vol,
130
"volume %s %d", VOLBAR(v), v));
131
}
132
}
133
else if (!my_stricmp(arg, "VOLUP"))
134
{
135
int vol;
136
if (check_xmms())
137
{
138
vol = xmms_remote_get_main_volume(xmms_session) + 10;
139
if (vol > 100)
140
vol = 100;
141
xmms_remote_set_main_volume(xmms_session, vol);
142
put_it("%s", convert_output_format(xmms_format_vol,
143
"volume %s %d", VOLBAR(vol), vol));
144
}
145
}
146
else if (!my_stricmp(arg, "VOLDOWN"))
147
{
148
int vol;
149
if (check_xmms())
150
{
151
vol = xmms_remote_get_main_volume(xmms_session) - 10;
152
if (vol < 0)
153
vol = 0;
154
xmms_remote_set_main_volume(xmms_session, vol);
155
put_it("%s", convert_output_format(xmms_format_vol,
156
"volume %s %d", VOLBAR(vol), vol));
157
}
158
}
159
else if (!my_stricmp(arg, "BALANCE"))
160
{
161
int bal;
162
arg = next_arg(args, &args);
163
164
if (arg && check_xmms()) {
165
bal = atoi(arg);
166
if (bal > 100)
167
bal = 100;
168
if (bal < -100)
169
bal = -100;
170
xmms_remote_set_balance(xmms_session, bal);
171
}
172
}
173
else if (!my_stricmp(arg, "TOGSHUFFLE"))
174
{
175
if (check_xmms())
176
xmms_remote_toggle_shuffle(xmms_session);
177
}
178
else if (!my_stricmp(arg, "TOGREPEAT"))
179
{
180
if (check_xmms())
181
xmms_remote_toggle_repeat(xmms_session);
182
}
183
else if (!my_stricmp(arg, "HELP"))
184
{
185
put_it("%s", convert_output_format(xmms_format, "%s",
186
"Usage: /XMMS <command>"));
187
put_it(" - PLAY Play a song");
188
put_it(" - PAUSE Pause/resume the playing song");
189
put_it(" - STOP Stop the playing song");
190
put_it(" - NEXT Scream to XMMS: next song!");
191
put_it(" - PREV "
192
"Change to previous song in XMMS playlist");
193
put_it(" - VOL "
194
"Set's the XMMS Volume (range from 0%% to 100%%)");
195
put_it(" - VOLUP Increase volume +10");
196
put_it(" - VOLDOWN Decrease volume -10");
197
put_it(" - BALANCE "
198
"Set balance, -100 (full left) to 100 (full right)");
199
put_it(" - TOGREPEAT Toggle repeat");
200
put_it(" - TOGSHUFFLE Toggle shuffle");
201
put_it(" - LIST Show XMMS playlist songs");
202
put_it(" - INFO "
203
"Show what song is selected in the playlist");
204
put_it(" - INFOCHANNEL "
205
"Spam the current channel with the song you're "
206
"listening to");
207
put_it(" - SETTIME "
208
"Jump to position in song (percentage)");
209
put_it(" - QUIT Close XMMS");
210
}
211
else if (!my_stricmp(arg, "INFO"))
212
{
213
char *title;
214
int pl_len, pl_pos;
215
216
if (check_xmms()) {
217
pl_len = xmms_remote_get_playlist_length(xmms_session);
218
if (pl_len) {
219
pl_pos = xmms_remote_get_playlist_pos(xmms_session);
220
title = xmms_remote_get_playlist_title(xmms_session, pl_pos);
221
put_it("%s", convert_output_format(xmms_format_track,
222
"track %d %d %s", pl_pos + 1, pl_len,
223
title));
224
} else {
225
put_it("%s", convert_output_format(xmms_format2,
226
"track (playlist empty)"));
227
}
228
}
229
}
230
else if (!my_stricmp(arg, "QUIT"))
231
{
232
if (check_xmms())
233
xmms_remote_quit(xmms_session);
234
}
235
else if (!my_stricmp(arg, "SETTIME"))
236
{
237
int pl_pos;
238
int full_time;
239
int set_time;
240
arg = next_arg(args, &args);
241
242
if (arg && check_xmms())
243
{
244
pl_pos = xmms_remote_get_playlist_pos(xmms_session);
245
full_time = xmms_remote_get_playlist_time(xmms_session,
246
pl_pos);
247
set_time = atoi(arg);
248
if (set_time < 0)
249
set_time = 0;
250
if (set_time > 100)
251
set_time = 100;
252
253
xmms_remote_jump_to_time(xmms_session,
254
set_time * full_time / 100);
255
}
256
}
257
else if (!my_stricmp(arg, "INFOCHANNEL"))
258
{
259
if (check_xmms())
260
{
261
char *target;
262
char *title;
263
int pl_pos = xmms_remote_get_playlist_pos(xmms_session);
264
int pl_len = xmms_remote_get_playlist_length(xmms_session);
265
target = get_current_channel_by_refnum(0);
266
if (pl_len && target)
267
{
268
char message[512];
269
char putbuf[IRCD_BUFFER_SIZE];
270
271
title = xmms_remote_get_playlist_title(xmms_session, pl_pos);
272
sprintf(message,
273
"[XMMS Playing: %s]",
274
title);
275
276
set_display_target(target, LOG_ACTION);
277
278
do_hook(SEND_CTCP_LIST, "PRIVMSG %s ACTION %s",
279
target, message);
280
sprintf(putbuf, "%cACTION %s%c",
281
CTCP_DELIM_CHAR, message,
282
CTCP_DELIM_CHAR);
283
send_text(target, putbuf, "PRIVMSG", 0, 0);
284
285
if (do_hook(SEND_ACTION_LIST, "%s %s", target, message))
286
{
287
if (strchr("&#", *target))
288
put_it("%s", convert_output_format(fget_string_var(FORMAT_SEND_ACTION_FSET), "%s %s %s %s", update_clock(GET_TIME), get_server_nickname(from_server), target, message));
289
else
290
put_it("%s", convert_output_format(fget_string_var(FORMAT_SEND_ACTION_OTHER_FSET), "%s %s %s %s", update_clock(GET_TIME), get_server_nickname(from_server), target, message));
291
}
292
reset_display_target();
293
}
294
}
295
}
296
}
297
298
static int check_xmms(void)
299
{
300
int xmms_running = xmms_remote_is_running(xmms_session);
301
302
if (!xmms_running)
303
{
304
put_it("%s", convert_output_format(xmms_format, "%s",
305
"Could not find a running instance of XMMS."));
306
}
307
return xmms_running;
308
}
309
310
int Xmms_Cleanup(IrcCommandDll **interp, Function_ptr *global_table)
311
{
312
remove_module_proc(COMMAND_PROC, MODULE_NAME, NULL, NULL);
313
put_it("%s", convert_output_format(xmms_format, "%s",
314
"by Andr� Camargo, DavidW2 and caf unloaded."));
315
return 2;
316
}
317
318
int Xmms_Init(IrcCommandDll **interp, Function_ptr *global_table)
319
{
320
initialize_module(MODULE_NAME);
321
add_module_proc(COMMAND_PROC, "Xmms", "Xmms", NULL, 0, 0, xmms_cmd, empty_string);
322
put_it("%s", convert_output_format(xmms_format, "%s",
323
"by Andr� Camargo, DavidW2 and caf loaded. "
324
"Type /XMMS for command help."));
325
return 0;
326
}
327
#endif
328
329