00001 00002 // Name: mp3encoder.h 00003 // Purpose: A wxWidgets wrapper around LAME 00004 // Author: Julian Smart 00005 // Modified by: 00006 // Created: 2009-02-10 00007 // RCS-ID: 00008 // Copyright: (c) Julian Smart 00009 // Licence: New BSD License 00011 00012 #ifndef _MP3ENCODER_H_ 00013 #define _MP3ENCODER_H_ 00014 00015 /* 00016 * Includes 00017 */ 00018 00019 #include "wx/dynarray.h" 00020 00021 /* 00022 * Styles and types 00023 */ 00024 00025 // MPEG1 format 00026 #define wxMP3ENCODER_OPTION_MPEG1 0x01 00027 00028 // MPEG2 format 00029 #define wxMP3ENCODER_OPTION_MPEG2 0x02 00030 00031 // Include ID3 information 00032 #define wxMP3ENCODER_OPTION_ID3 0x04 00033 00034 // Quiet operation 00035 #define wxMP3ENCODER_OPTION_QUIET 0x08 00036 00045 class wxID3Info 00046 { 00047 public: 00048 wxID3Info() { Init(); } 00049 wxID3Info(const wxID3Info& info) { Init(); Copy(info); } 00050 00051 void operator=(const wxID3Info& info) { Copy(info); } 00052 bool operator==(const wxID3Info& info) const; 00053 void Copy(const wxID3Info& info); 00054 void Init(); 00055 00056 void SetTitle(const wxString& title) { m_title = title; } 00057 const wxString& GetTitle() const { return m_title; } 00058 00059 void SetArtist(const wxString& artist) { m_artist = artist; } 00060 const wxString& GetArtist() const { return m_artist; } 00061 00062 void SetAlbum(const wxString& album) { m_album = album; } 00063 const wxString& GetAlbum() const { return m_album; } 00064 00065 void SetYear(const wxString& year) { m_year = year; } 00066 const wxString& GetYear() const { return m_year; } 00067 00068 void SetComment(const wxString& comment) { m_comment = comment; } 00069 const wxString& GetComment() const { return m_comment; } 00070 00071 void SetGenre(const wxString& genre) { m_genre = genre; } 00072 const wxString& GetGenre() const { return m_genre; } 00073 00074 void SetTrackNumber(int trackNumber) { m_trackNumber = trackNumber; } 00075 int GetTrackNumber() const { return m_trackNumber; } 00076 00077 void SetTrackCount(int trackCount) { m_trackCount = trackCount; } 00078 int GetTrackCount() const { return m_trackCount; } 00079 00080 protected: 00081 wxString m_title; 00082 wxString m_artist; 00083 wxString m_album; 00084 wxString m_year; 00085 wxString m_comment; 00086 wxString m_genre; 00087 int m_trackNumber; 00088 int m_trackCount; 00089 }; 00090 00091 WX_DECLARE_OBJARRAY(wxID3Info, wxID3InfoArray); 00092 00101 class wxMP3EncoderInfo 00102 { 00103 public: 00104 wxMP3EncoderInfo() { Init(); } 00105 00106 void Init() { m_enabled = true; m_bitRate = 128; } 00107 void Copy(const wxMP3EncoderInfo& info) 00108 { m_enabled = info.m_enabled; m_encoderPath = info.m_encoderPath; m_bitRate = info.m_bitRate; } 00109 void operator=(const wxMP3EncoderInfo& info) { Copy(info); } 00110 00111 bool m_enabled; 00112 int m_bitRate; 00113 wxString m_encoderPath; 00114 }; 00115 00124 class wxMP3EncoderProcess; 00125 00126 class wxMP3Encoder: public wxEvtHandler 00127 { 00128 DECLARE_DYNAMIC_CLASS( wxMP3Encoder ) 00129 00130 public: 00131 // Constructors 00132 00133 wxMP3Encoder(); 00134 ~wxMP3Encoder(); 00135 00136 // Operations 00137 00139 void Init(); 00140 00142 virtual bool Encode(const wxString& inputFilename, const wxString& outputFilename, int options = 0); 00143 00145 virtual bool IsEncoding() { return (GetProcess() != NULL); } 00146 00148 virtual bool Stop(); 00149 00151 void SetOptions(int options) { m_options = options; } 00152 int GetOptions() const { return m_options; } 00153 00155 void SetInfo(const wxMP3EncoderInfo& info) { m_info = info; } 00156 const wxMP3EncoderInfo& GetInfo() const { return m_info; } 00157 00159 void SetProgramLocation(const wxString& location) { m_info.m_encoderPath = location; } 00160 const wxString& GetProgramLocation() const { return m_info.m_encoderPath; } 00161 00163 void SetExtraSwitches(const wxString& switches) { m_extraSwitches = switches; } 00164 const wxString& GetExtraSwitches() const { return m_extraSwitches; } 00165 00167 void SetID3(const wxID3Info& info) { m_id3Info = info; } 00168 const wxID3Info& GetID3Info() const { return m_id3Info; } 00169 00171 void SetBitRate(int bitRate) { m_info.m_bitRate = bitRate; } 00172 int GetBitRate() const { return m_info.m_bitRate; } 00173 00175 void SetLastCommand(const wxString& command) { m_command = command; } 00176 const wxString& GetLastCommand() const { return m_command; } 00177 00179 void SetErrorCode(int errorCode) { m_errorCode = errorCode; } 00180 int GetErrorCode() const { return m_errorCode; } 00181 00183 void SetPID(long pid) { m_pid = pid; } 00184 long GetPID() const { return m_pid; } 00185 00187 void SetOutput(const wxArrayString& output) { m_output = output; } 00188 const wxArrayString& GetOutput() const { return m_output; } 00189 00191 void WriteOutput(const wxString& output) { m_output.Add(output); } 00192 00194 bool ProcessInput(); 00195 00197 void SetProcess(wxMP3EncoderProcess* process) { m_process = process; } 00198 wxMP3EncoderProcess* GetProcess() const { return m_process; } 00199 00200 protected: 00201 int m_options; // remember the options 00202 00203 wxMP3EncoderInfo m_info; 00204 //wxString m_programLocation; 00205 //wxString m_voice; 00206 wxString m_command; 00207 wxString m_extraSwitches; 00208 wxArrayString m_output; 00209 //int m_bitRate; 00210 wxID3Info m_id3Info; 00211 int m_errorCode; 00212 wxMP3EncoderProcess* m_process; 00213 long m_pid; 00214 }; 00215 00216 #endif 00217 // _MP3ENCODER_H_ 00218