2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2014-11-01 19:30:40 +01:00
|
|
|
Copyright 2009-2012, David Sansome <me@davidsansome.com>
|
|
|
|
Copyright 2010, 2012, 2014, John Maguire <john.maguire@gmail.com>
|
|
|
|
Copyright 2011, Paweł Bara <keirangtp@gmail.com>
|
|
|
|
Copyright 2011, Andrea Decorte <adecorte@gmail.com>
|
|
|
|
Copyright 2012, Anand <anandtp@live.in>
|
|
|
|
Copyright 2013, Andreas <asfa194@gmail.com>
|
|
|
|
Copyright 2013, Kevin Cox <kevincox.ca@gmail.com>
|
|
|
|
Copyright 2014, Arnaud Bienner <arnaud.bienner@gmail.com>
|
|
|
|
Copyright 2014, Mark Furneaux <mark@romaco.ca>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
Clementine 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-11-01 19:26:05 +01:00
|
|
|
#ifndef CORE_PLAYER_H_
|
|
|
|
#define CORE_PLAYER_H_
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-06 14:48:00 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2015-01-08 04:10:35 +01:00
|
|
|
#include <QDateTime>
|
2009-12-24 20:16:07 +01:00
|
|
|
#include <QObject>
|
|
|
|
#include <QSettings>
|
|
|
|
|
2010-12-26 18:24:44 +01:00
|
|
|
#include "config.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "core/song.h"
|
2011-04-28 17:10:28 +02:00
|
|
|
#include "core/urlhandler.h"
|
2011-04-02 15:34:06 +02:00
|
|
|
#include "covers/albumcoverloader.h"
|
2010-04-04 19:50:11 +02:00
|
|
|
#include "engines/engine_fwd.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "playlist/playlistitem.h"
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
class Application;
|
2014-03-27 18:55:58 +01:00
|
|
|
class Scrobbler;
|
2010-12-04 23:27:58 +01:00
|
|
|
|
2011-02-13 19:36:29 +01:00
|
|
|
class PlayerInterface : public QObject {
|
2009-12-24 20:16:07 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2014-11-01 19:26:05 +01:00
|
|
|
explicit PlayerInterface(QObject* parent = nullptr) : QObject(parent) {}
|
2011-02-13 19:36:29 +01:00
|
|
|
|
|
|
|
virtual EngineBase* engine() const = 0;
|
|
|
|
virtual Engine::State GetState() const = 0;
|
|
|
|
virtual int GetVolume() const = 0;
|
|
|
|
|
|
|
|
virtual PlaylistItemPtr GetCurrentItem() const = 0;
|
|
|
|
virtual PlaylistItemPtr GetItemAt(int pos) const = 0;
|
|
|
|
|
2011-04-28 19:50:45 +02:00
|
|
|
virtual void RegisterUrlHandler(UrlHandler* handler) = 0;
|
|
|
|
virtual void UnregisterUrlHandler(UrlHandler* handler) = 0;
|
2011-04-28 17:10:28 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public slots:
|
2011-02-13 19:36:29 +01:00
|
|
|
virtual void ReloadSettings() = 0;
|
|
|
|
|
|
|
|
// Manual track change to the specified track
|
2014-02-07 16:34:20 +01:00
|
|
|
virtual void PlayAt(int i, Engine::TrackChangeFlags change,
|
|
|
|
bool reshuffle) = 0;
|
2011-02-13 19:36:29 +01:00
|
|
|
|
|
|
|
// If there's currently a song playing, pause it, otherwise play the track
|
|
|
|
// that was playing last, or the first one on the playlist
|
|
|
|
virtual void PlayPause() = 0;
|
2013-05-29 21:27:07 +02:00
|
|
|
virtual void RestartOrPrevious() = 0;
|
2011-02-13 19:36:29 +01:00
|
|
|
|
|
|
|
// Skips this track. Might load more of the current radio station.
|
|
|
|
virtual void Next() = 0;
|
|
|
|
|
|
|
|
virtual void Previous() = 0;
|
|
|
|
virtual void SetVolume(int value) = 0;
|
|
|
|
virtual void VolumeUp() = 0;
|
|
|
|
virtual void VolumeDown() = 0;
|
|
|
|
virtual void SeekTo(int seconds) = 0;
|
|
|
|
// Moves the position of the currently playing song five seconds forward.
|
|
|
|
virtual void SeekForward() = 0;
|
|
|
|
// Moves the position of the currently playing song five seconds backwards.
|
|
|
|
virtual void SeekBackward() = 0;
|
|
|
|
|
|
|
|
virtual void CurrentMetadataChanged(const Song& metadata) = 0;
|
|
|
|
|
|
|
|
virtual void Mute() = 0;
|
|
|
|
virtual void Pause() = 0;
|
2014-04-26 06:58:08 +02:00
|
|
|
virtual void Stop(bool stop_after = false) = 0;
|
2011-02-13 19:36:29 +01:00
|
|
|
virtual void Play() = 0;
|
|
|
|
virtual void ShowOSD() = 0;
|
|
|
|
|
2015-06-15 22:27:40 +02:00
|
|
|
signals:
|
2011-02-13 19:36:29 +01:00
|
|
|
void Playing();
|
|
|
|
void Paused();
|
|
|
|
void Stopped();
|
|
|
|
void PlaylistFinished();
|
|
|
|
void VolumeChanged(int volume);
|
|
|
|
void Error(const QString& message);
|
|
|
|
void TrackSkipped(PlaylistItemPtr old_track);
|
|
|
|
// Emitted when there's a manual change to the current's track position.
|
|
|
|
void Seeked(qlonglong microseconds);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Emitted when Player has processed a request to play another song. This
|
|
|
|
// contains
|
2011-03-10 19:01:35 +01:00
|
|
|
// the URL of the song and a flag saying whether it was able to play the song.
|
|
|
|
void SongChangeRequestProcessed(const QUrl& url, bool valid);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// The toggle parameter is true when user requests to toggle visibility for
|
|
|
|
// Pretty OSD
|
2018-06-18 15:21:44 +02:00
|
|
|
void ForceShowOSD(Song, bool toggle);
|
2011-02-13 19:36:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class Player : public PlayerInterface {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2014-11-02 21:37:15 +01:00
|
|
|
explicit Player(Application* app, QObject* parent = nullptr);
|
2010-05-28 21:51:51 +02:00
|
|
|
~Player();
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2015-01-06 05:33:47 +01:00
|
|
|
static const char* kSettingsGroup;
|
|
|
|
|
2015-01-19 15:01:33 +01:00
|
|
|
// Don't change the values: they are saved in preferences
|
2015-01-06 05:33:47 +01:00
|
|
|
enum PreviousBehaviour {
|
|
|
|
PreviousBehaviour_DontRestart = 1,
|
|
|
|
PreviousBehaviour_Restart = 2
|
|
|
|
};
|
|
|
|
|
2010-02-03 22:48:00 +01:00
|
|
|
void Init();
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
EngineBase* engine() const { return engine_.get(); }
|
2010-12-11 14:38:51 +01:00
|
|
|
Engine::State GetState() const { return last_state_; }
|
2009-12-24 20:16:07 +01:00
|
|
|
int GetVolume() const;
|
|
|
|
|
2010-10-16 17:22:14 +02:00
|
|
|
PlaylistItemPtr GetCurrentItem() const { return current_item_; }
|
2010-11-21 16:13:26 +01:00
|
|
|
PlaylistItemPtr GetItemAt(int pos) const;
|
2010-03-24 21:58:17 +01:00
|
|
|
|
2011-04-28 19:50:45 +02:00
|
|
|
void RegisterUrlHandler(UrlHandler* handler);
|
|
|
|
void UnregisterUrlHandler(UrlHandler* handler);
|
2011-04-28 17:10:28 +02:00
|
|
|
|
2012-01-04 12:50:19 +01:00
|
|
|
const UrlHandler* HandlerForUrl(const QUrl& url) const;
|
|
|
|
|
2015-07-17 20:01:02 +02:00
|
|
|
bool PreviousWouldRestartTrack() const;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public slots:
|
2010-02-03 17:51:56 +01:00
|
|
|
void ReloadSettings();
|
|
|
|
|
2011-03-13 19:37:46 +01:00
|
|
|
void PlayAt(int i, Engine::TrackChangeFlags change, bool reshuffle);
|
2009-12-24 20:16:07 +01:00
|
|
|
void PlayPause();
|
2013-05-29 21:27:07 +02:00
|
|
|
void RestartOrPrevious();
|
2010-04-30 01:30:24 +02:00
|
|
|
void Next();
|
2009-12-24 20:16:07 +01:00
|
|
|
void Previous();
|
|
|
|
void SetVolume(int value);
|
2010-12-05 12:39:06 +01:00
|
|
|
void VolumeUp() { SetVolume(GetVolume() + 5); }
|
2010-12-07 19:52:21 +01:00
|
|
|
void VolumeDown() { SetVolume(GetVolume() - 5); }
|
2011-02-13 19:36:29 +01:00
|
|
|
void SeekTo(int seconds);
|
2011-01-19 17:05:16 +01:00
|
|
|
void SeekForward();
|
|
|
|
void SeekBackward();
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-03-08 00:28:40 +01:00
|
|
|
void CurrentMetadataChanged(const Song& metadata);
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2010-03-24 21:58:17 +01:00
|
|
|
void Mute();
|
|
|
|
void Pause();
|
2014-04-26 06:58:08 +02:00
|
|
|
void Stop(bool stop_after = false);
|
2013-07-20 19:38:37 +02:00
|
|
|
void StopAfterCurrent();
|
2015-06-15 22:27:40 +02:00
|
|
|
void IntroPointReached();
|
2010-03-24 21:58:17 +01:00
|
|
|
void Play();
|
|
|
|
void ShowOSD();
|
2011-06-05 10:21:17 +02:00
|
|
|
void TogglePrettyOSD();
|
2010-03-24 21:58:17 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
private slots:
|
|
|
|
void EngineStateChanged(Engine::State);
|
2010-02-03 23:20:31 +01:00
|
|
|
void EngineMetadataReceived(const Engine::SimpleMetaBundle& bundle);
|
2010-04-21 15:55:30 +02:00
|
|
|
void TrackAboutToEnd();
|
2010-04-30 01:30:24 +02:00
|
|
|
void TrackEnded();
|
|
|
|
// Play the next item on the playlist - disregarding radio stations like
|
|
|
|
// last.fm that might have more tracks.
|
2011-03-13 19:37:46 +01:00
|
|
|
void NextItem(Engine::TrackChangeFlags change);
|
2012-08-26 14:10:38 +02:00
|
|
|
void PreviousItem(Engine::TrackChangeFlags change);
|
2010-04-30 01:30:24 +02:00
|
|
|
|
2011-03-13 19:37:46 +01:00
|
|
|
void NextInternal(Engine::TrackChangeFlags);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2011-03-10 19:01:35 +01:00
|
|
|
void ValidSongRequested(const QUrl&);
|
|
|
|
void InvalidSongRequested(const QUrl&);
|
|
|
|
|
2011-04-28 17:10:28 +02:00
|
|
|
void UrlHandlerDestroyed(QObject* object);
|
2011-07-21 01:22:20 +02:00
|
|
|
void HandleLoadResult(const UrlHandler::LoadResult& result);
|
2011-04-28 17:10:28 +02:00
|
|
|
|
2011-09-28 00:31:15 +02:00
|
|
|
private:
|
|
|
|
// Returns true if we were supposed to stop after this track.
|
|
|
|
bool HandleStopAfter();
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
private:
|
2012-02-12 14:41:50 +01:00
|
|
|
Application* app_;
|
2014-03-27 18:55:58 +01:00
|
|
|
Scrobbler* lastfm_;
|
2009-12-24 20:16:07 +01:00
|
|
|
QSettings settings_;
|
|
|
|
|
2010-10-16 17:22:14 +02:00
|
|
|
PlaylistItemPtr current_item_;
|
2010-02-03 15:21:53 +01:00
|
|
|
|
2014-02-06 14:48:00 +01:00
|
|
|
std::unique_ptr<EngineBase> engine_;
|
2011-03-13 19:37:46 +01:00
|
|
|
Engine::TrackChangeFlags stream_change_type_;
|
2010-12-11 14:38:51 +01:00
|
|
|
Engine::State last_state_;
|
2014-02-04 22:08:32 +01:00
|
|
|
int nb_errors_received_;
|
2010-05-18 22:43:10 +02:00
|
|
|
|
2011-04-28 17:10:28 +02:00
|
|
|
QMap<QString, UrlHandler*> url_handlers_;
|
|
|
|
|
2010-05-18 22:43:10 +02:00
|
|
|
QUrl loading_async_;
|
2010-06-14 22:00:17 +02:00
|
|
|
|
2010-07-14 00:22:04 +02:00
|
|
|
int volume_before_mute_;
|
2015-01-06 05:33:47 +01:00
|
|
|
|
|
|
|
QDateTime last_pressed_previous_;
|
|
|
|
PreviousBehaviour menu_previousmode_;
|
2015-07-03 20:54:17 +02:00
|
|
|
int seek_step_sec_;
|
2009-12-24 20:16:07 +01:00
|
|
|
};
|
|
|
|
|
2014-11-01 19:26:05 +01:00
|
|
|
#endif // CORE_PLAYER_H_
|