2
* The XMMS plugin portion of IMMS
9
#include <xmms/plugin.h>
10
#include <xmms/xmmsctrl.h>
19
#define SPECTRUM_SKIP 0.15
23
static Imms *imms = NULL;
24
unsigned int time_left = 1000, sloppy_skips = 0;
25
int last_plpos = -2, cur_plpos, pl_length = -1;
26
int good_length = 0, song_length = 0, delay = 0;
27
string cur_path = "", last_path = "";
28
bool spectrum_ok = false;
30
// Extern from interface.c
31
extern VisPlugin imms_vp;
32
int &session = imms_vp.xmms_session;
41
void Player::reset_selection() {}
43
// Wrapper that frees memory
44
string imms_get_playlist_item(int at)
46
if (at > pl_length - 1)
50
tmp = xmms_remote_get_playlist_file(session, at);
56
void imms_setup(int use_xidle)
59
imms->setup(use_xidle);
70
void imms_cleanup(void)
76
void imms_spectrum(uint16_t spectrum[256])
78
if (imms && spectrum_ok)
79
imms->integrate_spectrum(spectrum);
86
// make sure shuffle is disabled
87
if (imms && xmms_remote_is_shuffle(session))
88
xmms_remote_toggle_shuffle(session);
90
// update playlist length
91
int new_pl_length = xmms_remote_get_playlist_length(session);
92
if (new_pl_length != pl_length)
94
pl_length = new_pl_length;
95
imms->playlist_changed();
98
// check if xmms is reporting the song length correctly
99
song_length = xmms_remote_get_playlist_time(session, cur_plpos);
100
if (song_length > 1000)
103
// have imms do it's internal processing
109
if (last_plpos == -2)
110
last_plpos = xmms_remote_get_playlist_pos(session) - 1;
112
// if not playing make sure we stopped collecting spectrum statistics
113
if (!xmms_remote_is_playing(session))
115
imms->do_idle_events();
119
// run these checks less frequently so as not to waste cpu time
120
if (++delay > POLL_DELAY || pl_length < 0 || good_length < 3)
123
// do not preemptively end the song if imms is disabled
124
// to allow the built in shuffle/sequential to take effect
125
bool ending = good_length > 2 && time_left == 0;
126
cur_plpos = xmms_remote_get_playlist_pos(session);
128
if (ending || cur_plpos != last_plpos)
130
cur_path = imms_get_playlist_item(cur_plpos);
132
if (ending || last_path != cur_path)
134
xmms_remote_stop(session);
139
last_plpos = cur_plpos;
142
// check the time to catch the end of the song
143
int cur_time = xmms_remote_get_output_time(session);
144
if (cur_time > 1000 || good_length < 3)
145
time_left = (song_length - cur_time) / 500;
147
spectrum_ok = (cur_time > song_length * SPECTRUM_SKIP
148
&& cur_time < song_length * (1 - SPECTRUM_SKIP));
156
cur_plpos = xmms_remote_get_playlist_pos(session);
157
bool forced = (cur_plpos != last_plpos) &&
158
((last_plpos + 1) % pl_length) != cur_plpos;
159
bool back = ((last_plpos + pl_length - 1) % pl_length) == cur_plpos;
160
bool bad = good_length < 3 || song_length <= 30*1000;
162
// notify imms that the previous song has ended
164
imms->end_song(!time_left, forced, bad);
166
if (!forced && pl_length > 2)
168
// have imms select the next song for us
169
cur_plpos = imms->select_next();
173
int previous = imms->get_previous();
175
cur_plpos = previous;
178
cur_path = imms_get_playlist_item(cur_plpos);
179
xmms_remote_set_playlist_pos(session, cur_plpos);
181
// notify imms of the next song
182
imms->start_song(cur_plpos, cur_path);
184
last_path = cur_path;
187
xmms_remote_play(session);