Commit ee7c8dfe authored by Scott Wheeler's avatar Scott Wheeler

Some API cleanups in the Player class hierarchy. Removed the volume parameter

for Player::play() and the unneeded overload.  Now simply initialize the volume
when setting up the Player class.  There were also a couple of minor code
cleanups that didn't affect functionality.

svn path=/trunk/kdemultimedia/juk/; revision=287344
parent 595cc5cb
......@@ -44,7 +44,7 @@ ArtsPlayer::ArtsPlayer() : Player(),
m_playobject(0),
m_amanPlay(0),
m_volumeControl(Arts::StereoVolumeControl::null()),
m_currentVolume(1.0)
m_currentVolume(1.0)
{
setupPlayer();
}
......@@ -58,36 +58,32 @@ ArtsPlayer::~ArtsPlayer()
delete m_dispatcher;
}
void ArtsPlayer::play(const QString &fileName, float volume)
{
m_currentURL.setPath(fileName);
play(volume);
}
void ArtsPlayer::play(float volume)
void ArtsPlayer::play(const QString &fileName)
{
// kdDebug(65432) << k_funcinfo << endl;
// Make sure that the server still exists, if it doesn't a new one should
// be started automatically and the factory and amanPlay are created again.
if(!fileName.isNull())
m_currentURL.setPath(fileName);
if(m_server->server().isNull()) {
KMessageBox::error(0, i18n("Cannot find the aRts soundserver."));
return;
}
if(!m_playobject || m_playobject->state() != Arts::posPaused)
{
if(!m_playobject || m_playobject->state() != Arts::posPaused) {
stop();
delete m_playobject;
m_playobject = m_factory->createPlayObject(m_currentURL, false);
m_currentVolume = volume; //save volume for playObjectCreated
if(m_playobject->object().isNull())
connect(m_playobject, SIGNAL(playObjectCreated()), SLOT(playObjectCreated()));
else
playObjectCreated();
}
else
setVolume(volume);
m_playobject->play();
}
......@@ -115,18 +111,20 @@ void ArtsPlayer::stop()
void ArtsPlayer::setVolume(float volume)
{
// kdDebug( 65432 ) << k_funcinfo << endl;
m_currentVolume = volume;
if(serverRunning() && m_playobject && !m_playobject->isNull()) {
if(m_volumeControl.isNull())
setupVolumeControl();
if(!m_volumeControl.isNull()) {
m_currentVolume = volume;
m_volumeControl.scaleFactor(volume);
// kdDebug( 65432 ) << "set volume to " << volume << endl;
}
}
}
float ArtsPlayer::getVolume() const
float ArtsPlayer::volume() const
{
return m_currentVolume;
}
......@@ -163,7 +161,7 @@ long ArtsPlayer::currentTime() const
{
if(serverRunning() && m_playobject &&
(m_playobject->state() == Arts::posPlaying ||
m_playobject->state() == Arts::posPaused))
m_playobject->state() == Arts::posPaused))
{
return m_playobject->currentTime().seconds;
}
......
......@@ -28,6 +28,7 @@ class QString;
class KArtsDispatcher;
class KArtsServer;
class KAudioManagerPlay;
namespace KDE {
class PlayObjectFactory;
class PlayObject;
......@@ -41,13 +42,12 @@ public:
ArtsPlayer();
virtual ~ArtsPlayer();
virtual void play(const QString &fileName, float volume = 1.0);
virtual void play(float volume = 1.0);
virtual void play(const QString &fileName = QString::null);
virtual void pause();
virtual void stop();
virtual void setVolume(float volume = 1.0);
virtual float getVolume() const;
virtual float volume() const;
virtual bool playing() const;
virtual bool paused() const;
......@@ -76,6 +76,7 @@ private:
// This is a pretty heavy module for the needs that JuK has, it would probably
// be good to use two Synth_MUL instead or the one from Noatun.
Arts::StereoVolumeControl m_volumeControl;
KURL m_currentURL;
......
......@@ -33,7 +33,7 @@ using namespace KDE::GSTPlay;
////////////////////////////////////////////////////////////////////////////////
GStreamerPlayer::GStreamerPlayer() : QObject(0), Player(),
m_positionNs(0), m_durationNs(0), m_currentVolume(1.0)
m_positionNs(0), m_durationNs(0), m_currentVolume(1.0)
{
setupPlayer();
}
......@@ -43,37 +43,29 @@ GStreamerPlayer::~GStreamerPlayer()
delete m_player;
}
void GStreamerPlayer::play(const QString &fileName, float volume)
void GStreamerPlayer::play(const QString &fileName)
{
m_currentFile = fileName;
m_positionNs = 0;
m_durationNs = 0;
if(!fileName.isEmpty()) {
m_player->setLocation(fileName);
play(volume);
}
}
if(!fileName.isEmpty()) {
m_player->setLocation(fileName);
void GStreamerPlayer::play(float volume)
{
// 1.0 is full volume
if (m_player->getState() != Element::STATE_PLAYING) {
m_player->setState(Element::STATE_PLAYING);
m_player->setVolume(volume);
}
if(m_player->getState() != Element::STATE_PLAYING)
m_player->setState(Element::STATE_PLAYING);
}
void GStreamerPlayer::pause()
{
if(m_player->getState() != Element::STATE_PAUSED)
m_player->setState(Element::STATE_PAUSED);
m_player->setState(Element::STATE_PAUSED);
}
void GStreamerPlayer::stop()
{
if(m_player->getState() != Element::STATE_READY)
m_player->setState(Element::STATE_READY);
m_player->setState(Element::STATE_READY);
}
void GStreamerPlayer::setVolume(float volume)
......@@ -82,7 +74,7 @@ void GStreamerPlayer::setVolume(float volume)
m_player->setVolume(volume);
}
float GStreamerPlayer::getVolume() const
float GStreamerPlayer::volume() const
{
// 1.0 is full volume
return m_player->getVolume();
......@@ -117,9 +109,9 @@ long GStreamerPlayer::currentTime() const
int GStreamerPlayer::position() const
{
if (m_durationNs > 0)
return (int)((m_positionNs * 1000.0) / m_durationNs);
return int((m_positionNs * 1000.0) / m_durationNs);
else
return 0;
return 0;
}
/////////////////////////////////////////////////////////////////////////////////
......@@ -136,9 +128,9 @@ void GStreamerPlayer::seekPosition(int position)
{
// position unit is 1/1000th
if(m_durationNs > 0)
m_player->seekToTime(position * m_durationNs / 1000L);
m_player->seekToTime(position * m_durationNs / 1000L);
else
m_player->seekToTime(0);
m_player->seekToTime(0);
}
......@@ -150,16 +142,16 @@ void GStreamerPlayer::setupPlayer()
{
m_player = new Play(Play::PIPE_AUDIO_BUFFER_THREADED, this, "Play");
connect(m_player, SIGNAL(timeTick(long long)),
SLOT(slotSetPosition(long long)));
SLOT(slotSetPosition(long long)));
connect(m_player, SIGNAL(streamLength(long long)),
SLOT(slotSetDuration(long long)));
SLOT(slotSetDuration(long long)));
connect(m_player, SIGNAL(streamEnd()), SLOT(slotStopIfNotPlaying()));
}
void GStreamerPlayer::slotStopIfNotPlaying()
{
if(!playing())
stop();
stop();
}
#include "gstreamerplayer.moc"
......
......@@ -38,11 +38,10 @@ public:
GStreamerPlayer();
virtual ~GStreamerPlayer();
virtual void play(const QString &fileName, float volume = 1.0);
virtual void play(float volume = 1.0);
virtual void play(const QString &fileName = QString::null);
virtual void setVolume(float volume = 1.0);
virtual float getVolume() const;
virtual float volume() const;
virtual bool playing() const;
virtual bool paused() const;
......
......@@ -110,7 +110,7 @@ void JuK::play()
return;
if(m_player->paused()) {
m_player->play(m_player->getVolume());
m_player->play();
m_statusLabel->setPlayingItemInfo(playingString(), m_splitter->playingList());
// Here, before doing anything, we want to make sure that the m_player did
......@@ -550,6 +550,12 @@ void JuK::setupPlayer()
}
m_player = Player::createPlayer(playerType);
float volume =
float(m_sliderAction->volumeSlider()->value()) /
float(m_sliderAction->volumeSlider()->maxValue());
m_player->setVolume(volume);
}
......@@ -751,13 +757,10 @@ void JuK::play(const QString &file)
if(!m_player || !m_sliderAction || !m_sliderAction->volumeSlider())
return;
float volume = float(m_sliderAction->volumeSlider()->value()) /
float(m_sliderAction->volumeSlider()->maxValue());
if(m_player->paused())
m_player->stop();
m_player->play(file, volume);
m_player->play(file);
// Make sure that the m_player actually starts before doing anything.
......@@ -948,9 +951,12 @@ void JuK::slotPlaySelectedFile()
void JuK::slotSetVolume(int volume)
{
if(m_player && m_sliderAction && m_sliderAction->volumeSlider() &&
if(m_player &&
m_sliderAction &&
m_sliderAction->volumeSlider() &&
m_sliderAction->volumeSlider()->maxValue() > 0 &&
volume >= 0 && m_sliderAction->volumeSlider()->maxValue() >= volume)
volume >= 0 &&
m_sliderAction->volumeSlider()->maxValue() >= volume)
{
m_player->setVolume(float(volume) /
float(m_sliderAction->volumeSlider()->maxValue()));
......
......@@ -34,13 +34,12 @@ public:
virtual ~Player() {}
virtual void play(const QString &fileName, float volume = 1.0) = 0;
virtual void play(float volume = 1.0) = 0;
virtual void play(const QString &fileName = QString::null) = 0;
virtual void pause() = 0;
virtual void stop() = 0;
virtual void setVolume(float volume = 1.0) = 0;
virtual float getVolume() const = 0;
virtual float volume() const = 0;
virtual bool playing() const = 0;
virtual bool paused() const = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment