extended_panels.cpp 58 KB
Newer Older
Clément Stenac's avatar
Clément Stenac committed
1
/*****************************************************************************
Clément Stenac's avatar
Clément Stenac committed
2
 * extended_panels.cpp : Extended controls panels
Clément Stenac's avatar
Clément Stenac committed
3
 ****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2006-2013 the VideoLAN team
5
 * $Id$
Clément Stenac's avatar
Clément Stenac committed
6 7
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
8
 *          Antoine Cellerier <dionoea .t videolan d@t org>
9
 *          Jean-Baptiste Kempf <jb@videolan.org>
Clément Stenac's avatar
Clément Stenac committed
10 11 12 13
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
14
 * ( at your option ) any later version.
Clément Stenac's avatar
Clément Stenac committed
15 16 17 18 19 20 21 22 23 24
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/
25

26 27 28
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
Clément Stenac's avatar
Clément Stenac committed
29

30 31
#include <math.h>

Clément Stenac's avatar
Clément Stenac committed
32 33 34 35 36
#include <QLabel>
#include <QVariant>
#include <QString>
#include <QFont>
#include <QGridLayout>
37
#include <QComboBox>
38
#include <QTimer>
39
#include <QFileDialog>
40 41
#include <QGraphicsScene>
#include <QPainter>
Clément Stenac's avatar
Clément Stenac committed
42

Clément Stenac's avatar
Clément Stenac committed
43
#include "components/extended_panels.hpp"
44
#include "dialogs/preferences.hpp"
45
#include "qt.hpp"
46
#include "input_manager.hpp"
47
#include "util/qt_dirs.hpp"
48
#include "util/customwidgets.hpp"
Clément Stenac's avatar
Clément Stenac committed
49

50
#include "../../audio_filter/equalizer_presets.h"
51
#include <vlc_vout.h>
52
#include <vlc_modules.h>
53
#include <vlc_plugin.h>
Clément Stenac's avatar
Clément Stenac committed
54

55
static char *ChangeFiltersString( struct intf_thread_t *p_intf, const char *psz_filter_type, const char *psz_name, bool b_add );
56
static void ChangeAFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add );
57 58
static void ChangeVFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add );

59
const QString ModuleFromWidgetName( QObject *obj )
60
{
61
    return obj->objectName().replace( "Enable","" );
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
}

QString OptionFromWidgetName( QObject *obj )
{
    /* Gruik ? ... nah */
    QString option = obj->objectName().replace( "Slider", "" )
                                      .replace( "Combo" , "" )
                                      .replace( "Dial"  , "" )
                                      .replace( "Check" , "" )
                                      .replace( "Spin"  , "" )
                                      .replace( "Text"  , "" );
    for( char a = 'A'; a <= 'Z'; a++ )
    {
        option = option.replace( QString( a ),
                                 QString( '-' ) + QString( a + 'a' - 'A' ) );
    }
    return option;
}
80

81
static inline void setup_vfilter( intf_thread_t *p_intf, const char* psz_name, QWidget *widget )
82
{
83
    vlc_object_t *p_obj = ( vlc_object_t * )
84
        vlc_object_find_name( p_intf->obj.libvlc, psz_name );
85 86 87 88 89 90 91 92 93 94 95 96 97 98
    QCheckBox *checkbox = qobject_cast<QCheckBox*>( widget );
    QGroupBox *groupbox = qobject_cast<QGroupBox*>( widget );
    if( p_obj )
    {
        vlc_object_release( p_obj ); \
        if( checkbox ) checkbox->setChecked( true ); \
        else if (groupbox) groupbox->setChecked( true ); \
    }
    else
    {
        if( checkbox ) checkbox->setChecked( false );
        else if (groupbox) groupbox->setChecked( false );
    }
}
99

100
#define SETUP_VFILTER( widget ) \
101
    setup_vfilter( p_intf, #widget, ui.widget##Enable ); \
102
    CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
103

104
#define SETUP_VFILTER_OPTION( widget, signal ) \
105
    initComboBoxItems( ui.widget ); \
106 107
    setWidgetValue( ui.widget ); \
    CONNECT( ui.widget, signal, this, updateFilterOptions() );
Antoine Cellerier's avatar
Antoine Cellerier committed
108

109 110 111 112 113
ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
            QObject( _parent ), p_intf( _p_intf )
{
    ui.setupUi( _parent );

114
    SETUP_VFILTER( adjust )
115 116 117 118 119 120
    SETUP_VFILTER_OPTION( hueSlider, valueChanged( int ) )
    SETUP_VFILTER_OPTION( contrastSlider, valueChanged( int ) )
    SETUP_VFILTER_OPTION( brightnessSlider, valueChanged( int ) )
    SETUP_VFILTER_OPTION( saturationSlider, valueChanged( int ) )
    SETUP_VFILTER_OPTION( gammaSlider, valueChanged( int ) )
    SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged( int ) )
121 122

    SETUP_VFILTER( extract )
123
    SETUP_VFILTER_OPTION( extractComponentText, textChanged( const QString& ) )
124

125 126
    SETUP_VFILTER( posterize )

127
    SETUP_VFILTER( colorthres )
128
    SETUP_VFILTER_OPTION( colorthresColorText, textChanged( const QString& ) )
129 130
    SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged( int ) )
    SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged( int ) )
131

132 133 134
    SETUP_VFILTER( sepia )
    SETUP_VFILTER_OPTION( sepiaIntensitySpin, valueChanged( int ) )

135 136 137
    SETUP_VFILTER( invert )

    SETUP_VFILTER( gradient )
138 139 140
    SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged( QString ) )
    SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged( int ) )
    SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged( int ) )
141

142
    SETUP_VFILTER( motionblur )
143
    SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged( int ) )
144 145 146 147 148 149

    SETUP_VFILTER( motiondetect )

    SETUP_VFILTER( psychedelic )

    SETUP_VFILTER( sharpen )
150
    SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged( int ) )
151 152 153 154 155 156

    SETUP_VFILTER( ripple )

    SETUP_VFILTER( wave )

    SETUP_VFILTER( transform )
