1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-18 20:40:43 +01:00

Add support for crossfading when changing tracks automatically

This commit is contained in:
David Sansome 2010-04-11 23:52:16 +00:00
parent 152470e5b3
commit 031752823c
14 changed files with 85 additions and 20 deletions

View File

@ -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();
}

View File

@ -72,6 +72,10 @@ class Base : public QObject {
virtual void SetEqualizerParameters(int preamp, const QList<int>& 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_;
};

View File

@ -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) {

View File

@ -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)));

View File

@ -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());
}

View File

@ -51,7 +51,7 @@
<string>Playback</string>
</property>
<property name="icon">
<iconset resource="../data/data.qrc">
<iconset>
<normaloff>:/media-playback-start-32.png</normaloff>:/media-playback-start-32.png</iconset>
</property>
</item>
@ -60,7 +60,7 @@
<string>Behaviour</string>
</property>
<property name="icon">
<iconset resource="../data/data.qrc">
<iconset>
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
</property>
</item>
@ -69,7 +69,7 @@
<string>Notifications</string>
</property>
<property name="icon">
<iconset resource="../data/data.qrc">
<iconset>
<normaloff>:/lightbulb.png</normaloff>:/lightbulb.png</iconset>
</property>
</item>
@ -78,7 +78,7 @@
<string>Music Library</string>
</property>
<property name="icon">
<iconset resource="../data/data.qrc">
<iconset>
<normaloff>:/library.png</normaloff>:/library.png</iconset>
</property>
</item>
@ -87,7 +87,7 @@
<string>Last.fm</string>
</property>
<property name="icon">
<iconset resource="../data/data.qrc">
<iconset>
<normaloff>:/last.fm/as.png</normaloff>:/last.fm/as.png</iconset>
</property>
</item>
@ -134,13 +134,20 @@
<item>
<widget class="QCheckBox" name="fading_cross">
<property name="text">
<string>Cross-fade between tracks</string>
<string>Cross-fade when changing tracks manually</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="fading_auto">
<property name="text">
<string>Cross-fade when changing tracks automatically</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="fading_options" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
@ -582,9 +589,7 @@
<tabstop>notifications_fg_choose</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources>
<include location="../data/data.qrc"/>
</resources>
<resources/>
<connections>
<connection>
<sender>list</sender>

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"