2016-09-23 16:04:26 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop 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.
|
|
|
|
|
|
|
|
It 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.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-09-23 16:04:26 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace Notify {
|
|
|
|
struct PeerUpdate;
|
|
|
|
} // namespace Notify
|
|
|
|
class AudioMsgId;
|
|
|
|
|
|
|
|
namespace Media {
|
|
|
|
namespace Player {
|
|
|
|
|
|
|
|
void start();
|
|
|
|
void finish();
|
|
|
|
|
|
|
|
class Instance;
|
|
|
|
Instance *instance();
|
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
struct TrackState;
|
2016-09-23 16:04:26 +00:00
|
|
|
|
2016-09-28 21:16:02 +00:00
|
|
|
class Instance : private base::Subscriber {
|
2016-09-23 16:04:26 +00:00
|
|
|
public:
|
2017-05-19 18:11:33 +00:00
|
|
|
void play(AudioMsgId::Type type);
|
2017-02-10 22:37:37 +00:00
|
|
|
void pause(AudioMsgId::Type type);
|
2017-05-19 18:11:33 +00:00
|
|
|
void stop(AudioMsgId::Type type);
|
|
|
|
void playPause(AudioMsgId::Type type);
|
2017-05-21 13:16:39 +00:00
|
|
|
bool next(AudioMsgId::Type type);
|
|
|
|
bool previous(AudioMsgId::Type type);
|
|
|
|
|
|
|
|
AudioMsgId::Type getActiveType() const;
|
2016-09-23 16:04:26 +00:00
|
|
|
|
2017-05-19 18:11:33 +00:00
|
|
|
void play() {
|
|
|
|
play(getActiveType());
|
|
|
|
}
|
|
|
|
void pause() {
|
|
|
|
pause(getActiveType());
|
|
|
|
}
|
|
|
|
void stop() {
|
|
|
|
stop(getActiveType());
|
|
|
|
}
|
|
|
|
void playPause() {
|
|
|
|
playPause(getActiveType());
|
|
|
|
}
|
2017-05-21 13:16:39 +00:00
|
|
|
bool next() {
|
|
|
|
return next(getActiveType());
|
2017-05-19 18:11:33 +00:00
|
|
|
}
|
2017-05-21 13:16:39 +00:00
|
|
|
bool previous() {
|
|
|
|
return previous(getActiveType());
|
2017-05-19 18:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void playPauseCancelClicked(AudioMsgId::Type type);
|
2016-10-09 17:08:16 +00:00
|
|
|
|
2016-09-23 16:04:26 +00:00
|
|
|
void play(const AudioMsgId &audioId);
|
2017-05-19 18:11:33 +00:00
|
|
|
AudioMsgId current(AudioMsgId::Type type) const {
|
|
|
|
if (auto data = getData(type)) {
|
|
|
|
return data->current;
|
|
|
|
}
|
|
|
|
return AudioMsgId();
|
2016-09-23 16:04:26 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 18:11:33 +00:00
|
|
|
bool repeatEnabled(AudioMsgId::Type type) const {
|
|
|
|
if (auto data = getData(type)) {
|
|
|
|
return data->repeatEnabled;
|
|
|
|
}
|
|
|
|
return false;
|
2016-09-23 16:04:26 +00:00
|
|
|
}
|
2017-05-19 18:11:33 +00:00
|
|
|
void toggleRepeat(AudioMsgId::Type type) {
|
|
|
|
if (auto data = getData(type)) {
|
|
|
|
data->repeatEnabled = !data->repeatEnabled;
|
2017-05-21 13:16:39 +00:00
|
|
|
_repeatChangedNotifier.notify(type);
|
2017-05-19 18:11:33 +00:00
|
|
|
}
|
2016-09-23 16:04:26 +00:00
|
|
|
}
|
|
|
|
|
2017-02-10 22:37:37 +00:00
|
|
|
bool isSeeking(AudioMsgId::Type type) const {
|
2017-05-19 18:11:33 +00:00
|
|
|
if (auto data = getData(type)) {
|
|
|
|
return (data->seeking == data->current);
|
2017-02-10 22:37:37 +00:00
|
|
|
}
|
|
|
|
return false;
|
2016-09-23 16:04:26 +00:00
|
|
|
}
|
2017-02-10 22:37:37 +00:00
|
|
|
void startSeeking(AudioMsgId::Type type);
|
|
|
|
void stopSeeking(AudioMsgId::Type type);
|
2016-09-23 16:04:26 +00:00
|
|
|
|
2017-05-19 18:11:33 +00:00
|
|
|
QList<FullMsgId> playlist(AudioMsgId::Type type) const {
|
|
|
|
if (auto data = getData(type)) {
|
|
|
|
return data->playlist;
|
|
|
|
}
|
|
|
|
return QList<FullMsgId>();
|
2016-09-23 16:04:26 +00:00
|
|
|
}
|
|
|
|
|
2016-10-14 17:10:15 +00:00
|
|
|
base::Observable<bool> &usePanelPlayer() {
|
|
|
|
return _usePanelPlayer;
|
|
|
|
}
|
|
|
|
base::Observable<bool> &titleButtonOver() {
|
|
|
|
return _titleButtonOver;
|
2016-09-23 16:04:26 +00:00
|
|
|
}
|
2016-10-14 17:10:15 +00:00
|
|
|
base::Observable<bool> &playerWidgetOver() {
|
|
|
|
return _playerWidgetOver;
|
2016-10-12 19:34:25 +00:00
|
|
|
}
|
2017-01-24 21:24:39 +00:00
|
|
|
base::Observable<TrackState> &updatedNotifier() {
|
2016-09-23 16:04:26 +00:00
|
|
|
return _updatedNotifier;
|
|
|
|
}
|
2017-05-21 13:16:39 +00:00
|
|
|
base::Observable<AudioMsgId::Type> &tracksFinishedNotifier() {
|
|
|
|
return _tracksFinishedNotifier;
|
|
|
|
}
|
|
|
|
base::Observable<AudioMsgId::Type> &playlistChangedNotifier() {
|
2016-09-23 16:04:26 +00:00
|
|
|
return _playlistChangedNotifier;
|
|
|
|
}
|
2017-05-21 13:16:39 +00:00
|
|
|
base::Observable<AudioMsgId::Type> &trackChangedNotifier() {
|
|
|
|
return _trackChangedNotifier;
|
2016-09-23 16:04:26 +00:00
|
|
|
}
|
2017-05-21 13:16:39 +00:00
|
|
|
base::Observable<AudioMsgId::Type> &repeatChangedNotifier() {
|
2016-10-12 19:34:25 +00:00
|
|
|
return _repeatChangedNotifier;
|
|
|
|
}
|
2016-09-23 16:04:26 +00:00
|
|
|
|
|
|
|
void documentLoadProgress(DocumentData *document);
|
|
|
|
|
2016-10-19 08:59:19 +00:00
|
|
|
void clear();
|
|
|
|
|
2016-09-23 16:04:26 +00:00
|
|
|
private:
|
|
|
|
Instance();
|
|
|
|
friend void start();
|
|
|
|
|
2017-05-19 18:11:33 +00:00
|
|
|
struct Data {
|
|
|
|
Data(AudioMsgId::Type type, MediaOverviewType overview) : type(type), overview(overview) {
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioMsgId::Type type;
|
|
|
|
MediaOverviewType overview;
|
|
|
|
AudioMsgId current;
|
|
|
|
AudioMsgId seeking;
|
|
|
|
History *history = nullptr;
|
|
|
|
History *migrated = nullptr;
|
|
|
|
bool repeatEnabled = false;
|
|
|
|
QList<FullMsgId> playlist;
|
|
|
|
bool isPlaying = false;
|
|
|
|
};
|
|
|
|
|
2016-09-23 16:04:26 +00:00
|
|
|
// Observed notifications.
|
|
|
|
void notifyPeerUpdated(const Notify::PeerUpdate &update);
|
|
|
|
void handleSongUpdate(const AudioMsgId &audioId);
|
|
|
|
|
2017-05-19 18:11:33 +00:00
|
|
|
void checkPeerUpdate(AudioMsgId::Type type, const Notify::PeerUpdate &update);
|
2016-09-23 16:04:26 +00:00
|
|
|
void setCurrent(const AudioMsgId &audioId);
|
2017-05-19 18:11:33 +00:00
|
|
|
void rebuildPlaylist(Data *data);
|
2017-05-21 13:16:39 +00:00
|
|
|
bool moveInPlaylist(Data *data, int delta);
|
2017-05-19 18:11:33 +00:00
|
|
|
void preloadNext(Data *data);
|
2016-10-19 08:59:19 +00:00
|
|
|
void handleLogout();
|
2016-09-23 16:04:26 +00:00
|
|
|
|
|
|
|
template <typename CheckCallback>
|
2017-02-10 22:37:37 +00:00
|
|
|
void emitUpdate(AudioMsgId::Type type, CheckCallback check);
|
2016-09-23 16:04:26 +00:00
|
|
|
|
2017-05-19 18:11:33 +00:00
|
|
|
Data *getData(AudioMsgId::Type type) {
|
|
|
|
if (type == AudioMsgId::Type::Song) {
|
|
|
|
return &_songData;
|
|
|
|
} else if (type == AudioMsgId::Type::Voice) {
|
|
|
|
return &_voiceData;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-09-23 16:04:26 +00:00
|
|
|
|
2017-05-19 18:11:33 +00:00
|
|
|
const Data *getData(AudioMsgId::Type type) const {
|
|
|
|
if (type == AudioMsgId::Type::Song) {
|
|
|
|
return &_songData;
|
|
|
|
} else if (type == AudioMsgId::Type::Voice) {
|
|
|
|
return &_voiceData;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-09-23 16:04:26 +00:00
|
|
|
|
2017-05-19 18:11:33 +00:00
|
|
|
Data _songData;
|
|
|
|
Data _voiceData;
|
2017-02-10 22:37:37 +00:00
|
|
|
|
2016-10-14 17:10:15 +00:00
|
|
|
base::Observable<bool> _usePanelPlayer;
|
|
|
|
base::Observable<bool> _titleButtonOver;
|
|
|
|
base::Observable<bool> _playerWidgetOver;
|
2017-01-24 21:24:39 +00:00
|
|
|
base::Observable<TrackState> _updatedNotifier;
|
2017-05-21 13:16:39 +00:00
|
|
|
base::Observable<AudioMsgId::Type> _tracksFinishedNotifier;
|
|
|
|
base::Observable<AudioMsgId::Type> _playlistChangedNotifier;
|
|
|
|
base::Observable<AudioMsgId::Type> _trackChangedNotifier;
|
|
|
|
base::Observable<AudioMsgId::Type> _repeatChangedNotifier;
|
2016-09-23 16:04:26 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Clip
|
|
|
|
} // namespace Media
|