2
* The XMMS plugin portion of IMMS
10
# include <bmp/plugin.h>
11
# include <bmp/beepctrl.h>
13
# include <xmms/plugin.h>
14
# include <xmms/xmmsctrl.h>
20
#include "clientstub.h"
29
unsigned int time_left = 1000, sloppy_skips = 0;
30
int last_plpos = -2, cur_plpos, pl_length = -1;
31
int good_length = 0, song_length = 0, delay = 0, xidle_val = 0;
32
string cur_path = "", last_path = "";
34
// Extern from interface.c
35
extern GeneralPlugin imms_gp;
36
int &session = imms_gp.xmms_session;
45
// Wrapper that frees memory
46
string imms_get_playlist_item(int at)
48
if (at > pl_length - 1)
52
tmp = xmms_remote_get_playlist_file(session, at);
59
typedef IMMSClient<FilterOps> XMMSClient;
64
static void set_next(int next)
68
cur_path = imms_get_playlist_item(cur_plpos);
69
xmms_remote_set_playlist_pos(session, cur_plpos);
71
// notify imms of the next song
73
imms->start_song(cur_plpos, cur_path);
78
xmms_remote_play(session);
80
static void reset_selection() {}
81
static string get_item(int index)
83
return imms_get_playlist_item(index);
85
static int get_length()
87
return (int)xmms_remote_get_playlist_length(session);
94
imms = new XMMSClient();
99
void imms_setup(int use_xidle)
101
xidle_val = use_xidle;
103
imms->setup(use_xidle);
106
void imms_cleanup(void)
112
void do_more_checks()
116
// make sure shuffle is disabled
117
if (imms && xmms_remote_is_shuffle(session))
118
xmms_remote_toggle_shuffle(session);
120
// update playlist length
121
int new_pl_length = xmms_remote_get_playlist_length(session);
122
if (new_pl_length != pl_length)
124
pl_length = new_pl_length;
125
imms->playlist_changed(pl_length);
128
// check if xmms is reporting the song length correctly
129
song_length = xmms_remote_get_playlist_time(session, cur_plpos);
130
if (song_length > 1000)
136
if (imms->check_connection() || last_plpos == -2)
138
imms->setup(xidle_val);
139
imms->playlist_changed(pl_length
140
= xmms_remote_get_playlist_length(session));
141
last_plpos = xmms_remote_get_playlist_pos(session);
142
if (xmms_remote_is_playing(session))
144
cur_plpos = last_plpos;
145
last_path = cur_path = imms_get_playlist_item(cur_plpos);
146
imms->start_song(cur_plpos, cur_path);
150
if (!xmms_remote_is_playing(session))
153
// run these checks less frequently so as not to waste cpu time
154
if (++delay > POLL_DELAY || pl_length < 0 || good_length < 3)
157
// do not preemptively end the song if imms is disabled
158
// to allow the built in shuffle/sequential to take effect
159
bool ending = good_length > 2 && time_left == 0;
160
cur_plpos = xmms_remote_get_playlist_pos(session);
162
if (ending || cur_plpos != last_plpos)
164
cur_path = imms_get_playlist_item(cur_plpos);
166
if (ending || last_path != cur_path)
168
xmms_remote_stop(session);
173
last_plpos = cur_plpos;
176
// check the time to catch the end of the song
177
int cur_time = xmms_remote_get_output_time(session);
178
if (cur_time > 1000 || good_length < 3)
179
time_left = (song_length - cur_time) / 500;
187
cur_plpos = xmms_remote_get_playlist_pos(session);
188
bool forced = (cur_plpos != last_plpos) &&
189
((last_plpos + 1) % pl_length) != cur_plpos;
190
bool bad = good_length < 3 || song_length <= 30*1000;
192
// notify imms that the previous song has ended
194
imms->end_song(!time_left, forced, bad);
196
if (!forced && pl_length > 2)
200
last_plpos = cur_plpos = xmms_remote_get_playlist_pos(session);
201
last_path = cur_path = imms_get_playlist_item(cur_plpos);
202
xmms_remote_play(session);
203
imms->start_song(cur_plpos, cur_path);