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