Equaliser presets

This commit is contained in:
David Sansome 2010-04-07 17:39:07 +00:00
parent c6fe113e79
commit 333ac7d90d
12 changed files with 806 additions and 14 deletions

View File

@ -19,6 +19,8 @@
#include <QSettings>
#include <QtDebug>
#include <QInputDialog>
#include <QMessageBox>
// We probably don't need to translate these, right?
const char* Equalizer::kGainText[] = {
@ -27,11 +29,15 @@ const char* Equalizer::kGainText[] = {
const char* Equalizer::kSettingsGroup = "Equalizer";
Equalizer::Equalizer(QWidget *parent)
: QDialog(parent)
: QDialog(parent),
loading_(false)
{
ui_.setupUi(this);
connect(ui_.enable, SIGNAL(toggled(bool)), SIGNAL(EnabledChanged(bool)));
connect(ui_.enable, SIGNAL(toggled(bool)), ui_.slider_container, SLOT(setEnabled(bool)));
connect(ui_.preset, SIGNAL(currentIndexChanged(QString)), SLOT(PresetChanged(QString)));
connect(ui_.preset_add, SIGNAL(clicked()), SLOT(AddPreset()));
connect(ui_.preset_del, SIGNAL(clicked()), SLOT(DelPreset()));
preamp_ = AddSlider(tr("Pre-amp"));
@ -45,18 +51,119 @@ Equalizer::Equalizer(QWidget *parent)
}
void Equalizer::ReloadSettings() {
loading_ = true;
QSettings s;
s.beginGroup(kSettingsGroup);
ui_.enable->setChecked(s.value("enabled", false).toBool());
presets_.clear();
ui_.preset->clear();
preamp_->set_value(s.value("preamp", 0).toInt());
for (int i=0 ; i<kBands ; ++i) {
gain_[i]->set_value(s.value("gain_" + QString::number(i+1), 0).toInt());
// Load presets
int count = s.beginReadArray("presets");
for (int i=0 ; i<count ; ++i) {
s.setArrayIndex(i);
AddPreset(s.value("name").toString(),
s.value("params").value<Equalizer::Params>());
}
s.endArray();
if (count == 0)
LoadDefaultPresets();
// Selected preset
QString selected_preset = s.value("selected_preset", "Custom").toString();
int selected_index = ui_.preset->findText(selected_preset);
if (selected_index != -1) {
ui_.preset->setCurrentIndex(selected_index);
PresetChanged(selected_preset);
}
// Enabled?
ui_.enable->setChecked(s.value("enabled", false).toBool());
emit EnabledChanged(ui_.enable->isChecked());
ParametersChanged();
loading_ = false;
}
void Equalizer::LoadDefaultPresets() {
AddPreset("Custom", Params(0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
AddPreset(tr("Classical"), Params(0, 0, 0, 0, 0, 0, -40, -40, -40, -50));
AddPreset(tr("Club"), Params(0, 0, 20, 30, 30, 30, 20, 0, 0, 0));
AddPreset(tr("Dance"), Params(50, 35, 10, 0, 0, -30, -40, -40, 0, 0));
AddPreset(tr("Full Bass"), Params(70, 70, 70, 40, 20, -45, -50, -55, -55, -55));
AddPreset(tr("Full Treble"), Params(-50, -50, -50, -25, 15, 55, 80, 80, 80, 85));
AddPreset(tr("Full Bass + Treble"), Params(35, 30, 0, -40, -25, 10, 45, 55, 60, 60));
AddPreset(tr("Laptop/Headphones"), Params(25, 50, 25, -20, 0, -30, -40, -40, 0, 0));
AddPreset(tr("Large Hall"), Params(50, 50, 30, 30, 0, -25, -25, -25, 0, 0));
AddPreset(tr("Live"), Params(-25, 0, 20, 25, 30, 30, 20, 15, 15, 10));
AddPreset(tr("Party"), Params(35, 35, 0, 0, 0, 0, 0, 0, 35, 35));
AddPreset(tr("Pop"), Params(-10, 25, 35, 40, 25, -5, -15, -15, -10, -10));
AddPreset(tr("Reggae"), Params(0, 0, -5, -30, 0, -35, -35, 0, 0, 0));
AddPreset(tr("Rock"), Params(40, 25, -30, -40, -20, 20, 45, 55, 55, 55));
AddPreset(tr("Soft"), Params(25, 10, -5, -15, -5, 20, 45, 50, 55, 60));
AddPreset(tr("Ska"), Params(-15, -25, -25, -5, 20, 30, 45, 50, 55, 50));
AddPreset(tr("Soft Rock"), Params(20, 20, 10, -5, -25, -30, -20, -5, 15, 45));
AddPreset(tr("Techno"), Params(40, 30, 0, -30, -25, 0, 40, 50, 50, 45));
AddPreset(tr("Zero"), Params(0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
}
void Equalizer::AddPreset(const QString& name, const Params& params) {
presets_[name] = params;
ui_.preset->addItem(name);
}
void Equalizer::PresetChanged(const QString& name) {
Params& p = presets_[name];
loading_ = true;
preamp_->set_value(p.preamp);
for (int i=0 ; i<kBands ; ++i)
gain_[i]->set_value(p.gain[i]);
loading_ = false;
ParametersChanged();
}
void Equalizer::AddPreset() {
QString name;
forever {
name = QInputDialog::getText(this, tr("New preset"), tr("Name"),
QLineEdit::Normal, name);
if (name.isEmpty())
return;
if (presets_.contains(name)) {
QMessageBox::information(this, tr("New preset"), tr("There is already a preset with that name"),
QMessageBox::Ok);
continue;
}
break;
}
AddPreset(name, Params());
ui_.preset->setCurrentIndex(ui_.preset->findText(name));
Save();
}
void Equalizer::DelPreset() {
QString name = ui_.preset->currentText();
if (!presets_.contains(name) || name.isEmpty())
return;
int ret = QMessageBox::question(
this, tr("Delete preset"),
tr("Are you sure you want to delete the \"%1\" preset?").arg(name),
QMessageBox::Yes, QMessageBox::No);
if (ret == QMessageBox::No)
return;
presets_.remove(name);
ui_.preset->removeItem(ui_.preset->currentIndex());
Save();
}
EqualizerSlider* Equalizer::AddSlider(const QString &label) {
@ -81,6 +188,74 @@ QList<int> Equalizer::gain_values() const {
void Equalizer::ParametersChanged() {
emit ParametersChanged(preamp_value(), gain_values());
// Update the preset
if (!loading_) {
QString name = ui_.preset->currentText();
if (!presets_.contains(name) || name.isEmpty())
return;
Params& p = presets_[name];
p.preamp = preamp_->value();
for (int i=0 ; i<kBands ; ++i)
p.gain[i] = gain_[i]->value();
Save();
}
}
void Equalizer::Save() {
if (loading_)
return;
QSettings s;
s.beginGroup(kSettingsGroup);
// Presets
s.beginWriteArray("presets", presets_.count());
int i=0;
foreach (const QString& name, presets_.keys()) {
s.setArrayIndex(i++);
s.setValue("name", name);
s.setValue("params", QVariant::fromValue(presets_[name]));
}
s.endArray();
// Selected preset
s.setValue("selected_preset", ui_.preset->currentText());
// Enabled?
s.setValue("enabled", ui_.enable->isChecked());
}
Equalizer::Params::Params()
: preamp(0)
{
for (int i=0 ; i<Equalizer::kBands ; ++i)
gain[i] = 0;
}
Equalizer::Params::Params(int g0, int g1, int g2, int g3, int g4, int g5,
int g6, int g7, int g8, int g9, int pre)
: preamp(pre)
{
gain[0] = g0; gain[1] = g1; gain[2] = g2; gain[3] = g3; gain[4] = g4;
gain[5] = g5; gain[6] = g6; gain[7] = g7; gain[8] = g8; gain[9] = g9;
}
QDataStream &operator<<(QDataStream& s, const Equalizer::Params& p) {
s << p.preamp;
for (int i=0 ; i<Equalizer::kBands ; ++i)
s << p.gain[i];
return s;
}
QDataStream &operator>>(QDataStream& s, Equalizer::Params& p) {
s >> p.preamp;
for (int i=0 ; i<Equalizer::kBands ; ++i)
s >> p.gain[i];
return s;
}

View File

@ -18,6 +18,7 @@
#define EQUALIZER_H
#include <QDialog>
#include <QMetaType>
#include "ui_equalizer.h"
@ -33,6 +34,15 @@ class Equalizer : public QDialog {
static const char* kGainText[kBands];
static const char* kSettingsGroup;
struct Params {
Params();
Params(int g0, int g1, int g2, int g3, int g4, int g5, int g6, int g7,
int g8, int g9, int pre = 0);
int preamp;
int gain[kBands];
};
int preamp_value() const;
QList<int> gain_values() const;
@ -45,15 +55,28 @@ class Equalizer : public QDialog {
private slots:
void ParametersChanged();
void PresetChanged(const QString& name);
void AddPreset();
void DelPreset();
private:
EqualizerSlider* AddSlider(const QString& label);
void LoadDefaultPresets();
void AddPreset(const QString& name, const Params& params);
void Save();
private:
Ui::Equalizer ui_;
bool loading_;
EqualizerSlider* preamp_;
EqualizerSlider* gain_[kBands];
QMap<QString, Params> presets_;
};
Q_DECLARE_METATYPE(Equalizer::Params);
QDataStream &operator<<(QDataStream& s, const Equalizer::Params& p);
QDataStream &operator>>(QDataStream& s, Equalizer::Params& p);
#endif // EQUALIZER_H

View File

@ -47,6 +47,20 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="preset_del">
<property name="icon">
<iconset resource="../data/data.qrc">
<normaloff>:/list-remove.png</normaloff>:/list-remove.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>

View File

@ -25,6 +25,7 @@
#include "mainwindow.h"
#include "player.h"
#include "song.h"
#include "equalizer.h"
#include <QtSingleApplication>
#include <QtDebug>
@ -75,6 +76,8 @@ int main(int argc, char *argv[]) {
qRegisterMetaType<SubdirectoryList>("SubdirectoryList");
qRegisterMetaType<SongList>("SongList");
qRegisterMetaType<Engine::State>("Engine::State");
qRegisterMetaType<Equalizer::Params>("Equalizer::Params");
qRegisterMetaTypeStreamOperators<Equalizer::Params>("Equalizer::Params");
lastfm::ws::ApiKey = LastFMService::kApiKey;

View File

@ -404,6 +404,79 @@ msgstr "Proud"
msgid "Pre-amp"
msgstr "Proud"
msgid "Classical"
msgstr ""
msgid "Club"
msgstr ""
msgid "Dance"
msgstr ""
#, fuzzy
msgid "Full Bass"
msgstr "Všichni umělci"
msgid "Full Treble"
msgstr ""
msgid "Full Bass + Treble"
msgstr ""
msgid "Laptop/Headphones"
msgstr ""
msgid "Large Hall"
msgstr ""
#, fuzzy
msgid "Live"
msgstr "Oblíbená"
#, fuzzy
msgid "Party"
msgstr "Přehrát"
msgid "Pop"
msgstr ""
msgid "Reggae"
msgstr ""
msgid "Rock"
msgstr ""
msgid "Soft"
msgstr ""
msgid "Ska"
msgstr ""
msgid "Soft Rock"
msgstr ""
msgid "Techno"
msgstr ""
msgid "Zero"
msgstr ""
msgid "New preset"
msgstr ""
msgid "Name"
msgstr ""
msgid "There is already a preset with that name"
msgstr ""
msgid "Delete preset"
msgstr ""
#, qt-format
msgid "Are you sure you want to delete the \"%1\" preset?"
msgstr ""
msgid "Clementine"
msgstr "Clementine"

View File

@ -405,6 +405,81 @@ msgstr "Stream"
msgid "Pre-amp"
msgstr "Stream"
msgid "Classical"
msgstr ""
msgid "Club"
msgstr ""
msgid "Dance"
msgstr ""
#, fuzzy
msgid "Full Bass"
msgstr "Όλοι οι καλλιτέχνες"
msgid "Full Treble"
msgstr ""
msgid "Full Bass + Treble"
msgstr ""
msgid "Laptop/Headphones"
msgstr ""
msgid "Large Hall"
msgstr ""
#, fuzzy
msgid "Live"
msgstr "Αγάπη"
#, fuzzy
msgid "Party"
msgstr "Αναπαραγωγή"
msgid "Pop"
msgstr ""
msgid "Reggae"
msgstr ""
msgid "Rock"
msgstr ""
msgid "Soft"
msgstr ""
msgid "Ska"
msgstr ""
msgid "Soft Rock"
msgstr ""
msgid "Techno"
msgstr ""
msgid "Zero"
msgstr ""
#, fuzzy
msgid "New preset"
msgstr "Νέα λίστα"
msgid "Name"
msgstr ""
msgid "There is already a preset with that name"
msgstr ""
#, fuzzy
msgid "Delete preset"
msgstr "Νέα λίστα"
#, qt-format
msgid "Are you sure you want to delete the \"%1\" preset?"
msgstr ""
msgid "Clementine"
msgstr "Clementine"
@ -887,9 +962,6 @@ msgstr ""
#~ msgid "Configure &Global Shortcuts..."
#~ msgstr "Ρύθμιση &καθολικών συντομεύσεων..."
#~ msgid "New playlist"
#~ msgstr "Νέα λίστα"
#~ msgid "Don't show notifications"
#~ msgstr "Μην εμφανίζεις ειδοποιήσεις"

View File

@ -404,6 +404,81 @@ msgstr ""
msgid "Pre-amp"
msgstr ""
msgid "Classical"
msgstr ""
msgid "Club"
msgstr ""
msgid "Dance"
msgstr ""
#, fuzzy
msgid "Full Bass"
msgstr "Todos los artistas"
msgid "Full Treble"
msgstr ""
msgid "Full Bass + Treble"
msgstr ""
msgid "Laptop/Headphones"
msgstr ""
msgid "Large Hall"
msgstr ""
#, fuzzy
msgid "Live"
msgstr "Me encanta"
#, fuzzy
msgid "Party"
msgstr "Reproducir"
msgid "Pop"
msgstr ""
msgid "Reggae"
msgstr ""
msgid "Rock"
msgstr ""
msgid "Soft"
msgstr ""
msgid "Ska"
msgstr ""
msgid "Soft Rock"
msgstr ""
msgid "Techno"
msgstr ""
msgid "Zero"
msgstr ""
#, fuzzy
msgid "New preset"
msgstr "Nueva lista de reproducción"
msgid "Name"
msgstr ""
msgid "There is already a preset with that name"
msgstr ""
#, fuzzy
msgid "Delete preset"
msgstr "Nueva lista de reproducción"
#, qt-format
msgid "Are you sure you want to delete the \"%1\" preset?"
msgstr ""
msgid "Clementine"
msgstr "Clementine"
@ -900,9 +975,6 @@ msgstr ""
#~ msgid "Configure &Global Shortcuts..."
#~ msgstr "Configurar los accesos rápidos &globales..."
#~ msgid "New playlist"
#~ msgstr "Nueva lista de reproducción"
#~ msgid "Don't show notifications"
#~ msgstr "No mostrar notificaciones"

View File

@ -406,6 +406,79 @@ msgstr "Flux"
msgid "Pre-amp"
msgstr "Flux"
msgid "Classical"
msgstr ""
msgid "Club"
msgstr ""
msgid "Dance"
msgstr ""
#, fuzzy
msgid "Full Bass"
msgstr "Tous les artistes"
msgid "Full Treble"
msgstr ""
msgid "Full Bass + Treble"
msgstr ""
msgid "Laptop/Headphones"
msgstr ""
msgid "Large Hall"
msgstr ""
#, fuzzy
msgid "Live"
msgstr "J'aime"
#, fuzzy
msgid "Party"
msgstr "Lecture"
msgid "Pop"
msgstr ""
msgid "Reggae"
msgstr ""
msgid "Rock"
msgstr ""
msgid "Soft"
msgstr ""
msgid "Ska"
msgstr ""
msgid "Soft Rock"
msgstr ""
msgid "Techno"
msgstr ""
msgid "Zero"
msgstr ""
msgid "New preset"
msgstr ""
msgid "Name"
msgstr ""
msgid "There is already a preset with that name"
msgstr ""
msgid "Delete preset"
msgstr ""
#, qt-format
msgid "Are you sure you want to delete the \"%1\" preset?"
msgstr ""
msgid "Clementine"
msgstr "Clementine"

View File

@ -402,6 +402,79 @@ msgstr ""
msgid "Pre-amp"
msgstr ""
msgid "Classical"
msgstr ""
msgid "Club"
msgstr ""
msgid "Dance"
msgstr ""
#, fuzzy
msgid "Full Bass"
msgstr "Wszyscy wykonawcy"
msgid "Full Treble"
msgstr ""
msgid "Full Bass + Treble"
msgstr ""
msgid "Laptop/Headphones"
msgstr ""
msgid "Large Hall"
msgstr ""
#, fuzzy
msgid "Live"
msgstr "Dodaj do ulubionych"
#, fuzzy
msgid "Party"
msgstr "Odtwarzaj"
msgid "Pop"
msgstr ""
msgid "Reggae"
msgstr ""
msgid "Rock"
msgstr ""
msgid "Soft"
msgstr ""
msgid "Ska"
msgstr ""
msgid "Soft Rock"
msgstr ""
msgid "Techno"
msgstr ""
msgid "Zero"
msgstr ""
msgid "New preset"
msgstr ""
msgid "Name"
msgstr ""
msgid "There is already a preset with that name"
msgstr ""
msgid "Delete preset"
msgstr ""
#, qt-format
msgid "Are you sure you want to delete the \"%1\" preset?"
msgstr ""
msgid "Clementine"
msgstr ""

View File

@ -403,6 +403,78 @@ msgstr ""
msgid "Pre-amp"
msgstr ""
msgid "Classical"
msgstr ""
msgid "Club"
msgstr ""
msgid "Dance"
msgstr ""
msgid "Full Bass"
msgstr ""
msgid "Full Treble"
msgstr ""
msgid "Full Bass + Treble"
msgstr ""
msgid "Laptop/Headphones"
msgstr ""
msgid "Large Hall"
msgstr ""
#, fuzzy
msgid "Live"
msgstr "Полюбить"
#, fuzzy
msgid "Party"
msgstr "Воспроизвести"
msgid "Pop"
msgstr ""
msgid "Reggae"
msgstr ""
msgid "Rock"
msgstr ""
msgid "Soft"
msgstr ""
msgid "Ska"
msgstr ""
msgid "Soft Rock"
msgstr ""
msgid "Techno"
msgstr ""
msgid "Zero"
msgstr ""
msgid "New preset"
msgstr ""
msgid "Name"
msgstr ""
msgid "There is already a preset with that name"
msgstr ""
msgid "Delete preset"
msgstr ""
#, qt-format
msgid "Are you sure you want to delete the \"%1\" preset?"
msgstr ""
msgid "Clementine"
msgstr "Clementine"

View File

@ -403,6 +403,81 @@ msgstr ""
msgid "Pre-amp"
msgstr ""
msgid "Classical"
msgstr ""
msgid "Club"
msgstr ""
msgid "Dance"
msgstr ""
#, fuzzy
msgid "Full Bass"
msgstr "Všetci interpréti"
msgid "Full Treble"
msgstr ""
msgid "Full Bass + Treble"
msgstr ""
msgid "Laptop/Headphones"
msgstr ""
msgid "Large Hall"
msgstr ""
#, fuzzy
msgid "Live"
msgstr "Obľúbené"
#, fuzzy
msgid "Party"
msgstr "Hrať"
msgid "Pop"
msgstr ""
msgid "Reggae"
msgstr ""
msgid "Rock"
msgstr ""
msgid "Soft"
msgstr ""
msgid "Ska"
msgstr ""
msgid "Soft Rock"
msgstr ""
msgid "Techno"
msgstr ""
msgid "Zero"
msgstr ""
#, fuzzy
msgid "New preset"
msgstr "Nový playlist"
msgid "Name"
msgstr ""
msgid "There is already a preset with that name"
msgstr ""
#, fuzzy
msgid "Delete preset"
msgstr "Nový playlist"
#, qt-format
msgid "Are you sure you want to delete the \"%1\" preset?"
msgstr ""
msgid "Clementine"
msgstr ""
@ -890,9 +965,6 @@ msgstr ""
#~ msgid "Configure &Global Shortcuts..."
#~ msgstr "Nastaviť &Globálne skratky..."
#~ msgid "New playlist"
#~ msgstr "Nový playlist"
#~ msgid "Don't show notifications"
#~ msgstr "Nezobrazovať notifikácie"

View File

@ -401,6 +401,76 @@ msgstr ""
msgid "Pre-amp"
msgstr ""
msgid "Classical"
msgstr ""
msgid "Club"
msgstr ""
msgid "Dance"
msgstr ""
msgid "Full Bass"
msgstr ""
msgid "Full Treble"
msgstr ""
msgid "Full Bass + Treble"
msgstr ""
msgid "Laptop/Headphones"
msgstr ""
msgid "Large Hall"
msgstr ""
msgid "Live"
msgstr ""
msgid "Party"
msgstr ""
msgid "Pop"
msgstr ""
msgid "Reggae"
msgstr ""
msgid "Rock"
msgstr ""
msgid "Soft"
msgstr ""
msgid "Ska"
msgstr ""
msgid "Soft Rock"
msgstr ""
msgid "Techno"
msgstr ""
msgid "Zero"
msgstr ""
msgid "New preset"
msgstr ""
msgid "Name"
msgstr ""
msgid "There is already a preset with that name"
msgstr ""
msgid "Delete preset"
msgstr ""
#, qt-format
msgid "Are you sure you want to delete the \"%1\" preset?"
msgstr ""
msgid "Clementine"
msgstr ""