1 |
< |
// Beep Remote |
1 |
> |
// Display (Crystalfontz CFA-635 USB LCD) |
2 |
|
// |
3 |
|
// Douglas Thrift |
4 |
|
// |
5 |
|
// $Id$ |
6 |
|
|
7 |
< |
#include <cxx/standard.hh> |
7 |
> |
#include <iostream> |
8 |
|
|
9 |
< |
#include <audacious/beepctrl.h> |
9 |
> |
#include <fcntl.h> |
10 |
> |
#include <termios.h> |
11 |
|
|
12 |
< |
#include "Audacious.hpp" |
12 |
> |
#include "Display.hpp" |
13 |
|
|
14 |
< |
void Audacious::Playlist(char **list, int size, bool enqueue) |
14 |
> |
static uint16_t GetCRC(uint8_t *buffer, size_t length) |
15 |
|
{ |
16 |
< |
::xmms_remote_playlist(session, list, size, enqueue); |
17 |
< |
} |
18 |
< |
|
19 |
< |
int Audacious::GetVersion() const |
20 |
< |
{ |
21 |
< |
return ::xmms_remote_get_version(session); |
22 |
< |
} |
23 |
< |
|
24 |
< |
void Audacious::PlaylistAdd(::GList *list) |
25 |
< |
{ |
26 |
< |
::xmms_remote_playlist_add(session, list); |
27 |
< |
} |
28 |
< |
|
29 |
< |
void Audacious::PlaylistDelete(int position) |
30 |
< |
{ |
31 |
< |
::xmms_remote_playlist_delete(session, position); |
32 |
< |
} |
33 |
< |
|
34 |
< |
void Audacious::Play() |
35 |
< |
{ |
36 |
< |
::xmms_remote_play(session); |
37 |
< |
} |
38 |
< |
|
39 |
< |
void Audacious::Pause() |
40 |
< |
{ |
41 |
< |
::xmms_remote_pause(session); |
42 |
< |
} |
43 |
< |
|
44 |
< |
void Audacious::Stop() |
45 |
< |
{ |
46 |
< |
::xmms_remote_stop(session); |
47 |
< |
} |
48 |
< |
|
49 |
< |
bool Audacious::IsPlaying() const |
50 |
< |
{ |
50 |
< |
return ::xmms_remote_is_playing(session); |
51 |
< |
} |
52 |
< |
|
53 |
< |
bool Audacious::IsPaused() const |
54 |
< |
{ |
55 |
< |
return ::xmms_remote_is_paused(session); |
56 |
< |
} |
57 |
< |
|
58 |
< |
int Audacious::GetPlaylistPosition() const |
59 |
< |
{ |
60 |
< |
return ::xmms_remote_get_playlist_pos(session); |
61 |
< |
} |
62 |
< |
|
63 |
< |
void Audacious::SetPlaylistPosition(int position) |
64 |
< |
{ |
65 |
< |
::xmms_remote_set_playlist_pos(session, position); |
66 |
< |
} |
67 |
< |
|
68 |
< |
int Audacious::GetPlaylistLength() const |
69 |
< |
{ |
70 |
< |
return ::xmms_remote_get_playlist_length(session); |
71 |
< |
} |
72 |
< |
|
73 |
< |
void Audacious::PlaylistClear() |
74 |
< |
{ |
75 |
< |
return ::xmms_remote_playlist_clear(session); |
76 |
< |
} |
77 |
< |
|
78 |
< |
int Audacious::GetOutputTime() const |
79 |
< |
{ |
80 |
< |
return ::xmms_remote_get_output_time(session); |
81 |
< |
} |
82 |
< |
|
83 |
< |
void Audacious::JumpToTime(int position) |
84 |
< |
{ |
85 |
< |
::xmms_remote_jump_to_time(session, position); |
86 |
< |
} |
87 |
< |
|
88 |
< |
void Audacious::GetVolume(int& left, int& right) const |
89 |
< |
{ |
90 |
< |
::xmms_remote_get_volume(session, &left, &right); |
91 |
< |
} |
16 |
> |
static const uint16_t table[256] = { |
17 |
> |
0x00000,0x01189,0x02312,0x0329B,0x04624,0x057AD,0x06536,0x074BF, |
18 |
> |
0x08C48,0x09DC1,0x0AF5A,0x0BED3,0x0CA6C,0x0DBE5,0x0E97E,0x0F8F7, |
19 |
> |
0x01081,0x00108,0x03393,0x0221A,0x056A5,0x0472C,0x075B7,0x0643E, |
20 |
> |
0x09CC9,0x08D40,0x0BFDB,0x0AE52,0x0DAED,0x0CB64,0x0F9FF,0x0E876, |
21 |
> |
0x02102,0x0308B,0x00210,0x01399,0x06726,0x076AF,0x04434,0x055BD, |
22 |
> |
0x0AD4A,0x0BCC3,0x08E58,0x09FD1,0x0EB6E,0x0FAE7,0x0C87C,0x0D9F5, |
23 |
> |
0x03183,0x0200A,0x01291,0x00318,0x077A7,0x0662E,0x054B5,0x0453C, |
24 |
> |
0x0BDCB,0x0AC42,0x09ED9,0x08F50,0x0FBEF,0x0EA66,0x0D8FD,0x0C974, |
25 |
> |
0x04204,0x0538D,0x06116,0x0709F,0x00420,0x015A9,0x02732,0x036BB, |
26 |
> |
0x0CE4C,0x0DFC5,0x0ED5E,0x0FCD7,0x08868,0x099E1,0x0AB7A,0x0BAF3, |
27 |
> |
0x05285,0x0430C,0x07197,0x0601E,0x014A1,0x00528,0x037B3,0x0263A, |
28 |
> |
0x0DECD,0x0CF44,0x0FDDF,0x0EC56,0x098E9,0x08960,0x0BBFB,0x0AA72, |
29 |
> |
0x06306,0x0728F,0x04014,0x0519D,0x02522,0x034AB,0x00630,0x017B9, |
30 |
> |
0x0EF4E,0x0FEC7,0x0CC5C,0x0DDD5,0x0A96A,0x0B8E3,0x08A78,0x09BF1, |
31 |
> |
0x07387,0x0620E,0x05095,0x0411C,0x035A3,0x0242A,0x016B1,0x00738, |
32 |
> |
0x0FFCF,0x0EE46,0x0DCDD,0x0CD54,0x0B9EB,0x0A862,0x09AF9,0x08B70, |
33 |
> |
0x08408,0x09581,0x0A71A,0x0B693,0x0C22C,0x0D3A5,0x0E13E,0x0F0B7, |
34 |
> |
0x00840,0x019C9,0x02B52,0x03ADB,0x04E64,0x05FED,0x06D76,0x07CFF, |
35 |
> |
0x09489,0x08500,0x0B79B,0x0A612,0x0D2AD,0x0C324,0x0F1BF,0x0E036, |
36 |
> |
0x018C1,0x00948,0x03BD3,0x02A5A,0x05EE5,0x04F6C,0x07DF7,0x06C7E, |
37 |
> |
0x0A50A,0x0B483,0x08618,0x09791,0x0E32E,0x0F2A7,0x0C03C,0x0D1B5, |
38 |
> |
0x02942,0x038CB,0x00A50,0x01BD9,0x06F66,0x07EEF,0x04C74,0x05DFD, |
39 |
> |
0x0B58B,0x0A402,0x09699,0x08710,0x0F3AF,0x0E226,0x0D0BD,0x0C134, |
40 |
> |
0x039C3,0x0284A,0x01AD1,0x00B58,0x07FE7,0x06E6E,0x05CF5,0x04D7C, |
41 |
> |
0x0C60C,0x0D785,0x0E51E,0x0F497,0x08028,0x091A1,0x0A33A,0x0B2B3, |
42 |
> |
0x04A44,0x05BCD,0x06956,0x078DF,0x00C60,0x01DE9,0x02F72,0x03EFB, |
43 |
> |
0x0D68D,0x0C704,0x0F59F,0x0E416,0x090A9,0x08120,0x0B3BB,0x0A232, |
44 |
> |
0x05AC5,0x04B4C,0x079D7,0x0685E,0x01CE1,0x00D68,0x03FF3,0x02E7A, |
45 |
> |
0x0E70E,0x0F687,0x0C41C,0x0D595,0x0A12A,0x0B0A3,0x08238,0x093B1, |
46 |
> |
0x06B46,0x07ACF,0x04854,0x059DD,0x02D62,0x03CEB,0x00E70,0x01FF9, |
47 |
> |
0x0F78F,0x0E606,0x0D49D,0x0C514,0x0B1AB,0x0A022,0x092B9,0x08330, |
48 |
> |
0x07BC7,0x06A4E,0x058D5,0x0495C,0x03DE3,0x02C6A,0x01EF1,0x00F78, |
49 |
> |
}; |
50 |
> |
register uint16_t crc(0xffff); |
51 |
|
|
52 |
< |
int Audacious::GetMainVolume() const |
53 |
< |
{ |
95 |
< |
return ::xmms_remote_get_main_volume(session); |
96 |
< |
} |
52 |
> |
while (length--) |
53 |
> |
crc = (crc >> 8) ^ table[(crc ^ *buffer++) & 0xff]; |
54 |
|
|
55 |
< |
int Audacious::GetBalance() const |
99 |
< |
{ |
100 |
< |
return ::xmms_remote_get_balance(session); |
55 |
> |
return ~crc; |
56 |
|
} |
57 |
|
|
58 |
< |
void Audacious::SetVolume(int left, int right) |
58 |
> |
Display::Packet::Packet(Display::Packet::Command command, const std::string &data) : command(command), length(data.size()) |
59 |
|
{ |
60 |
< |
::xmms_remote_set_volume(session, left, right); |
61 |
< |
} |
60 |
> |
if (length > sizeof (this->data)) |
61 |
> |
throw; |
62 |
|
|
63 |
< |
void Audacious::SetMainVolume(int volume) |
109 |
< |
{ |
110 |
< |
::xmms_remote_set_main_volume(session, volume); |
111 |
< |
} |
63 |
> |
::memcpy(this->data, data.data(), length); |
64 |
|
|
65 |
< |
void Audacious::SetBalance(int balance) |
114 |
< |
{ |
115 |
< |
::xmms_remote_set_balance(session, balance); |
65 |
> |
crc = GetCRC(reinterpret_cast<uint8_t *>(this), length + 2); |
66 |
|
} |
67 |
|
|
68 |
< |
cse::String Audacious::GetSkin() const |
68 |
> |
void operator<<(int fd, const Display::Packet::Packet &packet) |
69 |
|
{ |
70 |
< |
return ::xmms_remote_get_skin(session); |
71 |
< |
} |
70 |
> |
if (packet.length != sizeof (packet.data)) |
71 |
> |
::memcpy(const_cast<uint8_t *>(packet.data) + packet.length, &packet.crc, 2); |
72 |
|
|
73 |
< |
void Audacious::SetSkin(const cse::String &skin) |
124 |
< |
{ |
125 |
< |
::xmms_remote_set_skin(session, const_cast<char*>(skin.NullTerminate())); |
73 |
> |
Posix::Write(fd, &packet, packet.length + 4); |
74 |
|
} |
75 |
|
|
76 |
< |
cse::String Audacious::GetPlaylistFile(int position) const |
76 |
> |
void operator>>(int fd, Display::Packet::Packet &packet) |
77 |
|
{ |
78 |
< |
return ::xmms_remote_get_playlist_file(session, position); |
79 |
< |
} |
78 |
> |
Posix::Read(fd, &packet, 2); |
79 |
> |
Posix::Read(fd, packet.data, packet.length); |
80 |
> |
Posix::Read(fd, &packet.crc, 2); |
81 |
|
|
82 |
< |
cse::String Audacious::GetPlaylistTitle(int position) const |
134 |
< |
{ |
135 |
< |
return ::xmms_remote_get_playlist_title(session, position); |
136 |
< |
} |
82 |
> |
std::printf("0x%02x\n%i\n", packet.command, packet.length); |
83 |
|
|
84 |
< |
int Audacious::GetPlaylistTime(int position) const |
139 |
< |
{ |
140 |
< |
return ::xmms_remote_get_playlist_time(session, position); |
84 |
> |
std::cout << '[' << std::string((char*)(packet.data), size_t(packet.length)) << ']' << std::endl; |
85 |
|
} |
86 |
|
|
87 |
< |
void Audacious::GetInfo(int &rate, int &frequency, int &channels) const |
87 |
> |
Display::Display(const std::string &device) : ucom(Posix::Open(device, O_RDWR | O_NOCTTY)) |
88 |
|
{ |
89 |
< |
::xmms_remote_get_info(session, &rate, &frequency, &channels); |
146 |
< |
} |
89 |
> |
::termios state; |
90 |
|
|
91 |
< |
void Audacious::MainWindowToggle(bool show) |
92 |
< |
{ |
93 |
< |
::xmms_remote_main_win_toggle(session, show); |
151 |
< |
} |
91 |
> |
Posix::CheckError(::tcgetattr(ucom, &state)); |
92 |
> |
Posix::CheckError(::cfsetospeed(&state, B115200)); |
93 |
> |
Posix::CheckError(::cfsetispeed(&state, B115200)); |
94 |
|
|
95 |
< |
void Audacious::PlaylistWindowToggle(bool show) |
96 |
< |
{ |
97 |
< |
::xmms_remote_pl_win_toggle(session, show); |
98 |
< |
} |
95 |
> |
state.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | INPCK | ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF); |
96 |
> |
state.c_iflag |= IGNPAR; |
97 |
> |
state.c_oflag &= ~(OPOST | ONLCR | ONOCR | ONLRET); |
98 |
> |
state.c_cflag &= ~(CSIZE | PARENB | PARODD | HUPCL | CRTSCTS); |
99 |
> |
state.c_cflag |= CREAD | CS8 | CSTOPB | CLOCAL; |
100 |
> |
state.c_lflag &= ~(ISIG | ICANON | IEXTEN | ECHO); |
101 |
> |
state.c_lflag |= NOFLSH; |
102 |
|
|
103 |
< |
void Audacious::EqualizerWindowToggle(bool show) |
159 |
< |
{ |
160 |
< |
::xmms_remote_eq_win_toggle(session, show); |
103 |
> |
Posix::CheckError(::tcsetattr(ucom, TCSANOW, &state)); |
104 |
|
} |
105 |
|
|
106 |
< |
bool Audacious::IsMainWindow() const |
106 |
> |
bool Display::Ping(const std::string &data) |
107 |
|
{ |
108 |
< |
return ::xmms_remote_is_main_win(session); |
166 |
< |
} |
108 |
> |
Packet packet(Packet::PingCommand, data), response; |
109 |
|
|
110 |
< |
bool Audacious::IsPlaylistWindow() const |
169 |
< |
{ |
170 |
< |
return ::xmms_remote_is_pl_win(session); |
171 |
< |
} |
110 |
> |
ucom << packet; |
111 |
|
|
112 |
< |
bool Audacious::IsEqualizerWindow() const |
113 |
< |
{ |
114 |
< |
return ::xmms_remote_is_eq_win(session); |
115 |
< |
} |
116 |
< |
|
178 |
< |
void Audacious::ShowPreferencesBox() |
179 |
< |
{ |
180 |
< |
::xmms_remote_show_prefs_box(session); |
181 |
< |
} |
182 |
< |
|
183 |
< |
void Audacious::ToggleAlwaysOnTop(bool always) |
184 |
< |
{ |
185 |
< |
::xmms_remote_toggle_aot(session, always); |
186 |
< |
} |
187 |
< |
|
188 |
< |
void Audacious::Eject() |
189 |
< |
{ |
190 |
< |
::xmms_remote_eject(session); |
191 |
< |
} |
112 |
> |
do |
113 |
> |
{ |
114 |
> |
ucom >> response; |
115 |
> |
} |
116 |
> |
while (packet.command | Packet::Response != response.command); |
117 |
|
|
118 |
< |
void Audacious::PlaylistPrevious() |
194 |
< |
{ |
195 |
< |
::xmms_remote_playlist_prev(session); |
196 |
< |
} |
197 |
< |
|
198 |
< |
void Audacious::PlaylistNext() |
199 |
< |
{ |
200 |
< |
::xmms_remote_playlist_next(session); |
201 |
< |
} |
202 |
< |
|
203 |
< |
void Audacious::PlaylistAddUrl(const cse::String &url) |
204 |
< |
{ |
205 |
< |
::xmms_remote_playlist_add_url_string(session, const_cast<char*>(url.NullTerminate())); |
206 |
< |
} |
207 |
< |
|
208 |
< |
bool Audacious::IsRunning() const |
209 |
< |
{ |
210 |
< |
return ::xmms_remote_is_running(session); |
211 |
< |
} |
212 |
< |
|
213 |
< |
void Audacious::ToggleRepeat() |
214 |
< |
{ |
215 |
< |
::xmms_remote_toggle_repeat(session); |
216 |
< |
} |
217 |
< |
|
218 |
< |
void Audacious::ToggleShuffle() |
219 |
< |
{ |
220 |
< |
::xmms_remote_toggle_shuffle(session); |
221 |
< |
} |
222 |
< |
|
223 |
< |
bool Audacious::IsRepeat() const |
224 |
< |
{ |
225 |
< |
return ::xmms_remote_is_repeat(session); |
226 |
< |
} |
227 |
< |
|
228 |
< |
bool Audacious::IsShuffle() const |
229 |
< |
{ |
230 |
< |
return ::xmms_remote_is_shuffle(session); |
231 |
< |
} |
232 |
< |
|
233 |
< |
void Audacious::GetEqualizer(float& preamp, float bands[10]) const |
234 |
< |
{ |
235 |
< |
float* bands_; |
236 |
< |
|
237 |
< |
::xmms_remote_get_eq(session, &preamp, &bands_); |
238 |
< |
|
239 |
< |
_forall (uint8_t, index, 0, 10) |
240 |
< |
bands[index] = bands[index]; |
241 |
< |
|
242 |
< |
::g_free(bands_); |
243 |
< |
} |
244 |
< |
|
245 |
< |
float Audacious::GetEqualizerPreamp() const |
246 |
< |
{ |
247 |
< |
return ::xmms_remote_get_eq_preamp(session); |
248 |
< |
} |
249 |
< |
|
250 |
< |
float Audacious::GetEqualizerBand(int band) const |
251 |
< |
{ |
252 |
< |
return ::xmms_remote_get_eq_band(session, band); |
253 |
< |
} |
254 |
< |
|
255 |
< |
void Audacious::SetEqualizer(float preamp, float bands[10]) |
256 |
< |
{ |
257 |
< |
::xmms_remote_set_eq(session, preamp, bands); |
258 |
< |
} |
259 |
< |
|
260 |
< |
void Audacious::SetEqualizerPreamp(float preamp) |
261 |
< |
{ |
262 |
< |
::xmms_remote_set_eq_preamp(session, preamp); |
263 |
< |
} |
264 |
< |
|
265 |
< |
void Audacious::SetEqualizerBand(int band, float value) |
266 |
< |
{ |
267 |
< |
::xmms_remote_set_eq_band(session, band, value); |
268 |
< |
} |
269 |
< |
|
270 |
< |
// XMMS 1.2.1 |
271 |
< |
void Audacious::Quit() |
272 |
< |
{ |
273 |
< |
::xmms_remote_quit(session); |
274 |
< |
} |
275 |
< |
|
276 |
< |
// XMMS 1.2.6 |
277 |
< |
void Audacious::PlayPause() |
278 |
< |
{ |
279 |
< |
::xmms_remote_play_pause(session); |
280 |
< |
} |
281 |
< |
|
282 |
< |
void Audacious::PlaylistInsertUrl(const cse::String &url, int position) |
283 |
< |
{ |
284 |
< |
::xmms_remote_playlist_ins_url_string(session, const_cast<char*>(url.NullTerminate()), position); |
285 |
< |
} |
286 |
< |
|
287 |
< |
// XMMS 1.2.11 |
288 |
< |
void Audacious::PlayqueueAdd(int position) |
289 |
< |
{ |
290 |
< |
::xmms_remote_playqueue_add(session, position); |
291 |
< |
} |
292 |
< |
|
293 |
< |
void Audacious::PlayqueueRemove(int position) |
294 |
< |
{ |
295 |
< |
::xmms_remote_playqueue_remove(session, position); |
296 |
< |
} |
297 |
< |
|
298 |
< |
int Audacious::GetPlayqueueLength() const |
299 |
< |
{ |
300 |
< |
return ::xmms_remote_get_playqueue_length(session); |
301 |
< |
} |
302 |
< |
|
303 |
< |
void Audacious::ToggleAdvance() |
304 |
< |
{ |
305 |
< |
::xmms_remote_toggle_advance(session); |
306 |
< |
} |
307 |
< |
|
308 |
< |
bool Audacious::IsAdvance() const |
309 |
< |
{ |
310 |
< |
return ::xmms_remote_is_advance(session); |
311 |
< |
} |
312 |
< |
|
313 |
< |
// BMP 0.9.7 |
314 |
< |
void Audacious::Activate() |
315 |
< |
{ |
316 |
< |
::xmms_remote_activate(session); |
317 |
< |
} |
318 |
< |
|
319 |
< |
// Audacious 1.1 |
320 |
< |
void Audacious::ShowJumpToFileBox() |
321 |
< |
{ |
322 |
< |
::xmms_remote_show_jtf_box(session); |
323 |
< |
} |
324 |
< |
|
325 |
< |
void Audacious::PlayqueueClear() |
326 |
< |
{ |
327 |
< |
::xmms_remote_playqueue_clear(session); |
328 |
< |
} |
329 |
< |
|
330 |
< |
bool Audacious::PlayqueueIsQueued(int position) const |
331 |
< |
{ |
332 |
< |
return ::xmms_remote_playqueue_is_queued(session, position); |
333 |
< |
} |
334 |
< |
|
335 |
< |
int Audacious::GetPlayqueuePosition(int position) const |
336 |
< |
{ |
337 |
< |
return ::xmms_remote_get_playqueue_position(session, position); |
338 |
< |
} |
339 |
< |
|
340 |
< |
int Audacious::GetPlayqueueQueuePosition(int position) const |
341 |
< |
{ |
342 |
< |
return ::xmms_remote_get_playqueue_queue_position(session, position); |
343 |
< |
} |
344 |
< |
|
345 |
< |
// Audacious 1.2 |
346 |
< |
void Audacious::SetSessionUri(const cse::String &uri) |
347 |
< |
{ |
348 |
< |
::audacious_set_session_uri(const_cast<char *>(uri.NullTerminate())); |
349 |
< |
} |
350 |
< |
|
351 |
< |
cse::String Audacious::GetSessionUri() const |
352 |
< |
{ |
353 |
< |
return ::audacious_get_session_uri(session); |
354 |
< |
} |
355 |
< |
|
356 |
< |
void Audacious::SetSessionType(Type type) |
357 |
< |
{ |
358 |
< |
::audacious_set_session_type(type); |
359 |
< |
} |
360 |
< |
|
361 |
< |
// Audacious 1.3 |
362 |
< |
void Audacious::PlaylistEnqueueToTemp(const cse::String &string) |
363 |
< |
{ |
364 |
< |
::xmms_remote_playlist_enqueue_to_temp(session, const_cast<char *>(string.NullTerminate())); |
365 |
< |
} |
366 |
< |
|
367 |
< |
cse::String Audacious::GetTupleFieldData(const cse::String &field, int position) |
368 |
< |
{ |
369 |
< |
return ::audacious_get_tuple_field_data(session, const_cast<char *>(field.NullTerminate()), position); |
118 |
> |
return true; |
119 |
|
} |