157
    SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged( QString ) )
158 159

    SETUP_VFILTER( rotate )
160
    SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged( int ) )
161 162
    ui.rotateAngleDial->setWrapping( true );
    ui.rotateAngleDial->setNotchesVisible( true );
163 164

    SETUP_VFILTER( puzzle )
165 166 167
    SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged( int ) )
    SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged( int ) )
    SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged( int ) )
168 169 170 171

    SETUP_VFILTER( magnify )

    SETUP_VFILTER( clone )
172
    SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged( int ) )
173 174

    SETUP_VFILTER( wall )
175 176
    SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged( int ) )
    SETUP_VFILTER_OPTION( wallColsSpin, valueChanged( int ) )
177

178

179 180
    SETUP_VFILTER( erase )
    SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
181 182
    SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
    SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
183
    BUTTONACT( ui.eraseBrowseBtn, browseEraseFile() );
184 185

    SETUP_VFILTER( marq )
186
    SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( const QString& ) )
187
    SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged( QString ) )
188 189 190

    SETUP_VFILTER( logo )
    SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
191 192
    SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
    SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
193
    SETUP_VFILTER_OPTION( logoOpacitySlider, valueChanged( int ) )
194
    BUTTONACT( ui.logoBrowseBtn, browseLogo() );
195

196 197 198
    SETUP_VFILTER( gradfun )
    SETUP_VFILTER_OPTION( gradfunRadiusSlider, valueChanged( int ) )

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
199 200 201
    SETUP_VFILTER( grain )
    SETUP_VFILTER_OPTION( grainVarianceSlider, valueChanged( int ) )

202 203 204
    SETUP_VFILTER( mirror )

    SETUP_VFILTER( gaussianblur )
205
    SETUP_VFILTER_OPTION( gaussianblurSigmaSlider, valueChanged( int ) )
206 207 208 209

    SETUP_VFILTER( antiflicker )
    SETUP_VFILTER_OPTION( antiflickerSofteningSizeSlider, valueChanged( int ) )

210 211 212 213 214 215
    SETUP_VFILTER( hqdn3d )
    SETUP_VFILTER_OPTION( hqdn3dLumaSpatSlider, valueChanged( int ) )
    SETUP_VFILTER_OPTION( hqdn3dLumaTempSlider, valueChanged( int ) )
    SETUP_VFILTER_OPTION( hqdn3dChromaSpatSlider, valueChanged( int ) )
    SETUP_VFILTER_OPTION( hqdn3dChromaTempSlider, valueChanged( int ) )

216

217 218
    SETUP_VFILTER( anaglyph )

219 220
#undef SETUP_VFILTER
#undef SETUP_VFILTER_OPTION
221 222 223 224 225

    CONNECT( ui.cropTopPx, valueChanged( int ), this, cropChange() );
    CONNECT( ui.cropBotPx, valueChanged( int ), this, cropChange() );
    CONNECT( ui.cropLeftPx, valueChanged( int ), this, cropChange() );
    CONNECT( ui.cropRightPx, valueChanged( int ), this, cropChange() );
226 227
    CONNECT( ui.leftRightCropSync, toggled ( bool ), this, cropChange() );
    CONNECT( ui.topBotCropSync, toggled ( bool ), this, cropChange() );
228 229 230 231
    CONNECT( ui.topBotCropSync, toggled( bool ),
             ui.cropBotPx, setDisabled( bool ) );
    CONNECT( ui.leftRightCropSync, toggled( bool ),
             ui.cropRightPx, setDisabled( bool ) );
232 233
}

234 235
void ExtVideo::cropChange()
{
236 237 238 239 240
    if( ui.topBotCropSync->isChecked() )
        ui.cropBotPx->setValue( ui.cropTopPx->value() );
    if( ui.leftRightCropSync->isChecked() )
        ui.cropRightPx->setValue( ui.cropLeftPx->value() );

241
    vout_thread_t *p_vout = THEMIM->getVout();
242
    if( p_vout )
243
    {
244 245 246 247
        var_SetInteger( p_vout, "crop-top", ui.cropTopPx->value() );
        var_SetInteger( p_vout, "crop-bottom", ui.cropBotPx->value() );
        var_SetInteger( p_vout, "crop-left", ui.cropLeftPx->value() );
        var_SetInteger( p_vout, "crop-right", ui.cropRightPx->value() );
248
        vlc_object_release( p_vout );
249 250 251
    }
}

252 253 254 255 256 257 258 259
void ExtVideo::clean()
{
    ui.cropTopPx->setValue( 0 );
    ui.cropBotPx->setValue( 0 );
    ui.cropLeftPx->setValue( 0 );
    ui.cropRightPx->setValue( 0 );
}

260
static char *ChangeFiltersString( struct intf_thread_t *p_intf, const char *psz_filter_type, const char *psz_name, bool b_add )
261 262
{
    char *psz_parser, *psz_string;
263 264

    psz_string = config_GetPsz( p_intf, psz_filter_type );
265

266
    if( !psz_string ) psz_string = strdup( "" );
267 268 269 270 271 272 273 274

    psz_parser = strstr( psz_string, psz_name );

    if( b_add )
    {
        if( !psz_parser )
        {
            psz_parser = psz_string;
275 276
            if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
                            psz_string, psz_name ) == -1 )
Rémi Duraffort's avatar
Rémi Duraffort committed
277 278
            {
                free( psz_parser );
279
                return NULL;
Rémi Duraffort's avatar
Rémi Duraffort committed
280
            }
281 282 283 284
            free( psz_parser );
        }
        else
        {
Erwan Tulou's avatar
Erwan Tulou committed
285
            free( psz_string );
286
            return NULL;
287 288 289 290 291 292
        }
    }
    else
    {
        if( psz_parser )
        {
293
            if( *( psz_parser + strlen( psz_name ) ) == ':' )
294
            {
295 296
                memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
                         strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
297 298 299 300 301
            }
            else
            {
                *psz_parser = '\0';
            }
302 303

            /* Remove trailing : : */
304 305
            size_t i_len = strlen( psz_string );
            if( i_len > 0 && *( psz_string + i_len - 1 ) == ':' )
306
            {
307
                *( psz_string + i_len - 1 ) = '\0';
308
            }
309 310 311 312
        }
        else
        {
            free( psz_string );
313
            return NULL;
314
        }
315
    }
