Commit 529f231c authored by Matthias Kretz's avatar Matthias Kretz

remove Player abstraction and implement the Player class using Phonon (this is

only a first fast hack to make Phonon work, JuK can profit from the Phonon API
some more by removing the Player class as well)
Also fix the remaining KAction/KToggleAction problems.

svn path=/trunk/KDE/kdemultimedia/juk/; revision=536887
parent f7238cb8
......@@ -13,8 +13,6 @@ add_definitions(${TAGLIB_CFLAGS})
set(juk_SRCS
advancedsearchdialog.cpp
actioncollection.cpp
akodeplayer.cpp
artsplayer.cpp
cache.cpp
categoryreaderinterface.cpp
collectionlist.cpp
......@@ -31,7 +29,6 @@ set(juk_SRCS
filerenamer.cpp
filerenameroptions.cpp
filerenamerconfigdlg.cpp
gstreamerplayer.cpp
googlefetcher.cpp
googlefetcherdialog.cpp
historyplaylist.cpp
......@@ -43,6 +40,7 @@ set(juk_SRCS
musicbrainzquery.cpp
nowplaying.cpp
playermanager.cpp
player.cpp
playlist.cpp
playlistbox.cpp
playlistcollection.cpp
......@@ -94,7 +92,7 @@ kde4_add_executable(juk ${juk_SRCS})
# Add gstreamer here too...
SET(backendLibs ${AKODE_LIBRARIES})
target_link_libraries(juk ${KDE4_KDECORE_LIBS} m kio khtml kdeui tag
target_link_libraries(juk ${KDE4_KDECORE_LIBS} m kio khtml kdeui tag phononcore
${backendLibs})
install_targets(/bin juk )
......
/***************************************************************************
copyright : (C) 2004 by Allan Sandfeld Jensen
email : kde@carewolf.com
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include <config.h>
#ifdef HAVE_AKODE
#include <kdebug.h>
#include <qfile.h>
#include <akode/player.h>
#include <akode/decoder.h>
#include "akodeplayer.h"
using namespace aKode;
////////////////////////////////////////////////////////////////////////////////
// public methods
////////////////////////////////////////////////////////////////////////////////
aKodePlayer::aKodePlayer() : Player(),
m_player(0),
m_volume(1.0)
{}
aKodePlayer::~aKodePlayer()
{
delete m_player;
}
void aKodePlayer::play(const FileHandle &file)
{
kDebug( 65432 ) << k_funcinfo << endl;
if (file.isNull()) { // null FileHandle file means unpause
if (paused())
m_player->resume();
else
stop();
return;
}
QString filename = file.absFilePath();
kDebug( 65432 ) << "Opening: " << filename << endl;
if (m_player)
m_player->stop();
else {
m_player = new aKode::Player();
m_player->open("auto");
m_player->setVolume(m_volume);
}
if (m_player->load(filename.local8Bit().data()))
m_player->play();
}
void aKodePlayer::pause()
{
if (m_player)
m_player->pause();
}
void aKodePlayer::stop()
{
if (m_player) {
m_player->stop();
m_player->unload();
}
}
void aKodePlayer::setVolume(float volume)
{
m_volume = volume;
if (m_player)
m_player->setVolume(m_volume);
}
float aKodePlayer::volume() const
{
return m_volume;
}
/////////////////////////////////////////////////////////////////////////////////
// m_player status functions
/////////////////////////////////////////////////////////////////////////////////
bool aKodePlayer::playing() const
{
if (m_player && m_player->decoder() && m_player->state() == aKode::Player::Playing)
return !m_player->decoder()->eof();
else
return false;
}
bool aKodePlayer::paused() const
{
return m_player && (m_player->state() == aKode::Player::Paused);
}
int aKodePlayer::totalTime() const
{
if (m_player) {
Decoder *d = m_player->decoder();
if (d)
return d->length() / 1000;
}
return -1;
}
int aKodePlayer::currentTime() const
{
if (m_player) {
Decoder *d = m_player->decoder();
if (d)
return d->position() / 1000;
}
return -1;
}
int aKodePlayer::position() const
{
if (m_player) {
Decoder *d = m_player->decoder();
if (d && d->length())
return (d->position()*1000)/(d->length());
else
return -1;
}
else
return -1;
}
/////////////////////////////////////////////////////////////////////////////////
// m_player seek functions
/////////////////////////////////////////////////////////////////////////////////
void aKodePlayer::seek(int seekTime)
{
// seek time in seconds?
if (m_player)
m_player->decoder()->seek(seekTime*1000);
}
void aKodePlayer::seekPosition(int position)
{
// position unit is 1/1000th
if (m_player)
m_player->decoder()->seek((position * m_player->decoder()->length())/1000);
}
#include "akodeplayer.moc"
#endif
// vim: set et sw=4 tw=0 sta:
/***************************************************************************
copyright : (C) 2004 by Allan Sandfeld Jensen
email : kde@carewolf.com
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifndef AKODEPLAYER_H
#define AKODEPLAYER_H
#include <config.h>
#ifdef HAVE_AKODE
#include <qstring.h>
#include "player.h"
#include <kdemacros.h>
namespace aKode {
class File;
class Player;
}
class KDE_EXPORT aKodePlayer : public Player
{
Q_OBJECT
public:
aKodePlayer();
virtual ~aKodePlayer();
virtual void play(const FileHandle &file = FileHandle::null());
virtual void setVolume(float volume = 1.0);
virtual float volume() const;
virtual bool playing() const;
virtual bool paused() const;
virtual int totalTime() const;
virtual int currentTime() const;
virtual int position() const;
virtual void seek(int seekTime);
virtual void seekPosition(int position);
public slots:
void pause();
void stop();
private:
aKode::Player *m_player;
float m_volume;
};
#endif
#endif
// vim: set et sw=4 tw=0 sta:
/***************************************************************************
begin : Sun Feb 17 2002
copyright : (C) 2002 - 2004 by Scott Wheeler
email : wheeler@kde.org
copyright : (C) 2003 by Matthias Kretz
email : kretz@kde.org
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include "artsplayer.h"
#if HAVE_ARTS
#include <kdebug.h>
#include <kconfig.h>
#include <kstandarddirs.h>
#include <qdir.h>
#include <kartsserver.h>
#include <kartsdispatcher.h>
#include <kplayobject.h>
#include <kplayobjectfactory.h>
#include <sys/wait.h>
#include <kmessagebox.h>
#include <kaudiomanagerplay.h>
#include <klocale.h>
////////////////////////////////////////////////////////////////////////////////
// public methods
////////////////////////////////////////////////////////////////////////////////
ArtsPlayer::ArtsPlayer() : Player(),
m_dispatcher(0),
m_server(0),
m_factory(0),
m_playobject(0),
m_amanPlay(0),
m_volumeControl(Arts::StereoVolumeControl::null()),
m_currentVolume(1.0)
{
setupPlayer();
}
ArtsPlayer::~ArtsPlayer()
{
delete m_playobject;
delete m_factory;
delete m_amanPlay;
delete m_server;
delete m_dispatcher;
}
void ArtsPlayer::play(const FileHandle &file)
{
// kDebug(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(!file.isNull())
m_currentURL.setPath(file.absFilePath());
if(m_server->server().isNull()) {
KMessageBox::error(0, i18n("Cannot find the aRts soundserver."));
return;
}
if(!m_playobject || !file.isNull()) {
stop();
delete m_playobject;
m_playobject = m_factory->createPlayObject(m_currentURL, false);
if(m_playobject->object().isNull())
connect(m_playobject, SIGNAL(playObjectCreated()), SLOT(playObjectCreated()));
else
playObjectCreated();
}
m_playobject->play();
}
void ArtsPlayer::pause()
{
// kDebug(65432) << k_funcinfo << endl;
if(m_playobject)
m_playobject->pause();
}
void ArtsPlayer::stop()
{
// kDebug(65432) << k_funcinfo << endl;
if(m_playobject) {
m_playobject->halt();
delete m_playobject;
m_playobject = 0;
}
if(!m_volumeControl.isNull()) {
m_volumeControl.stop();
m_volumeControl = Arts::StereoVolumeControl::null();
}
}
void ArtsPlayer::setVolume(float volume)
{
// kDebug( 65432 ) << k_funcinfo << endl;
m_currentVolume = volume;
if(serverRunning() && m_playobject && !m_playobject->isNull()) {
if(m_volumeControl.isNull())
setupVolumeControl();
if(!m_volumeControl.isNull()) {
m_volumeControl.scaleFactor(volume);
// kDebug( 65432 ) << "set volume to " << volume << endl;
}
}
}
float ArtsPlayer::volume() const
{
return m_currentVolume;
}
/////////////////////////////////////////////////////////////////////////////////
// player status functions
/////////////////////////////////////////////////////////////////////////////////
bool ArtsPlayer::playing() const
{
if(serverRunning() && m_playobject && m_playobject->state() == Arts::posPlaying)
return true;
else
return false;
}
bool ArtsPlayer::paused() const
{
if(serverRunning() && m_playobject && m_playobject->state() == Arts::posPaused)
return true;
else
return false;
}
int ArtsPlayer::totalTime() const
{
if(serverRunning() && m_playobject)
return m_playobject->overallTime().seconds;
else
return -1;
}
int ArtsPlayer::currentTime() const
{
if(serverRunning() && m_playobject &&
(m_playobject->state() == Arts::posPlaying ||
m_playobject->state() == Arts::posPaused))
{
return m_playobject->currentTime().seconds;
}
else
return -1;
}
int ArtsPlayer::position() const
{
if(serverRunning() && m_playobject && m_playobject->state() == Arts::posPlaying) {
long total = m_playobject->overallTime().seconds * 1000 + m_playobject->overallTime().ms;
long current = m_playobject->currentTime().seconds * 1000 + m_playobject->currentTime().ms;
// add .5 to make rounding happen properly
return int(double(current) * 1000 / total + .5);
}
else
return -1;
}
/////////////////////////////////////////////////////////////////////////////////
// player seek functions
/////////////////////////////////////////////////////////////////////////////////
void ArtsPlayer::seek(int seekTime)
{
if(serverRunning() && m_playobject) {
Arts::poTime poSeekTime;
poSeekTime.custom = 0;
poSeekTime.ms = 0;
poSeekTime.seconds = seekTime;
m_playobject->object().seek(poSeekTime);
}
}
void ArtsPlayer::seekPosition(int position)
{
if(serverRunning() && m_playobject) {
Arts::poTime poSeekTime;
long total = m_playobject->overallTime().seconds;
poSeekTime.custom = 0;
poSeekTime.ms = 0;
poSeekTime.seconds = long(double(total) * position / 1000 + .5);
m_playobject->object().seek(poSeekTime);
}
}
/////////////////////////////////////////////////////////////////////////////////
// private
/////////////////////////////////////////////////////////////////////////////////
void ArtsPlayer::setupArtsObjects()
{
// kDebug( 65432 ) << k_funcinfo << endl;
delete m_factory;
delete m_amanPlay;
m_volumeControl = Arts::StereoVolumeControl::null();
m_factory = new KDE::PlayObjectFactory(m_server);
m_amanPlay = new KAudioManagerPlay(m_server);
if(m_amanPlay->isNull() || !m_factory) {
KMessageBox::error(0, i18n("Connecting/starting aRts soundserver failed. "
"Make sure that artsd is configured properly."));
exit(1);
}
m_amanPlay->setTitle(i18n("JuK"));
m_amanPlay->setAutoRestoreID("JuKAmanPlay");
m_factory->setAudioManagerPlay(m_amanPlay);
}
void ArtsPlayer::playObjectCreated()
{
// kDebug(65432) << k_funcinfo << endl;
setVolume(m_currentVolume);
}
void ArtsPlayer::setupPlayer()
{
m_dispatcher = new KArtsDispatcher;
m_server = new KArtsServer;
setupArtsObjects();
connect(m_server, SIGNAL(restartedServer()), SLOT(setupArtsObjects()));
}
void ArtsPlayer::setupVolumeControl()
{
// kDebug( 65432 ) << k_funcinfo << endl;
m_volumeControl = Arts::DynamicCast(m_server->server().createObject("Arts::StereoVolumeControl"));
if(!m_volumeControl.isNull() && !m_playobject->isNull() && !m_playobject->object().isNull()) {
Arts::Synth_AMAN_PLAY ap = m_amanPlay->amanPlay();
Arts::PlayObject po = m_playobject->object();
ap.stop();
Arts::disconnect(po, "left" , ap, "left" );
Arts::disconnect(po, "right", ap, "right");
m_volumeControl.start();
ap.start();
Arts::connect(po, "left" , m_volumeControl, "inleft" );
Arts::connect(po, "right", m_volumeControl, "inright");
Arts::connect(m_volumeControl, "outleft" , ap, "left" );
Arts::connect(m_volumeControl, "outright", ap, "right");
// kDebug( 65432 ) << "connected volume control" << endl;
}
else {
m_volumeControl = Arts::StereoVolumeControl::null();
kDebug(65432) << "Could not initialize volume control!" << endl;
}
}
bool ArtsPlayer::serverRunning() const
{
if(m_server)
return !(m_server->server().isNull());
else
return false;
}
#include "artsplayer.moc"
#endif
// vim: set et sw=4 tw=0 sta:
/***************************************************************************
begin : Sun Feb 17 2002
copyright : (C) 2002 - 2004 by Scott Wheeler
email : wheeler@kde.org
copyright : (C) 2003 by Matthias Kretz
email : kretz@kde.org
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifndef ARTSPLAYER_H
#define ARTSPLAYER_H
#include <config.h>
#ifdef HAVE_ARTS
#include "player.h"
#include <kurl.h>
#include <qstring.h>
#include <qobject.h>
#include <artsflow.h>
class KArtsDispatcher;
class KArtsServer;
class KAudioManagerPlay;
namespace KDE {
class PlayObjectFactory;
class PlayObject;
}
class ArtsPlayer : public Player
{
Q_OBJECT
public:
ArtsPlayer();
virtual ~ArtsPlayer();
virtual void play(const FileHandle &file = FileHandle::null());
virtual void pause();
virtual void stop();
virtual void setVolume(float volume = 1.0);
virtual float volume() const;
virtual bool playing() const;
virtual bool paused() const;
virtual int totalTime() const;
virtual int currentTime() const;
virtual int position() const; // in this case not really the percent
virtual void seek(int seekTime);
virtual void seekPosition(int position);
private slots:
void setupArtsObjects();
void playObjectCreated();
private:
void setupPlayer();
void setupVolumeControl();
bool serverRunning() const;
KArtsDispatcher *m_dispatcher;
KArtsServer *m_server;
KDE::PlayObjectFactory *m_factory;
KDE::PlayObject *m_playobject;
KAudioManagerPlay *m_amanPlay;
// 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;
float m_currentVolume;
};
#endif