File indexing completed on 2024-04-21 08:39:24

0001 /*
0002     SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 
0008 #ifndef _K3B_MSF_H_
0009 #define _K3B_MSF_H_
0010 
0011 #include "k3bdevice_export.h"
0012 #include <KIO/Global>
0013 #include <QDebug>
0014 #include <QSharedDataPointer>
0015 
0016 class QRegExp;
0017 
0018 namespace K3b
0019 {
0020     /**
0021      * int values are always treated as frames
0022      * except in the set methods
0023      * A MSF is never < 0.
0024      */
0025     class LIBK3BDEVICE_EXPORT Msf
0026     {
0027     public:
0028         Msf();
0029         Msf( const Msf& );
0030         Msf( int, int, int );
0031         Msf( int );
0032         ~Msf();
0033 
0034         Msf& operator=( const Msf& );
0035         Msf& operator=( int );
0036         Msf& operator+=( const Msf& );
0037         Msf& operator+=( int );
0038         Msf& operator-=( const Msf& );
0039         Msf& operator-=( int );
0040         const Msf operator++( int );
0041         Msf& operator++();
0042         const Msf operator--( int );
0043         Msf& operator--();
0044 
0045         int minutes() const;
0046         int seconds() const;
0047         int frames() const;
0048 
0049         int totalFrames() const;
0050         int lba() const;
0051 
0052         //      operator int () const { return lba(); }
0053 
0054         void setValue( int m, int s, int f );
0055 
0056         void addMinutes( int m );
0057         void addSeconds( int s );
0058         void addFrames( int f );
0059 
0060         QString toString( bool showFrames = true ) const;
0061 
0062         KIO::filesize_t mode1Bytes() const;
0063         KIO::filesize_t mode2Form1Bytes() const;
0064         KIO::filesize_t mode2Form2Bytes() const;
0065         KIO::filesize_t audioBytes() const;
0066         KIO::filesize_t rawBytes() const;
0067         unsigned long long pcmSamples() const;
0068 
0069         /**
0070          * Convert a string representation into an Msf object.
0071          *
0072          * Valid strings include:
0073          * \li 100       - treated as 100 frames
0074          * \li 100:23    - treated as 100 minutes and 23 seconds
0075          * \li 100:23:57 - treated as 100 minutes, 23 seconds, and 57 frames
0076          * \li 100:23.57 - treated as 100 minutes, 23 seconds, and 57 frames
0077          */
0078         static Msf fromString( const QString&, bool* ok = 0 );
0079 
0080         /**
0081          * @param ms seconds
0082          * frames will be rounded up
0083          */
0084         static Msf fromSeconds( double ms );
0085 
0086         static Msf fromAudioBytes( qint64 bytes );
0087 
0088         static QRegExp regExp();
0089 
0090     private:
0091         class Private;
0092         QSharedDataPointer<Private> d;
0093     };
0094 
0095     LIBK3BDEVICE_EXPORT Msf operator+( const Msf&, const Msf& );
0096     LIBK3BDEVICE_EXPORT Msf operator+( const Msf&, int );
0097     LIBK3BDEVICE_EXPORT Msf operator-( const Msf&, const Msf& );
0098     LIBK3BDEVICE_EXPORT Msf operator-( const Msf&, int );
0099     LIBK3BDEVICE_EXPORT bool operator==( const Msf&, const Msf& );
0100     LIBK3BDEVICE_EXPORT bool operator!=( const Msf&, const Msf& );
0101     LIBK3BDEVICE_EXPORT bool operator<( const Msf&, const Msf& );
0102     LIBK3BDEVICE_EXPORT bool operator>( const Msf&, const Msf& );
0103     LIBK3BDEVICE_EXPORT bool operator<=( const Msf&, const Msf& );
0104     LIBK3BDEVICE_EXPORT bool operator>=( const Msf&, const Msf& );
0105 
0106     LIBK3BDEVICE_EXPORT QDebug& operator<<( QDebug&, const Msf& );
0107 }
0108 
0109 #endif