316 317 318
    return psz_string;
}

319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
static void ChangeAFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add )
{
    char *psz_string;

    module_t *p_obj = module_find( psz_name );
    if( !p_obj )
    {
        msg_Err( p_intf, "Unable to find filter module \"%s\".", psz_name );
        return;
    }

    psz_string = ChangeFiltersString( p_intf, "audio-filter", psz_name, b_add );
    if( !psz_string )
        return;

    config_PutPsz( p_intf, "audio-filter", psz_string );

    free( psz_string );
}

339
static const char* GetVFilterType( struct intf_thread_t *p_intf, const char *psz_name )
340 341 342 343 344
{
    module_t *p_obj = module_find( psz_name );
    if( !p_obj )
    {
        msg_Err( p_intf, "Unable to find filter module \"%s\".", psz_name );
345
        return NULL;
346 347 348
    }

    if( module_provides( p_obj, "video splitter" ) )
349
        return "video-splitter";
350
    else if( module_provides( p_obj, "video filter" ) )
351
        return "video-filter";
352
    else if( module_provides( p_obj, "sub source" ) )
353
        return "sub-source";
354
    else if( module_provides( p_obj, "sub filter" ) )
355
        return "sub-filter";
356 357 358
    else
    {
        msg_Err( p_intf, "Unknown video filter type." );
359
        return NULL;
360
    }
361 362 363 364 365 366
}

static void ChangeVFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add )
{
    char *psz_string;
    const char *psz_filter_type = GetVFilterType( p_intf, psz_name );
367 368 369 370 371

    psz_string = ChangeFiltersString( p_intf, psz_filter_type, psz_name, b_add );
    if( !psz_string )
        return;

372
    /* Vout is not kept, so put that in the config */
373
    config_PutPsz( p_intf, psz_filter_type, psz_string );
374 375

    /* Try to set on the fly */
376
    if( !strcmp( psz_filter_type, "video-splitter" ) )
377
    {
378
        playlist_t *p_playlist = THEPL;
379 380 381 382
        var_SetString( p_playlist, psz_filter_type, psz_string );
    }
    else
    {
383
        vout_thread_t *p_vout = THEMIM->getVout();
384 385 386 387 388
        if( p_vout )
        {
            var_SetString( p_vout, psz_filter_type, psz_string );
            vlc_object_release( p_vout );
        }
389 390 391 392 393 394 395
    }

    free( psz_string );
}

void ExtVideo::updateFilters()
{
396
    QString module = ModuleFromWidgetName( sender() );
397

398 399
    QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
    QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
400

401
    ChangeVFiltersString( p_intf, qtu( module ),
402 403
                          checkbox ? checkbox->isChecked()
                                   : groupbox->isChecked() );
404 405
}

406 407 408 409 410 411
#define UPDATE_AND_APPLY_TEXT( widget, file ) \
    CONNECT( ui.widget, textChanged( const QString& ), \
             this, updateFilterOptions() ); \
    ui.widget->setText( toNativeSeparators( file ) ); \
    ui.widget->disconnect( SIGNAL( textChanged( const QString& ) ) );

412 413 414 415
void ExtVideo::browseLogo()
{
    QString file = QFileDialog::getOpenFileName( NULL, qtr( "Logo filenames" ),
                   p_intf->p_sys->filepath, "Images (*.png *.jpg);;All (*)" );
416 417

    UPDATE_AND_APPLY_TEXT( logoFileText, file );
418 419 420 421 422 423
}

void ExtVideo::browseEraseFile()
{
    QString file = QFileDialog::getOpenFileName( NULL, qtr( "Image mask" ),
                   p_intf->p_sys->filepath, "Images (*.png *.jpg);;All (*)" );
424 425

    UPDATE_AND_APPLY_TEXT( eraseMaskText, file );
426 427
}

428 429
#undef UPDATE_AND_APPLY_TEXT

430 431
void ExtVideo::initComboBoxItems( QObject *widget )
{
432
    QComboBox *combobox = qobject_cast<QComboBox*>( widget );
433
    if( !combobox ) return;
434

435
    QString option = OptionFromWidgetName( widget );
436
    module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
437
                                                 qtu( option ) );
438
    if( p_item == NULL )
439
    {
440 441 442 443 444 445 446 447 448 449 450 451
        msg_Err( p_intf, "Couldn't find option \"%s\".", qtu( option ) );
        return;
    }

    if( p_item->i_type == CONFIG_ITEM_INTEGER
     || p_item->i_type == CONFIG_ITEM_BOOL )
    {
        int64_t *values;
        char **texts;
        ssize_t count = config_GetIntChoices( VLC_OBJECT( p_intf ),
                                              qtu( option ), &values, &texts );
        for( ssize_t i = 0; i < count; i++ )
452
        {
453
            combobox->addItem( qtr( texts[i] ), qlonglong(values[i]) );
454
            free( texts[i] );
455
        }
456 457
        free( texts );
        free( values );
458
    }
459
    else if( p_item->i_type == CONFIG_ITEM_STRING )
460
    {
461 462 463 464 465 466
        char **values;
        char **texts;
        ssize_t count = config_GetPszChoices( VLC_OBJECT( p_intf ),
                                              qtu( option ), &values, &texts );
        for( ssize_t i = 0; i < count; i++ )
        {
467
            combobox->addItem( qtr( texts[i] ), qfu(values[i]) );
468 469 470 471 472
            free( texts[i] );
            free( values[i] );
        }
        free( texts );
        free( values );
473 474 475
    }
}

