Use C++11 enum class
This commit is contained in:
@@ -20,9 +20,15 @@ class Base;
|
||||
*
|
||||
* It is vital to be Idle just after the track has ended!
|
||||
*/
|
||||
enum State { Empty, Idle, Playing, Paused, Error };
|
||||
enum class State {
|
||||
Empty,
|
||||
Idle,
|
||||
Playing,
|
||||
Paused,
|
||||
Error
|
||||
};
|
||||
|
||||
enum TrackChangeType {
|
||||
enum class TrackChangeType {
|
||||
// One of:
|
||||
First = 0x01,
|
||||
Manual = 0x02,
|
||||
@@ -39,4 +45,7 @@ Q_DECLARE_FLAGS(TrackChangeFlags, TrackChangeType)
|
||||
|
||||
using EngineBase = Engine::Base;
|
||||
|
||||
Q_DECLARE_METATYPE(Engine::State)
|
||||
Q_DECLARE_METATYPE(Engine::TrackChangeType)
|
||||
|
||||
#endif // ENGINE_FWD_H
|
||||
|
||||
@@ -159,8 +159,8 @@ void Engine::Base::ReloadSettings() {
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup(NetworkProxySettingsPage::kSettingsGroup);
|
||||
NetworkProxyFactory::Mode proxy_mode = NetworkProxyFactory::Mode(s.value("mode", NetworkProxyFactory::Mode_System).toInt());
|
||||
if (proxy_mode == NetworkProxyFactory::Mode_Manual && s.contains("engine") && s.value("engine").toBool()) {
|
||||
const NetworkProxyFactory::Mode proxy_mode = static_cast<NetworkProxyFactory::Mode>(s.value("mode", static_cast<int>(NetworkProxyFactory::Mode::System)).toInt());
|
||||
if (proxy_mode == NetworkProxyFactory::Mode::Manual && s.contains("engine") && s.value("engine").toBool()) {
|
||||
QString proxy_host = s.value("hostname").toString();
|
||||
int proxy_port = s.value("port").toInt();
|
||||
if (proxy_host.isEmpty() || proxy_port <= 0) {
|
||||
|
||||
@@ -223,11 +223,11 @@ class Base : public QObject {
|
||||
};
|
||||
|
||||
struct SimpleMetaBundle {
|
||||
SimpleMetaBundle() : type(Type_Any), length(-1), year(-1), track(-1), filetype(Song::FileType_Unknown), samplerate(-1), bitdepth(-1), bitrate(-1) {}
|
||||
enum Type {
|
||||
Type_Any,
|
||||
Type_Current,
|
||||
Type_Next,
|
||||
SimpleMetaBundle() : type(Type::Any), length(-1), year(-1), track(-1), filetype(Song::FileType::Unknown), samplerate(-1), bitdepth(-1), bitrate(-1) {}
|
||||
enum class Type {
|
||||
Any,
|
||||
Current,
|
||||
Next
|
||||
};
|
||||
Type type;
|
||||
QUrl url;
|
||||
@@ -250,5 +250,6 @@ struct SimpleMetaBundle {
|
||||
} // namespace Engine
|
||||
|
||||
Q_DECLARE_METATYPE(EngineBase::OutputDetails)
|
||||
Q_DECLARE_METATYPE(Engine::SimpleMetaBundle)
|
||||
|
||||
#endif // ENGINEBASE_H
|
||||
|
||||
@@ -27,26 +27,26 @@ namespace Engine {
|
||||
|
||||
Engine::EngineType EngineTypeFromName(const QString &enginename) {
|
||||
QString lower = enginename.toLower();
|
||||
if (lower == "gstreamer") return Engine::GStreamer;
|
||||
else if (lower == "vlc") return Engine::VLC;
|
||||
else return Engine::None;
|
||||
if (lower == "gstreamer") return Engine::EngineType::GStreamer;
|
||||
else if (lower == "vlc") return Engine::EngineType::VLC;
|
||||
else return Engine::EngineType::None;
|
||||
}
|
||||
|
||||
QString EngineName(const Engine::EngineType enginetype) {
|
||||
switch (enginetype) {
|
||||
case Engine::GStreamer: return QString("gstreamer");
|
||||
case Engine::VLC: return QString("vlc");
|
||||
case Engine::None:
|
||||
default: return QString("None");
|
||||
case Engine::EngineType::GStreamer: return QString("gstreamer");
|
||||
case Engine::EngineType::VLC: return QString("vlc");
|
||||
case Engine::EngineType::None:
|
||||
default: return QString("None");
|
||||
}
|
||||
}
|
||||
|
||||
QString EngineDescription(Engine::EngineType enginetype) {
|
||||
switch (enginetype) {
|
||||
case Engine::GStreamer: return QString("GStreamer");
|
||||
case Engine::VLC: return QString("VLC");
|
||||
case Engine::None:
|
||||
default: return QString("None");
|
||||
case Engine::EngineType::GStreamer: return QString("GStreamer");
|
||||
case Engine::EngineType::VLC: return QString("VLC");
|
||||
case Engine::EngineType::None:
|
||||
default: return QString("None");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
namespace Engine {
|
||||
|
||||
enum EngineType {
|
||||
enum class EngineType {
|
||||
None,
|
||||
GStreamer,
|
||||
VLC,
|
||||
|
||||
@@ -72,7 +72,7 @@ const char *GstEngine::kOSXAudioSink = "osxaudiosink";
|
||||
const int GstEngine::kDiscoveryTimeoutS = 10;
|
||||
|
||||
GstEngine::GstEngine(TaskManager *task_manager, QObject *parent)
|
||||
: Engine::Base(Engine::GStreamer, parent),
|
||||
: Engine::Base(Engine::EngineType::GStreamer, parent),
|
||||
task_manager_(task_manager),
|
||||
gst_startup_(nullptr),
|
||||
discoverer_(nullptr),
|
||||
@@ -137,19 +137,19 @@ bool GstEngine::Init() {
|
||||
|
||||
Engine::State GstEngine::state() const {
|
||||
|
||||
if (!current_pipeline_) return stream_url_.isEmpty() ? Engine::Empty : Engine::Idle;
|
||||
if (!current_pipeline_) return stream_url_.isEmpty() ? Engine::State::Empty : Engine::State::Idle;
|
||||
|
||||
switch (current_pipeline_->state()) {
|
||||
case GST_STATE_NULL:
|
||||
return Engine::Empty;
|
||||
return Engine::State::Empty;
|
||||
case GST_STATE_READY:
|
||||
return Engine::Idle;
|
||||
return Engine::State::Idle;
|
||||
case GST_STATE_PLAYING:
|
||||
return Engine::Playing;
|
||||
return Engine::State::Playing;
|
||||
case GST_STATE_PAUSED:
|
||||
return Engine::Paused;
|
||||
return Engine::State::Paused;
|
||||
default:
|
||||
return Engine::Empty;
|
||||
return Engine::State::Empty;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -181,12 +181,12 @@ bool GstEngine::Load(const QUrl &stream_url, const QUrl &original_url, Engine::T
|
||||
|
||||
QByteArray gst_url = FixupUrl(stream_url);
|
||||
|
||||
bool crossfade = current_pipeline_ && ((crossfade_enabled_ && change & Engine::Manual) || (autocrossfade_enabled_ && change & Engine::Auto) || ((crossfade_enabled_ || autocrossfade_enabled_) && change & Engine::Intro));
|
||||
bool crossfade = current_pipeline_ && ((crossfade_enabled_ && change & Engine::TrackChangeType::Manual) || (autocrossfade_enabled_ && change & Engine::TrackChangeType::Auto) || ((crossfade_enabled_ || autocrossfade_enabled_) && change & Engine::TrackChangeType::Intro));
|
||||
|
||||
if (change & Engine::Auto && change & Engine::SameAlbum && !crossfade_same_album_)
|
||||
if (change & Engine::TrackChangeType::Auto && change & Engine::TrackChangeType::SameAlbum && !crossfade_same_album_)
|
||||
crossfade = false;
|
||||
|
||||
if (!crossfade && current_pipeline_ && current_pipeline_->stream_url() == gst_url && change & Engine::Auto) {
|
||||
if (!crossfade && current_pipeline_ && current_pipeline_->stream_url() == gst_url && change & Engine::TrackChangeType::Auto) {
|
||||
// We're not crossfading, and the pipeline is already playing the URI we want, so just do nothing.
|
||||
return true;
|
||||
}
|
||||
@@ -275,7 +275,7 @@ void GstEngine::Stop(const bool stop_after) {
|
||||
|
||||
current_pipeline_.reset();
|
||||
BufferingFinished();
|
||||
emit StateChanged(Engine::Empty);
|
||||
emit StateChanged(Engine::State::Empty);
|
||||
|
||||
}
|
||||
|
||||
@@ -289,7 +289,7 @@ void GstEngine::Pause() {
|
||||
current_pipeline_->StartFader(fadeout_pause_duration_nanosec_, QTimeLine::Forward, QEasingCurve::InOutQuad, false);
|
||||
is_fading_out_to_pause_ = false;
|
||||
has_faded_out_ = false;
|
||||
emit StateChanged(Engine::Playing);
|
||||
emit StateChanged(Engine::State::Playing);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ void GstEngine::Pause() {
|
||||
}
|
||||
else {
|
||||
current_pipeline_->SetState(GST_STATE_PAUSED);
|
||||
emit StateChanged(Engine::Paused);
|
||||
emit StateChanged(Engine::State::Paused);
|
||||
StopTimers();
|
||||
}
|
||||
}
|
||||
@@ -321,7 +321,7 @@ void GstEngine::Unpause() {
|
||||
has_faded_out_ = false;
|
||||
}
|
||||
|
||||
emit StateChanged(Engine::Playing);
|
||||
emit StateChanged(Engine::State::Playing);
|
||||
|
||||
StartTimers();
|
||||
}
|
||||
@@ -542,7 +542,7 @@ void GstEngine::HandlePipelineError(const int pipeline_id, const int domain, con
|
||||
|
||||
current_pipeline_.reset();
|
||||
BufferingFinished();
|
||||
emit StateChanged(Engine::Error);
|
||||
emit StateChanged(Engine::State::Error);
|
||||
|
||||
if (
|
||||
(domain == static_cast<int>(GST_RESOURCE_ERROR) && (
|
||||
@@ -596,7 +596,7 @@ void GstEngine::FadeoutPauseFinished() {
|
||||
|
||||
fadeout_pause_pipeline_->SetState(GST_STATE_PAUSED);
|
||||
current_pipeline_->SetState(GST_STATE_PAUSED);
|
||||
emit StateChanged(Engine::Paused);
|
||||
emit StateChanged(Engine::State::Paused);
|
||||
StopTimers();
|
||||
|
||||
is_fading_out_to_pause_ = false;
|
||||
@@ -651,7 +651,7 @@ void GstEngine::PlayDone(const GstStateChangeReturn ret, const quint64 offset_na
|
||||
Seek(offset_nanosec);
|
||||
}
|
||||
|
||||
emit StateChanged(Engine::Playing);
|
||||
emit StateChanged(Engine::State::Playing);
|
||||
// We've successfully started playing a media stream with this url
|
||||
emit ValidSongRequested(stream_url_);
|
||||
|
||||
@@ -828,7 +828,7 @@ std::shared_ptr<GstEnginePipeline> GstEngine::CreatePipeline(const QByteArray &g
|
||||
if (!ret->InitFromUrl(gst_url, original_url, end_nanosec, error)) {
|
||||
ret.reset();
|
||||
emit Error(error);
|
||||
emit StateChanged(Engine::Error);
|
||||
emit StateChanged(Engine::State::Error);
|
||||
emit FatalError();
|
||||
}
|
||||
|
||||
@@ -919,11 +919,11 @@ void GstEngine::StreamDiscovered(GstDiscoverer*, GstDiscovererInfo *info, GError
|
||||
|
||||
Engine::SimpleMetaBundle bundle;
|
||||
if (discovered_url == instance->current_pipeline_->stream_url()) {
|
||||
bundle.type = Engine::SimpleMetaBundle::Type_Current;
|
||||
bundle.type = Engine::SimpleMetaBundle::Type::Current;
|
||||
bundle.url = instance->current_pipeline_->original_url();
|
||||
}
|
||||
else if (discovered_url == instance->current_pipeline_->next_stream_url()) {
|
||||
bundle.type = Engine::SimpleMetaBundle::Type_Next;
|
||||
bundle.type = Engine::SimpleMetaBundle::Type::Next;
|
||||
bundle.url = instance->current_pipeline_->next_original_url();
|
||||
}
|
||||
bundle.stream_url = QUrl(discovered_url);
|
||||
@@ -940,19 +940,19 @@ void GstEngine::StreamDiscovered(GstDiscoverer*, GstDiscovererInfo *info, GError
|
||||
QString mimetype = gst_structure_get_name(gst_structure);
|
||||
if (!mimetype.isEmpty() && mimetype != "audio/mpeg") {
|
||||
bundle.filetype = Song::FiletypeByMimetype(mimetype);
|
||||
if (bundle.filetype == Song::FileType_Unknown) {
|
||||
if (bundle.filetype == Song::FileType::Unknown) {
|
||||
qLog(Error) << "Unknown mimetype" << mimetype;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bundle.filetype == Song::FileType_Unknown) {
|
||||
if (bundle.filetype == Song::FileType::Unknown) {
|
||||
gchar *codec_description = gst_pb_utils_get_codec_description(caps);
|
||||
QString filetype_description = (codec_description ? QString(codec_description) : QString());
|
||||
g_free(codec_description);
|
||||
if (!filetype_description.isEmpty()) {
|
||||
bundle.filetype = Song::FiletypeByDescription(filetype_description);
|
||||
if (bundle.filetype == Song::FileType_Unknown) {
|
||||
if (bundle.filetype == Song::FileType::Unknown) {
|
||||
qLog(Error) << "Unknown filetype" << filetype_description;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1292,7 +1292,7 @@ void GstEnginePipeline::TagMessageReceived(GstMessage *msg) {
|
||||
gst_message_parse_tag(msg, &taglist);
|
||||
|
||||
Engine::SimpleMetaBundle bundle;
|
||||
bundle.type = Engine::SimpleMetaBundle::Type_Current;
|
||||
bundle.type = Engine::SimpleMetaBundle::Type::Current;
|
||||
bundle.url = original_url_;
|
||||
bundle.title = ParseStrTag(taglist, GST_TAG_TITLE);
|
||||
bundle.artist = ParseStrTag(taglist, GST_TAG_ARTIST);
|
||||
|
||||
@@ -39,10 +39,10 @@
|
||||
#include "vlcscopedref.h"
|
||||
|
||||
VLCEngine::VLCEngine(TaskManager *task_manager, QObject *parent)
|
||||
: Engine::Base(Engine::VLC, parent),
|
||||
: Engine::Base(Engine::EngineType::VLC, parent),
|
||||
instance_(nullptr),
|
||||
player_(nullptr),
|
||||
state_(Engine::Empty) {
|
||||
state_(Engine::State::Empty) {
|
||||
|
||||
Q_UNUSED(task_manager);
|
||||
|
||||
@@ -52,7 +52,7 @@ VLCEngine::VLCEngine(TaskManager *task_manager, QObject *parent)
|
||||
|
||||
VLCEngine::~VLCEngine() {
|
||||
|
||||
if (state_ == Engine::Playing || state_ == Engine::Paused) {
|
||||
if (state_ == Engine::State::Playing || state_ == Engine::State::Paused) {
|
||||
libvlc_media_player_stop(player_);
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ void VLCEngine::SetVolumeSW(const uint percent) {
|
||||
|
||||
qint64 VLCEngine::position_nanosec() const {
|
||||
|
||||
if (state_ == Engine::Empty) return 0;
|
||||
if (state_ == Engine::State::Empty) return 0;
|
||||
const qint64 result = (position() * kNsecPerMsec);
|
||||
return qMax(0LL, result);
|
||||
|
||||
@@ -205,7 +205,7 @@ qint64 VLCEngine::position_nanosec() const {
|
||||
|
||||
qint64 VLCEngine::length_nanosec() const {
|
||||
|
||||
if (state_ == Engine::Empty) return 0;
|
||||
if (state_ == Engine::State::Empty) return 0;
|
||||
const qint64 result = (end_nanosec_ - static_cast<qint64>(beginning_nanosec_));
|
||||
if (result > 0) {
|
||||
return result;
|
||||
@@ -293,31 +293,31 @@ void VLCEngine::StateChangedCallback(const libvlc_event_t *e, void *data) {
|
||||
|
||||
case libvlc_MediaPlayerStopped:{
|
||||
const Engine::State state = engine->state_;
|
||||
engine->state_ = Engine::Empty;
|
||||
if (state == Engine::Playing) {
|
||||
engine->state_ = Engine::State::Empty;
|
||||
if (state == Engine::State::Playing) {
|
||||
emit engine->StateChanged(engine->state_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case libvlc_MediaPlayerEncounteredError:
|
||||
engine->state_ = Engine::Error;
|
||||
engine->state_ = Engine::State::Error;
|
||||
emit engine->StateChanged(engine->state_);
|
||||
emit engine->FatalError();
|
||||
break;
|
||||
|
||||
case libvlc_MediaPlayerPlaying:
|
||||
engine->state_ = Engine::Playing;
|
||||
engine->state_ = Engine::State::Playing;
|
||||
emit engine->StateChanged(engine->state_);
|
||||
break;
|
||||
|
||||
case libvlc_MediaPlayerPaused:
|
||||
engine->state_ = Engine::Paused;
|
||||
engine->state_ = Engine::State::Paused;
|
||||
emit engine->StateChanged(engine->state_);
|
||||
break;
|
||||
|
||||
case libvlc_MediaPlayerEndReached:
|
||||
engine->state_ = Engine::Idle;
|
||||
engine->state_ = Engine::State::Idle;
|
||||
emit engine->TrackEnded();
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user