-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.cpp | 13 | ||||
-rw-r--r-- | core/multimedia/opieplayer/wavplugin/wavplugin.cpp | 2 |
2 files changed, 6 insertions, 9 deletions
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp index 1a0c7ca..a6202bc 100644 --- a/core/multimedia/opieplayer/playlistwidget.cpp +++ b/core/multimedia/opieplayer/playlistwidget.cpp | |||
@@ -373,106 +373,103 @@ void PlayListWidget::writeConfig( Config& cfg ) const { | |||
373 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { | 373 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { |
374 | qDebug("add"); | 374 | qDebug("add"); |
375 | d->setDocumentUsed = FALSE; | 375 | d->setDocumentUsed = FALSE; |
376 | if ( mediaPlayerState->playlist() ) | 376 | if ( mediaPlayerState->playlist() ) |
377 | d->selectedFiles->addToSelection( lnk ); | 377 | d->selectedFiles->addToSelection( lnk ); |
378 | else | 378 | else |
379 | mediaPlayerState->setPlaying( TRUE ); | 379 | mediaPlayerState->setPlaying( TRUE ); |
380 | } | 380 | } |
381 | 381 | ||
382 | 382 | ||
383 | void PlayListWidget::clearList() { | 383 | void PlayListWidget::clearList() { |
384 | while ( first() ) | 384 | while ( first() ) |
385 | d->selectedFiles->removeSelected(); | 385 | d->selectedFiles->removeSelected(); |
386 | } | 386 | } |
387 | 387 | ||
388 | 388 | ||
389 | void PlayListWidget::addAllToList() { | 389 | void PlayListWidget::addAllToList() { |
390 | DocLnkSet files; | 390 | DocLnkSet files; |
391 | Global::findDocuments(&files, "video/*;audio/*"); | 391 | Global::findDocuments(&files, "video/*;audio/*"); |
392 | QListIterator<DocLnk> dit( files.children() ); | 392 | QListIterator<DocLnk> dit( files.children() ); |
393 | for ( ; dit.current(); ++dit ) | 393 | for ( ; dit.current(); ++dit ) |
394 | d->selectedFiles->addToSelection( **dit ); | 394 | d->selectedFiles->addToSelection( **dit ); |
395 | } | 395 | } |
396 | 396 | ||
397 | 397 | ||
398 | void PlayListWidget::addAllMusicToList() { | 398 | void PlayListWidget::addAllMusicToList() { |
399 | DocLnkSet files; | 399 | DocLnkSet files; |
400 | Global::findDocuments(&files, "audio/*"); | 400 | Global::findDocuments(&files, "audio/*"); |
401 | QListIterator<DocLnk> dit( files.children() ); | 401 | QListIterator<DocLnk> dit( files.children() ); |
402 | for ( ; dit.current(); ++dit ) | 402 | for ( ; dit.current(); ++dit ) |
403 | d->selectedFiles->addToSelection( **dit ); | 403 | d->selectedFiles->addToSelection( **dit ); |
404 | } | 404 | } |
405 | 405 | ||
406 | 406 | ||
407 | void PlayListWidget::addAllVideoToList() { | 407 | void PlayListWidget::addAllVideoToList() { |
408 | DocLnkSet files; | 408 | DocLnkSet files; |
409 | Global::findDocuments(&files, "video/*"); | 409 | Global::findDocuments(&files, "video/*"); |
410 | QListIterator<DocLnk> dit( files.children() ); | 410 | QListIterator<DocLnk> dit( files.children() ); |
411 | for ( ; dit.current(); ++dit ) | 411 | for ( ; dit.current(); ++dit ) |
412 | d->selectedFiles->addToSelection( **dit ); | 412 | d->selectedFiles->addToSelection( **dit ); |
413 | } | 413 | } |
414 | 414 | ||
415 | 415 | ||
416 | void PlayListWidget::setDocument(const QString& fileref) { | 416 | void PlayListWidget::setDocument(const QString& fileref) { |
417 | if ( fileref.isNull() ) { | 417 | if ( fileref.isNull() ) { |
418 | QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); | 418 | QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); |
419 | return; | 419 | return; |
420 | } | 420 | } |
421 | if ( mediaPlayerState->playlist() ) | 421 | addToSelection( DocLnk( fileref ) ); |
422 | addToSelection( DocLnk( fileref ) ); | 422 | d->setDocumentUsed = TRUE; |
423 | else { | 423 | qApp->processEvents(); |
424 | d->setDocumentUsed = TRUE; | ||
425 | if ( d->current ) | ||
426 | delete d->current; | ||
427 | d->current = new DocLnk( fileref ); | ||
428 | } | ||
429 | mediaPlayerState->setPlaying( FALSE ); | 424 | mediaPlayerState->setPlaying( FALSE ); |
425 | qApp->processEvents(); | ||
430 | mediaPlayerState->setPlaying( TRUE ); | 426 | mediaPlayerState->setPlaying( TRUE ); |
427 | d->selectedFiles->removeSelected( ); | ||
431 | } | 428 | } |
432 | 429 | ||
433 | 430 | ||
434 | void PlayListWidget::setActiveWindow() { | 431 | void PlayListWidget::setActiveWindow() { |
435 | // When we get raised we need to ensure that it switches views | 432 | // When we get raised we need to ensure that it switches views |
436 | char origView = mediaPlayerState->view(); | 433 | char origView = mediaPlayerState->view(); |
437 | mediaPlayerState->setView( 'l' ); // invalidate | 434 | mediaPlayerState->setView( 'l' ); // invalidate |
438 | mediaPlayerState->setView( origView ); // now switch back | 435 | mediaPlayerState->setView( origView ); // now switch back |
439 | } | 436 | } |
440 | 437 | ||
441 | 438 | ||
442 | void PlayListWidget::useSelectedDocument() { | 439 | void PlayListWidget::useSelectedDocument() { |
443 | d->setDocumentUsed = FALSE; | 440 | d->setDocumentUsed = FALSE; |
444 | } | 441 | } |
445 | 442 | ||
446 | 443 | ||
447 | const DocLnk *PlayListWidget::current() { | 444 | const DocLnk *PlayListWidget::current() { |
448 | 445 | ||
449 | // qDebug("in Playlist widget ::current"); | 446 | // qDebug("in Playlist widget ::current"); |
450 | if ( mediaPlayerState->playlist() ) { | 447 | if ( mediaPlayerState->playlist() ) { |
451 | return d->selectedFiles->current(); | 448 | return d->selectedFiles->current(); |
452 | } | 449 | } |
453 | else if ( d->setDocumentUsed && d->current ) { | 450 | else if ( d->setDocumentUsed && d->current ) { |
454 | return d->current; | 451 | return d->current; |
455 | } else { | 452 | } else { |
456 | return d->files->selected(); | 453 | return d->files->selected(); |
457 | } | 454 | } |
458 | } | 455 | } |
459 | 456 | ||
460 | 457 | ||
461 | bool PlayListWidget::prev() { | 458 | bool PlayListWidget::prev() { |
462 | if ( mediaPlayerState->playlist() ) { | 459 | if ( mediaPlayerState->playlist() ) { |
463 | if ( mediaPlayerState->shuffled() ) { | 460 | if ( mediaPlayerState->shuffled() ) { |
464 | const DocLnk *cur = current(); | 461 | const DocLnk *cur = current(); |
465 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); | 462 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); |
466 | for ( int i = 0; i < j; i++ ) { | 463 | for ( int i = 0; i < j; i++ ) { |
467 | if ( !d->selectedFiles->next() ) | 464 | if ( !d->selectedFiles->next() ) |
468 | d->selectedFiles->first(); | 465 | d->selectedFiles->first(); |
469 | } | 466 | } |
470 | if ( cur == current() ) | 467 | if ( cur == current() ) |
471 | if ( !d->selectedFiles->next() ) | 468 | if ( !d->selectedFiles->next() ) |
472 | d->selectedFiles->first(); | 469 | d->selectedFiles->first(); |
473 | return TRUE; | 470 | return TRUE; |
474 | } else { | 471 | } else { |
475 | if ( !d->selectedFiles->prev() ) { | 472 | if ( !d->selectedFiles->prev() ) { |
476 | if ( mediaPlayerState->looping() ) { | 473 | if ( mediaPlayerState->looping() ) { |
477 | return d->selectedFiles->last(); | 474 | return d->selectedFiles->last(); |
478 | } else { | 475 | } else { |
diff --git a/core/multimedia/opieplayer/wavplugin/wavplugin.cpp b/core/multimedia/opieplayer/wavplugin/wavplugin.cpp index 4a0da16..4e82900 100644 --- a/core/multimedia/opieplayer/wavplugin/wavplugin.cpp +++ b/core/multimedia/opieplayer/wavplugin/wavplugin.cpp | |||
@@ -29,97 +29,96 @@ | |||
29 | 29 | ||
30 | //#define debugMsg(a) qDebug(a) | 30 | //#define debugMsg(a) qDebug(a) |
31 | #define debugMsg(a) | 31 | #define debugMsg(a) |
32 | 32 | ||
33 | 33 | ||
34 | struct RiffChunk { | 34 | struct RiffChunk { |
35 | char id[4]; | 35 | char id[4]; |
36 | Q_UINT32 size; | 36 | Q_UINT32 size; |
37 | char data[4]; | 37 | char data[4]; |
38 | }; | 38 | }; |
39 | 39 | ||
40 | 40 | ||
41 | struct ChunkData { | 41 | struct ChunkData { |
42 | Q_INT16 formatTag; | 42 | Q_INT16 formatTag; |
43 | Q_INT16 channels; | 43 | Q_INT16 channels; |
44 | Q_INT32 samplesPerSec; | 44 | Q_INT32 samplesPerSec; |
45 | Q_INT32 avgBytesPerSec; | 45 | Q_INT32 avgBytesPerSec; |
46 | Q_INT16 blockAlign; | 46 | Q_INT16 blockAlign; |
47 | Q_INT16 wBitsPerSample; | 47 | Q_INT16 wBitsPerSample; |
48 | }; | 48 | }; |
49 | 49 | ||
50 | 50 | ||
51 | const int sound_buffer_size = 512; // 4096; // you got to be kidding right? | 51 | const int sound_buffer_size = 512; // 4096; // you got to be kidding right? |
52 | 52 | ||
53 | 53 | ||
54 | class WavPluginData { | 54 | class WavPluginData { |
55 | public: | 55 | public: |
56 | QFile *input; | 56 | QFile *input; |
57 | 57 | ||
58 | int wavedata_remaining; | 58 | int wavedata_remaining; |
59 | ChunkData chunkdata; | 59 | ChunkData chunkdata; |
60 | RiffChunk chunk; | 60 | RiffChunk chunk; |
61 | uchar data[sound_buffer_size+32]; // +32 to handle badly aligned input data | 61 | uchar data[sound_buffer_size+32]; // +32 to handle badly aligned input data |
62 | int out,max; | 62 | int out,max; |
63 | int samples_due; | 63 | int samples_due; |
64 | int samples; | 64 | int samples; |
65 | 65 | ||
66 | WavPluginData() { | 66 | WavPluginData() { |
67 | max = out = sound_buffer_size; | 67 | max = out = sound_buffer_size; |
68 | wavedata_remaining = 0; | 68 | wavedata_remaining = 0; |
69 | samples_due = 0; | 69 | samples_due = 0; |
70 | samples = -1; | 70 | samples = -1; |
71 | } | 71 | } |
72 | 72 | ||
73 | // expands out samples to the frequency of 44kHz //not any more | 73 | // expands out samples to the frequency of 44kHz //not any more |
74 | bool add( short *output, long count, long& done, bool stereo ) | 74 | bool add( short *output, long count, long& done, bool stereo ) |
75 | { | 75 | { |
76 | done = 0; | 76 | done = 0; |
77 | qApp->processEvents(); | ||
78 | 77 | ||
79 | if ( input == 0 ) { | 78 | if ( input == 0 ) { |
80 | qDebug("no input"); | 79 | qDebug("no input"); |
81 | return FALSE; | 80 | return FALSE; |
82 | } | 81 | } |
83 | 82 | ||
84 | while ( count ) { | 83 | while ( count ) { |
85 | int l,r; | 84 | int l,r; |
86 | if ( getSample(l, r) == FALSE ) { | 85 | if ( getSample(l, r) == FALSE ) { |
87 | qDebug("didn't get sample"); | 86 | qDebug("didn't get sample"); |
88 | return FALSE; | 87 | return FALSE; |
89 | } | 88 | } |
90 | samples_due += chunkdata.samplesPerSec; | 89 | samples_due += chunkdata.samplesPerSec; |
91 | printf("samples due %d\r", samples_due); | 90 | printf("samples due %d\r", samples_due); |
92 | fflush(stdout); | 91 | fflush(stdout); |
93 | while ( count && (samples_due > chunkdata.samplesPerSec) ) { | 92 | while ( count && (samples_due > chunkdata.samplesPerSec) ) { |
94 | *output++ = l; | 93 | *output++ = l; |
95 | if ( stereo ) | 94 | if ( stereo ) |
96 | *output++ = r; | 95 | *output++ = r; |
97 | samples_due -= chunkdata.samplesPerSec; | 96 | samples_due -= chunkdata.samplesPerSec; |
98 | count--; | 97 | count--; |
99 | done++; | 98 | done++; |
100 | } | 99 | } |
101 | } | 100 | } |
102 | return TRUE; | 101 | return TRUE; |
103 | } | 102 | } |
104 | 103 | ||
105 | bool initialise() { | 104 | bool initialise() { |
106 | if ( input == 0 ) | 105 | if ( input == 0 ) |
107 | return FALSE; | 106 | return FALSE; |
108 | 107 | ||
109 | wavedata_remaining = -1; | 108 | wavedata_remaining = -1; |
110 | 109 | ||
111 | while ( wavedata_remaining == -1 ) { | 110 | while ( wavedata_remaining == -1 ) { |
112 | // Keep reading chunks... | 111 | // Keep reading chunks... |
113 | const int n = sizeof(chunk) - sizeof(chunk.data); | 112 | const int n = sizeof(chunk) - sizeof(chunk.data); |
114 | int t = input->readBlock( (char*)&chunk, n ); | 113 | int t = input->readBlock( (char*)&chunk, n ); |
115 | if ( t != n ) { | 114 | if ( t != n ) { |
116 | if ( t == -1 ) | 115 | if ( t == -1 ) |
117 | return FALSE; | 116 | return FALSE; |
118 | return TRUE; | 117 | return TRUE; |
119 | } | 118 | } |
120 | if ( qstrncmp(chunk.id,"data",4) == 0 ) { | 119 | if ( qstrncmp(chunk.id,"data",4) == 0 ) { |
121 | samples = wavedata_remaining = chunk.size; | 120 | samples = wavedata_remaining = chunk.size; |
122 | } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) { | 121 | } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) { |
123 | char d[4]; | 122 | char d[4]; |
124 | if ( input->readBlock(d,4) != 4 ) { | 123 | if ( input->readBlock(d,4) != 4 ) { |
125 | return FALSE; | 124 | return FALSE; |
@@ -197,96 +196,97 @@ public: | |||
197 | 196 | ||
198 | WavPlugin::WavPlugin() { | 197 | WavPlugin::WavPlugin() { |
199 | d = new WavPluginData; | 198 | d = new WavPluginData; |
200 | d->input = 0; | 199 | d->input = 0; |
201 | } | 200 | } |
202 | 201 | ||
203 | 202 | ||
204 | WavPlugin::~WavPlugin() { | 203 | WavPlugin::~WavPlugin() { |
205 | close(); | 204 | close(); |
206 | delete d; | 205 | delete d; |
207 | } | 206 | } |
208 | 207 | ||
209 | 208 | ||
210 | bool WavPlugin::isFileSupported( const QString& path ) { | 209 | bool WavPlugin::isFileSupported( const QString& path ) { |
211 | // qDebug( "WavPlugin::isFileSupported" ); | 210 | // qDebug( "WavPlugin::isFileSupported" ); |
212 | 211 | ||
213 | char *ext = strrchr( path.latin1(), '.' ); | 212 | char *ext = strrchr( path.latin1(), '.' ); |
214 | 213 | ||
215 | // Test file extension | 214 | // Test file extension |
216 | if ( ext ) { | 215 | if ( ext ) { |
217 | if ( strncasecmp(ext, ".raw", 4) == 0 ) | 216 | if ( strncasecmp(ext, ".raw", 4) == 0 ) |
218 | return TRUE; | 217 | return TRUE; |
219 | if ( strncasecmp(ext, ".wav", 4) == 0 ) | 218 | if ( strncasecmp(ext, ".wav", 4) == 0 ) |
220 | return TRUE; | 219 | return TRUE; |
221 | if ( strncasecmp(ext, ".wave", 4) == 0 ) | 220 | if ( strncasecmp(ext, ".wave", 4) == 0 ) |
222 | return TRUE; | 221 | return TRUE; |
223 | } | 222 | } |
224 | 223 | ||
225 | return FALSE; | 224 | return FALSE; |
226 | } | 225 | } |
227 | 226 | ||
228 | 227 | ||
229 | bool WavPlugin::open( const QString& path ) { | 228 | bool WavPlugin::open( const QString& path ) { |
230 | // qDebug( "WavPlugin::open" ); | 229 | // qDebug( "WavPlugin::open" ); |
231 | 230 | ||
232 | d->max = d->out = sound_buffer_size; | 231 | d->max = d->out = sound_buffer_size; |
233 | d->wavedata_remaining = 0; | 232 | d->wavedata_remaining = 0; |
234 | d->samples_due = 0; | 233 | d->samples_due = 0; |
235 | 234 | ||
236 | d->input = new QFile( path ); | 235 | d->input = new QFile( path ); |
237 | if ( d->input->open(IO_ReadOnly) == FALSE ) { | 236 | if ( d->input->open(IO_ReadOnly) == FALSE ) { |
238 | qDebug("couldn't open file"); | 237 | qDebug("couldn't open file"); |
239 | delete d->input; | 238 | delete d->input; |
240 | d->input = 0; | 239 | d->input = 0; |
241 | return FALSE; | 240 | return FALSE; |
242 | } | 241 | } |
243 | 242 | ||
244 | d->initialise(); | 243 | d->initialise(); |
244 | qApp->processEvents(); | ||
245 | 245 | ||
246 | return TRUE; | 246 | return TRUE; |
247 | } | 247 | } |
248 | 248 | ||
249 | 249 | ||
250 | bool WavPlugin::close() { | 250 | bool WavPlugin::close() { |
251 | // qDebug( "WavPlugin::close" ); | 251 | // qDebug( "WavPlugin::close" ); |
252 | 252 | ||
253 | d->input->close(); | 253 | d->input->close(); |
254 | delete d->input; | 254 | delete d->input; |
255 | d->input = 0; | 255 | d->input = 0; |
256 | return TRUE; | 256 | return TRUE; |
257 | } | 257 | } |
258 | 258 | ||
259 | 259 | ||
260 | bool WavPlugin::isOpen() { | 260 | bool WavPlugin::isOpen() { |
261 | // qDebug( "WavPlugin::isOpen" ); | 261 | // qDebug( "WavPlugin::isOpen" ); |
262 | return ( d->input != 0 ); | 262 | return ( d->input != 0 ); |
263 | } | 263 | } |
264 | 264 | ||
265 | 265 | ||
266 | int WavPlugin::audioStreams() { | 266 | int WavPlugin::audioStreams() { |
267 | // qDebug( "WavPlugin::audioStreams" ); | 267 | // qDebug( "WavPlugin::audioStreams" ); |
268 | return 1; | 268 | return 1; |
269 | } | 269 | } |
270 | 270 | ||
271 | 271 | ||
272 | int WavPlugin::audioChannels( int ) { | 272 | int WavPlugin::audioChannels( int ) { |
273 | // qDebug( "WavPlugin::audioChannels" ); | 273 | // qDebug( "WavPlugin::audioChannels" ); |
274 | return d->chunkdata.channels;// 2; // ### Always scale audio to stereo samples | 274 | return d->chunkdata.channels;// 2; // ### Always scale audio to stereo samples |
275 | } | 275 | } |
276 | 276 | ||
277 | 277 | ||
278 | int WavPlugin::audioFrequency( int ) { | 278 | int WavPlugin::audioFrequency( int ) { |
279 | // qDebug( "WavPlugin::audioFrequency %d", d->chunkdata.samplesPerSec ); | 279 | // qDebug( "WavPlugin::audioFrequency %d", d->chunkdata.samplesPerSec ); |
280 | return d->chunkdata.samplesPerSec; //44100; // ### Always scale to frequency of 44100 | 280 | return d->chunkdata.samplesPerSec; //44100; // ### Always scale to frequency of 44100 |
281 | } | 281 | } |
282 | 282 | ||
283 | 283 | ||
284 | int WavPlugin::audioSamples( int ) { | 284 | int WavPlugin::audioSamples( int ) { |
285 | // qDebug( "WavPlugin::audioSamples" ); | 285 | // qDebug( "WavPlugin::audioSamples" ); |
286 | return d->samples / d->chunkdata.channels/2; // ### Scaled samples will be made stereo, | 286 | return d->samples / d->chunkdata.channels/2; // ### Scaled samples will be made stereo, |
287 | // Therefore if source is mono we will double the number of samples | 287 | // Therefore if source is mono we will double the number of samples |
288 | } | 288 | } |
289 | 289 | ||
290 | 290 | ||
291 | bool WavPlugin::audioSetSample( long, int ) { | 291 | bool WavPlugin::audioSetSample( long, int ) { |
292 | // qDebug( "WavPlugin::audioSetSample" ); | 292 | // qDebug( "WavPlugin::audioSetSample" ); |