[112] | 1 | /* smplayer, GUI front-end for mplayer.
|
---|
[188] | 2 | Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
[112] | 3 |
|
---|
| 4 | This program is free software; you can redistribute it and/or modify
|
---|
| 5 | it under the terms of the GNU General Public License as published by
|
---|
| 6 | the Free Software Foundation; either version 2 of the License, or
|
---|
| 7 | (at your option) any later version.
|
---|
| 8 |
|
---|
| 9 | This program is distributed in the hope that it will be useful,
|
---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 12 | GNU General Public License for more details.
|
---|
| 13 |
|
---|
| 14 | You should have received a copy of the GNU General Public License
|
---|
| 15 | along with this program; if not, write to the Free Software
|
---|
| 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | #include "audioequalizer.h"
|
---|
| 20 | #include "eqslider.h"
|
---|
| 21 | #include "images.h"
|
---|
| 22 | #include "preferences.h"
|
---|
| 23 | #include "global.h"
|
---|
| 24 | #include <QLayout>
|
---|
| 25 | #include <QPushButton>
|
---|
[165] | 26 | #include <QLabel>
|
---|
| 27 | #include <QComboBox>
|
---|
[112] | 28 | #include <QMessageBox>
|
---|
[181] | 29 | #include <QDebug>
|
---|
[112] | 30 |
|
---|
| 31 | using namespace Global;
|
---|
| 32 |
|
---|
| 33 | AudioEqualizer::AudioEqualizer( QWidget* parent, Qt::WindowFlags f)
|
---|
| 34 | : QWidget(parent, f)
|
---|
| 35 | {
|
---|
[165] | 36 | createPresets();
|
---|
| 37 |
|
---|
[112] | 38 | QBoxLayout *bl = new QHBoxLayout; //(0, 4, 2);
|
---|
| 39 |
|
---|
| 40 | for (int n = 0; n < 10; n++) {
|
---|
| 41 | eq[n] = new EqSlider(this);
|
---|
| 42 | eq[n]->setIcon( QPixmap() );
|
---|
| 43 | eq[n]->sliderWidget()->setRange(-120, 120);
|
---|
[176] | 44 | eq[n]->sliderWidget()->setTracking(false);
|
---|
| 45 | connect(eq[n], SIGNAL(valueChanged(int)), this, SLOT(updatePresetCombo()));
|
---|
[112] | 46 | bl->addWidget(eq[n]);
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[165] | 49 | presets_combo = new QComboBox(this);
|
---|
| 50 | connect(presets_combo, SIGNAL(activated(int)), this, SLOT(presetChanged(int)));
|
---|
| 51 |
|
---|
| 52 | presets_label = new QLabel("&Preset", this);
|
---|
| 53 | presets_label->setBuddy(presets_combo);
|
---|
| 54 |
|
---|
[112] | 55 | reset_button = new QPushButton( "&Reset", this);
|
---|
| 56 | connect( reset_button, SIGNAL(clicked()), this, SLOT(reset()) );
|
---|
| 57 |
|
---|
| 58 | set_default_button = new QPushButton( "&Set as default values", this );
|
---|
| 59 | connect( set_default_button, SIGNAL(clicked()), this, SLOT(setDefaults()) );
|
---|
| 60 |
|
---|
| 61 | apply_button = new QPushButton( "&Apply", this );
|
---|
| 62 | connect( apply_button, SIGNAL(clicked()), this, SLOT(applyButtonClicked()) );
|
---|
| 63 |
|
---|
[181] | 64 | close_button = new QPushButton( "&Close", this );
|
---|
| 65 | connect( close_button, SIGNAL(clicked()), this, SLOT(close()) );
|
---|
| 66 |
|
---|
[112] | 67 | QBoxLayout *button_layout = new QHBoxLayout; //(0, 4, 2);
|
---|
[165] | 68 | button_layout->addWidget(presets_label);
|
---|
| 69 | button_layout->addWidget(presets_combo);
|
---|
[112] | 70 | button_layout->addStretch();
|
---|
| 71 | button_layout->addWidget(apply_button);
|
---|
[181] | 72 | button_layout->addWidget(set_default_button);
|
---|
[112] | 73 | button_layout->addWidget(reset_button);
|
---|
[181] | 74 | button_layout->addWidget(close_button);
|
---|
[112] | 75 |
|
---|
| 76 | QBoxLayout *layout = new QVBoxLayout(this); //, 4, 2);
|
---|
| 77 | layout->addLayout(bl);
|
---|
| 78 | layout->addLayout(button_layout);
|
---|
| 79 |
|
---|
| 80 | retranslateStrings();
|
---|
| 81 |
|
---|
| 82 | adjustSize();
|
---|
| 83 | //setFixedSize( sizeHint() );
|
---|
[181] | 84 |
|
---|
| 85 | if (size().height() < 244) resize(size().width(), 244);
|
---|
[112] | 86 | }
|
---|
| 87 |
|
---|
| 88 | AudioEqualizer::~AudioEqualizer() {
|
---|
[181] | 89 | //qDebug() << "AudioEqualizer::~AudioEqualizer: size:" << size();
|
---|
[112] | 90 | }
|
---|
| 91 |
|
---|
[165] | 92 | void AudioEqualizer::createPresets() {
|
---|
| 93 | preset_list.clear();
|
---|
| 94 | AudioEqualizerList preset;
|
---|
| 95 |
|
---|
| 96 | // Classical
|
---|
| 97 | preset.clear();
|
---|
| 98 | preset << 0 << 0 << 0 << 0 << 0 << 0 << -41 << -41 << -41 << -53;
|
---|
| 99 | preset_list[Classical] = preset;
|
---|
| 100 |
|
---|
| 101 | // Club
|
---|
| 102 | preset.clear();
|
---|
| 103 | preset << 0 << 0 << 47 << 29 << 29 << 29 << 17 << 0 << 0 << 0;
|
---|
| 104 | preset_list[Club] = preset;
|
---|
| 105 |
|
---|
| 106 | // Dance
|
---|
| 107 | preset.clear();
|
---|
| 108 | preset << 53 << 41 << 11 << 0 << 0 << -29 << -41 << -41 << 0 << 0;
|
---|
| 109 | preset_list[Dance] = preset;
|
---|
| 110 |
|
---|
| 111 | // Flat
|
---|
| 112 | preset.clear();
|
---|
| 113 | preset << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0;
|
---|
| 114 | preset_list[Flat] = preset;
|
---|
| 115 |
|
---|
| 116 | // Fullbass
|
---|
| 117 | preset.clear();
|
---|
| 118 | preset << 53 << 53 << 53 << 29 << 5 << -23 << -47 << -59 << -65 << -65;
|
---|
| 119 | preset_list[Fullbass] = preset;
|
---|
| 120 |
|
---|
| 121 | // FullbassTreble
|
---|
| 122 | preset.clear();
|
---|
| 123 | preset << 41 << 29 << 0 << -41 << -23 << 5 << 47 << 65 << 71 << 71;
|
---|
| 124 | preset_list[FullbassTreble] = preset;
|
---|
| 125 |
|
---|
| 126 | // Fulltreble
|
---|
| 127 | preset.clear();
|
---|
| 128 | preset << -53 << -53 << -53 << -23 << 11 << 65 << 95 << 95 << 95 << 95;
|
---|
| 129 | preset_list[Fulltreble] = preset;
|
---|
| 130 |
|
---|
| 131 | // Headphones
|
---|
| 132 | preset.clear();
|
---|
| 133 | preset << 23 << 65 << 29 << -17 << -11 << 5 << 23 << 53 << 71 << 83;
|
---|
| 134 | preset_list[Headphones] = preset;
|
---|
| 135 |
|
---|
| 136 | // LargeHall
|
---|
| 137 | preset.clear();
|
---|
| 138 | preset << 59 << 59 << 29 << 29 << 0 << -23 << -23 << -23 << 0 << 0;
|
---|
| 139 | preset_list[LargeHall] = preset;
|
---|
| 140 |
|
---|
| 141 | // Live
|
---|
| 142 | preset.clear();
|
---|
| 143 | preset << -23 << 0 << 23 << 29 << 29 << 29 << 23 << 11 << 11 << 11;
|
---|
| 144 | preset_list[Live] = preset;
|
---|
| 145 |
|
---|
| 146 | // Party
|
---|
| 147 | preset.clear();
|
---|
| 148 | preset << 41 << 41 << 0 << 0 << 0 << 0 << 0 << 0 << 41 << 41;
|
---|
| 149 | preset_list[Party] = preset;
|
---|
| 150 |
|
---|
| 151 | // Pop
|
---|
| 152 | preset.clear();
|
---|
| 153 | preset << -5 << 23 << 41 << 47 << 29 << 0 << -11 << -11 << -5 << -5;
|
---|
| 154 | preset_list[Pop] = preset;
|
---|
| 155 |
|
---|
| 156 | // Reggae
|
---|
| 157 | preset.clear();
|
---|
| 158 | preset << 0 << 0 << 0 << -29 << 0 << 35 << 35 << 0 << 0 << 0;
|
---|
| 159 | preset_list[Reggae] = preset;
|
---|
| 160 |
|
---|
| 161 | // Rock
|
---|
| 162 | preset.clear();
|
---|
| 163 | preset << 47 << 23 << 29 << -47 << -17 << 23 << 47 << 65 << 65 << 65;
|
---|
| 164 | preset_list[Rock] = preset;
|
---|
| 165 |
|
---|
| 166 | // Ska
|
---|
| 167 | preset.clear();
|
---|
| 168 | preset << -11 << -23 << -23 << 0 << 23 << 29 << 47 << 53 << 65 << 53;
|
---|
| 169 | preset_list[Ska] = preset;
|
---|
| 170 |
|
---|
| 171 | // Soft
|
---|
| 172 | preset.clear();
|
---|
| 173 | preset << 23 << 5 << 0 << -11 << 0 << 23 << 47 << 53 << 65 << 71;
|
---|
| 174 | preset_list[Soft] = preset;
|
---|
| 175 |
|
---|
| 176 | // SoftRock
|
---|
| 177 | preset.clear();
|
---|
| 178 | preset << 23 << 23 << 11 << 0 << -23 << -29 << -17 << 0 << 11 << 47;
|
---|
| 179 | preset_list[SoftRock] = preset;
|
---|
| 180 |
|
---|
| 181 | // Techno
|
---|
| 182 | preset.clear();
|
---|
| 183 | preset << 47 << 29 << 0 << -29 << -23 << 0 << 47 << 53 << 53 << 47;
|
---|
| 184 | preset_list[Techno] = preset;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 |
|
---|
[112] | 188 | void AudioEqualizer::retranslateStrings() {
|
---|
| 189 | setWindowTitle( tr("Audio Equalizer") );
|
---|
| 190 | setWindowIcon( Images::icon("logo") );
|
---|
| 191 |
|
---|
[165] | 192 | eq[0]->setLabel( tr("%1 Hz").arg("31.25") );
|
---|
| 193 | eq[1]->setLabel( tr("%1 Hz").arg("62.50") );
|
---|
| 194 | eq[2]->setLabel( tr("%1 Hz").arg("125") );
|
---|
| 195 | eq[3]->setLabel( tr("%1 Hz").arg("250") );
|
---|
| 196 | eq[4]->setLabel( tr("%1 Hz").arg("500") );
|
---|
| 197 | eq[5]->setLabel( tr("%1 kHz").arg("1") );
|
---|
| 198 | eq[6]->setLabel( tr("%1 kHz").arg("2") );
|
---|
| 199 | eq[7]->setLabel( tr("%1 kHz").arg("4") );
|
---|
| 200 | eq[8]->setLabel( tr("%1 kHz").arg("8") );
|
---|
| 201 | eq[9]->setLabel( tr("%1 kHz").arg("16") );
|
---|
[112] | 202 |
|
---|
[165] | 203 | presets_label->setText( tr("&Preset") );
|
---|
[112] | 204 | apply_button->setText( tr("&Apply") );
|
---|
| 205 | reset_button->setText( tr("&Reset") );
|
---|
| 206 | set_default_button->setText( tr("&Set as default values") );
|
---|
[181] | 207 | close_button->setText(tr("&Close"));
|
---|
[112] | 208 |
|
---|
[165] | 209 | int presets_combo_index = presets_combo->currentIndex();
|
---|
| 210 | if (presets_combo_index < 0) presets_combo_index = 0;
|
---|
| 211 | presets_combo->clear();
|
---|
| 212 | presets_combo->addItem( tr("Flat"), Flat);
|
---|
| 213 | presets_combo->addItem( tr("Classical"), Classical);
|
---|
| 214 | presets_combo->addItem( tr("Club"), Club);
|
---|
| 215 | presets_combo->addItem( tr("Dance"), Dance);
|
---|
| 216 | presets_combo->addItem( tr("Full bass"), Fullbass);
|
---|
| 217 | presets_combo->addItem( tr("Full bass and treble"), FullbassTreble);
|
---|
| 218 | presets_combo->addItem( tr("Full treble"), Fulltreble);
|
---|
| 219 | presets_combo->addItem( tr("Headphones"), Headphones);
|
---|
| 220 | presets_combo->addItem( tr("Large hall"), LargeHall);
|
---|
| 221 | presets_combo->addItem( tr("Live"), Live);
|
---|
| 222 | presets_combo->addItem( tr("Party"), Party);
|
---|
| 223 | presets_combo->addItem( tr("Pop"), Pop);
|
---|
| 224 | presets_combo->addItem( tr("Reggae"), Reggae);
|
---|
| 225 | presets_combo->addItem( tr("Rock"), Rock);
|
---|
| 226 | presets_combo->addItem( tr("Ska"), Ska);
|
---|
| 227 | presets_combo->addItem( tr("Soft"), Soft);
|
---|
| 228 | presets_combo->addItem( tr("Soft rock"), SoftRock);
|
---|
| 229 | presets_combo->addItem( tr("Techno"), Techno);
|
---|
| 230 | presets_combo->addItem( tr("Custom"), User_defined);
|
---|
| 231 | presets_combo->setCurrentIndex(presets_combo_index);
|
---|
| 232 |
|
---|
[112] | 233 | // What's this help:
|
---|
| 234 | set_default_button->setWhatsThis(
|
---|
| 235 | tr("Use the current values as default values for new videos.") );
|
---|
| 236 |
|
---|
| 237 | reset_button->setWhatsThis( tr("Set all controls to zero.") );
|
---|
| 238 | }
|
---|
| 239 |
|
---|
| 240 | void AudioEqualizer::reset() {
|
---|
[176] | 241 | setValues(preset_list[Flat]);
|
---|
[165] | 242 | presets_combo->setCurrentIndex(presets_combo->findData(Flat));
|
---|
[112] | 243 | }
|
---|
| 244 |
|
---|
| 245 | void AudioEqualizer::setDefaults() {
|
---|
| 246 | AudioEqualizerList l;
|
---|
| 247 | for (int n = 0; n < 10; n++) {
|
---|
| 248 | l << eq[n]->value();
|
---|
| 249 | }
|
---|
| 250 | pref->initial_audio_equalizer = l;
|
---|
| 251 |
|
---|
| 252 | QMessageBox::information(this, tr("Information"),
|
---|
| 253 | tr("The current values have been stored to be "
|
---|
| 254 | "used as default.") );
|
---|
| 255 | }
|
---|
| 256 |
|
---|
[165] | 257 | void AudioEqualizer::setEqualizer(AudioEqualizerList l) {
|
---|
| 258 | int p = findPreset(l);
|
---|
| 259 | int index = presets_combo->findData(p);
|
---|
| 260 | if (index != 1) {
|
---|
| 261 | presets_combo->setCurrentIndex(index);
|
---|
| 262 | } else {
|
---|
| 263 | qWarning("AudioEqualizer::setEqualizer: preset not found");
|
---|
| 264 | }
|
---|
| 265 | setValues(l);
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | void AudioEqualizer::setValues(AudioEqualizerList l) {
|
---|
| 269 | qDebug("AudioEqualizer::setValues");
|
---|
| 270 |
|
---|
| 271 | for (int n = 0; n < 10; n++) {
|
---|
[176] | 272 | eq[n]->blockSignals(true);
|
---|
[165] | 273 | eq[n]->setValue(l[n].toInt());
|
---|
[176] | 274 | eq[n]->blockSignals(false);
|
---|
[165] | 275 | }
|
---|
[176] | 276 |
|
---|
| 277 | emit valuesChanged(l);
|
---|
[165] | 278 | }
|
---|
| 279 |
|
---|
| 280 | void AudioEqualizer::presetChanged(int index) {
|
---|
| 281 | qDebug("AudioEqualizer::presetChanged: %d", index);
|
---|
| 282 | int p = presets_combo->itemData(index).toInt();
|
---|
| 283 | if (p != User_defined) {
|
---|
| 284 | setValues(preset_list[p]);
|
---|
| 285 | }
|
---|
| 286 | }
|
---|
| 287 |
|
---|
| 288 | int AudioEqualizer::findPreset(AudioEqualizerList l) {
|
---|
| 289 | QMap<int,AudioEqualizerList>::iterator i;
|
---|
| 290 | for (i = preset_list.begin(); i != preset_list.end(); ++i) {
|
---|
| 291 | if (l == i.value()) return i.key();
|
---|
| 292 | }
|
---|
| 293 | return User_defined;
|
---|
| 294 | }
|
---|
| 295 |
|
---|
[112] | 296 | void AudioEqualizer::applyButtonClicked() {
|
---|
| 297 | AudioEqualizerList l;
|
---|
| 298 | for (int n = 0; n < 10; n++) {
|
---|
| 299 | l << eq[n]->value();
|
---|
| 300 | }
|
---|
| 301 | emit applyClicked( l );
|
---|
| 302 | }
|
---|
| 303 |
|
---|
[176] | 304 | void AudioEqualizer::updatePresetCombo() {
|
---|
| 305 | qDebug("AudioEqualizer::updatePresetCombo");
|
---|
| 306 |
|
---|
| 307 | AudioEqualizerList l;
|
---|
| 308 | for (int n = 0; n < 10; n++) {
|
---|
| 309 | l << eq[n]->value();
|
---|
| 310 | }
|
---|
| 311 |
|
---|
| 312 | int p = findPreset(l);
|
---|
| 313 | int index = presets_combo->findData(p);
|
---|
| 314 | if (index != 1) {
|
---|
| 315 | presets_combo->setCurrentIndex(index);
|
---|
| 316 | }
|
---|
| 317 | }
|
---|
| 318 |
|
---|
[112] | 319 | void AudioEqualizer::hideEvent( QHideEvent * ) {
|
---|
| 320 | emit visibilityChanged();
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | void AudioEqualizer::showEvent( QShowEvent * ) {
|
---|
| 324 | emit visibilityChanged();
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | // Language change stuff
|
---|
| 328 | void AudioEqualizer::changeEvent(QEvent *e) {
|
---|
| 329 | if (e->type() == QEvent::LanguageChange) {
|
---|
| 330 | retranslateStrings();
|
---|
| 331 | } else {
|
---|
| 332 | QWidget::changeEvent(e);
|
---|
| 333 | }
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 | #include "moc_audioequalizer.cpp"
|
---|