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 / audiocdencoder.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-01-19  |  4.6 KB  |  146 lines

  1. /*
  2.   Copyright (C) 2004, 2005 Benjamin Meyer <ben at meyerhome dot net>
  3.  
  4.   This program is free software; you can redistribute it and/or modify
  5.   it under the terms of the GNU General Public License as published by
  6.   the Free Software Foundation; either version 2 of the License, or
  7.   (at your option) any later version.
  8.  
  9.   This program is distributed in the hope that it will be useful,
  10.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12.   GNU General Public License for more details.
  13.  
  14.   You should have received a copy of the GNU General Public License
  15.   along with this program; if not, write to the Free Software
  16.   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17. */
  18.  
  19. #ifndef AUDIOCD_ENCODER_H
  20. #define AUDIOCD_ENCODER_H
  21.  
  22. #include <sys/types.h>
  23. #include <kio/slavebase.h>
  24. #include <cdinfo.h>
  25.  
  26. class KConfigSkeleton;
  27. using namespace KCDDB;
  28.  
  29. class AudioCDEncoder {
  30.  
  31. public:
  32.   /**
  33.    * Constructor.
  34.    * @param slave parent that this classes can use to call data() with
  35.    * when finished encoding bits.
  36.    */ 
  37.   explicit AudioCDEncoder(KIO::SlaveBase *slave) : ioslave(slave) {};
  38.   
  39.   /**
  40.    * Deconstructor.
  41.    */
  42.   virtual ~AudioCDEncoder(){};
  43.   
  44.   /**
  45.    * Initiallizes the decoder, loading libraries, etc.  Encoders
  46.    * that don't return true will will deleted and not used.
  47.    * @returns false if unable to initialize the encoder.
  48.    */
  49.   virtual bool init() = 0;
  50.  
  51.   /**
  52.    * The encoder should read in its config data here.
  53.    */ 
  54.   virtual void loadSettings() = 0;
  55.  
  56.   /**
  57.    * Helper function to determine the end size of a
  58.    * encoded file.
  59.    * @param time_secs the lengh of the audio track in seconds.
  60.    * @returns the size of a file if it is time_secs in length.
  61.    */ 
  62.   virtual unsigned long size(long time_secs) const = 0;
  63.  
  64.   /**
  65.    * @returns the generic user string type/name of this encoder
  66.    * Examples: "MP3", "Ogg Vorbis", "Wav", "FID Level 2", etc
  67.    */ 
  68.   virtual QString type() const = 0;
  69.   
  70.   /**
  71.    * @returns the mime type for the files this encoder produces.
  72.    * Example: "audio/x-wav"
  73.    */ 
  74.   virtual const char * mimeType() const = 0;
  75.  
  76.   /**
  77.    * @returns the file type for the files this encoder produces.
  78.    * Used in naming of the file for example foo.mp3
  79.    * Examples: "mp3", "ogg", "wav"
  80.    */ 
  81.   virtual const char * fileType() const = 0;
  82.  
  83.   /**
  84.    * Before the read functions are called this is 
  85.    * called to allow the encoders to store the cddb
  86.    * information if they want to so it can be inserted 
  87.    * where neccessary (start, middle, end, or combos etc).
  88.    */ 
  89.   virtual void fillSongInfo( KCDDB::CDInfo info, int track, const QString &comment ) = 0;
  90.   
  91.   /**
  92.    * Perform any initial file creation necessary for a new song (that
  93.    * has just been sent via fillSongInfo())
  94.    * @param size - the total binary size of the end file (via size()).
  95.    * @return size of the data that was created by this function.
  96.    */ 
  97.   virtual long readInit(long size) = 0;
  98.   
  99.   /**
  100.    * Passes a little bit of cd data to be encoded
  101.    * This function is most likly called many many times.
  102.    * @param buf pointer to the audio that has been read in so far
  103.    * @param frames the number of frames of audio that are in buf
  104.    * @return size of the data that was created by this function, -1 on error.
  105.    */
  106.   virtual long read(int16_t * buf, int frames) = 0;
  107.  
  108.   /**
  109.    * Perform any final file creation/padding that is necessary
  110.    * @return size of the data that was created by this function.
  111.    */ 
  112.   virtual long readCleanup() = 0;
  113.  
  114.   /**
  115.    * Returns a configure widget for the encoder
  116.    */ 
  117.   virtual QWidget* getConfigureWidget(KConfigSkeleton** manager) const
  118.                    { Q_UNUSED(manager); return NULL; }; 
  119.  
  120.   /**
  121.    * Returns the last error message; called when e.g. read() returns -1.
  122.    */
  123.   virtual QString lastErrorMessage() const { return QString::null; }
  124.  
  125.   /**
  126.    * Helper function to load all of the AudioCD Encoders from libraries.
  127.    * Uses KStandardDirs to find where libraries could be, opens all of the ones
  128.    * that we might own audiocd_encoder_* and then uses the symbol 
  129.    * create_audiocd_encoders to obtain the encoders from that library.
  130.    * @param slave ioslave needed if the plugin is going to be used to encode something.
  131.    * @param encoders container for new encoders.
  132.    */
  133.   static void findAllPlugins(KIO::SlaveBase *slave, QPtrList<AudioCDEncoder> &encoders);
  134.  
  135. protected:
  136.   /**
  137.    * Pointer to the ioslave that is running this encoder.
  138.    * Used (only?) for the data() function to pass back encoded data.
  139.    */
  140.   KIO::SlaveBase *ioslave;
  141.  
  142. };
  143.  
  144. #endif // AUDIOCD_ENCODER_H
  145.  
  146.