mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-30 19:15:08 +01:00
Add stereo balance slider as part of equalizer.
This commit is contained in:
parent
6fa77b8749
commit
36975c41d2
@ -101,6 +101,7 @@ class Base : public QObject, boost::noncopyable {
|
||||
|
||||
virtual void SetEqualizerEnabled(bool) {}
|
||||
virtual void SetEqualizerParameters(int preamp, const QList<int>& bandGains) {}
|
||||
virtual void SetStereoBalance(float value) {}
|
||||
|
||||
signals:
|
||||
// Emitted when crossfading is enabled and the track is crossfade_duration_
|
||||
|
@ -77,6 +77,7 @@ GstEngine::GstEngine(TaskManager* task_manager)
|
||||
delayq_(g_queue_new()),
|
||||
current_sample_(0),
|
||||
equalizer_enabled_(false),
|
||||
stereo_balance_(0.0f),
|
||||
rg_enabled_(false),
|
||||
rg_mode_(0),
|
||||
rg_preamp_(0.0),
|
||||
@ -351,6 +352,7 @@ bool GstEngine::Load(const QUrl& url, Engine::TrackChangeFlags change,
|
||||
SetVolume(volume_);
|
||||
SetEqualizerEnabled(equalizer_enabled_);
|
||||
SetEqualizerParameters(equalizer_preamp_, equalizer_gains_);
|
||||
SetStereoBalance(stereo_balance_);
|
||||
|
||||
// Maybe fade in this track
|
||||
if (crossfade)
|
||||
@ -581,6 +583,13 @@ void GstEngine::SetEqualizerParameters(int preamp, const QList<int>& band_gains)
|
||||
current_pipeline_->SetEqualizerParams(preamp, band_gains);
|
||||
}
|
||||
|
||||
void GstEngine::SetStereoBalance(float value) {
|
||||
stereo_balance_ = value;
|
||||
|
||||
if (current_pipeline_)
|
||||
current_pipeline_->SetStereoBalance(value);
|
||||
}
|
||||
|
||||
void GstEngine::SetVolumeSW( uint percent ) {
|
||||
if (current_pipeline_)
|
||||
current_pipeline_->SetVolume(percent);
|
||||
|
@ -105,6 +105,9 @@ class GstEngine : public Engine::Base, public BufferConsumer {
|
||||
/** Set equalizer preamp and gains, range -100..100. Gains are 10 values. */
|
||||
void SetEqualizerParameters(int preamp, const QList<int>& bandGains);
|
||||
|
||||
/** Set Stereo balance, range -1.0f..1.0f */
|
||||
void SetStereoBalance(float value);
|
||||
|
||||
void ReloadSettings();
|
||||
|
||||
void AddBufferConsumer(BufferConsumer* consumer);
|
||||
@ -184,6 +187,7 @@ class GstEngine : public Engine::Base, public BufferConsumer {
|
||||
bool equalizer_enabled_;
|
||||
int equalizer_preamp_;
|
||||
QList<int> equalizer_gains_;
|
||||
float stereo_balance_;
|
||||
|
||||
bool rg_enabled_;
|
||||
int rg_mode_;
|
||||
|
@ -57,6 +57,7 @@ GstEnginePipeline::GstEnginePipeline(GstEngine* engine)
|
||||
emit_track_ended_on_segment_start_(false),
|
||||
eq_enabled_(false),
|
||||
eq_preamp_(0),
|
||||
stereo_balance_(0.0f),
|
||||
rg_enabled_(false),
|
||||
rg_mode_(0),
|
||||
rg_preamp_(0.0),
|
||||
@ -84,6 +85,7 @@ GstEnginePipeline::GstEnginePipeline(GstEngine* engine)
|
||||
rglimiter_(NULL),
|
||||
audioconvert2_(NULL),
|
||||
equalizer_(NULL),
|
||||
stereo_panorama_(NULL),
|
||||
volume_(NULL),
|
||||
audioscale_(NULL),
|
||||
audiosink_(NULL)
|
||||
@ -243,13 +245,14 @@ bool GstEnginePipeline::Init() {
|
||||
audio_queue = engine_->CreateElement("queue", audiobin_);
|
||||
equalizer_preamp_ = engine_->CreateElement("volume", audiobin_);
|
||||
equalizer_ = engine_->CreateElement("equalizer-nbands", audiobin_);
|
||||
stereo_panorama_ = engine_->CreateElement("audiopanorama", audiobin_);
|
||||
volume_ = engine_->CreateElement("volume", audiobin_);
|
||||
audioscale_ = engine_->CreateElement("audioresample", audiobin_);
|
||||
convert = engine_->CreateElement("audioconvert", audiobin_);
|
||||
|
||||
if (!queue_ || !audioconvert_ || !tee || !probe_queue || !probe_converter ||
|
||||
!probe_sink || !audio_queue || !equalizer_preamp_ || !equalizer_ ||
|
||||
!volume_ || !audioscale_ || !convert) {
|
||||
!stereo_panorama_ || !volume_ || !audioscale_ || !convert) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -310,6 +313,9 @@ bool GstEnginePipeline::Init() {
|
||||
g_object_unref(G_OBJECT(band));
|
||||
}
|
||||
|
||||
// Set the stereo balance.
|
||||
g_object_set(G_OBJECT(stereo_panorama_), "panorama", stereo_balance_, NULL);
|
||||
|
||||
// Set the buffer duration. We set this on this queue instead of the
|
||||
// decode bin (in ReplaceDecodeBin()) because setting it on the decode bin
|
||||
// only affects network sources.
|
||||
@ -356,8 +362,8 @@ bool GstEnginePipeline::Init() {
|
||||
|
||||
// Link everything else.
|
||||
gst_element_link(probe_queue, probe_converter);
|
||||
gst_element_link_many(audio_queue, equalizer_preamp_, equalizer_, volume_,
|
||||
audioscale_, convert, audiosink_, NULL);
|
||||
gst_element_link_many(audio_queue, equalizer_preamp_, equalizer_, stereo_panorama_,
|
||||
volume_, audioscale_, convert, audiosink_, NULL);
|
||||
|
||||
// Add probes and handlers.
|
||||
gst_pad_add_buffer_probe(gst_element_get_static_pad(probe_converter, "src"), G_CALLBACK(HandoffCallback), this);
|
||||
@ -878,6 +884,11 @@ void GstEnginePipeline::SetEqualizerParams(int preamp, const QList<int>& band_ga
|
||||
UpdateEqualizer();
|
||||
}
|
||||
|
||||
void GstEnginePipeline::SetStereoBalance(float value) {
|
||||
stereo_balance_ = value;
|
||||
UpdateStereoBalance();
|
||||
}
|
||||
|
||||
void GstEnginePipeline::UpdateEqualizer() {
|
||||
// Update band gains
|
||||
for (int i=0 ; i<kEqBandCount ; ++i) {
|
||||
@ -900,6 +911,12 @@ void GstEnginePipeline::UpdateEqualizer() {
|
||||
g_object_set(G_OBJECT(equalizer_preamp_), "volume", preamp, NULL);
|
||||
}
|
||||
|
||||
void GstEnginePipeline::UpdateStereoBalance() {
|
||||
if (stereo_panorama_) {
|
||||
g_object_set(G_OBJECT(stereo_panorama_), "panorama", stereo_balance_, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void GstEnginePipeline::SetVolume(int percent) {
|
||||
volume_percent_ = percent;
|
||||
UpdateVolume();
|
||||
|
@ -69,6 +69,7 @@ class GstEnginePipeline : public QObject {
|
||||
void SetEqualizerEnabled(bool enabled);
|
||||
void SetEqualizerParams(int preamp, const QList<int>& band_gains);
|
||||
void SetVolume(int percent);
|
||||
void SetStereoBalance(float value);
|
||||
void StartFader(qint64 duration_nanosec,
|
||||
QTimeLine::Direction direction = QTimeLine::Forward,
|
||||
QTimeLine::CurveShape shape = QTimeLine::LinearCurve,
|
||||
@ -145,6 +146,7 @@ class GstEnginePipeline : public QObject {
|
||||
|
||||
void UpdateVolume();
|
||||
void UpdateEqualizer();
|
||||
void UpdateStereoBalance();
|
||||
bool ReplaceDecodeBin(GstElement* new_bin);
|
||||
bool ReplaceDecodeBin(const QUrl& url);
|
||||
|
||||
@ -192,6 +194,11 @@ class GstEnginePipeline : public QObject {
|
||||
int eq_preamp_;
|
||||
QList<int> eq_band_gains_;
|
||||
|
||||
// Stereo balance.
|
||||
// From -1.0 - 1.0
|
||||
// -1.0 is left, 1.0 is right.
|
||||
float stereo_balance_;
|
||||
|
||||
// ReplayGain
|
||||
bool rg_enabled_;
|
||||
int rg_mode_;
|
||||
@ -263,6 +270,7 @@ class GstEnginePipeline : public QObject {
|
||||
GstElement* audioconvert2_;
|
||||
GstElement* equalizer_preamp_;
|
||||
GstElement* equalizer_;
|
||||
GstElement* stereo_panorama_;
|
||||
GstElement* volume_;
|
||||
GstElement* audioscale_;
|
||||
GstElement* audiosink_;
|
||||
|
@ -17,8 +17,6 @@
|
||||
|
||||
#include "equalizer.h"
|
||||
#include "ui_equalizer.h"
|
||||
#include "widgets/equalizerslider.h"
|
||||
#include "ui/iconloader.h"
|
||||
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
@ -26,6 +24,9 @@
|
||||
#include <QShortcut>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "ui/iconloader.h"
|
||||
#include "widgets/equalizerslider.h"
|
||||
|
||||
// We probably don't need to translate these, right?
|
||||
const char* Equalizer::kGainText[] = {
|
||||
"60", "170", "310", "600", "1k", "3k", "6k", "12k", "14k", "16k"};
|
||||
@ -62,6 +63,7 @@ Equalizer::Equalizer(QWidget *parent)
|
||||
connect(ui_->preset, SIGNAL(currentIndexChanged(int)), SLOT(PresetChanged(int)));
|
||||
connect(ui_->preset_save, SIGNAL(clicked()), SLOT(SavePreset()));
|
||||
connect(ui_->preset_del, SIGNAL(clicked()), SLOT(DelPreset()));
|
||||
connect(ui_->balance_slider, SIGNAL(valueChanged(int)), SLOT(StereoSliderChanged(int)));
|
||||
|
||||
QShortcut* close = new QShortcut(QKeySequence::Close, this);
|
||||
connect(close, SIGNAL(activated()), SLOT(close()));
|
||||
@ -101,6 +103,10 @@ void Equalizer::ReloadSettings() {
|
||||
ui_->enable->setChecked(s.value("enabled", false).toBool());
|
||||
ui_->slider_container->setEnabled(ui_->enable->isChecked());
|
||||
|
||||
int stereo_balance = s.value("stereo_balance", 0).toInt();
|
||||
ui_->balance_slider->setValue(stereo_balance);
|
||||
StereoSliderChanged(stereo_balance);
|
||||
|
||||
PresetChanged(selected_preset);
|
||||
}
|
||||
|
||||
@ -232,6 +238,18 @@ Equalizer::Params Equalizer::current_params() const {
|
||||
return ret;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
float Clamp(float min, float value, float max) {
|
||||
return qMin(1.0f, qMax(-1.0f, value));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float Equalizer::stereo_balance() const {
|
||||
return Clamp(-1.0f, ui_->balance_slider->value(), 1.0f);
|
||||
}
|
||||
|
||||
void Equalizer::ParametersChanged() {
|
||||
if (loading_)
|
||||
return;
|
||||
@ -259,6 +277,8 @@ void Equalizer::Save() {
|
||||
|
||||
// Enabled?
|
||||
s.setValue("enabled", ui_->enable->isChecked());
|
||||
|
||||
s.setValue("stereo_balance", ui_->balance_slider->value());
|
||||
}
|
||||
|
||||
void Equalizer::closeEvent(QCloseEvent* e) {
|
||||
@ -300,6 +320,11 @@ bool Equalizer::Params::operator !=(const Equalizer::Params& other) const {
|
||||
return ! (*this == other);
|
||||
}
|
||||
|
||||
void Equalizer::StereoSliderChanged(int value) {
|
||||
emit StereoBalanceChanged(stereo_balance());
|
||||
Save();
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream& s, const Equalizer::Params& p) {
|
||||
s << p.preamp;
|
||||
for (int i=0 ; i<Equalizer::kBands ; ++i)
|
||||
|
@ -52,10 +52,12 @@ class Equalizer : public QDialog {
|
||||
int preamp_value() const;
|
||||
QList<int> gain_values() const;
|
||||
Params current_params() const;
|
||||
float stereo_balance() const;
|
||||
|
||||
signals:
|
||||
void EnabledChanged(bool enabled);
|
||||
void ParametersChanged(int preamp, const QList<int>& band_gains);
|
||||
void StereoBalanceChanged(float balance);
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *);
|
||||
@ -67,6 +69,7 @@ class Equalizer : public QDialog {
|
||||
void SavePreset();
|
||||
void DelPreset();
|
||||
void Save();
|
||||
void StereoSliderChanged(int value);
|
||||
|
||||
private:
|
||||
EqualizerSlider* AddSlider(const QString& label);
|
||||
|
@ -81,6 +81,22 @@
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2"/>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSlider" name="balance_slider">
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>-100</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="tickPosition">
|
||||
<enum>QSlider::TicksBelow</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
|
@ -642,9 +642,12 @@ MainWindow::MainWindow(Application* app,
|
||||
app_->player()->engine(), SLOT(SetEqualizerParameters(int,QList<int>)));
|
||||
connect(equalizer_.get(), SIGNAL(EnabledChanged(bool)),
|
||||
app_->player()->engine(), SLOT(SetEqualizerEnabled(bool)));
|
||||
connect(equalizer_.get(), SIGNAL(StereoBalanceChanged(float)),
|
||||
app_->player()->engine(), SLOT(SetStereoBalance(float)));
|
||||
app_->player()->engine()->SetEqualizerEnabled(equalizer_->is_enabled());
|
||||
app_->player()->engine()->SetEqualizerParameters(
|
||||
equalizer_->preamp_value(), equalizer_->gain_values());
|
||||
app_->player()->engine()->SetStereoBalance(equalizer_->stereo_balance());
|
||||
|
||||
// Statusbar widgets
|
||||
ui_->playlist_summary->setMinimumWidth(QFontMetrics(font()).width("WW selected of WW tracks - [ WW:WW ]"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user