476 477 478 479 480 481 482
void ExtVideo::setWidgetValue( QObject *widget )
{
    QString module = ModuleFromWidgetName( widget->parent() );
    //std::cout << "Module name: " << module.toStdString() << std::endl;
    QString option = OptionFromWidgetName( widget );
    //std::cout << "Option name: " << option.toStdString() << std::endl;

483
    vlc_object_t *p_obj = ( vlc_object_t * )
484
        vlc_object_find_name( p_intf->obj.libvlc, qtu( module ) );
485 486 487 488 489
    int i_type;
    vlc_value_t val;

    if( !p_obj )
    {
490
#if 0
491 492
        msg_Dbg( p_intf,
                 "Module instance %s not found, looking in config values.",
493
                 qtu( module ) );
494
#endif
495
        i_type = config_GetType( p_intf, qtu( option ) ) & VLC_VAR_CLASS;
496 497 498 499
        switch( i_type )
        {
            case VLC_VAR_INTEGER:
            case VLC_VAR_BOOL:
500
                val.i_int = config_GetInt( p_intf, qtu( option ) );
501 502
                break;
            case VLC_VAR_FLOAT:
503
                val.f_float = config_GetFloat( p_intf, qtu( option ) );
504 505
                break;
            case VLC_VAR_STRING:
506
                val.psz_string = config_GetPsz( p_intf, qtu( option ) );
507 508 509 510 511
                break;
        }
    }
    else
    {
512
        i_type = var_Type( p_obj, qtu( option ) ) & VLC_VAR_CLASS;
513
        var_Get( p_obj, qtu( option ), &val );
514 515 516 517 518
        vlc_object_release( p_obj );
    }

    /* Try to cast to all the widgets we're likely to encounter. Only
     * one of the casts is expected to work. */
519 520 521 522
    QSlider        *slider        = qobject_cast<QSlider*>       ( widget );
    QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     ( widget );
    QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      ( widget );
    QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
523
    VLCQDial       *dial          = qobject_cast<VLCQDial*>      ( widget );
524 525
    QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     ( widget );
    QComboBox      *combobox      = qobject_cast<QComboBox*>     ( widget );
526 527 528 529 530 531 532

    if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
    {
        if( slider )        slider->setValue( val.i_int );
        else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
                                                              : Qt::Unchecked );
        else if( spinbox )  spinbox->setValue( val.i_int );
533
        else if( dial )     dial->setValue( (360 - val.i_int) % 360 );
534 535 536
        else if( lineedit )
        {
            char str[30];
Tristan Matthews's avatar
Tristan Matthews committed
537
            snprintf( str, sizeof(str), "%06" PRIX64, val.i_int );
538 539
            lineedit->setText( str );
        }
540
        else if( combobox ) combobox->setCurrentIndex(
541
                            combobox->findData( qlonglong(val.i_int) ) );
542
        else msg_Warn( p_intf, "Could not find the correct Integer widget" );
543 544 545
    }
    else if( i_type == VLC_VAR_FLOAT )
    {
546 547
        if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
        else if( doublespinbox ) doublespinbox->setValue( val.f_float );
548
        else if( dial ) dial->setValue( (360 - lroundf(val.f_float)) % 360 );
549
        else msg_Warn( p_intf, "Could not find the correct Float widget" );
550 551 552
    }
    else if( i_type == VLC_VAR_STRING )
    {
553
        if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
554
        else if( combobox ) combobox->setCurrentIndex(
555
                            combobox->findData( qfu( val.psz_string ) ) );
556
        else msg_Warn( p_intf, "Could not find the correct String widget" );
557 558 559
        free( val.psz_string );
    }
    else
560 561 562 563 564 565
        if( p_obj )
            msg_Err( p_intf,
                     "Module %s's %s variable is of an unsupported type ( %d )",
                     qtu( module ),
                     qtu( option ),
                     i_type );
566 567
}

568 569
void ExtVideo::setFilterOption( struct intf_thread_t *p_intf, const char *psz_module, const char *psz_option,
        int i_int, double f_float, QString val )
570
{
571
    vlc_object_t *p_obj = ( vlc_object_t * )vlc_object_find_name( p_intf->obj.libvlc, psz_module );
572 573
    int i_type;
    bool b_is_command;
574

575 576
    if( !p_obj )
    {
577 578
        msg_Warn( p_intf, "Module %s not found. You'll need to restart the filter to take the change into account.", psz_module );
        i_type = config_GetType( p_intf, psz_option );
579 580 581 582
        b_is_command = false;
    }
    else
    {
583
        i_type = var_Type( p_obj, psz_option );
584
        if( i_type == 0 )
585
            i_type = config_GetType( p_intf, psz_option );
586
        b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
587 588
    }

589
    i_type &= VLC_VAR_CLASS;
590 591
    if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
    {
592 593 594
        if( i_int == -1 )
            msg_Warn( p_intf, "Could not find the correct Integer widget" );
        config_PutInt( p_intf, psz_option, i_int );
595 596 597
        if( b_is_command )
        {
            if( i_type == VLC_VAR_INTEGER )
598
                var_SetInteger( p_obj, psz_option, i_int );
599
            else
600
                var_SetBool( p_obj, psz_option, i_int );
601
        }
602 603 604
    }
    else if( i_type == VLC_VAR_FLOAT )
    {
605 606 607
        if( f_float == -1 )
            msg_Warn( p_intf, "Could not find the correct Float widget" );
        config_PutFloat( p_intf, psz_option, f_float );
608
        if( b_is_command )
609
            var_SetFloat( p_obj, psz_option, f_float );
610 611 612
    }
    else if( i_type == VLC_VAR_STRING )
    {
613
        if( val.isNull() )
614
            msg_Warn( p_intf, "Could not find the correct String widget" );
615
        config_PutPsz( p_intf, psz_option, qtu( val ) );
616
        if( b_is_command )
617
            var_SetString( p_obj, psz_option, qtu( val ) );
618 619 620
    }
    else
        msg_Err( p_intf,
621
                 "Module %s's %s variable is of an unsupported type ( %d )",
622 623
                 psz_module,
                 psz_option,
624 625
                 i_type );

626 627 628
    if( !b_is_command )
    {
        msg_Warn( p_intf, "Module %s's %s variable isn't a command. Brute-restarting the filter.",
629 630 631 632
                 psz_module,
                 psz_option );
        ChangeVFiltersString( p_intf, psz_module, false );
        ChangeVFiltersString( p_intf, psz_module, true );
633 634
    }

635
    if( p_obj ) vlc_object_release( p_obj );
636 637
}

