home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / k3baudiodatasource.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-05-27  |  4.9 KB  |  169 lines

  1. /* 
  2.  *
  3.  * $Id: k3baudiodatasource.h 619556 2007-01-03 17:38:12Z trueg $
  4.  * Copyright (C) 2004 Sebastian Trueg <trueg@k3b.org>
  5.  *
  6.  * This file is part of the K3b project.
  7.  * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  * See the file "COPYING" for the exact licensing terms.
  14.  */
  15.  
  16. #ifndef _K3B_AUDIO_DATA_SOURCE_H_
  17. #define _K3B_AUDIO_DATA_SOURCE_H_
  18.  
  19. #include <k3bmsf.h>
  20. #include "k3b_export.h"
  21. class K3bAudioTrack;
  22. class K3bAudioDoc;
  23.  
  24.  
  25. /**
  26.  * An AudioDataSource has an original length which represents the maximum amount of audio
  27.  * sectors this source can provide (in special cases this is not true, see K3bAudioZeroData).
  28.  *
  29.  * It is possible to just use a portion of that data by changing the startOffset and endOffset.
  30.  * This will change the actual length of the data provided by this source through the read method.
  31.  *
  32.  * Sources are part of a list which can be traversed via the prev() and next() methods. This list 
  33.  * is part of a K3bAudioTrack which in turn is part of a list which is owned by a K3bAudioDoc.
  34.  *
  35.  * The list may be modified with the take(), moveAfter(), and moveAhead() methods. The source takes
  36.  * care of fixing the list and notifying the track about the change (It is also possible to move sources
  37.  * from one track to the other).
  38.  *
  39.  * When a source is deleted it automatically removes itself from it's list.
  40.  */
  41. class LIBK3B_EXPORT K3bAudioDataSource 
  42. {
  43.   friend class K3bAudioTrack;
  44.  
  45.  public:
  46.   K3bAudioDataSource();
  47.  
  48.   /**
  49.    * Create en identical copy except that the copy will not be in any list.
  50.    */
  51.   K3bAudioDataSource( const K3bAudioDataSource& );
  52.   virtual ~K3bAudioDataSource();
  53.  
  54.   /**
  55.    * The original length of the source is the maximum data which is available
  56.    * when startOffset is 0 this is the max for endOffset
  57.    *
  58.    * Be aware that this may change (see K3bAudioZeroData)
  59.    */
  60.   virtual K3b::Msf originalLength() const = 0;
  61.  
  62.   /**
  63.    * The default implementation returns the originalLength modified by startOffset and endOffset
  64.    */
  65.   virtual K3b::Msf length() const;
  66.  
  67.   /** 
  68.    * @return The raw size in pcm samples (16bit, 44800 kHz, stereo) 
  69.    */
  70.   KIO::filesize_t size() const { return length().audioBytes(); }
  71.  
  72.   virtual bool seek( const K3b::Msf& ) = 0;
  73.  
  74.   /**
  75.    * Read data from the source.
  76.    */
  77.   virtual int read( char* data, unsigned int max ) = 0;
  78.  
  79.   /**
  80.    * Type of the data in readable form.
  81.    */
  82.   virtual QString type() const = 0;
  83.  
  84.   /**
  85.    * The source in readable form (this is the filename for files)
  86.    */
  87.   virtual QString sourceComment() const = 0;
  88.  
  89.   /**
  90.    * Used in case an error occurred. For now this is used if the
  91.    * decoder was not able to decode an audiofile
  92.    */
  93.   virtual bool isValid() const { return true; }
  94.  
  95.   /**
  96.    * The doc the source is currently a part of or null.
  97.    */
  98.   K3bAudioDoc* doc() const;
  99.   K3bAudioTrack* track() const { return m_track; }
  100.  
  101.   K3bAudioDataSource* prev() const { return m_prev; }
  102.   K3bAudioDataSource* next() const { return m_next; }
  103.  
  104.   K3bAudioDataSource* take();
  105.  
  106.   void moveAfter( K3bAudioDataSource* track );
  107.   void moveAhead( K3bAudioDataSource* track );
  108.  
  109.   /**
  110.    * Set the start offset from the beginning of the source's originalLength.
  111.    */
  112.   virtual void setStartOffset( const K3b::Msf& );
  113.  
  114.   /**
  115.    * Set the end offset from the beginning of the file. The endOffset sector
  116.    * is not included in the data.
  117.    * The maximum value is originalLength() which means to use all data.
  118.    * 0 means the same as originalLength().
  119.    * This has to be bigger than the start offset.
  120.    */
  121.   virtual void setEndOffset( const K3b::Msf& );
  122.  
  123.   virtual const K3b::Msf& startOffset() const { return m_startOffset; }
  124.  
  125.   /**
  126.    * The end offset. It is the first sector not included in the data.
  127.    * If 0 the last sector is determined by the originalLength
  128.    */
  129.   virtual const K3b::Msf& endOffset() const { return m_endOffset; }
  130.  
  131.   /**
  132.    * Get the last used sector in the source.
  133.    * The default implementation uses originalLength() and endOffset()
  134.    */
  135.   virtual K3b::Msf lastSector() const;
  136.  
  137.   /**
  138.    * Create a copy of this source which is not part of a list
  139.    */
  140.   virtual K3bAudioDataSource* copy() const = 0;
  141.  
  142.   /**
  143.    * Split the source at position pos and return the splitted source
  144.    * on success.
  145.    * The new source will be moved after this source.
  146.    *
  147.    * The default implementation uses copy() to create a new source instance
  148.    */
  149.   virtual K3bAudioDataSource* split( const K3b::Msf& pos );
  150.  
  151.  protected:
  152.   /**
  153.    * Informs the parent track about changes.
  154.    */
  155.   void emitChange();
  156.  
  157.  private:
  158.   void fixupOffsets();
  159.  
  160.   K3bAudioTrack* m_track;
  161.   K3bAudioDataSource* m_prev;
  162.   K3bAudioDataSource* m_next;
  163.  
  164.   K3b::Msf m_startOffset;
  165.   K3b::Msf m_endOffset;
  166. };
  167.  
  168. #endif
  169.