2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.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-02-07 16:34:20 +01:00
|
|
|
// Copyright: (C) 2003 Mark Kretschmann
|
2009-12-24 20:16:07 +01:00
|
|
|
// (C) 2004 Max Howell, <max.howell@methylblue.com>
|
2014-02-07 16:34:20 +01:00
|
|
|
// License: See COPYING
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
#ifndef AMAROK_ENGINEBASE_H
|
|
|
|
#define AMAROK_ENGINEBASE_H
|
|
|
|
|
2012-11-21 14:41:37 +01:00
|
|
|
#include <stdint.h>
|
2009-12-24 20:16:07 +01:00
|
|
|
#include <sys/types.h>
|
2012-11-13 14:41:15 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
#include <vector>
|
2012-11-13 14:41:15 +01:00
|
|
|
|
|
|
|
#include <QList>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QUrl>
|
|
|
|
|
2010-04-12 01:24:03 +02:00
|
|
|
#include "engine_fwd.h"
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-04-12 01:24:03 +02:00
|
|
|
namespace Engine {
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-04-12 01:24:03 +02:00
|
|
|
typedef std::vector<int16_t> Scope;
|
|
|
|
|
2014-02-06 14:48:00 +01:00
|
|
|
class Base : public QObject {
|
2010-04-12 01:24:03 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~Base();
|
|
|
|
|
|
|
|
virtual bool Init() = 0;
|
|
|
|
|
2011-03-29 00:11:07 +02:00
|
|
|
virtual void StartPreloading(const QUrl&, bool, qint64, qint64) {}
|
2011-02-13 19:29:27 +01:00
|
|
|
virtual bool Play(quint64 offset_nanosec) = 0;
|
2014-04-26 06:58:08 +02:00
|
|
|
virtual void Stop(bool stop_after = false) = 0;
|
2010-04-12 01:24:03 +02:00
|
|
|
virtual void Pause() = 0;
|
|
|
|
virtual void Unpause() = 0;
|
2011-02-13 19:29:27 +01:00
|
|
|
virtual void Seek(quint64 offset_nanosec) = 0;
|
2010-04-12 01:24:03 +02:00
|
|
|
|
2010-06-14 21:15:10 +02:00
|
|
|
virtual int AddBackgroundStream(const QUrl& url);
|
|
|
|
virtual void StopBackgroundStream(int id) {}
|
2010-12-03 14:53:43 +01:00
|
|
|
virtual void SetBackgroundStreamVolume(int id, int volume) {}
|
2010-06-14 21:15:10 +02:00
|
|
|
|
2010-04-12 01:24:03 +02:00
|
|
|
virtual State state() const = 0;
|
2011-02-13 19:29:27 +01:00
|
|
|
virtual qint64 position_nanosec() const = 0;
|
|
|
|
virtual qint64 length_nanosec() const = 0;
|
2010-04-12 01:24:03 +02:00
|
|
|
|
2011-01-02 19:53:45 +01:00
|
|
|
// Subclasses should respect given markers (beginning and end) which are
|
|
|
|
// in miliseconds.
|
2011-03-13 19:37:46 +01:00
|
|
|
virtual bool Load(const QUrl& url, TrackChangeFlags change,
|
2014-02-07 16:34:20 +01:00
|
|
|
bool force_stop_at_end, quint64 beginning_nanosec,
|
|
|
|
qint64 end_nanosec);
|
2011-03-12 21:20:13 +01:00
|
|
|
// Sets new values for the beginning and end markers of the currently playing
|
|
|
|
// song.
|
|
|
|
// This doesn't change the state of engine or the stream's current position.
|
|
|
|
virtual void RefreshMarkers(quint64 beginning_nanosec, qint64 end_nanosec) {
|
|
|
|
beginning_nanosec_ = beginning_nanosec;
|
|
|
|
end_nanosec_ = end_nanosec;
|
|
|
|
}
|
2010-04-12 01:24:03 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Plays a media stream represented with the URL 'u' from the given
|
|
|
|
// 'beginning'
|
2011-01-02 19:53:45 +01:00
|
|
|
// to the given 'end' (usually from 0 to a song's length). Both markers
|
2011-02-13 19:29:27 +01:00
|
|
|
// should be passed in nanoseconds. 'end' can be negative, indicating that the
|
2011-01-02 19:53:45 +01:00
|
|
|
// real length of 'u' stream is unknown.
|
2014-02-07 16:34:20 +01:00
|
|
|
bool Play(const QUrl& u, TrackChangeFlags c, bool force_stop_at_end,
|
2011-02-13 19:29:27 +01:00
|
|
|
quint64 beginning_nanosec, qint64 end_nanosec);
|
2011-01-02 19:53:45 +01:00
|
|
|
|
|
|
|
void SetVolume(uint value);
|
2010-06-14 21:15:10 +02:00
|
|
|
|
2010-04-21 15:55:30 +02:00
|
|
|
// Simple accessors
|
2010-04-12 01:24:03 +02:00
|
|
|
inline uint volume() const { return volume_; }
|
2014-04-30 03:38:21 +02:00
|
|
|
virtual const Scope& scope(int chunk_length) { return scope_; }
|
2010-12-07 21:29:13 +01:00
|
|
|
bool is_fadeout_enabled() const { return fadeout_enabled_; }
|
2010-04-21 15:55:30 +02:00
|
|
|
bool is_crossfade_enabled() const { return crossfade_enabled_; }
|
|
|
|
bool is_autocrossfade_enabled() const { return autocrossfade_enabled_; }
|
2011-03-13 19:37:46 +01:00
|
|
|
bool crossfade_same_album() const { return crossfade_same_album_; }
|
2010-04-12 01:24:03 +02:00
|
|
|
|
|
|
|
static const char* kSettingsGroup;
|
|
|
|
static const int kScopeSize = 1024;
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
virtual void ReloadSettings();
|
|
|
|
|
|
|
|
virtual void SetEqualizerEnabled(bool) {}
|
2014-02-07 16:34:20 +01:00
|
|
|
virtual void SetEqualizerParameters(int preamp, const QList<int>& bandGains) {
|
|
|
|
}
|
2013-04-27 05:05:42 +02:00
|
|
|
virtual void SetStereoBalance(float value) {}
|
2010-04-12 01:24:03 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
signals:
|
2010-04-12 01:52:16 +02:00
|
|
|
// Emitted when crossfading is enabled and the track is crossfade_duration_
|
|
|
|
// away from finishing
|
|
|
|
void TrackAboutToEnd();
|
|
|
|
|
2010-04-12 01:24:03 +02:00
|
|
|
void TrackEnded();
|
|
|
|
|
2011-02-16 23:43:05 +01:00
|
|
|
void FadeoutFinishedSignal();
|
|
|
|
|
2010-04-12 01:24:03 +02:00
|
|
|
void StatusText(const QString&);
|
|
|
|
void Error(const QString&);
|
|
|
|
|
2011-03-10 19:01:35 +01:00
|
|
|
// Emitted when Engine was unable to play a song with the given QUrl.
|
|
|
|
void InvalidSongRequested(const QUrl&);
|
2014-02-07 16:34:20 +01:00
|
|
|
// Emitted when Engine successfully started playing a song with the
|
2011-03-10 19:01:35 +01:00
|
|
|
// given QUrl.
|
|
|
|
void ValidSongRequested(const QUrl&);
|
|
|
|
|
2010-04-12 01:24:03 +02:00
|
|
|
void MetaData(const Engine::SimpleMetaBundle&);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Signals that the engine's state has changed (a stream was stopped for
|
|
|
|
// example).
|
2010-12-13 00:20:41 +01:00
|
|
|
// Always use the state from event, because it's not guaranteed that immediate
|
|
|
|
// subsequent call to state() won't return a stale value.
|
2010-04-12 01:24:03 +02:00
|
|
|
void StateChanged(Engine::State);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Base();
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
virtual void SetVolumeSW(uint percent) = 0;
|
|
|
|
static uint MakeVolumeLogarithmic(uint volume);
|
2010-04-12 01:52:16 +02:00
|
|
|
void EmitAboutToEnd();
|
2010-04-12 01:24:03 +02:00
|
|
|
|
2010-04-12 01:52:16 +02:00
|
|
|
protected:
|
2011-02-13 19:29:27 +01:00
|
|
|
uint volume_;
|
|
|
|
quint64 beginning_nanosec_;
|
|
|
|
qint64 end_nanosec_;
|
|
|
|
QUrl url_;
|
2010-04-12 01:24:03 +02:00
|
|
|
Scope scope_;
|
|
|
|
|
|
|
|
bool fadeout_enabled_;
|
2011-02-13 19:29:27 +01:00
|
|
|
qint64 fadeout_duration_nanosec_;
|
2010-04-12 01:24:03 +02:00
|
|
|
bool crossfade_enabled_;
|
2010-04-12 01:52:16 +02:00
|
|
|
bool autocrossfade_enabled_;
|
2011-03-13 19:37:46 +01:00
|
|
|
bool crossfade_same_album_;
|
2010-06-14 21:15:10 +02:00
|
|
|
int next_background_stream_id_;
|
2013-04-22 21:42:04 +02:00
|
|
|
bool fadeout_pause_enabled_;
|
|
|
|
qint64 fadeout_pause_duration_nanosec_;
|
2010-04-12 01:52:16 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool about_to_end_emitted_;
|
2014-02-06 14:48:00 +01:00
|
|
|
Q_DISABLE_COPY(Base);
|
2010-04-12 01:24:03 +02:00
|
|
|
};
|
|
|
|
|
2010-04-12 02:26:16 +02:00
|
|
|
struct SimpleMetaBundle {
|
2010-04-12 01:24:03 +02:00
|
|
|
QString title;
|
|
|
|
QString artist;
|
|
|
|
QString album;
|
|
|
|
QString comment;
|
|
|
|
QString genre;
|
|
|
|
QString bitrate;
|
|
|
|
QString samplerate;
|
|
|
|
QString length;
|
|
|
|
QString year;
|
|
|
|
QString tracknr;
|
|
|
|
};
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
} // namespace
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
#endif
|