638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
void ExtVideo::updateFilterOptions()
{
    QString module = ModuleFromWidgetName( sender()->parent() );
    //msg_Dbg( p_intf, "Module name: %s", qtu( module ) );
    QString option = OptionFromWidgetName( sender() );
    //msg_Dbg( p_intf, "Option name: %s", qtu( option ) );

    /* Try to cast to all the widgets we're likely to encounter. Only
     * one of the casts is expected to work. */
    QSlider        *slider        = qobject_cast<QSlider*>       ( sender() );
    QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     ( sender() );
    QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      ( sender() );
    QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
    VLCQDial       *dial          = qobject_cast<VLCQDial*>      ( sender() );
    QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     ( sender() );
    QComboBox      *combobox      = qobject_cast<QComboBox*>     ( sender() );

    int i_int = -1;
    double f_float = -1.;
    QString val;

    if( slider ) {
        i_int = slider->value();
        f_float = ( double )slider->value() / ( double )slider->tickInterval(); /* hack alert! */
    }
    else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
    else if( spinbox ) i_int = spinbox->value();
    else if( doublespinbox ) f_float = doublespinbox->value();
    else if( dial ) {
667 668
        i_int = (360 - dial->value()) % 360;
        f_float = i_int;
669 670 671 672 673 674 675 676 677 678 679 680 681 682
    }
    else if( lineedit ) {
        i_int = lineedit->text().toInt( NULL,16 );
        f_float = lineedit->text().toDouble();
        val = lineedit->text();
    }
    else if( combobox ) {
        i_int = combobox->itemData( combobox->currentIndex() ).toInt();
        val = combobox->itemData( combobox->currentIndex() ).toString();
    }

    setFilterOption( p_intf, qtu( module ), qtu( option ), i_int, f_float, val);
}

683 684 685 686 687 688 689 690 691 692 693 694
int ExtVideo::getPostprocessing( struct intf_thread_t *p_intf)
{
    char *psz_config = config_GetPsz(p_intf, "video-filter");
    int i_q = -1;
    if (psz_config) {
        if (strstr(psz_config, "postproc"))
            i_q = config_GetInt(p_intf, "postproc-q");
        free(psz_config);
    }
    return i_q;
}

695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
void ExtVideo::setPostprocessing( struct intf_thread_t *p_intf, int q)
{
    const char *psz_name = "postproc";

    if( q == -1 )
    {
        ChangeVFiltersString( p_intf, psz_name, false );
    }
    else
    {
        ChangeVFiltersString( p_intf, psz_name, false );
        setFilterOption( p_intf, "postproc", "postproc-q", q, -1, QString() );
    }
}

710 711 712 713 714
/**********************************************************************
 * v4l2 controls
 **********************************************************************/

ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
715
    : QWidget( _parent ), p_intf( _p_intf ), box( NULL )
716
{
717 718 719 720 721 722
    QVBoxLayout *layout = new QVBoxLayout( this );
    help = new QLabel( qtr("No v4l2 instance found.\n"
      "Please check that the device has been opened with VLC and is playing.\n\n"
      "Controls will automatically appear here.")
      , this );
    help->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
723
    help->setWordWrap( true );
724 725
    layout->addWidget( help );
    setLayout( layout );
726 727
}

728 729 730 731 732 733
void ExtV4l2::showEvent( QShowEvent *event )
{
    QWidget::showEvent( event );
    Refresh();
}

734 735
void ExtV4l2::Refresh( void )
{
736
    vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( THEPL, "v4l2" );
737
    help->hide();
738 739
    if( box )
    {
740
        layout()->removeWidget( box );
741 742 743
        delete box;
        box = NULL;
    }
744 745
    if( p_obj )
    {
746
        vlc_value_t val, text;
747 748 749 750
        int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
                                &val, &text );
        if( i_ret < 0 )
        {
751
            msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
752
            help->show();
753 754 755
            vlc_object_release( p_obj );
            return;
        }
756 757

        box = new QGroupBox( this );
758
        layout()->addWidget( box );
759 760 761
        QVBoxLayout *layout = new QVBoxLayout( box );
        box->setLayout( layout );

762 763
        for( int i = 0; i < val.p_list->i_count; i++ )
        {
764
            vlc_value_t vartext;
765
            const char *psz_var = text.p_list->p_values[i].psz_string;
766 767 768 769 770 771

            if( var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &vartext, NULL ) )
                continue;

            QString name = qtr( vartext.psz_string );
            free( vartext.psz_string );
Tristan Matthews's avatar
Tristan Matthews committed
772
            msg_Dbg( p_intf, "v4l2 control \"%" PRIx64 "\": %s (%s)",
773
                     val.p_list->p_values[i].i_int, psz_var, qtu( name ) );
774 775 776 777 778 779

            int i_type = var_Type( p_obj, psz_var );
            switch( i_type & VLC_VAR_TYPE )
            {
                case VLC_VAR_INTEGER:
                {
780
                    QLabel *label = new QLabel( name, box );
781
                    QHBoxLayout *hlayout = new QHBoxLayout();
782 783 784 785
                    hlayout->addWidget( label );
                    int i_val = var_GetInteger( p_obj, psz_var );
                    if( i_type & VLC_VAR_HASCHOICE )
                    {
786
                        QComboBox *combobox = new QComboBox( box );
787
                        combobox->setObjectName( qfu( psz_var ) );
788 789 790 791 792 793 794 795

                        vlc_value_t val2, text2;
                        var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
                                    &val2, &text2 );
                        for( int j = 0; j < val2.p_list->i_count; j++ )
                        {
                            combobox->addItem(
                                       text2.p_list->p_values[j].psz_string,
796
                                       qlonglong( val2.p_list->p_values[j].i_int) );
797 798 799
                            if( i_val == val2.p_list->p_values[j].i_int )
                                combobox->setCurrentIndex( j );
                        }
800
                        var_FreeList( &val2, &text2 );
801 802 803 804 805 806

                        CONNECT( combobox, currentIndexChanged( int ), this,
                                 ValueChange( int ) );
                        hlayout->addWidget( combobox );
                    }
                    else
807
                    if( (i_type & VLC_VAR_HASMIN) && (i_type & VLC_VAR_HASMAX) )
808
                    {
809
                        QSlider *slider = new QSlider( box );
810
                        slider->setObjectName( qfu( psz_var ) );
811 812 813 814
                        slider->setOrientation( Qt::Horizontal );
                        vlc_value_t val2;
                        var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
                                    &val2, NULL );
815 816
                        if( val2.i_int < INT_MIN )
                            val2.i_int = INT_MIN; /* FIXME */
817 818 819
                        slider->setMinimum( val2.i_int );
                        var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
                                    &val2, NULL );
820 821
                        if( val2.i_int > INT_MAX )
                            val2.i_int = INT_MAX; /* FIXME */
822
                        slider->setMaximum( val2.i_int );
823 824 825
                        if( !var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
                                         &val2, NULL ) )
                            slider->setSingleStep( val2.i_int );
