Skip to content

Commit 0176dfe

Browse files
author
ThePBone
committed
Remember preset names
1 parent cebd253 commit 0176dfe

File tree

9 files changed

+186
-63
lines changed

9 files changed

+186
-63
lines changed

V4L_Frontend.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ SOURCES += \
6565
misc/converter.cpp \
6666
misc/loghelper.cpp \
6767
misc/overlaymsgproxy.cpp \
68+
misc/presetprovider.cpp \
6869
misc/stylehelper.cpp
6970

7071
HEADERS += \
@@ -114,7 +115,7 @@ HEADERS += \
114115
misc/loghelper.h \
115116
misc/mathfunctions.h \
116117
misc/overlaymsgproxy.h \
117-
misc/presetextension.h \
118+
misc/presetprovider.h \
118119
misc/stylehelper.h \
119120
misc/styles/darkstyle.h \
120121
misc/versioncontainer.h

dialog/liquidequalizerwidget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ void LiquidEqualizerWidget::mousePressEvent(QMouseEvent *event){
9090
void LiquidEqualizerWidget::mouseReleaseEvent(QMouseEvent *event){
9191
mHoldDown = false;
9292
emit bandsUpdated();
93+
emit mouseReleased();
9394
repaint();
9495
}
9596
void LiquidEqualizerWidget::mouseMoveEvent(QMouseEvent *event){

dialog/liquidequalizerwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class LiquidEqualizerWidget : public QWidget
5555
void setAnimationDuration(int animationDuration);
5656

5757
signals:
58+
void mouseReleased();
5859
void redrawRequired();
5960
void bandsUpdated();
6061
void cancelAnimations();

mainwindow.cpp

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ void MainWindow::LoadConfig(){
691691
ui->dyn_ycoeff1->setValue(conf->getInt("dynsys_ycoeff1"));
692692
ui->dyn_ycoeff2->setValue(conf->getInt("dynsys_ycoeff2"));
693693
ui->dyn_sidegain1->setValue(conf->getInt("dynsys_sidegain1"));
694-
ui->dyn_sidegain2->setValue(conf->getInt("dynsys_sidegain1"));
694+
ui->dyn_sidegain2->setValue(conf->getInt("dynsys_sidegain2"));
695695
ui->dyn_bassgain->setValue(conf->getInt("dynsys_bassgain"));
696696

697697
int eq1 = conf->getInt("eq_band1");
@@ -718,8 +718,10 @@ void MainWindow::LoadConfig(){
718718
it++;
719719
}
720720
if(eqReloadRequired)
721-
ui->eq_widget->setBands(eq_data);
721+
ui->eq_widget->setBands(eq_data,false);
722722

723+
UpdateEqStringFromWidget();
724+
UpdateDynsysStringFromWidget();
723725
UpdateAllUnitLabels();
724726

725727
QString ir = conf->getString("conv_ir_path",false);
@@ -834,13 +836,18 @@ void MainWindow::ApplyConfig(bool restart){
834836

835837
//---Predefined Presets
836838
void MainWindow::EqPresetSelectionUpdated(){
837-
auto preset = EQ::lookupEQPreset(ui->eqpreset->currentText());
839+
if(ui->eqpreset->currentText() == "Custom")
840+
return;
841+
auto preset = PresetProvider::EQ::lookupPreset(ui->eqpreset->currentText());
838842
if(preset.size() > 0)SetEQ(preset);
839843
else ResetEQ();
840844
}
841845
void MainWindow::DynsysPresetSelectionUpdated(){
842-
const auto data = EQ::lookupDynsysPreset(ui->dynsys_preset->currentText());
843-
if(data.size() <= 1)return;
846+
if(ui->dynsys_preset->currentText() == "Custom")
847+
return;
848+
const auto data = PresetProvider::Dynsys::lookupPreset(ui->dynsys_preset->currentText());
849+
if(data.size() <= 1)
850+
return;
844851
lockapply=true;
845852
ui->dyn_xcoeff1->setValue(data.begin()[0]);
846853
ui->dyn_xcoeff2->setValue(data.begin()[1]);
@@ -853,7 +860,7 @@ void MainWindow::DynsysPresetSelectionUpdated(){
853860
}
854861
void MainWindow::ColmPresetSelectionUpdated(){
855862
QString selection = ui->colmpreset->text();
856-
const auto data = EQ::lookupColmPreset(selection);
863+
const auto data = PresetProvider::Colm::lookupPreset(selection);
857864
lockapply=true;
858865
ui->colmwide->setValue(data.begin()[0]);
859866
ui->colmdepth->setValue(data.begin()[1]);
@@ -887,10 +894,10 @@ void MainWindow::UpdateUnitLabel(int d,QObject *alt){
887894
}
888895
else if(obj==ui->gain){
889896
//AGC
890-
if(d < 50) UpdateTooltipLabelUnit(obj,tr("Very Slight (%1)").arg(QString::number(d)),alt==nullptr);
891-
else if(d < 100) UpdateTooltipLabelUnit(obj,tr("Slight (%1)").arg(QString::number(d)),alt==nullptr);
892-
else if(d < 300) UpdateTooltipLabelUnit(obj,tr("Moderate (%1)").arg(QString::number(d)),alt==nullptr);
893-
else UpdateTooltipLabelUnit(obj,tr("Mode %1").arg(QString::number( d )),alt==nullptr);
897+
if(d <= 50) UpdateTooltipLabelUnit(obj,tr("Very Slight (%1)").arg(QString::number(d)),alt==nullptr);
898+
else if(d <= 100) UpdateTooltipLabelUnit(obj,tr("Slight (%1)").arg(QString::number(d)),alt==nullptr);
899+
else if(d <= 300) UpdateTooltipLabelUnit(obj,tr("Moderate (%1)").arg(QString::number(d)),alt==nullptr);
900+
else UpdateTooltipLabelUnit(obj,tr("Extreme (%1)").arg(QString::number( d )),alt==nullptr);
894901
}
895902
else if(obj==ui->axmode){
896903
//AnalogX
@@ -913,7 +920,7 @@ void MainWindow::UpdateUnitLabel(int d,QObject *alt){
913920

914921
UpdateTooltipLabelUnit(obj,
915922
QString::number(result, 'f', 2) + "dB "
916-
"(" + QString::number( (d-100)/20 ) + "%)",
923+
"(" + QString::number( (d-100)/20 ) + "%)",
917924
alt==nullptr);
918925
}
919926
//Diff-Surround
@@ -1017,7 +1024,8 @@ void MainWindow::ResetEQ(){
10171024
QTimer::singleShot(510,this,[this](){
10181025
ui->reset_eq->setEnabled(true);
10191026
});
1020-
SetEQ(EQ::defaultEQPreset());
1027+
ui->eqpreset->setCurrentIndex(0);
1028+
SetEQ(PresetProvider::EQ::defaultPreset());
10211029
}
10221030
void MainWindow::SetIRS(const QString& irs,bool apply){
10231031
if(activeirs != irs) m_irsNeedUpdate = true;
@@ -1027,6 +1035,19 @@ void MainWindow::SetIRS(const QString& irs,bool apply){
10271035
ui->convpath->setCursorPosition(0);
10281036
if(apply)ApplyConfig();
10291037
}
1038+
void MainWindow::UpdateEqStringFromWidget(){
1039+
QString currentEqPresetName =
1040+
PresetProvider::EQ::reverseLookup(ui->eq_widget->getBands());
1041+
ui->eqpreset->setCurrentText(currentEqPresetName);
1042+
}
1043+
void MainWindow::UpdateDynsysStringFromWidget(){
1044+
QString currentDynsysPresetName =
1045+
PresetProvider::Dynsys::reverseLookup({ui->dyn_xcoeff1->value(),ui->dyn_xcoeff2->value(),
1046+
ui->dyn_ycoeff1->value(),ui->dyn_ycoeff2->value(),
1047+
ui->dyn_sidegain1->value(),ui->dyn_sidegain2->value()});
1048+
ui->dynsys_preset->setCurrentText(currentDynsysPresetName);
1049+
}
1050+
10301051
QVariantMap MainWindow::readConfig(){
10311052
QVariantMap confmap = ConfigIO::readFile(m_appwrapper->getPath());
10321053
if(confmap.count() < 1){
@@ -1066,6 +1087,9 @@ void MainWindow::ConnectActions(){
10661087
{ui->vb,ui->clarity,ui->vcure,ui->tubesim,ui->vhp,ui->diff,ui->reverb,ui->enable_eq,ui->enable_comp,ui->noclip,ui->m_gain,
10671088
ui->m_width,ui->m_attack,ui->m_release,ui->vb,ui->clarity,ui->vcure,ui->tubesim,ui->agc,ui->colm,ui->vse,ui->conv,ui->ax,ui->dynsys});
10681089

1090+
QList<QWidget*> registerDynsysUpdate(
1091+
{ui->dyn_xcoeff1,ui->dyn_xcoeff2,ui->dyn_ycoeff1,ui->dyn_ycoeff2,ui->dyn_sidegain1,ui->dyn_sidegain2});
1092+
10691093
foreach (QWidget* w, registerValueChange)
10701094
connect(w, SIGNAL(valueChanged(int)), this, SLOT(UpdateUnitLabel(int)));
10711095

@@ -1075,6 +1099,9 @@ void MainWindow::ConnectActions(){
10751099
foreach (QWidget* w, registerClick)
10761100
connect(w, SIGNAL(clicked()), this, SLOT(OnUpdate()));
10771101

1102+
foreach (QWidget* w, registerDynsysUpdate)
1103+
connect(w, SIGNAL(sliderReleased()), this, SLOT(UpdateDynsysStringFromWidget()));
1104+
10781105
connect(ui->apply, SIGNAL(clicked()), this, SLOT(ApplyConfig()));
10791106
connect(ui->disableFX, SIGNAL(clicked()), this, SLOT(DisableFX()));
10801107
connect(ui->reset_eq, SIGNAL(clicked()), this, SLOT(ResetEQ()));
@@ -1083,6 +1110,7 @@ void MainWindow::ConnectActions(){
10831110
connect(ui->cpreset, SIGNAL(clicked()), this, SLOT(DialogHandler()));
10841111
connect(ui->set, SIGNAL(clicked()), this, SLOT(DialogHandler()));
10851112
connect(ui->eq_widget, SIGNAL(bandsUpdated()), this, SLOT(ApplyConfig()));
1113+
connect(ui->eq_widget, SIGNAL(mouseReleased()), this, SLOT(UpdateEqStringFromWidget()));
10861114
connect(ui->eqpreset, SIGNAL(currentIndexChanged(int)), this, SLOT(EqPresetSelectionUpdated()));
10871115
connect(ui->dynsys_preset, SIGNAL(currentIndexChanged(int)), this, SLOT(DynsysPresetSelectionUpdated()));
10881116
connect(ui->vbmode, SIGNAL(valueChanged(int)), this, SLOT(OnRelease()));

mainwindow.h

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "config/appconfigwrapper.h"
3535
#include "misc/mathfunctions.h"
3636
#include "misc/loghelper.h"
37-
#include "misc/presetextension.h"
37+
#include "misc/presetprovider.h"
3838
#include "misc/common.h"
3939
#include "config/dbusproxy.h"
4040
#include "misc/overlaymsgproxy.h"
@@ -88,6 +88,8 @@ private slots:
8888
void DialogHandler();
8989
void updateTrayPresetList();
9090
void RefreshSpectrumParameters();
91+
void UpdateEqStringFromWidget();
92+
void UpdateDynsysStringFromWidget();
9193
private:
9294
ConfigContainer* conf;
9395
AppConfigWrapper* m_appwrapper;
@@ -133,19 +135,6 @@ private slots:
133135
void ShowDBusError();
134136
void CheckDBusVersion();
135137
QVariantMap readConfig();
136-
137-
template<typename TReal>
138-
static bool isApproximatelyEqual(TReal a, TReal b, TReal tolerance = std::numeric_limits<TReal>::epsilon())
139-
{
140-
TReal diff = std::fabs(a - b);
141-
if (diff <= tolerance)
142-
return true;
143-
144-
if (diff < std::fmax(std::fabs(a), std::fabs(b)) * tolerance)
145-
return true;
146-
147-
return false;
148-
}
149138
};
150139

151140
#endif // MAINWINDOW_H

mainwindow.ui

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,11 @@
630630
<string>Unknown Type IV</string>
631631
</property>
632632
</item>
633+
<item>
634+
<property name="text">
635+
<string>Custom</string>
636+
</property>
637+
</item>
633638
</widget>
634639
</item>
635640
</layout>
@@ -1260,6 +1265,11 @@
12601265
<string>Volume Boost</string>
12611266
</property>
12621267
</item>
1268+
<item>
1269+
<property name="text">
1270+
<string>Custom</string>
1271+
</property>
1272+
</item>
12631273
</widget>
12641274
</item>
12651275
<item>

misc/common.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <QDir>
1818
#include <string>
1919
#include <algorithm>
20+
#include <cmath>
21+
2022
static std::string default_config = "fx_enable=true\nconv_enable=false\nconv_ir_path=\nconv_cc_level=0\nvhe_enable=false\nvhe_level=0\nvse_enable=false\nvse_ref_bark=7600\nvse_bark_cons=10\neq_enable=false\neq_band1=0\neq_band2=0\neq_band3=0\neq_band4=0\neq_band5=0\neq_band6=0\neq_band7=0\neq_band8=0\neq_band9=0\neq_band10=0\ncolm_enable=false\ncolm_widening=100\ncolm_depth=0\nds_enable=false\nds_level=0\nreverb_enable=false\nreverb_roomsize=30\nreverb_width=40\nreverb_damp=10\nreverb_wet=20\nreverb_dry=80\nagc_enable=false\nagc_ratio=100\nagc_volume=100\nagc_maxgain=100\nvb_enable=false\nvb_mode=0\nvb_freq=76\nvb_gain=0\nvc_enable=false\nvc_mode=0\nvc_level=0\ncure_enable=false\ncure_level=0\ntube_enable=false\nax_enable=false\nax_mode=0\nfetcomp_enable=false\nfetcomp_threshold=0\nfetcomp_ratio=0\nfetcomp_kneewidth=0\nfetcomp_autoknee=true\nfetcomp_gain=0\nfetcomp_autogain=true\nfetcomp_attack=51\nfetcomp_autoattack=true\nfetcomp_release=38\nfetcomp_autorelease=true\nfetcomp_meta_kneemulti=50\nfetcomp_meta_maxattack=88\nfetcomp_meta_maxrelease=88\nfetcomp_meta_crest=61\nfetcomp_meta_adapt=66\nfetcomp_noclip=true\nout_volume=100\nout_pan=0\nlim_threshold=100\ndynsys_bassgain=0\ndynsys_xcoeff1=0\ndynsys_xcoeff2=0\ndynsys_ycoeff1=0\ndynsys_ycoeff2=0\ndynsys_sidegain1=0\ndynsys_sidegain2=0\ndynsys_enable=false";
2123
static inline bool is_number(const std::string& s)
2224
{
@@ -43,4 +45,16 @@ static inline QString pathAppend(const QString& path1, const QString& path2)
4345
return QDir::cleanPath(path1 + QDir::separator() + path2);
4446
}
4547

48+
template<typename TReal>
49+
static bool isApproximatelyEqual(TReal a, TReal b, TReal tolerance = std::numeric_limits<TReal>::epsilon())
50+
{
51+
TReal diff = std::fabs(a - b);
52+
if (diff <= tolerance)
53+
return true;
54+
55+
if (diff < std::fmax(std::fabs(a), std::fabs(b)) * tolerance)
56+
return true;
57+
58+
return false;
59+
}
4660
#endif // COMMON_H
Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,50 @@
1212
*
1313
* ThePBone <tim.schneeberger(at)outlook.de> (c) 2020
1414
*/
15-
#ifndef PRESETEXTENSION_H
16-
#define PRESETEXTENSION_H
17-
#include <QString>
18-
#include <QMap>
19-
#include "initializableqmap.h"
15+
#include "presetprovider.h"
16+
#include "common.h"
17+
namespace PresetProvider {
18+
const FLOAT_LIST EQ::defaultPreset(){
19+
return EQ_LOOKUP_TABLE()["Default"];
20+
}
2021

21-
#define FLOAT_LIST std::initializer_list<float>
22-
#define INT_LIST std::initializer_list<int>
22+
const FLOAT_LIST EQ::lookupPreset(QString preset){
23+
auto table = EQ_LOOKUP_TABLE();
24+
if(table.contains(preset))
25+
return table[preset];
26+
else
27+
return table["Default"];
28+
}
2329

24-
#define EQ_UNIT QString,FLOAT_LIST
25-
#define DYNSYS_UNIT QString,INT_LIST
26-
#define COLM_UNIT QString,INT_LIST
30+
const QString EQ::reverseLookup(QVector<float> data){
31+
auto table = EQ_LOOKUP_TABLE();
32+
for(auto key : table.keys()){
33+
QVector<float> row(table[key]);
34+
int it = 0;
35+
bool different = false;
36+
for(auto cur_data : row){
37+
bool equal = isApproximatelyEqual<float>(cur_data,data.at(it),0.01);
38+
if(!equal){
39+
different = true;
40+
break;
41+
}
42+
it++;
43+
}
44+
if(!different)
45+
return key;
46+
}
47+
return "Custom";
48+
}
2749

28-
namespace EQ {
29-
inline const QMap<EQ_UNIT> EQ_LOOKUP_TABLE(){
50+
const QMap<EQ_UNIT> EQ::EQ_LOOKUP_TABLE(){
3051
InitializableQMap<EQ_UNIT> table;
3152
table << QPair<EQ_UNIT>("Default",FLOAT_LIST({0,0,0,0,0,0,0,0,0,0}))
3253
<< QPair<EQ_UNIT>("Pop",FLOAT_LIST({0,0,0,1.25,2.50,5.00,-1.50,-3.00,-3.00,-3.00}))
3354
<< QPair<EQ_UNIT>("Rock",FLOAT_LIST({0,0,3.00,-10.00,-1.50,0.75,3.00,3.00,3.00,3.00}))
3455
<< QPair<EQ_UNIT>("Jazz",FLOAT_LIST({0,0,2.73,6.00,-6.00,-2.50,2.50,-0.75,-0.75,-0.75}))
3556
<< QPair<EQ_UNIT>("Classic",FLOAT_LIST({0,0,-9.00,0,1.50,0,0,9.00,9.00,9.00}))
3657
<< QPair<EQ_UNIT>("Bass",FLOAT_LIST({11.50,8.50,5.00,2.00,0,0,0,0,0,0}))
37-
<< QPair<EQ_UNIT>("Clear",FLOAT_LIST({0,0,0,1.25,2.50,5.00,-1.50,-3.00,-3.00,-3.00}))
58+
<< QPair<EQ_UNIT>("Clear",FLOAT_LIST({3.50,6.50,9.50,6.50,3.50,1.25,5.00,9.00,11.00,9.00}))
3859
<< QPair<EQ_UNIT>("Volume Boost",FLOAT_LIST({12.00,12.00,12.00,12.00,12.00,12.00,12.00,12.00,12.00,12.00}))
3960
<< QPair<EQ_UNIT>("Hip-Hop",FLOAT_LIST({4.50,4.00,1.50,3.00,-1.50,-1.50,1.50,-1.00,1.50,3.00}))
4061
<< QPair<EQ_UNIT>("Dubstep",FLOAT_LIST({12.00,0.50,-2.00,-5.00,-5.00,-4.50,-2.50,0,-3.00,-.050}))
@@ -51,7 +72,7 @@ inline const QMap<EQ_UNIT> EQ_LOOKUP_TABLE(){
5172
return std::move(table);
5273
}
5374

54-
inline const QMap<DYNSYS_UNIT> DYNSYS_LOOKUP_TABLE(){
75+
const QMap<DYNSYS_UNIT> Dynsys::DYNSYS_LOOKUP_TABLE(){
5576
InitializableQMap<DYNSYS_UNIT> table;
5677
table << QPair<DYNSYS_UNIT>("Unknown",INT_LIST({0}))
5778
<< QPair<DYNSYS_UNIT>("Extreme Headphone (v2)",INT_LIST({140,6200,40,60,10,80}))
@@ -76,7 +97,36 @@ inline const QMap<DYNSYS_UNIT> DYNSYS_LOOKUP_TABLE(){
7697
return std::move(table);
7798
}
7899

79-
inline const QMap<COLM_UNIT> COLM_LOOKUP_TABLE(){
100+
const INT_LIST Dynsys::lookupPreset(QString preset){
101+
auto table = DYNSYS_LOOKUP_TABLE();
102+
if(table.contains(preset))
103+
return table[preset];
104+
else
105+
return table["Unknown"];
106+
}
107+
108+
109+
const QString Dynsys::reverseLookup(QVector<int> data){
110+
auto table = DYNSYS_LOOKUP_TABLE();
111+
for(auto key : table.keys()){
112+
QVector<int> row(table[key]);
113+
int it = 0;
114+
bool different = false;
115+
for(auto cur_data : row){
116+
bool equal = cur_data == data.at(it);
117+
if(!equal){
118+
different = true;
119+
break;
120+
}
121+
it++;
122+
}
123+
if(!different)
124+
return key;
125+
}
126+
return "Custom";
127+
}
128+
129+
const QMap<COLM_UNIT> Colm::COLM_LOOKUP_TABLE(){
80130
InitializableQMap<COLM_UNIT> table;
81131
table << QPair<COLM_UNIT>("Unknown",INT_LIST({0,0}))
82132
<< QPair<COLM_UNIT>("Slight",INT_LIST({120,200}))
@@ -91,31 +141,11 @@ inline const QMap<COLM_UNIT> COLM_LOOKUP_TABLE(){
91141
return std::move(table);
92142
}
93143

94-
inline const FLOAT_LIST lookupEQPreset(QString preset){
95-
auto table = EQ_LOOKUP_TABLE();
96-
if(table.contains(preset))
97-
return table[preset];
98-
else
99-
return table["Default"];
100-
}
101-
inline const INT_LIST lookupDynsysPreset(QString preset){
102-
auto table = DYNSYS_LOOKUP_TABLE();
103-
if(table.contains(preset))
104-
return table[preset];
105-
else
106-
return table["Unknown"];
107-
}
108-
109-
inline const INT_LIST lookupColmPreset(QString preset){
144+
const std::initializer_list<int> Colm::lookupPreset(QString preset){
110145
auto table = COLM_LOOKUP_TABLE();
111146
if(table.contains(preset))
112147
return table[preset];
113148
else
114149
return table["Unknown"];
115150
}
116-
117-
inline const std::initializer_list<float> defaultEQPreset(){
118-
return EQ_LOOKUP_TABLE()["Default"];
119-
}
120151
}
121-
#endif // PRESETEXTENSION_H

0 commit comments

Comments
 (0)