File: player.cpp

package info (click to toggle)
madman 0.93.0-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,060 kB
  • ctags: 3,309
  • sloc: cpp: 14,194; ansic: 13,331; sh: 100; makefile: 62; python: 54
file content (182 lines) | stat: -rw-r--r-- 3,975 bytes parent folder | download
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
madman - a music manager
Copyright (C) 2003  Andreas Kloeckner <ak@ixion.net>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/




#include <unistd.h>
#include <cstdlib>
#include <stdexcept>
#include "utility/player_xmms.h"




// tPlayer --------------------------------------------------------------------
tPlayer::~tPlayer()
{
}




void tPlayer::skipTo(float percentage)
{
  float total = totalTime();
  if (total == 0)
    return;

  skipToSeconds(int(total * percentage / 100));
}




// tPlayerFacade --------------------------------------------------------------
void tPlayerFacade::setBackend(tPlayer *backend)
{
  if (Backend.get())
    disconnect(Backend.get(), NULL, backend, NULL);
  auto_ptr<tPlayer> be(backend);
  Backend = be;
  if (Backend.get())
  {
    connect(Backend.get(), SIGNAL(currentSongChanged()), this, SLOT(slotCurrentSongChanged()));
    connect(Backend.get(), SIGNAL(stateChanged()), this, SLOT(slotStateChanged()));
  }
}




QString tPlayerFacade::name()
{
  if (Backend.get()) return Backend->name();
  else return QString();
}
void tPlayerFacade::playNow(tSongList const &songlist)
{
  if (Backend.get()) Backend->playNow(songlist);
}
void tPlayerFacade::playNext(tSongList const &songlist)
{
  if (Backend.get()) Backend->playNext(songlist);
}
void tPlayerFacade::playEventually(tSongList const &songlist)
{
  if (Backend.get()) Backend->playEventually(songlist);
}
void tPlayerFacade::setPlayList(tSongList const &songlist)
{
  if (Backend.get()) Backend->setPlayList(songlist);
}
tFilename tPlayerFacade::currentFilename()
{
  if (Backend.get()) return Backend->currentFilename();
  else return "";
}
QString tPlayerFacade::currentTitle()
{
  if (Backend.get()) return Backend->currentTitle();
  else return QString::null;
}
void tPlayerFacade::getPlayList(vector<tFilename> &songs)
{
  if (Backend.get()) Backend->getPlayList(songs);
  else songs.clear();
}
void tPlayerFacade::clearPlaylist()
{
  if (Backend.get()) Backend->clearPlaylist();
}
bool tPlayerFacade::isPlaying()
{
  if (Backend.get()) return Backend->isPlaying();
  else return false;
}
bool tPlayerFacade::isPaused()
{
  if (Backend.get()) return Backend->isPaused();
  else return false;
}
float tPlayerFacade::currentTime()
{
  if (Backend.get()) return Backend->currentTime();
  else return 0;
}
float tPlayerFacade::totalTime()
{
  if (Backend.get()) return Backend->totalTime();
  else return 0;
}
void tPlayerFacade::play()
{
  if (Backend.get()) Backend->play();
}
void tPlayerFacade::stop()
{
  if (Backend.get()) Backend->stop();
}
void tPlayerFacade::pause()
{
  if (Backend.get()) Backend->pause();
}
void tPlayerFacade::skipForward()
{
  if (Backend.get()) Backend->skipForward();
}
void tPlayerFacade::skipBack()
{
  if (Backend.get()) Backend->skipBack();
}
void tPlayerFacade::skipToSeconds(float seconds)
{
  if (Backend.get()) Backend->skipToSeconds(seconds);
}
void tPlayerFacade::slotCurrentSongChanged()
{
  emit currentSongChanged();
}
void tPlayerFacade::slotStateChanged()
{
  emit stateChanged();
}




// factory interface ----------------------------------------------------------
void listPlayers(vector<QString> &players)
{
  players.clear();
  players.push_back("XMMS");
}




tPlayer *createPlayer(QString const &name)
{
  if (name == "XMMS")
  {
    return new tXMMSPlayer;
  }
  else
    return NULL;
}