826 827 828 829 830
                        slider->setValue( i_val );
                        CONNECT( slider, valueChanged( int ), this,
                                 ValueChange( int ) );
                        hlayout->addWidget( slider );
                    }
831 832 833 834 835 836 837 838 839 840 841
                    else
                    {
                        QSpinBox *spinBox = new QSpinBox( box );
                        spinBox->setObjectName( qfu( psz_var ) );
                        spinBox->setMinimum( INT_MIN );
                        spinBox->setMaximum( INT_MAX );
                        spinBox->setValue( i_val );
                        CONNECT( spinBox, valueChanged( int ), this,
                                 ValueChange( int ) );
                        hlayout->addWidget( spinBox );
                    }
842 843 844 845 846
                    layout->addLayout( hlayout );
                    break;
                }
                case VLC_VAR_BOOL:
                {
847
                    QCheckBox *button = new QCheckBox( name, box );
848
                    button->setObjectName( qfu( psz_var ) );
849 850 851 852 853 854 855 856 857
                    button->setChecked( var_GetBool( p_obj, psz_var ) );

                    CONNECT( button, clicked( bool ), this,
                             ValueChange( bool ) );
                    layout->addWidget( button );
                    break;
                }
                case VLC_VAR_VOID:
                {
858 859
                    if( i_type & VLC_VAR_ISCOMMAND )
                    {
860
                        QPushButton *button = new QPushButton( name, box );
861
                        button->setObjectName( qfu( psz_var ) );
862

863 864 865 866 867 868
                        CONNECT( button, clicked( bool ), this,
                                 ValueChange( bool ) );
                        layout->addWidget( button );
                    }
                    else
                    {
869
                        QLabel *label = new QLabel( name, box );
870 871
                        layout->addWidget( label );
                    }
872 873 874 875 876 877 878
                    break;
                }
                default:
                    msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
                    break;
            }
        }
879
        var_FreeList( &val, &text );
880 881 882 883 884
        vlc_object_release( p_obj );
    }
    else
    {
        msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
885 886 887
        help->show();
        if ( isVisible() )
            QTimer::singleShot( 2000, this, SLOT(Refresh()) );
888 889 890 891 892 893 894 895 896 897 898
    }
}

void ExtV4l2::ValueChange( bool value )
{
    ValueChange( (int)value );
}

void ExtV4l2::ValueChange( int value )
{
    QObject *s = sender();
899
    vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( THEPL, "v4l2" );
900 901
    if( p_obj )
    {
902 903
        QString var = s->objectName();
        int i_type = var_Type( p_obj, qtu( var ) );
904 905 906 907 908 909 910 911
        switch( i_type & VLC_VAR_TYPE )
        {
            case VLC_VAR_INTEGER:
                if( i_type & VLC_VAR_HASCHOICE )
                {
                    QComboBox *combobox = qobject_cast<QComboBox*>( s );
                    value = combobox->itemData( value ).toInt();
                }
912
                var_SetInteger( p_obj, qtu( var ), value );
913 914
                break;
            case VLC_VAR_BOOL:
915
                var_SetBool( p_obj, qtu( var ), value );
916 917
                break;
            case VLC_VAR_VOID:
918
                var_TriggerCallback( p_obj, qtu( var ) );
919 920 921 922 923 924 925 926 927 928 929
                break;
        }
        vlc_object_release( p_obj );
    }
    else
    {
        msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
        Refresh();
    }
}

930 931 932 933
/**********************************************************************
 * Sliders
 **********************************************************************/

934 935
FilterSliderData::FilterSliderData( QObject *parent, QSlider *_slider ) :
    QObject( parent ), slider( _slider )
936 937 938
{
    b_save_to_config = false;
}
939

940 941 942 943 944
FilterSliderData::FilterSliderData( QObject *parent,
                                    intf_thread_t *_p_intf,
                                    QSlider *_slider,
                                    QLabel *_label, QLabel *_nameLabel,
                                    const slider_data_t *_p_data ):
945 946
    QObject( parent ), slider( _slider ), valueLabel( _label ),
    nameLabel( _nameLabel ), p_data( _p_data ), p_intf( _p_intf )
947
{
948
    b_save_to_config = false;
949 950
    slider->setMinimum( p_data->f_min / p_data->f_resolution );
    slider->setMaximum( p_data->f_max / p_data->f_resolution );
951
    nameLabel->setText( p_data->descs );
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967
    CONNECT( slider, valueChanged( int ), this, updateText( int ) );
    setValue( initialValue() );
    /* In case current == min|max text would not be first updated */
    if ( slider->value() == slider->maximum() ||
         slider->value() == slider->minimum() )
        updateText( slider->value() );
    CONNECT( slider, valueChanged( int ), this, onValueChanged( int ) );
}

void FilterSliderData::setValue( float f )
{
    slider->setValue( f / p_data->f_resolution );
}

void FilterSliderData::updateText( int i )
{
968
    float f = ((float) i) * p_data->f_resolution * p_data->f_visual_multiplier;
969
    valueLabel->setText( QString( p_data->units )
970
                    .prepend( "%1 " )
971 972 973 974 975 976 977 978 979
                    .arg( QString::number( f, 'f', 1 ) ) );
}

