66
71
QWidget* EncoderLame::getConfigureWidget(KConfigSkeleton** manager) const {
67
(*manager) = Settings::self();
68
KGlobal::locale()->insertCatalogue("audiocd_encoder_lame");
69
EncoderLameConfig *config = new EncoderLameConfig();
70
config->cbr_settings->hide();
72
(*manager) = Settings::self();
73
KGlobal::locale()->insertCatalogue("audiocd_encoder_lame");
74
EncoderLameConfig *config = new EncoderLameConfig();
75
config->cbr_settings->hide();
74
79
bool EncoderLame::init(){
75
80
// Determine if lame is installed on the system or not.
77
proc << "which" << "lame";
78
proc.start(KProcess::Block);
79
if(proc.exitStatus() == 0)
81
if ( KStandardDirs::findExe( "lame" ).isEmpty() )
84
// Ask lame for the list of genres it knows; otherwise it barfs when doing
85
// e.g. lame --tg 'Vocal Jazz'
86
CollectingProcess proc;
87
proc << "lame" << "--genre-list";
88
proc.start(KProcess::Block, KProcess::Stdout);
90
if(proc.exitStatus() != 0)
93
const QByteArray data = proc.collectedStdout();
95
if ( !data.isEmpty() )
96
str = QString::fromLocal8Bit( data, data.size() );
98
d->genreList = QStringList::split( '\n', str );
99
// Remove the numbers in front of every genre
100
for( QStringList::Iterator it = d->genreList.begin(); it != d->genreList.end(); ++it ) {
101
QString& genre = *it;
103
while ( i < genre.length() && ( genre[i].isSpace() || genre[i].isDigit() ) )
105
genre = genre.mid( i );
108
//kdDebug(7117) << "Available genres:" << d->genreList << endl;
84
113
void EncoderLame::loadSettings(){
85
114
// Generate the command line arguments for the current settings
88
117
Settings *settings = Settings::self();
90
119
int quality = settings->quality();
182
211
long EncoderLame::readInit(long /*size*/){
183
212
// Create KProcess
184
d->currentEncodeProcess = new KProcess(0,"encodeprocess");
213
d->currentEncodeProcess = new KProcess(0);
185
214
QString prefix = locateLocal("tmp", "");
186
215
d->tempFile = new KTempFile(prefix, ".mp3");
187
216
d->tempFile->setAutoDelete(true);
217
d->lastErrorMessage = QString::null;
218
d->processHasExited = false;
198
229
// Read in stdin, output to the temp file
199
230
*d->currentEncodeProcess << "-" << d->tempFile->name().latin1();
232
//kdDebug(7117) << d->currentEncodeProcess->args() << endl;
202
235
connect(d->currentEncodeProcess, SIGNAL(receivedStdout(KProcess *, char *, int)),
203
this, SLOT(receivedStdout(KProcess *, char *, int)));
236
this, SLOT(receivedStdout(KProcess *, char *, int)));
204
237
connect(d->currentEncodeProcess, SIGNAL(receivedStderr(KProcess *, char *, int)),
205
this, SLOT(receivedStderr(KProcess *, char *, int)));
238
this, SLOT(receivedStderr(KProcess *, char *, int)));
206
239
connect(d->currentEncodeProcess, SIGNAL(wroteStdin(KProcess *)),
207
this, SLOT(wroteStdin(KProcess *)));
240
this, SLOT(wroteStdin(KProcess *)));
209
242
connect(d->currentEncodeProcess, SIGNAL(processExited(KProcess *)),
210
this, SLOT(processExited(KProcess *)));
243
this, SLOT(processExited(KProcess *)));
213
246
d->currentEncodeProcess->start(KProcess::NotifyOnExit, KShellProcess::All);
217
250
void EncoderLame::processExited ( KProcess *process ){
218
251
kdDebug(7117) << "Lame Encoding process exited with: " << process->exitStatus() << endl;
252
d->processHasExited = true;
221
255
void EncoderLame::receivedStderr( KProcess * /*process*/, char *buffer, int /*buflen*/ ){
222
256
kdDebug(7117) << "Lame stderr: " << buffer << endl;
257
if ( !d->lastErrorMessage.isEmpty() )
258
d->lastErrorMessage += '\t';
259
d->lastErrorMessage += QString::fromLocal8Bit( buffer );
225
262
void EncoderLame::receivedStdout( KProcess * /*process*/, char *buffer, int /*length*/ ){
233
270
long EncoderLame::read(int16_t *buf, int frames){
234
if(!d->currentEncodeProcess)
271
if(!d->currentEncodeProcess)
273
if (d->processHasExited)
237
276
// Pipe the raw data to lame
238
277
char * cbuf = reinterpret_cast<char *>(buf);
305
344
trackInfo.append("--tn");
306
345
trackInfo.append(QString("%1").arg(track+1));
308
trackInfo.append("--tg");
309
trackInfo.append(info.get("genre").toString());
347
const QString genre = info.get( "genre" ).toString();
348
if ( d->genreList.find( genre ) != d->genreList.end() )
350
trackInfo.append("--tg");
351
trackInfo.append(genre);
356
QString EncoderLame::lastErrorMessage() const
358
return d->lastErrorMessage;
313
361
#include "encoderlame.moc"