author | bipolar <bipolar> | 2002-03-05 00:42:40 (UTC) |
---|---|---|
committer | bipolar <bipolar> | 2002-03-05 00:42:40 (UTC) |
commit | dbc93b5de1b20489a05ce61e42874bf944165223 (patch) (side-by-side diff) | |
tree | 97faa0273f33a873d2eaa266a2f1e2ad2c2b3a96 | |
parent | 25be6fb98284dfa0c549d30db5b64c09798ee36d (diff) | |
download | opie-dbc93b5de1b20489a05ce61e42874bf944165223.zip opie-dbc93b5de1b20489a05ce61e42874bf944165223.tar.gz opie-dbc93b5de1b20489a05ce61e42874bf944165223.tar.bz2 |
committed by ljp: fixed a problem opening files from docs tab being added to playlist.
fixed (hopefully) problem with player redraw when playing wavfiles
-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 @@ -325,202 +325,199 @@ void PlayListWidget::readConfig( Config& cfg ) { for ( int i = 0; i < noOfFiles; i++ ) { QString entryName; entryName.sprintf( "File%i", i + 1 ); QString linkFile = cfg.readEntry( entryName ); DocLnk lnk( linkFile ); if ( lnk.isValid() ) d->selectedFiles->addToSelection( lnk ); } } void PlayListWidget::writeConfig( Config& cfg ) const { cfg.setGroup("PlayList"); int noOfFiles = 0; d->selectedFiles->first(); do { const DocLnk *lnk = d->selectedFiles->current(); if ( lnk ) { QString entryName; entryName.sprintf( "File%i", noOfFiles + 1 ); cfg.writeEntry( entryName, lnk->linkFile() ); // if this link does exist, add it so we have the file // next time... if ( !QFile::exists( lnk->linkFile() ) ) { // the way writing lnks doesn't really check for out // of disk space, but check it anyway. if ( !lnk->writeLink() ) { QMessageBox::critical( 0, tr("Out of space"), tr( "There was a problem saving " "the playlist.\n" "Your playlist " "may be missing some entries\n" "the next time you start it." ) ); } } noOfFiles++; } } while ( d->selectedFiles->next() ); cfg.writeEntry("NumberOfFiles", noOfFiles ); } void PlayListWidget::addToSelection( const DocLnk& lnk ) { qDebug("add"); d->setDocumentUsed = FALSE; if ( mediaPlayerState->playlist() ) d->selectedFiles->addToSelection( lnk ); else mediaPlayerState->setPlaying( TRUE ); } void PlayListWidget::clearList() { while ( first() ) d->selectedFiles->removeSelected(); } void PlayListWidget::addAllToList() { DocLnkSet files; Global::findDocuments(&files, "video/*;audio/*"); QListIterator<DocLnk> dit( files.children() ); for ( ; dit.current(); ++dit ) d->selectedFiles->addToSelection( **dit ); } void PlayListWidget::addAllMusicToList() { DocLnkSet files; Global::findDocuments(&files, "audio/*"); QListIterator<DocLnk> dit( files.children() ); for ( ; dit.current(); ++dit ) d->selectedFiles->addToSelection( **dit ); } void PlayListWidget::addAllVideoToList() { DocLnkSet files; Global::findDocuments(&files, "video/*"); QListIterator<DocLnk> dit( files.children() ); for ( ; dit.current(); ++dit ) d->selectedFiles->addToSelection( **dit ); } void PlayListWidget::setDocument(const QString& fileref) { if ( fileref.isNull() ) { QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); return; } - if ( mediaPlayerState->playlist() ) - addToSelection( DocLnk( fileref ) ); - else { - d->setDocumentUsed = TRUE; - if ( d->current ) - delete d->current; - d->current = new DocLnk( fileref ); - } + addToSelection( DocLnk( fileref ) ); + d->setDocumentUsed = TRUE; + qApp->processEvents(); mediaPlayerState->setPlaying( FALSE ); + qApp->processEvents(); mediaPlayerState->setPlaying( TRUE ); + d->selectedFiles->removeSelected( ); } void PlayListWidget::setActiveWindow() { // When we get raised we need to ensure that it switches views char origView = mediaPlayerState->view(); mediaPlayerState->setView( 'l' ); // invalidate mediaPlayerState->setView( origView ); // now switch back } void PlayListWidget::useSelectedDocument() { d->setDocumentUsed = FALSE; } const DocLnk *PlayListWidget::current() { // qDebug("in Playlist widget ::current"); if ( mediaPlayerState->playlist() ) { return d->selectedFiles->current(); } else if ( d->setDocumentUsed && d->current ) { return d->current; } else { return d->files->selected(); } } bool PlayListWidget::prev() { if ( mediaPlayerState->playlist() ) { if ( mediaPlayerState->shuffled() ) { const DocLnk *cur = current(); int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); for ( int i = 0; i < j; i++ ) { if ( !d->selectedFiles->next() ) d->selectedFiles->first(); } if ( cur == current() ) if ( !d->selectedFiles->next() ) d->selectedFiles->first(); return TRUE; } else { if ( !d->selectedFiles->prev() ) { if ( mediaPlayerState->looping() ) { return d->selectedFiles->last(); } else { return FALSE; } } return TRUE; } } else { return mediaPlayerState->looping(); } } bool PlayListWidget::next() { if ( mediaPlayerState->playlist() ) { if ( mediaPlayerState->shuffled() ) { return prev(); } else { if ( !d->selectedFiles->next() ) { if ( mediaPlayerState->looping() ) { return d->selectedFiles->first(); } else { return FALSE; } } return TRUE; } } else { return mediaPlayerState->looping(); } } bool PlayListWidget::first() { if ( mediaPlayerState->playlist() ) return d->selectedFiles->first(); else return mediaPlayerState->looping(); } bool PlayListWidget::last() { if ( mediaPlayerState->playlist() ) return d->selectedFiles->last(); else return mediaPlayerState->looping(); } void PlayListWidget::saveList() { 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 @@ -1,340 +1,340 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ // L.J.Potter added changes Fri 02-15-2002 #include <stdio.h> #include <stdarg.h> #include <stdlib.h> #include <errno.h> #include <unistd.h> #include <qfile.h> #include "wavplugin.h" //#define debugMsg(a) qDebug(a) #define debugMsg(a) struct RiffChunk { char id[4]; Q_UINT32 size; char data[4]; }; struct ChunkData { Q_INT16 formatTag; Q_INT16 channels; Q_INT32 samplesPerSec; Q_INT32 avgBytesPerSec; Q_INT16 blockAlign; Q_INT16 wBitsPerSample; }; const int sound_buffer_size = 512; // 4096; // you got to be kidding right? class WavPluginData { public: QFile *input; int wavedata_remaining; ChunkData chunkdata; RiffChunk chunk; uchar data[sound_buffer_size+32]; // +32 to handle badly aligned input data int out,max; int samples_due; int samples; WavPluginData() { max = out = sound_buffer_size; wavedata_remaining = 0; samples_due = 0; samples = -1; } // expands out samples to the frequency of 44kHz //not any more bool add( short *output, long count, long& done, bool stereo ) { done = 0; - qApp->processEvents(); if ( input == 0 ) { qDebug("no input"); return FALSE; } while ( count ) { int l,r; if ( getSample(l, r) == FALSE ) { qDebug("didn't get sample"); return FALSE; } samples_due += chunkdata.samplesPerSec; printf("samples due %d\r", samples_due); fflush(stdout); while ( count && (samples_due > chunkdata.samplesPerSec) ) { *output++ = l; if ( stereo ) *output++ = r; samples_due -= chunkdata.samplesPerSec; count--; done++; } } return TRUE; } bool initialise() { if ( input == 0 ) return FALSE; wavedata_remaining = -1; while ( wavedata_remaining == -1 ) { // Keep reading chunks... const int n = sizeof(chunk) - sizeof(chunk.data); int t = input->readBlock( (char*)&chunk, n ); if ( t != n ) { if ( t == -1 ) return FALSE; return TRUE; } if ( qstrncmp(chunk.id,"data",4) == 0 ) { samples = wavedata_remaining = chunk.size; } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) { char d[4]; if ( input->readBlock(d,4) != 4 ) { return FALSE; } if ( qstrncmp(d,"WAVE",4) != 0 ) { // skip if ( chunk.size > 1000000000 || !input->at(input->at()+chunk.size-4) ) { return FALSE; } } } else if ( qstrncmp(chunk.id,"fmt ",4) == 0 ) { if ( input->readBlock((char*)&chunkdata,sizeof(chunkdata)) != sizeof(chunkdata) ) { return FALSE; } #define WAVE_FORMAT_PCM 1 if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) { qDebug("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag); return FALSE; } } else { // ignored chunk if ( chunk.size > 1000000000 || !input->at(input->at()+chunk.size) ) { return FALSE; } } } // while qDebug("bits %d", chunkdata.wBitsPerSample); return TRUE; } // gets a sample from the file bool getSample(int& l, int& r) { l = r = 0; if ( input == 0 ) return FALSE; if ( (wavedata_remaining < 0) || !max ) return FALSE; if ( out >= max ) { max = input->readBlock( (char*)data, (uint)QMIN(sound_buffer_size,wavedata_remaining) ); wavedata_remaining -= max; out = 0; if ( max <= 0 ) { max = 0; return TRUE; } } if ( chunkdata.wBitsPerSample == 8 ) { l = (data[out++] - 128) * 128; } else { l = ((short*)data)[out/2]; out += 2; } if ( chunkdata.channels == 1 ) { r = l; } else { if ( chunkdata.wBitsPerSample == 8 ) { r = (data[out++] - 128) * 128; } else { r = ((short*)data)[out/2]; out += 2; } } return TRUE; } // getSample }; WavPlugin::WavPlugin() { d = new WavPluginData; d->input = 0; } WavPlugin::~WavPlugin() { close(); delete d; } bool WavPlugin::isFileSupported( const QString& path ) { // qDebug( "WavPlugin::isFileSupported" ); char *ext = strrchr( path.latin1(), '.' ); // Test file extension if ( ext ) { if ( strncasecmp(ext, ".raw", 4) == 0 ) return TRUE; if ( strncasecmp(ext, ".wav", 4) == 0 ) return TRUE; if ( strncasecmp(ext, ".wave", 4) == 0 ) return TRUE; } return FALSE; } bool WavPlugin::open( const QString& path ) { // qDebug( "WavPlugin::open" ); d->max = d->out = sound_buffer_size; d->wavedata_remaining = 0; d->samples_due = 0; d->input = new QFile( path ); if ( d->input->open(IO_ReadOnly) == FALSE ) { qDebug("couldn't open file"); delete d->input; d->input = 0; return FALSE; } d->initialise(); + qApp->processEvents(); return TRUE; } bool WavPlugin::close() { // qDebug( "WavPlugin::close" ); d->input->close(); delete d->input; d->input = 0; return TRUE; } bool WavPlugin::isOpen() { // qDebug( "WavPlugin::isOpen" ); return ( d->input != 0 ); } int WavPlugin::audioStreams() { // qDebug( "WavPlugin::audioStreams" ); return 1; } int WavPlugin::audioChannels( int ) { // qDebug( "WavPlugin::audioChannels" ); return d->chunkdata.channels;// 2; // ### Always scale audio to stereo samples } int WavPlugin::audioFrequency( int ) { // qDebug( "WavPlugin::audioFrequency %d", d->chunkdata.samplesPerSec ); return d->chunkdata.samplesPerSec; //44100; // ### Always scale to frequency of 44100 } int WavPlugin::audioSamples( int ) { // qDebug( "WavPlugin::audioSamples" ); return d->samples / d->chunkdata.channels/2; // ### Scaled samples will be made stereo, // Therefore if source is mono we will double the number of samples } bool WavPlugin::audioSetSample( long, int ) { // qDebug( "WavPlugin::audioSetSample" ); return FALSE; } long WavPlugin::audioGetSample( int ) { // qDebug( "WavPlugin::audioGetSample" ); return 0; } /* bool WavPlugin::audioReadSamples( short *, int, long, int ) { debugMsg( "WavPlugin::audioReadSamples" ); return FALSE; } bool WavPlugin::audioReReadSamples( short *, int, long, int ) { debugMsg( "WavPlugin::audioReReadSamples" ); return FALSE; } bool WavPlugin::audioReadMonoSamples( short *output, long samples, long& samplesMade, int ) { debugMsg( "WavPlugin::audioReadMonoSamples" ); return !d->add( output, samples, samplesMade, FALSE ); } bool WavPlugin::audioReadStereoSamples( short *output, long samples, long& samplesMade, int ) { debugMsg( "WavPlugin::audioReadStereoSamples" ); return !d->add( output, samples, samplesMade, TRUE ); } */ bool WavPlugin::audioReadSamples( short *output, int channels, long samples, long& samplesMade, int ) { // qDebug( "WavPlugin::audioReadSamples" ); return d->add( output, samples, samplesMade, channels != 1 ); } double WavPlugin::getTime() { // qDebug( "WavPlugin::getTime" ); //this is a stupid hack here!! return d->chunkdata.wBitsPerSample; /*0.0*/; } // int WavPlugin::audioBitsPerSample( int ) { // // qDebug( "WavPlugin::audioFormat %d", d->chunkdata.wBitsPerSample ); // return d->chunkdata.wBitsPerSample; // // } |