float FilterSliderData::initialValue()
{
    vlc_object_t *p_aout = (vlc_object_t *) THEMIM->getAout();
    float f = p_data->f_value;
    if( p_aout )
    {
980
        if ( var_Type( p_aout, qtu(p_data->name) ) == 0 )
981 982 983 984 985 986
        {
            vlc_object_release( p_aout );
            /* Not found, will try in config */
        }
        else
        {
987
            f = var_GetFloat( p_aout, qtu(p_data->name) );
988 989 990 991 992
            vlc_object_release( p_aout );
            return f;
        }
    }

993
    if ( ! config_FindConfig( VLC_OBJECT(p_intf), qtu(p_data->name) ) )
994 995
        return f;

996
    f = config_GetFloat( p_intf, qtu(p_data->name) );
997 998 999
    return f;
}

1000
void FilterSliderData::onValueChanged( int i ) const
1001 1002 1003 1004 1005
{
    float f = ((float) i) * p_data->f_resolution;
    vlc_object_t *p_aout = (vlc_object_t *) THEMIM->getAout();
    if ( p_aout )
    {
1006
        var_SetFloat( p_aout, qtu(p_data->name), f );
1007 1008 1009 1010 1011
        vlc_object_release( p_aout );
    }
    writeToConfig();
}

1012
void FilterSliderData::writeToConfig() const
1013
{
1014
    if ( !b_save_to_config ) return;
1015
    float f = ((float) slider->value()) * p_data->f_resolution;
1016 1017 1018
    config_PutFloat( p_intf, qtu(p_data->name), f );
}

1019 1020 1021 1022 1023
void FilterSliderData::setSaveToConfig( bool b )
{
    b_save_to_config = b;
}

1024 1025
AudioFilterControlWidget::AudioFilterControlWidget
( intf_thread_t *_p_intf, QWidget *parent, const char *_name ) :
1026
    QWidget( parent ), p_intf( _p_intf ), name( _name ), i_smallfont(0)
1027 1028 1029 1030 1031
{}

void AudioFilterControlWidget::build()
{
    QFont smallFont = QApplication::font();
1032
    smallFont.setPointSize( smallFont.pointSize() + i_smallfont );
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057

    QVBoxLayout *layout = new QVBoxLayout( this );
    slidersBox = new QGroupBox( qtr( "Enable" ) );
    slidersBox->setCheckable( true );
    layout->addWidget( slidersBox );

    QGridLayout *ctrlLayout = new QGridLayout( slidersBox );

    int i = 0;
    foreach( const FilterSliderData::slider_data_t &data, controls )
    {
        QSlider *slider = new QSlider( Qt::Vertical );
        QLabel *valueLabel = new QLabel();
        valueLabel->setFont( smallFont );
        valueLabel->setAlignment( Qt::AlignHCenter );
        QLabel *nameLabel = new QLabel();
        nameLabel->setFont( smallFont );
        nameLabel->setAlignment( Qt::AlignHCenter );
        FilterSliderData *filter =
            new FilterSliderData( this, p_intf,
                                  slider, valueLabel, nameLabel, & data );
        ctrlLayout->addWidget( slider, 0, i, Qt::AlignHCenter );
        ctrlLayout->addWidget( valueLabel, 1, i, Qt::AlignHCenter );
        ctrlLayout->addWidget( nameLabel, 2, i, Qt::AlignHCenter );
        i++;
1058
        sliderDatas << filter;
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
    }

    vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
    char *psz_af;
    if( p_aout )
    {
        psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
        vlc_object_release( p_aout );
    }
    else
        psz_af = config_GetPsz( p_intf, "audio-filter" );

    if( psz_af && strstr( psz_af, qtu(name) ) != NULL )
        slidersBox->setChecked( true );
    else
        slidersBox->setChecked( false );
1075
    CONNECT( slidersBox, toggled(bool), this, enable(bool) );
1076 1077 1078 1079 1080 1081 1082 1083 1084

    free( psz_af );
}

AudioFilterControlWidget::~AudioFilterControlWidget()
{

}

1085
void AudioFilterControlWidget::enable( bool b_enable ) const
1086
{
1087
    ChangeAFiltersString( p_intf, qtu(name), b_enable );
1088
    playlist_EnableAudioFilter( THEPL, qtu(name), b_enable );
1089 1090
}

1091 1092 1093 1094 1095 1096
void AudioFilterControlWidget::setSaveToConfig( bool b_save )
{
    foreach( FilterSliderData *f, sliderDatas )
        f->setSaveToConfig( b_save );
}

Clément Stenac's avatar
Clément Stenac committed
1097 1098 1099 1100
/**********************************************************************
 * Equalizer
 **********************************************************************/

1101 1102 1103 1104 1105
EqualizerSliderData::EqualizerSliderData( QObject *parent, intf_thread_t *_p_intf,
                                          QSlider *slider, QLabel *_label,
                                          QLabel *_nameLabel, const slider_data_t *_p_data,
                                          int _index )
    : FilterSliderData( parent, slider ), index( _index )
Clément Stenac's avatar
Clément Stenac committed
1106
{
1107 1108 1109 1110
    p_intf = _p_intf;
    valueLabel = _label;
    nameLabel = _nameLabel;
    p_data = _p_data;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
1111

1112 1113 1114 1115 1116 1117 1118
    slider->setMinimum( p_data->f_min / p_data->f_resolution );
    slider->setMaximum( p_data->f_max / p_data->f_resolution );
    nameLabel->setText( p_data->descs );
    CONNECT( slider, valueChanged( int ), this, updateText( int ) );
    setValue( initialValue() );
    updateText( slider->value() );
    CONNECT( slider, valueChanged( int ), this, onValueChanged( int ) );
1119 1120
}

