1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id: encoders.cpp 15212 2007-10-19 21:49:07Z domonoky $
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
21 #include "browsedirtree.h"
24 #include "encodersgui.h"
27 static QMap
<QString
,QString
> encoderList
;
28 static QMap
<QString
,EncBase
*> encoderCache
;
30 void initEncoderList()
32 encoderList
["rbspeex"] = "Rockbox Speex Encoder";
33 encoderList
["lame"] = "Lame Mp3 Encoder";
36 // function to get a specific encoder
37 EncBase
* getEncoder(QString encname
)
39 // init list if its empty
40 if(encoderList
.count() == 0) initEncoderList();
42 QString encoder
= encoderList
.key(encname
);
45 if(encoderCache
.contains(encoder
))
46 return encoderCache
.value(encoder
);
49 if(encoder
== "rbspeex")
51 enc
= new EncRbSpeex();
52 encoderCache
[encoder
] = enc
;
55 else if(encoder
== "lame")
57 enc
= new EncExes(encoder
);
58 encoderCache
[encoder
] = enc
;
65 // get the list of encoders, nice names
66 QStringList
getEncoderList()
68 // init list if its empty
69 if(encoderList
.count() == 0) initEncoderList();
72 QMapIterator
<QString
, QString
> i(encoderList
);
82 /*********************************************************************
84 **********************************************************************/
85 EncBase::EncBase(QWidget
*parent
): QDialog(parent
)
90 /*********************************************************************
92 **********************************************************************/
93 EncExes::EncExes(QString name
,QWidget
*parent
) : EncBase(parent
)
97 m_TemplateMap
["lame"] = "\"%exe\" %options \"%input\" \"%output\"";
100 bool EncExes::start()
102 m_EncExec
= settings
->encoderPath(m_name
);
103 m_EncOpts
= settings
->encoderOptions(m_name
);
105 m_EncTemplate
= m_TemplateMap
.value(m_name
);
107 QFileInfo
enc(m_EncExec
);
118 bool EncExes::encode(QString input
,QString output
)
120 //qDebug() << "encoding..";
121 QString execstring
= m_EncTemplate
;
123 execstring
.replace("%exe",m_EncExec
);
124 execstring
.replace("%options",m_EncOpts
);
125 execstring
.replace("%input",input
);
126 execstring
.replace("%output",output
);
127 qDebug() << execstring
;
128 QProcess::execute(execstring
);
134 void EncExes::showCfg()
137 gui
.setCfg(settings
);
141 bool EncExes::configOk()
143 QString path
= settings
->encoderPath(m_name
);
145 if (QFileInfo(path
).exists())
153 /*********************************************************************
155 **********************************************************************/
156 EncRbSpeex::EncRbSpeex(QWidget
*parent
) : EncBase(parent
)
159 defaultQuality
= 8.f
;
161 defaultComplexity
= 10;
166 bool EncRbSpeex::start()
169 // try to get config from settings
170 quality
= settings
->encoderQuality("rbspeex");
171 complexity
= settings
->encoderComplexity("rbspeex");
172 volume
= settings
->encoderVolume("rbspeex");
173 narrowband
= settings
->encoderNarrowband("rbspeex");
179 bool EncRbSpeex::encode(QString input
,QString output
)
181 //qDebug() << "encoding
185 if ((fin
= fopen(input
.toUtf8(), "rb")) == NULL
) {
186 qDebug() << "Error: could not open input file\n";
189 if ((fout
= fopen(output
.toUtf8(), "wb")) == NULL
) {
190 qDebug() << "Error: could not open output file\n";
195 int ret
= encode_file(fin
, fout
, quality
, complexity
, narrowband
, volume
,
196 errstr
, sizeof(errstr
));
201 /* Attempt to delete unfinished output */
202 qDebug() << "Error:" << errstr
;
203 QFile(output
).remove();
210 void EncRbSpeex::showCfg()
213 gui
.setCfg(settings
);
214 gui
.showCfg(defaultQuality
,defaultVolume
,defaultComplexity
,defaultBand
);
217 bool EncRbSpeex::configOk()
222 if(settings
->encoderVolume("rbspeex") <= 0)
225 if(settings
->encoderQuality("rbspeex") <= 0)
228 if(settings
->encoderComplexity("rbspeex") <= 0)