1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Wenger
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 ****************************************************************************/
22 #include "rbsettings.h"
24 /*********************************************************************
26 **********************************************************************/
27 QMap
<QString
,QString
> EncBase::encoderList
;
29 EncBase::EncBase(QObject
*parent
): EncTtsSettingInterface(parent
)
34 // initialize list of encoders
35 void EncBase::initEncodernamesList()
37 encoderList
["rbspeex"] = "Rockbox Speex Encoder";
38 encoderList
["lame"] = "Lame Mp3 Encoder";
42 // get nice name for a specific encoder
43 QString
EncBase::getEncoderName(QString encoder
)
45 if(encoderList
.isEmpty())
46 initEncodernamesList();
47 return encoderList
.value(encoder
);
51 // get a specific encoder object
52 EncBase
* EncBase::getEncoder(QObject
* parent
,QString encoder
)
57 enc
= new EncExes(encoder
,parent
);
60 else // rbspeex is default
62 enc
= new EncRbSpeex(parent
);
68 QStringList
EncBase::getEncoderList()
70 if(encoderList
.isEmpty())
71 initEncodernamesList();
72 return encoderList
.keys();
76 /*********************************************************************
78 **********************************************************************/
79 EncExes::EncExes(QString name
,QObject
*parent
) : EncBase(parent
)
83 m_TemplateMap
["lame"] = "\"%exe\" %options \"%input\" \"%output\"";
89 void EncExes::generateSettings()
91 QString exepath
=RbSettings::subValue(m_name
,RbSettings::EncoderPath
).toString();
92 if(exepath
== "") exepath
= Utils::findExecutable(m_name
);
94 insertSetting(eEXEPATH
,new EncTtsSetting(this,EncTtsSetting::eSTRING
,
95 tr("Path to Encoder:"),exepath
,EncTtsSetting::eBROWSEBTN
));
96 insertSetting(eEXEOPTIONS
,new EncTtsSetting(this,EncTtsSetting::eSTRING
,
97 tr("Encoder options:"),RbSettings::subValue(m_name
,RbSettings::EncoderOptions
)));
100 void EncExes::saveSettings()
102 RbSettings::setSubValue(m_name
,RbSettings::EncoderPath
,getSetting(eEXEPATH
)->current().toString());
103 RbSettings::setSubValue(m_name
,RbSettings::EncoderOptions
,getSetting(eEXEOPTIONS
)->current().toString());
107 bool EncExes::start()
109 m_EncExec
= RbSettings::subValue(m_name
, RbSettings::EncoderPath
).toString();
110 m_EncOpts
= RbSettings::subValue(m_name
, RbSettings::EncoderOptions
).toString();
112 m_EncTemplate
= m_TemplateMap
.value(m_name
);
114 QFileInfo
enc(m_EncExec
);
125 bool EncExes::encode(QString input
,QString output
)
127 //qDebug() << "encoding..";
128 QString execstring
= m_EncTemplate
;
130 execstring
.replace("%exe",m_EncExec
);
131 execstring
.replace("%options",m_EncOpts
);
132 execstring
.replace("%input",input
);
133 execstring
.replace("%output",output
);
134 qDebug() << "[EncExes] cmd: " << execstring
;
135 int result
= QProcess::execute(execstring
);
136 return (result
== 0) ? true : false;
140 bool EncExes::configOk()
142 QString path
= RbSettings::subValue(m_name
, RbSettings::EncoderPath
).toString();
144 if (QFileInfo(path
).exists())
150 /*********************************************************************
152 **********************************************************************/
153 EncRbSpeex::EncRbSpeex(QObject
*parent
) : EncBase(parent
)
158 void EncRbSpeex::generateSettings()
160 insertSetting(eVOLUME
,new EncTtsSetting(this,EncTtsSetting::eDOUBLE
,
161 tr("Volume:"),RbSettings::subValue("rbspeex",RbSettings::EncoderVolume
),1.0,10.0));
162 insertSetting(eQUALITY
,new EncTtsSetting(this,EncTtsSetting::eDOUBLE
,
163 tr("Quality:"),RbSettings::subValue("rbspeex",RbSettings::EncoderQuality
),0,10.0));
164 insertSetting(eCOMPLEXITY
,new EncTtsSetting(this,EncTtsSetting::eINT
,
165 tr("Complexity:"),RbSettings::subValue("rbspeex",RbSettings::EncoderComplexity
),0,10));
166 insertSetting(eNARROWBAND
,new EncTtsSetting(this,EncTtsSetting::eBOOL
,
167 tr("Use Narrowband:"),RbSettings::subValue("rbspeex",RbSettings::EncoderNarrowBand
)));
170 void EncRbSpeex::saveSettings()
172 //save settings in user config
173 RbSettings::setSubValue("rbspeex",RbSettings::EncoderVolume
,
174 getSetting(eVOLUME
)->current().toDouble());
175 RbSettings::setSubValue("rbspeex",RbSettings::EncoderQuality
,
176 getSetting(eQUALITY
)->current().toDouble());
177 RbSettings::setSubValue("rbspeex",RbSettings::EncoderComplexity
,
178 getSetting(eCOMPLEXITY
)->current().toInt());
179 RbSettings::setSubValue("rbspeex",RbSettings::EncoderNarrowBand
,
180 getSetting(eNARROWBAND
)->current().toBool());
185 bool EncRbSpeex::start()
188 // try to get config from settings
189 quality
= RbSettings::subValue("rbspeex", RbSettings::EncoderQuality
).toDouble();
190 complexity
= RbSettings::subValue("rbspeex", RbSettings::EncoderComplexity
).toInt();
191 volume
= RbSettings::subValue("rbspeex", RbSettings::EncoderVolume
).toDouble();
192 narrowband
= RbSettings::subValue("rbspeex", RbSettings::EncoderNarrowBand
).toBool();
198 bool EncRbSpeex::encode(QString input
,QString output
)
200 qDebug() << "[RbSpeex] Encoding " << input
<< " to "<< output
;
204 if ((fin
= fopen(input
.toLocal8Bit(), "rb")) == NULL
) {
205 qDebug() << "[RbSpeex] Error: could not open input file\n";
208 if ((fout
= fopen(output
.toLocal8Bit(), "wb")) == NULL
) {
209 qDebug() << "[RbSpeex] Error: could not open output file\n";
214 int ret
= encode_file(fin
, fout
, quality
, complexity
, narrowband
, volume
,
215 errstr
, sizeof(errstr
));
220 /* Attempt to delete unfinished output */
221 qDebug() << "[RbSpeex] Error:" << errstr
;
222 QFile(output
).remove();
228 bool EncRbSpeex::configOk()
233 if(RbSettings::subValue("rbspeex", RbSettings::EncoderVolume
).toDouble() <= 0)
236 if(RbSettings::subValue("rbspeex", RbSettings::EncoderQuality
).toDouble() <= 0)
239 if(RbSettings::subValue("rbspeex", RbSettings::EncoderComplexity
).toInt() <= 0)