File indexing completed on 2024-05-12 04:51:01

0001 /*
0002     SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "k3baudiofile.h"
0007 #include "k3baudiodecoder.h"
0008 #include "k3baudiodoc.h"
0009 #include "k3baudiofilereader.h"
0010 #include "k3baudiotrack.h"
0011 
0012 
0013 class K3b::AudioFile::Private
0014 {
0015 public:
0016     AudioDoc* doc;
0017     AudioDecoder* decoder;
0018 };
0019 
0020 
0021 K3b::AudioFile::AudioFile( K3b::AudioDecoder* decoder, K3b::AudioDoc* doc )
0022     : K3b::AudioDataSource(),
0023       d( new Private )
0024 {
0025     d->doc = doc;
0026     d->decoder = decoder;
0027     // FIXME: somehow make it possible to switch docs
0028     d->doc->increaseDecoderUsage( d->decoder );
0029 }
0030 
0031 
0032 K3b::AudioFile::AudioFile( const K3b::AudioFile& file )
0033     : K3b::AudioDataSource( file ),
0034       d( new Private )
0035 {
0036     d->doc = file.d->doc;
0037     d->decoder = file.d->decoder;
0038     d->doc->increaseDecoderUsage( d->decoder );
0039 }
0040 
0041 
0042 K3b::AudioFile::~AudioFile()
0043 {
0044     d->doc->decreaseDecoderUsage( d->decoder );
0045 }
0046 
0047 
0048 QString K3b::AudioFile::type() const
0049 {
0050     return d->decoder->fileType();
0051 }
0052 
0053 
0054 QString K3b::AudioFile::sourceComment() const
0055 {
0056     return d->decoder->filename().section( '/', -1 );
0057 }
0058 
0059 
0060 QString K3b::AudioFile::filename() const
0061 {
0062     return d->decoder->filename();
0063 }
0064 
0065 
0066 K3b::AudioDecoder* K3b::AudioFile::decoder() const
0067 {
0068     return d->decoder;
0069 }
0070 
0071 
0072 K3b::AudioDoc* K3b::AudioFile::doc() const
0073 {
0074     return d->doc;
0075 }
0076 
0077 
0078 bool K3b::AudioFile::isValid() const
0079 {
0080     return d->decoder->isValid();
0081 }
0082 
0083 
0084 K3b::Msf K3b::AudioFile::originalLength() const
0085 {
0086     return d->decoder->length();
0087 }
0088 
0089 
0090 K3b::AudioDataSource* K3b::AudioFile::copy() const
0091 {
0092     return new K3b::AudioFile( *this );
0093 }
0094 
0095 
0096 QIODevice* K3b::AudioFile::createReader( QObject* parent )
0097 {
0098     return new AudioFileReader( *this, parent );
0099 }