summaryrefslogtreecommitdiffstats
path: root/src/replaygain.cpp
blob: 2f897dca86a8a652b51090b755bfc02be0103267 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

#include "replaygain.h"
#include "config.h"
#include "logger.h"
#include "replaygainpluginloader.h"

#include <tqfile.h>

#include <kprocess.h>
#include <klocale.h>
#include <kurl.h>

ReplayGain::ReplayGain( Config* _config, Logger* _logger )
{
    config = _config;
    logger = _logger;
}

ReplayGain::~ReplayGain()
{}

bool ReplayGain::apply( TQStringList files, const TQString& format, TDEProcess* proc, int logID, Mode mode )
{
    TQStringList params;
    TQString param, paramSplinter;

    proc->clearArguments();

    ReplayGainPlugin* plugin = config->replaygainForFormat( format );
    if( plugin == 0 ) { // shouldn't happen
        logger->log( logID, " NULL POINTER: ReplayGain::replaygain( ... ) / plugin" );
        return false;
    }

    param = TQString();
    if( plugin->replaygain.param ) param.append( " " + plugin->replaygain.param );
    if( mode & remove ) {
        if( plugin->replaygain.remove ) param.append( " " + plugin->replaygain.remove );
    }
    else {
        if( (mode & calc_track) && plugin->replaygain.track ) param.append( " " + plugin->replaygain.track );
        if( (mode & calc_album) && plugin->replaygain.album ) param.append( " " + plugin->replaygain.album );
        if( mode & force ) {
            if( plugin->replaygain.force ) param.append( " " + plugin->replaygain.force );
        }
        else {
            if( plugin->replaygain.skip ) param.append( " " + plugin->replaygain.skip );
        }
    }

//     if( plugin->replaygain.in_files.find("%p") != -1 ) {
//         TQString t_str = plugin->replaygain.in_files;
//         t_str.replace( "%p", param );
//         param = plugin->replaygain.bin + " " + t_str;
//     }
//     else {
//         param = plugin->replaygain.bin + param + " " + plugin->replaygain.in_files;
//     }

    TQString t_str = plugin->replaygain.in_files;
    t_str.replace( "%p", param );
    param = config->binaries[plugin->replaygain.bin] + " " + t_str;

    // cosmetic surgery
    param.simplifyWhiteSpace();

    params = TQStringList::split( ' ', param );

    for( TQStringList::Iterator it = params.begin(); it != params.end(); ++it )
    {
        paramSplinter = *it;
        if( paramSplinter == "%i" ) {
            for( TQStringList::Iterator b = files.begin(); b != files.end(); ++b ) {
                *(proc) << KURL::decode_string( *b );
            }
        }
        else {
            *(proc) << paramSplinter;
        }
    }

    for( TQStringList::Iterator it = files.begin(); it != files.end(); ++it )
    {
        *it = KURL::decode_string( *it );
    }

    param.replace( "%i", "\""+files.join("\" \"")+"\"" );
    logger->log( logID, " " + i18n("Executing") + ": `" + param + "'" );

    proc->setPriority( config->data.general.priority );
    proc->start( TDEProcess::NotifyOnExit, TDEProcess::AllOutput );

    return true;
}

//TQValueList<float> ReplayGain::getReplayGain( TQString file ) {} // obsolete