1121
QStringList EqualizerSliderData::getBandsFromAout() const
1122
{
1123 1124
    vlc_object_t *p_aout = (vlc_object_t *) THEMIM->getAout();
    QStringList bands;
1125 1126
    if( p_aout )
    {
1127
        if ( var_Type( p_aout, qtu(p_data->name) ) == VLC_VAR_STRING )
1128
        {
1129 1130 1131 1132 1133 1134
            char *psz_bands = var_GetString( p_aout, qtu(p_data->name) );
            if ( psz_bands )
            {
                bands = QString( psz_bands ).split( " ", QString::SkipEmptyParts );
                free( psz_bands );
            }
1135
        }
1136
        vlc_object_release( p_aout );
1137
    }
Clément Stenac's avatar
Clément Stenac committed
1138

1139 1140
    if ( bands.count() ) return bands;
    /* Or try config then */
1141

1142 1143
    if ( ! config_FindConfig( VLC_OBJECT(p_intf), qtu(p_data->name) ) )
        return bands;
1144

1145 1146
    char *psz_bands = config_GetPsz( p_intf, qtu(p_data->name) );
    if ( psz_bands )
1147
    {
1148 1149
        bands = QString( psz_bands ).split( " ", QString::SkipEmptyParts );
        free( psz_bands );
1150
    }
1151 1152

    return bands;
1153 1154
}

1155
float EqualizerSliderData::initialValue()
Clément Stenac's avatar
Clément Stenac committed
1156
{
1157 1158
    float f = p_data->f_value;
    QStringList bands = getBandsFromAout();
1159

1160 1161
    if ( bands.count() > index )
        f = QLocale( QLocale::C ).toFloat( bands[ index ] );
1162

1163
    return f;
1164
}
Clément Stenac's avatar
Clément Stenac committed
1165

1166
void EqualizerSliderData::onValueChanged( int i ) const
1167
{
1168 1169
    QStringList bands = getBandsFromAout();
    if ( bands.count() > index )
Clément Stenac's avatar
Clément Stenac committed
1170
    {
1171 1172 1173 1174 1175 1176 1177 1178 1179
        float f = ((float) i) * p_data->f_resolution;
        bands[ index ] = QLocale( QLocale::C ).toString( f );
        vlc_object_t *p_aout = (vlc_object_t *) THEMIM->getAout();
        if ( p_aout )
        {
            var_SetString( p_aout, qtu(p_data->name), qtu(bands.join( " " )) );
            vlc_object_release( p_aout );
        }
        writeToConfig();
Clément Stenac's avatar
Clément Stenac committed
1180 1181 1182
    }
}

1183
void EqualizerSliderData::writeToConfig() const
Clément Stenac's avatar
Clément Stenac committed
1184
{
1185
    if ( !b_save_to_config ) return;
1186 1187
    QStringList bands = getBandsFromAout();
    if ( bands.count() > index )
Clément Stenac's avatar
Clément Stenac committed
1188
    {
1189 1190 1191
        float f = (float) slider->value() * p_data->f_resolution;
        bands[ index ] = QLocale( QLocale::C ).toString( f );
        config_PutPsz( p_intf, qtu(p_data->name), qtu(bands.join( " " )) );
Clément Stenac's avatar
Clément Stenac committed
1192 1193 1194
    }
}

1195 1196
Equalizer::Equalizer( intf_thread_t *p_intf, QWidget *parent )
    : AudioFilterControlWidget( p_intf, parent, "equalizer" )
Clément Stenac's avatar
Clément Stenac committed
1197
{
1198 1199
    i_smallfont = -3;
    bool b_vlcBands = var_InheritBool( p_intf, "equalizer-vlcfreqs" );
Clément Stenac's avatar
Clément Stenac committed
1200

1201
    const FilterSliderData::slider_data_t vlc_bands[10] =
Clément Stenac's avatar
Clément Stenac committed
1202
    {
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232
        { "equalizer-bands", qtr("60 Hz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
        { "equalizer-bands", qtr("170 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
        { "equalizer-bands", qtr("310 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
        { "equalizer-bands", qtr("600 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
        { "equalizer-bands", qtr("1 KHz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
        { "equalizer-bands", qtr("3 KHz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
        { "equalizer-bands", qtr("6 KHz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
        { "equalizer-bands", qtr("12 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
        { "equalizer-bands", qtr("14 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
        { "equalizer-bands", qtr("16 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
    };
    const FilterSliderData::slider_data_t iso_bands[10] =
    {
        { "equalizer-bands", qtr("31 Hz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
        { "equalizer-bands", qtr("63 Hz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
        { "equalizer-bands", qtr("125 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
        { "equalizer-bands", qtr("250 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
        { "equalizer-bands", qtr("500 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
        { "equalizer-bands", qtr("1 KHz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
        { "equalizer-bands", qtr("2 KHz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
        { "equalizer-bands", qtr("4 KHz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
        { "equalizer-bands", qtr("8 KHz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
        { "equalizer-bands", qtr("16 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
    };
    const FilterSliderData::slider_data_t preamp_vals =
        { "equalizer-preamp", qtr("Preamp"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 };

    for( int i=0; i<10 ;i++ ) controls.append( (b_vlcBands) ? vlc_bands[i] : iso_bands[i] );
    preamp_values = preamp_vals;
    build();
Clément Stenac's avatar
Clément Stenac committed
1233 1234
}

1235
void Equalizer::build()
Clément Stenac's avatar
Clément Stenac committed
1236
{
1237 1238 1239 1240 1241
    QFont smallFont = QApplication::font();
    smallFont.setPointSize( smallFont.pointSize() + i_smallfont );

    Ui::EqualizerWidget ui;
    ui.setupUi( this );
Clément Stenac's avatar
Clément Stenac committed
1242

1243
    QGridLayout *ctrlLayout = new QGridLayout( ui.slidersPlaceholder );
1244

1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
    /* set up preamp control */
    ui.preampLabel->setFont( smallFont );
    ui.preampValue->setFont( smallFont );
    preamp = new FilterSliderData( this, p_intf,
        ui.preampSlider, ui.preampValue, ui.preampLabel, & preamp_values );

    /* fix sliders spacing accurately */
    int i_width = qMax( QFontMetrics( smallFont ).width( "500 Hz" ),
                        QFontMetrics( smallFont ).width( "-20.0 dB" ) );
    int