2018-02-27 18:06:05 +01:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
|
|
|
* This file was part of Clementine.
|
|
|
|
* Copyright 2010, David Sansome <me@davidsansome.com>
|
2021-03-20 21:14:47 +01:00
|
|
|
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
2018-02-27 18:06:05 +01:00
|
|
|
*
|
|
|
|
* Strawberry 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.
|
|
|
|
*
|
|
|
|
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-09 18:39:44 +02:00
|
|
|
*
|
2018-02-27 18:06:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLAYER_H
|
|
|
|
#define PLAYER_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QtGlobal>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QObject>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QMap>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QString>
|
|
|
|
#include <QUrl>
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "urlhandler.h"
|
2018-02-27 18:06:05 +01:00
|
|
|
#include "engine/engine_fwd.h"
|
|
|
|
#include "engine/enginetype.h"
|
2020-08-23 19:37:24 +02:00
|
|
|
#include "playlist/playlist.h"
|
2018-02-27 18:06:05 +01:00
|
|
|
#include "playlist/playlistitem.h"
|
2019-11-17 23:46:10 +01:00
|
|
|
#include "settings/behavioursettingspage.h"
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
class Application;
|
2018-05-01 00:41:33 +02:00
|
|
|
class Song;
|
2018-02-27 18:06:05 +01:00
|
|
|
class AnalyzerContainer;
|
|
|
|
class Equalizer;
|
2020-02-08 03:40:30 +01:00
|
|
|
#ifdef HAVE_GSTREAMER
|
|
|
|
class GstStartup;
|
|
|
|
#endif
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
namespace Engine {
|
|
|
|
struct SimpleMetaBundle;
|
|
|
|
} // namespace Engine
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
class PlayerInterface : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit PlayerInterface(QObject *parent = nullptr) : QObject(parent) {}
|
|
|
|
|
|
|
|
virtual EngineBase *engine() const = 0;
|
|
|
|
virtual Engine::State GetState() const = 0;
|
2021-10-30 02:21:29 +02:00
|
|
|
virtual uint GetVolume() const = 0;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
virtual PlaylistItemPtr GetCurrentItem() const = 0;
|
2021-06-10 23:13:03 +02:00
|
|
|
virtual PlaylistItemPtr GetItemAt(const int pos) const = 0;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
virtual void RegisterUrlHandler(UrlHandler *handler) = 0;
|
|
|
|
virtual void UnregisterUrlHandler(UrlHandler *handler) = 0;
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
virtual void ReloadSettings() = 0;
|
2022-12-03 03:46:59 +01:00
|
|
|
virtual void LoadVolume() = 0;
|
|
|
|
virtual void SaveVolume() = 0;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
// Manual track change to the specified track
|
2021-10-30 02:21:29 +02:00
|
|
|
virtual void PlayAt(const int index, const quint64 offset_nanosec, Engine::TrackChangeFlags change, const Playlist::AutoScroll autoscroll, const bool reshuffle, const bool force_inform = false) = 0;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-05-01 00:41:33 +02: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
|
2021-06-10 23:13:03 +02:00
|
|
|
virtual void PlayPause(const quint64 offset_nanosec = 0, const Playlist::AutoScroll autoscroll = Playlist::AutoScroll_Always) = 0;
|
2021-01-26 16:48:04 +01:00
|
|
|
virtual void PlayPauseHelper() = 0;
|
2018-02-27 18:06:05 +01:00
|
|
|
virtual void RestartOrPrevious() = 0;
|
|
|
|
|
|
|
|
// Skips this track. Might load more of the current radio station.
|
|
|
|
virtual void Next() = 0;
|
|
|
|
virtual void Previous() = 0;
|
2020-12-04 19:13:21 +01:00
|
|
|
virtual void PlayPlaylist(const QString &playlist_name) = 0;
|
2022-12-03 03:46:59 +01:00
|
|
|
virtual void SetVolumeFromEngine(const uint volume) = 0;
|
|
|
|
virtual void SetVolumeFromSlider(const int value) = 0;
|
2022-09-12 23:18:54 +02:00
|
|
|
virtual void SetVolume(const uint volume) = 0;
|
2018-02-27 18:06:05 +01:00
|
|
|
virtual void VolumeUp() = 0;
|
|
|
|
virtual void VolumeDown() = 0;
|
2021-10-30 02:21:29 +02:00
|
|
|
virtual void SeekTo(const quint64 seconds) = 0;
|
2018-02-27 18:06:05 +01:00
|
|
|
// 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;
|
2021-06-10 23:13:03 +02:00
|
|
|
virtual void Stop(const bool stop_after = false) = 0;
|
|
|
|
virtual void Play(const quint64 offset_nanosec = 0) = 0;
|
|
|
|
virtual void PlayHelper() = 0;
|
2018-02-27 18:06:05 +01:00
|
|
|
virtual void ShowOSD() = 0;
|
|
|
|
|
2018-08-29 21:42:24 +02:00
|
|
|
signals:
|
2018-02-27 18:06:05 +01:00
|
|
|
void Playing();
|
|
|
|
void Paused();
|
2019-06-29 19:54:27 +02:00
|
|
|
// Emitted only when playback is manually resumed
|
|
|
|
void Resumed();
|
2018-02-27 18:06:05 +01:00
|
|
|
void Stopped();
|
2021-01-26 16:48:04 +01:00
|
|
|
void Error(QString message = QString());
|
2018-02-27 18:06:05 +01:00
|
|
|
void PlaylistFinished();
|
2019-03-09 16:48:45 +01:00
|
|
|
void VolumeEnabled(bool);
|
2021-10-30 02:21:29 +02:00
|
|
|
void VolumeChanged(uint volume);
|
2018-02-27 18:06:05 +01:00
|
|
|
void TrackSkipped(PlaylistItemPtr old_track);
|
|
|
|
// Emitted when there's a manual change to the current's track position.
|
2021-03-21 18:53:02 +01:00
|
|
|
void Seeked(qint64 microseconds);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// Emitted when Player has processed a request to play another song.
|
|
|
|
// This contains the URL of the song and a flag saying whether it was able to play the song.
|
2020-08-23 19:17:50 +02:00
|
|
|
void SongChangeRequestProcessed(QUrl url, bool valid);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
// The toggle parameter is true when user requests to toggle visibility for Pretty OSD
|
2018-12-02 14:00:53 +01:00
|
|
|
void ForceShowOSD(Song, bool toggle);
|
2018-10-14 00:08:33 +02:00
|
|
|
|
|
|
|
void Authenticated();
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class Player : public PlayerInterface {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-06-15 21:55:05 +02:00
|
|
|
explicit Player(Application *app, QObject *parent);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
static const char *kSettingsGroup;
|
|
|
|
|
2018-10-17 22:55:36 +02:00
|
|
|
Engine::EngineType CreateEngine(Engine::EngineType enginetype);
|
2018-02-27 18:06:05 +01:00
|
|
|
void Init();
|
|
|
|
|
2020-06-15 21:55:05 +02:00
|
|
|
EngineBase *engine() const override { return engine_.get(); }
|
2021-07-11 09:49:38 +02:00
|
|
|
Engine::State GetState() const override { return last_state_; }
|
2021-10-30 02:21:29 +02:00
|
|
|
uint GetVolume() const override;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-06-15 21:55:05 +02:00
|
|
|
PlaylistItemPtr GetCurrentItem() const override { return current_item_; }
|
2021-06-10 23:13:03 +02:00
|
|
|
PlaylistItemPtr GetItemAt(const int pos) const override;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-06-15 21:55:05 +02:00
|
|
|
void RegisterUrlHandler(UrlHandler *handler) override;
|
|
|
|
void UnregisterUrlHandler(UrlHandler *handler) override;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
const UrlHandler *HandlerForUrl(const QUrl &url) const;
|
|
|
|
|
|
|
|
bool PreviousWouldRestartTrack() const;
|
2018-07-01 01:29:52 +02:00
|
|
|
|
|
|
|
void SetAnalyzer(AnalyzerContainer *analyzer) { analyzer_ = analyzer; }
|
|
|
|
void SetEqualizer(Equalizer *equalizer) { equalizer_ = equalizer; }
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
public slots:
|
2020-06-15 21:55:05 +02:00
|
|
|
void ReloadSettings() override;
|
2022-12-03 03:46:59 +01:00
|
|
|
void LoadVolume() override;
|
|
|
|
void SaveVolume() override;
|
2020-06-15 21:55:05 +02:00
|
|
|
|
2021-10-30 02:21:29 +02:00
|
|
|
void PlayAt(const int index, const quint64 offset_nanosec, Engine::TrackChangeFlags change, const Playlist::AutoScroll autoscroll, const bool reshuffle, const bool force_inform = false) override;
|
2021-06-10 23:13:03 +02:00
|
|
|
void PlayPause(const quint64 offset_nanosec = 0, const Playlist::AutoScroll autoscroll = Playlist::AutoScroll_Always) override;
|
|
|
|
void PlayPauseHelper() override { PlayPause(play_offset_nanosec_); }
|
2020-06-15 21:55:05 +02:00
|
|
|
void RestartOrPrevious() override;
|
|
|
|
void Next() override;
|
|
|
|
void Previous() override;
|
2020-12-04 19:13:21 +01:00
|
|
|
void PlayPlaylist(const QString &playlist_name) override;
|
2022-12-03 03:46:59 +01:00
|
|
|
void SetVolumeFromSlider(const int value) override;
|
|
|
|
void SetVolumeFromEngine(const uint volume) override;
|
|
|
|
void SetVolume(const uint volume) override;
|
2022-01-29 20:32:15 +01:00
|
|
|
void VolumeUp() override;
|
|
|
|
void VolumeDown() override;
|
2021-10-30 02:21:29 +02:00
|
|
|
void SeekTo(const quint64 seconds) override;
|
2020-06-15 21:55:05 +02:00
|
|
|
void SeekForward() override;
|
|
|
|
void SeekBackward() override;
|
|
|
|
|
|
|
|
void CurrentMetadataChanged(const Song &metadata) override;
|
|
|
|
|
|
|
|
void Mute() override;
|
|
|
|
void Pause() override;
|
2021-06-10 23:13:03 +02:00
|
|
|
void Stop(const bool stop_after = false) override;
|
2018-02-27 18:06:05 +01:00
|
|
|
void StopAfterCurrent();
|
2021-06-10 23:13:03 +02:00
|
|
|
void Play(const quint64 offset_nanosec = 0) override;
|
|
|
|
void PlayHelper() override { Play(); }
|
2020-06-15 21:55:05 +02:00
|
|
|
void ShowOSD() override;
|
2018-02-27 18:06:05 +01:00
|
|
|
void TogglePrettyOSD();
|
2018-10-19 19:15:33 +02:00
|
|
|
|
2018-10-14 00:08:33 +02:00
|
|
|
void HandleAuthentication();
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-04-20 15:25:31 +02:00
|
|
|
signals:
|
|
|
|
void EngineChanged(Engine::EngineType enginetype);
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
private slots:
|
2020-08-23 19:17:50 +02:00
|
|
|
void EngineStateChanged(const Engine::State);
|
2018-02-27 18:06:05 +01:00
|
|
|
void EngineMetadataReceived(const Engine::SimpleMetaBundle &bundle);
|
|
|
|
void TrackAboutToEnd();
|
|
|
|
void TrackEnded();
|
|
|
|
// Play the next item on the playlist - disregarding radio stations like last.fm that might have more tracks.
|
2020-08-23 19:37:24 +02:00
|
|
|
void NextItem(const Engine::TrackChangeFlags change, const Playlist::AutoScroll autoscroll);
|
2020-08-23 19:17:50 +02:00
|
|
|
void PreviousItem(const Engine::TrackChangeFlags change);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-08-23 19:37:24 +02:00
|
|
|
void NextInternal(const Engine::TrackChangeFlags, const Playlist::AutoScroll autoscroll);
|
2021-06-10 23:13:03 +02:00
|
|
|
void PlayPlaylistInternal(const Engine::TrackChangeFlags, const Playlist::AutoScroll autoscroll, const QString &playlist_name);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-10-30 23:21:51 +01:00
|
|
|
void FatalError();
|
2018-02-27 18:06:05 +01:00
|
|
|
void ValidSongRequested(const QUrl&);
|
|
|
|
void InvalidSongRequested(const QUrl&);
|
|
|
|
|
|
|
|
void UrlHandlerDestroyed(QObject *object);
|
|
|
|
void HandleLoadResult(const UrlHandler::LoadResult &result);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Returns true if we were supposed to stop after this track.
|
2020-08-23 19:37:24 +02:00
|
|
|
bool HandleStopAfter(const Playlist::AutoScroll autoscroll);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2021-06-10 23:13:03 +02:00
|
|
|
void UnPause();
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
private:
|
|
|
|
Application *app_;
|
2021-07-01 01:50:12 +02:00
|
|
|
std::shared_ptr<EngineBase> engine_;
|
2019-04-20 15:25:31 +02:00
|
|
|
#ifdef HAVE_GSTREAMER
|
|
|
|
GstStartup *gst_startup_;
|
|
|
|
#endif
|
2018-02-27 18:06:05 +01:00
|
|
|
AnalyzerContainer *analyzer_;
|
|
|
|
Equalizer *equalizer_;
|
|
|
|
|
|
|
|
PlaylistItemPtr current_item_;
|
|
|
|
|
|
|
|
Engine::TrackChangeFlags stream_change_type_;
|
2020-08-23 19:37:24 +02:00
|
|
|
Playlist::AutoScroll autoscroll_;
|
2018-02-27 18:06:05 +01:00
|
|
|
Engine::State last_state_;
|
|
|
|
int nb_errors_received_;
|
|
|
|
|
|
|
|
QMap<QString, UrlHandler*> url_handlers_;
|
|
|
|
|
2019-06-15 19:32:26 +02:00
|
|
|
QList<QUrl> loading_async_;
|
2022-12-03 03:46:59 +01:00
|
|
|
uint volume_;
|
2021-10-30 02:21:29 +02:00
|
|
|
uint volume_before_mute_;
|
2018-02-27 18:06:05 +01:00
|
|
|
QDateTime last_pressed_previous_;
|
2018-10-30 23:21:51 +01:00
|
|
|
|
|
|
|
bool continue_on_error_;
|
|
|
|
bool greyout_;
|
2019-11-17 23:46:10 +01:00
|
|
|
BehaviourSettingsPage::PreviousBehaviour menu_previousmode_;
|
2018-02-27 18:06:05 +01:00
|
|
|
int seek_step_sec_;
|
|
|
|
|
2021-06-10 23:13:03 +02:00
|
|
|
QDateTime pause_time_;
|
|
|
|
quint64 play_offset_nanosec_;
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PLAYER_H
|