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 / k3baudioencoder.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-05-27  |  5.8 KB  |  204 lines

  1. /* 
  2.  *
  3.  * $Id: k3baudioencoder.h 619556 2007-01-03 17:38:12Z trueg $
  4.  * Copyright (C) 2003 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_ENCODER_H_
  17. #define _K3B_AUDIO_ENCODER_H_
  18.  
  19. #include <k3bplugin.h>
  20.  
  21. #include <k3bmsf.h>
  22. #include "k3b_export.h"
  23.  
  24.  
  25. /**
  26.  * The base class for all audio encoders.
  27.  * Do not be alarmed by the number of methods since most of them
  28.  * do not need to be touched. They are just there to keep the API 
  29.  * clean and extendable.
  30.  *
  31.  * see the skeleton files for further help.
  32.  */
  33. class LIBK3B_EXPORT K3bAudioEncoder : public K3bPlugin
  34. {
  35.   Q_OBJECT
  36.  
  37.  public:
  38.   K3bAudioEncoder( QObject* parent = 0, const char* name = 0 );
  39.   virtual ~K3bAudioEncoder();
  40.  
  41.   // TODO: if the following methods are to be activated the config methods in
  42.   //       K3bPluginConfigWidget also need to be changed since they do not allow
  43.   //       to use an extern config object yet.
  44.   //       Perhaps these two methods should even go into K3bPlugin.
  45.   /**
  46.    * This calls readConfig using the k3bcore config object
  47.    */
  48.   // void readConfig();
  49.  
  50.   /**
  51.    * Force the plugin to read it's configuration
  52.    */
  53.   // virtual void readConfig( KConfig* );
  54.  
  55.   QString group() const { return "AudioEncoder"; }
  56.  
  57.   /**
  58.    * This should return the fileextensions supported by the filetype written in the
  59.    * encoder.
  60.    * May return an empty list in which case the encoder will not be usable (this may come
  61.    * in handy if the encoder is based on some external program or lib which is not 
  62.    * available on runtime.)
  63.    */
  64.   virtual QStringList extensions() const = 0;
  65.  
  66.   /**
  67.    * The filetype as presented to the user.
  68.    */
  69.   virtual QString fileTypeComment( const QString& extension ) const = 0;
  70.  
  71.   /**
  72.    * Determine the filesize of the encoded file (~)
  73.    * default implementation returnes -1 (unknown)
  74.    * First parameter is the extension to be used
  75.    */
  76.   virtual long long fileSize( const QString&, const K3b::Msf& ) const { return -1; }
  77.  
  78.   /**
  79.    * The default implementation openes the file for writing with 
  80.    * writeData. Normally this does not need to be reimplemented.
  81.    * @param extension the filetype to be used.
  82.    *
  83.    */
  84.   virtual bool openFile( const QString& extension, const QString& filename, const K3b::Msf& length );
  85.  
  86.  
  87.   /**
  88.    * The default implementation returnes true if openFile (default implementation) has been
  89.    * successfully called. Normally this does not need to be reimplemented but it has to be 
  90.    * if openFile is reimplemented.
  91.    */
  92.   virtual bool isOpen() const;
  93.  
  94.   /**
  95.    * The default implementation closes the file opened by openFile
  96.    * (default implementation) 
  97.    * Normally this does not need to be reimplemented but it has to be 
  98.    * if openFile is reimplemented.
  99.    */
  100.   virtual void closeFile();
  101.  
  102.   /**
  103.    * The default implementation returnes the filename set in openFile
  104.    * or QString::null if no file has been opened.
  105.    * Normally this does not need to be reimplemented but it has to be 
  106.    * if openFile is reimplemented.
  107.    */
  108.   virtual const QString& filename() const;
  109.  
  110.   enum MetaDataField {
  111.     META_TRACK_TITLE,
  112.     META_TRACK_ARTIST,
  113.     META_TRACK_COMMENT,
  114.     META_TRACK_NUMBER,
  115.     META_ALBUM_TITLE,
  116.     META_ALBUM_ARTIST,
  117.     META_ALBUM_COMMENT,
  118.     META_YEAR,
  119.     META_GENRE };
  120.  
  121.   /**
  122.    * Calling this method does only make sense after successfully
  123.    * calling openFile and before calling encode.
  124.    * This calls setMetaDataInternal.
  125.    */
  126.   void setMetaData( MetaDataField, const QString& );
  127.  
  128.   /**
  129.    * Returnes the amount of actually written bytes or -1 if an error
  130.    * occurred.
  131.    *
  132.    * Be aware that the returned amount of written data may very well differ
  133.    * from len since the data is encoded.
  134.    */
  135.   long encode( const char*, Q_ULONG len );
  136.  
  137.   /**
  138.    * Use this signal in case of an error to provide the user with information
  139.    * about the problem.
  140.    */
  141.   virtual QString lastErrorString() const;
  142.  
  143.  protected:
  144.   /**
  145.    * Called by the default implementation of openFile
  146.    * This calls initEncoderInternal.
  147.    */
  148.   bool initEncoder( const QString& extension, const K3b::Msf& length );
  149.  
  150.   /**
  151.    * Called by the deafult implementation of openFile
  152.    * This calls finishEncoderInternal.
  153.    */
  154.   void finishEncoder();
  155.  
  156.   /**
  157.    * Use this to write the data to the file when
  158.    * using the default implementation of openFile
  159.    * Returnes the number of bytes actually written.
  160.    */
  161.   Q_LONG writeData( const char*, Q_ULONG len );
  162.  
  163.   /**
  164.    * initzialize the decoder structures.
  165.    * default implementation does nothing
  166.    * this may already write data.
  167.    */
  168.   virtual bool initEncoderInternal( const QString& extension, const K3b::Msf& length );
  169.  
  170.   /**
  171.    * reimplement this if the encoder needs to do some
  172.    * finishing touch.
  173.    */
  174.   virtual void finishEncoderInternal();
  175.  
  176.   /**
  177.    * encode the data and write it with writeData (when using
  178.    * the default)
  179.    * The data will always be 16bit 44100 Hz stereo little endian samples.
  180.    * Should return the amount of actually written bytes (may be 0) and -1
  181.    * on error.
  182.    */
  183.   // TODO: use Q_INT16* instead of char*
  184.   // FIXME: why little endian while CDs use big endian???
  185.   virtual long encodeInternal( const char*, Q_ULONG len ) = 0;
  186.  
  187.   /**
  188.    * default implementation does nothing
  189.    * this may already write data.
  190.    */
  191.   virtual void setMetaDataInternal( MetaDataField, const QString& );
  192.  
  193.   /**
  194.    * Use this in combination with the default implementation of lastError()
  195.    */
  196.   void setLastError( const QString& );
  197.  
  198.  private:
  199.   class Private;
  200.   Private* d;
  201. };
  202.  
  203. #endif
  204.