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