Chris@148: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
Chris@148: 
Chris@148: /*
Chris@148:     Sonic Visualiser
Chris@148:     An audio file viewer and annotation editor.
Chris@148:     Centre for Digital Music, Queen Mary, University of London.
Chris@148:     This file copyright 2006 Chris Cannam.
Chris@148:     
Chris@148:     This program is free software; you can redistribute it and/or
Chris@148:     modify it under the terms of the GNU General Public License as
Chris@148:     published by the Free Software Foundation; either version 2 of the
Chris@148:     License, or (at your option) any later version.  See the file
Chris@148:     COPYING included with this distribution for more information.
Chris@148: */
Chris@148: 
Chris@148: #ifndef _OGG_VORBIS_FILE_READER_H_
Chris@148: #define _OGG_VORBIS_FILE_READER_H_
Chris@148: 
Chris@148: #ifdef HAVE_OGGZ
Chris@148: #ifdef HAVE_FISHSOUND
Chris@148: 
Chris@148: #include "CodedAudioFileReader.h"
Chris@148: 
Chris@263: #include "base/Thread.h"
Chris@148: #include <oggz/oggz.h>
Chris@148: #include <fishsound/fishsound.h>
Chris@148: 
Chris@157: #include <set>
Chris@157: 
Chris@148: class QProgressDialog;
Chris@148: 
Chris@148: class OggVorbisFileReader : public CodedAudioFileReader
Chris@148: {
Chris@148: public:
Chris@263:     enum DecodeMode {
Chris@263:         DecodeAtOnce, // decode the file on construction, with progress dialog
Chris@263:         DecodeThreaded // decode in a background thread after construction
Chris@263:     };
Chris@263: 
Chris@263:     OggVorbisFileReader(QString path, DecodeMode decodeMode,
Chris@263:                         CacheMode cacheMode);
Chris@148:     virtual ~OggVorbisFileReader();
Chris@148: 
Chris@148:     virtual QString getError() const { return m_error; }
Chris@148: 
Chris@271:     virtual QString getTitle() const { return m_title; }
Chris@271:     
Chris@157:     static void getSupportedExtensions(std::set<QString> &extensions);
Chris@157: 
Chris@265:     virtual int getDecodeCompletion() const { return m_completion; }
Chris@265: 
Chris@263:     virtual bool isUpdating() const {
Chris@263:         return m_decodeThread && m_decodeThread->isRunning();
Chris@263:     }
Chris@263: 
Chris@148: protected:
Chris@148:     QString m_path;
Chris@148:     QString m_error;
Chris@271:     QString m_title;
Chris@148: 
Chris@263:     OGGZ *m_oggz;
Chris@148:     FishSound *m_fishSound;
Chris@148:     QProgressDialog *m_progress;
Chris@148:     size_t m_fileSize;
Chris@148:     size_t m_bytesRead;
Chris@271:     bool m_commentsRead;
Chris@148:     bool m_cancelled;
Chris@265:     int m_completion;
Chris@148:  
Chris@148:     static int readPacket(OGGZ *, ogg_packet *, long, void *);
Chris@148:     static int acceptFrames(FishSound *, float **, long, void *);
Chris@263: 
Chris@263:     class DecodeThread : public Thread
Chris@263:     {
Chris@263:     public:
Chris@263:         DecodeThread(OggVorbisFileReader *reader) : m_reader(reader) { }
Chris@263:         virtual void run();
Chris@263: 
Chris@263:     protected:
Chris@263:         OggVorbisFileReader *m_reader; 
Chris@263:     };
Chris@263: 
Chris@263:     DecodeThread *m_decodeThread;
Chris@148: };
Chris@148: 
Chris@148: #endif
Chris@148: #endif
Chris@148: 
Chris@148: #endif