diff --git a/src/engines/enginebase.cpp b/src/engines/enginebase.cpp index 36a64e753..ccad4e3e9 100644 --- a/src/engines/enginebase.cpp +++ b/src/engines/enginebase.cpp @@ -32,7 +32,8 @@ Engine::Base::Base() fadeout_enabled_(true), fadeout_duration_(2000), crossfade_enabled_(true), - crossfade_next_track_(false) + crossfade_next_track_(false), + about_to_end_emitted_(false) { } @@ -41,6 +42,7 @@ Engine::Base::~Base() { bool Engine::Base::Load(const QUrl &url) { url_ = url; + about_to_end_emitted_ = false; return true; } @@ -62,4 +64,13 @@ void Engine::Base::ReloadSettings() { fadeout_enabled_ = s.value("FadeoutEnabled", true).toBool(); fadeout_duration_ = s.value("FadeoutDuration", 2000).toInt(); crossfade_enabled_ = s.value("CrossfadeEnabled", true).toBool(); + autocrossfade_enabled_ = s.value("AutoCrossfadeEnabled", false).toBool(); +} + +void Engine::Base::EmitAboutToEnd() { + if (about_to_end_emitted_) + return; + + about_to_end_emitted_ = true; + emit TrackAboutToEnd(); } diff --git a/src/engines/enginebase.h b/src/engines/enginebase.h index f305c579a..4beeadd65 100644 --- a/src/engines/enginebase.h +++ b/src/engines/enginebase.h @@ -72,6 +72,10 @@ class Base : public QObject { virtual void SetEqualizerParameters(int preamp, const QList& bandGains) {} signals: + // Emitted when crossfading is enabled and the track is crossfade_duration_ + // away from finishing + void TrackAboutToEnd(); + void TrackEnded(); void StatusText(const QString&); @@ -86,11 +90,12 @@ class Base : public QObject { virtual void SetVolumeSW( uint percent ) = 0; static uint MakeVolumeLogarithmic( uint volume ); + void EmitAboutToEnd(); Base( const Base& ); const Base &operator=( const Base& ); -protected: + protected: uint volume_; QUrl url_; Scope scope_; @@ -98,7 +103,11 @@ protected: bool fadeout_enabled_; int fadeout_duration_; bool crossfade_enabled_; + bool autocrossfade_enabled_; bool crossfade_next_track_; + + private: + bool about_to_end_emitted_; }; diff --git a/src/engines/gstengine.cpp b/src/engines/gstengine.cpp index f575826cf..f9b999dbf 100644 --- a/src/engines/gstengine.cpp +++ b/src/engines/gstengine.cpp @@ -412,6 +412,17 @@ void GstEngine::timerEvent( QTimerEvent* ) { // this is why the timer must run as long as we are playing, and not just when // we are fading PruneScope(); + + // Emit TrackAboutToEnd when we're a few seconds away from finishing + if (current_pipeline_ && autocrossfade_enabled_) { + const qint64 position = current_pipeline_->position(); + const qint64 length = current_pipeline_->length(); + const qint64 msec_remaining = (length - position) / 1000000; + const qint64 fudge = 100; // Mmm fudge + + if (length > 0 && msec_remaining < fadeout_duration_ + fudge) + EmitAboutToEnd(); + } } void GstEngine::HandlePipelineError(const QString& message) { diff --git a/src/player.cpp b/src/player.cpp index c923c2093..584321e44 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -81,6 +81,7 @@ void Player::Init() { qFatal("Error initialising audio engine"); connect(engine_, SIGNAL(StateChanged(Engine::State)), SLOT(EngineStateChanged(Engine::State))); + connect(engine_, SIGNAL(TrackAboutToEnd()), SLOT(Next())); connect(engine_, SIGNAL(TrackEnded()), SLOT(TrackEnded())); connect(engine_, SIGNAL(MetaData(Engine::SimpleMetaBundle)), SLOT(EngineMetadataReceived(Engine::SimpleMetaBundle))); diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index fd1516c4c..28ade5ac6 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -39,6 +39,7 @@ SettingsDialog::SettingsDialog(QWidget* parent) // Playback connect(ui_.fading_cross, SIGNAL(toggled(bool)), SLOT(FadingOptionsChanged())); connect(ui_.fading_out, SIGNAL(toggled(bool)), SLOT(FadingOptionsChanged())); + connect(ui_.fading_auto, SIGNAL(toggled(bool)), SLOT(FadingOptionsChanged())); connect(ui_.gst_plugin, SIGNAL(currentIndexChanged(int)), SLOT(GstPluginChanged(int))); // Behaviour @@ -118,6 +119,7 @@ void SettingsDialog::accept() { s.setValue("FadeoutEnabled", ui_.fading_out->isChecked()); s.setValue("FadeoutDuration", ui_.fading_duration->value()); s.setValue("CrossfadeEnabled", ui_.fading_cross->isChecked()); + s.setValue("AutoCrossfadeEnabled", ui_.fading_auto->isChecked()); s.endGroup(); s.beginGroup(GstEngine::kSettingsGroup); @@ -175,6 +177,7 @@ void SettingsDialog::showEvent(QShowEvent*) { s.beginGroup(Engine::Base::kSettingsGroup); ui_.fading_out->setChecked(s.value("FadeoutEnabled", true).toBool()); ui_.fading_cross->setChecked(s.value("CrossfadeEnabled", true).toBool()); + ui_.fading_auto->setChecked(s.value("AutoCrossfadeEnabled", false).toBool()); ui_.fading_duration->setValue(s.value("FadeoutDuration", 2000).toInt()); s.endGroup(); @@ -329,5 +332,6 @@ void SettingsDialog::GstPluginChanged(int index) { void SettingsDialog::FadingOptionsChanged() { ui_.fading_options->setEnabled( - ui_.fading_out->isChecked() || ui_.fading_cross->isChecked()); + ui_.fading_out->isChecked() || ui_.fading_cross->isChecked() || + ui_.fading_auto->isChecked()); } diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui index 52648652e..4aad67430 100644 --- a/src/settingsdialog.ui +++ b/src/settingsdialog.ui @@ -51,7 +51,7 @@ Playback - + :/media-playback-start-32.png:/media-playback-start-32.png @@ -60,7 +60,7 @@ Behaviour - + :/icon.png:/icon.png @@ -69,7 +69,7 @@ Notifications - + :/lightbulb.png:/lightbulb.png @@ -78,7 +78,7 @@ Music Library - + :/library.png:/library.png @@ -87,7 +87,7 @@ Last.fm - + :/last.fm/as.png:/last.fm/as.png @@ -134,13 +134,20 @@ - Cross-fade between tracks + Cross-fade when changing tracks manually true + + + + Cross-fade when changing tracks automatically + + + @@ -582,9 +589,7 @@ notifications_fg_choose buttonBox - - - + list diff --git a/src/translations/cs.po b/src/translations/cs.po index ecf0eb365..0208e2733 100644 --- a/src/translations/cs.po +++ b/src/translations/cs.po @@ -715,7 +715,10 @@ msgstr "" msgid "Fade out when stopping a track" msgstr "" -msgid "Cross-fade between tracks" +msgid "Cross-fade when changing tracks manually" +msgstr "" + +msgid "Cross-fade when changing tracks automatically" msgstr "" #, fuzzy diff --git a/src/translations/el.po b/src/translations/el.po index 82bc6e902..7bfe81d41 100644 --- a/src/translations/el.po +++ b/src/translations/el.po @@ -718,7 +718,10 @@ msgstr "" msgid "Fade out when stopping a track" msgstr "" -msgid "Cross-fade between tracks" +msgid "Cross-fade when changing tracks manually" +msgstr "" + +msgid "Cross-fade when changing tracks automatically" msgstr "" #, fuzzy diff --git a/src/translations/es.po b/src/translations/es.po index 7f65deadb..30f5c9cce 100644 --- a/src/translations/es.po +++ b/src/translations/es.po @@ -722,7 +722,10 @@ msgstr "Cuidado" msgid "Fade out when stopping a track" msgstr "" -msgid "Cross-fade between tracks" +msgid "Cross-fade when changing tracks manually" +msgstr "" + +msgid "Cross-fade when changing tracks automatically" msgstr "" #, fuzzy diff --git a/src/translations/fr.po b/src/translations/fr.po index 1585e1227..f66769302 100644 --- a/src/translations/fr.po +++ b/src/translations/fr.po @@ -719,7 +719,10 @@ msgstr "" msgid "Fade out when stopping a track" msgstr "" -msgid "Cross-fade between tracks" +msgid "Cross-fade when changing tracks manually" +msgstr "" + +msgid "Cross-fade when changing tracks automatically" msgstr "" #, fuzzy diff --git a/src/translations/pl.po b/src/translations/pl.po index 3cefff1c6..b2b3b250b 100644 --- a/src/translations/pl.po +++ b/src/translations/pl.po @@ -711,7 +711,10 @@ msgstr "" msgid "Fade out when stopping a track" msgstr "" -msgid "Cross-fade between tracks" +msgid "Cross-fade when changing tracks manually" +msgstr "" + +msgid "Cross-fade when changing tracks automatically" msgstr "" #, fuzzy diff --git a/src/translations/ru.po b/src/translations/ru.po index 3402b386c..7028a8814 100644 --- a/src/translations/ru.po +++ b/src/translations/ru.po @@ -712,7 +712,10 @@ msgstr "" msgid "Fade out when stopping a track" msgstr "" -msgid "Cross-fade between tracks" +msgid "Cross-fade when changing tracks manually" +msgstr "" + +msgid "Cross-fade when changing tracks automatically" msgstr "" #, fuzzy diff --git a/src/translations/sk.po b/src/translations/sk.po index ea5c4c74a..43ba6488a 100644 --- a/src/translations/sk.po +++ b/src/translations/sk.po @@ -717,7 +717,10 @@ msgstr "Varovanie" msgid "Fade out when stopping a track" msgstr "" -msgid "Cross-fade between tracks" +msgid "Cross-fade when changing tracks manually" +msgstr "" + +msgid "Cross-fade when changing tracks automatically" msgstr "" #, fuzzy diff --git a/src/translations/translations.pot b/src/translations/translations.pot index b7923bf8a..5b2efeb14 100644 --- a/src/translations/translations.pot +++ b/src/translations/translations.pot @@ -705,7 +705,10 @@ msgstr "" msgid "Fade out when stopping a track" msgstr "" -msgid "Cross-fade between tracks" +msgid "Cross-fade when changing tracks manually" +msgstr "" + +msgid "Cross-fade when changing tracks automatically" msgstr "" msgid "Fading duration"