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
;
31 // initialize list of encoders
32 void initEncodernamesList()
34 encoderList
["rbspeex"] = "Rockbox Speex Encoder";
35 encoderList
["lame"] = "Lame Mp3 Encoder";
39 // get nice name for a specific encoder
40 QString
getEncoderName(QString encoder
)
42 if(encoderList
.isEmpty())
43 initEncodernamesList();
44 return encoderList
.value(encoder
);
48 // get a specific encoder object
49 EncBase
* getEncoder(QString encoder
)
52 if(encoderCache
.contains(encoder
))
53 return encoderCache
.value(encoder
);
56 if(encoder
== "rbspeex")
58 enc
= new EncRbSpeex();
59 encoderCache
[encoder
] = enc
;
62 else if(encoder
== "lame")
64 enc
= new EncExes(encoder
);
65 encoderCache
[encoder
] = enc
;
73 QStringList
getEncoderList()
75 if(encoderList
.isEmpty())
76 initEncodernamesList();
77 return encoderList
.keys();
81 /*********************************************************************
83 **********************************************************************/
84 EncBase::EncBase(QWidget
*parent
): QDialog(parent
)
89 /*********************************************************************
91 **********************************************************************/
92 EncExes::EncExes(QString name
,QWidget
*parent
) : EncBase(parent
)
96 m_TemplateMap
["lame"] = "\"%exe\" %options \"%input\" \"%output\"";
101 m_EncExec
= settings
->encoderPath(m_name
);
102 m_EncOpts
= settings
->encoderOptions(m_name
);
104 m_EncTemplate
= m_TemplateMap
.value(m_name
);
106 QFileInfo
enc(m_EncExec
);
117 bool EncExes::encode(QString input
,QString output
)
119 //qDebug() << "encoding..";
120 QString execstring
= m_EncTemplate
;
122 execstring
.replace("%exe",m_EncExec
);
123 execstring
.replace("%options",m_EncOpts
);
124 execstring
.replace("%input",input
);
125 execstring
.replace("%output",output
);
126 qDebug() << execstring
;
127 QProcess::execute(execstring
);
133 void EncExes::showCfg()
136 gui
.setCfg(settings
);
140 bool EncExes::configOk()
142 QString path
= settings
->encoderPath(m_name
);
144 if (QFileInfo(path
).exists())
152 /*********************************************************************
154 **********************************************************************/
155 EncRbSpeex::EncRbSpeex(QWidget
*parent
) : EncBase(parent
)
158 defaultQuality
= 8.f
;
160 defaultComplexity
= 10;
165 bool EncRbSpeex::start()
168 // try to get config from settings
169 quality
= settings
->encoderQuality("rbspeex");
170 complexity
= settings
->encoderComplexity("rbspeex");
171 volume
= settings
->encoderVolume("rbspeex");
172 narrowband
= settings
->encoderNarrowband("rbspeex");
178 bool EncRbSpeex::encode(QString input
,QString output
)
180 //qDebug() << "encoding
184 if ((fin
= fopen(input
.toUtf8(), "rb")) == NULL
) {
185 qDebug() << "Error: could not open input file\n";
188 if ((fout
= fopen(output
.toUtf8(), "wb")) == NULL
) {
189 qDebug() << "Error: could not open output file\n";
194 int ret
= encode_file(fin
, fout
, quality
, complexity
, narrowband
, volume
,
195 errstr
, sizeof(errstr
));
200 /* Attempt to delete unfinished output */
201 qDebug() << "Error:" << errstr
;
202 QFile(output
).remove();
209 void EncRbSpeex::showCfg()
212 gui
.setCfg(settings
);
213 gui
.showCfg(defaultQuality
,defaultVolume
,defaultComplexity
,defaultBand
);
216 bool EncRbSpeex::configOk()
221 if(settings
->encoderVolume("rbspeex") <= 0)
224 if(settings
->encoderQuality("rbspeex") <= 0)
227 if(settings
->encoderComplexity("rbspeex") <= 0)