1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
#include "playlistwrapper.h"
#include <cassert>
#include <iostream>
using namespace std;
playlistWrapper * playlistWrapper::m_self;
playlistWrapper & playlistWrapper::self()
{
if (m_self == 0)
m_self = new playlistWrapper;
return *m_self;
}
playlistWrapper::playlistWrapper()
{
cout << "Singleton playlistWrapper constructed" << endl;
}
void playlistWrapper::updatePlaylist()
{
m_list.clear();
assert(m_list.size() == 0);
gint playlist_length = xmms_remote_get_playlist_length(0);
for (int i=0; i<playlist_length; ++i)
{
gchar *title = xmms_remote_get_playlist_title(0, i);
gchar *filename = xmms_remote_get_playlist_file(0, i);
int time = xmms_remote_get_playlist_time(0, i);
// void xmms_remote_get_info(gint session, gint * rate, gint * freq, gint * nch);
int rate, freq, nch;
rate = freq = nch = 0;
t_songInfo info(title, filename, i, time, freq, rate, nch);
m_list[i] = info;
g_free(title);
g_free(filename);
}
}
void playlistWrapper::playFileByPos(int pos) const
{
xmms_remote_set_playlist_pos(0, pos);
if (!xmms_remote_is_playing(0))
xmms_remote_play(0);
}
unsigned int playlistWrapper::length() const
{
return m_list.size();
}
const t_songInfo & playlistWrapper::operator [](unsigned int i) const
{
return m_list.find(i)->second;
}
unsigned int playlistWrapper::getCurrentTime() const
{
return xmms_remote_get_output_time(0);
}
const t_songInfo & playlistWrapper::getCurrentSong() const
{
// get running pos
if (!xmms_remote_is_playing(0))
{
// FIXME
throw 0;
}
else
{
gint pos = xmms_remote_get_playlist_pos(0);
return (*this)[pos];
}
}
int playlistWrapper::getPlayerStatus() const
{
if (xmms_remote_is_paused(0))
{
return PAUSED;
}
else if (xmms_remote_is_playing(0))
{
return PLAYING;
}
return STOPPED;
}
bool playlistWrapper::getRandomStatus() const
{
return xmms_remote_is_shuffle(0);
}
void playlistWrapper::setRandomStatus() const
{
xmms_remote_toggle_shuffle(0);
}
void playlistWrapper::pressNext() const
{
xmms_remote_playlist_next(0);
}
void playlistWrapper::pressPrev() const
{
xmms_remote_playlist_prev(0);
}
void playlistWrapper::pressPlay() const
{
xmms_remote_play(0);
}
void playlistWrapper::pressStop() const
{
xmms_remote_stop(0);
}
void playlistWrapper::pressPause() const
{
xmms_remote_pause(0);
}
|