Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

modplugin.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2002 Simon Hausmann <hausmann@kde.org>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #include "modplugin.h"
00021 
00022 #include "memfile.h"
00023 
00024 #include <qfileinfo.h>
00025 
00026 ModPlugin::ModPlugin()
00027 {
00028 }
00029 
00030 ModPlugin::~ModPlugin()
00031 {
00032     close();
00033 }
00034 
00035 const char *ModPlugin::pluginName()
00036 {
00037     return "ModPlugin";
00038 }
00039 
00040 const char *ModPlugin::pluginComment()
00041 {
00042     return "LibModPlug based MOD/XM/S3M/IT module player plugin";
00043 }
00044 
00045 double ModPlugin::pluginVersion()
00046 {
00047     return 1.0;
00048 }
00049 
00050 bool ModPlugin::isFileSupported( const QString &file )
00051 {
00052     static const char * const patterns [] =
00053     {
00054         "669", "amf", "apun", "dsm", "far", "gdm", "imf", "it",
00055         "med", "mod", "mtm", "nst", "s3m", "stm", "stx", "ult",
00056         "uni", "xm"
00057     };
00058     static const uchar patternCount = sizeof( patterns ) / sizeof( patterns[ 0 ] );
00059 
00060     QString ext = QFileInfo( file ).extension( false /* complete */ ).lower();
00061     for ( uchar i = 0; i < patternCount; ++i )
00062         if ( QString::fromLatin1( patterns[ i ] ) == ext )
00063             return true;
00064 
00065     return false;
00066 }
00067 
00068 bool ModPlugin::open( const QString &_file )
00069 {
00070     MemFile f( _file );
00071     if ( !f.open( IO_ReadOnly ) )
00072         return false;
00073 
00074     CSoundFile::SetWaveConfig( s_frequency, s_bytesPerSample * 8, s_channels );
00075 
00076     CSoundFile::SetWaveConfigEx( false, /* surround */
00077                                  true, /* no oversampling */
00078                                  false, /* reverb */
00079                                  true, /* high quality resampler */
00080                                  true, /* megabass ;) */
00081                                  true, /* noise reduction */
00082                                  false /* some eq stuff I didn't really understand..*/ );
00083 
00084     CSoundFile::SetResamplingMode( SRCMODE_POLYPHASE );
00085 
00086     QByteArray &rawData = f.data();
00087     if ( !Create( reinterpret_cast<BYTE *>( rawData.data() ), rawData.size() ) )
00088         return false;
00089 
00090     m_songTime = GetSongTime();
00091     m_maxPosition = GetMaxPosition();
00092     return true;
00093 }
00094 
00095 bool ModPlugin::close()
00096 {
00097     return Destroy();
00098 }
00099 
00100 bool ModPlugin::isOpen()
00101 {
00102     return m_nType != MOD_TYPE_NONE;
00103 }
00104 
00105 const QString &ModPlugin::fileInfo()
00106 {
00107     return QString::null; // ###
00108 }
00109 
00110 int ModPlugin::audioStreams()
00111 {
00112     return 1;
00113 }
00114 
00115 int ModPlugin::audioChannels( int )
00116 {
00117     return s_channels;
00118 }
00119 
00120 int ModPlugin::audioFrequency( int )
00121 {
00122     return s_frequency;
00123 }
00124 
00125 int ModPlugin::audioSamples( int )
00126 {
00127     return m_songTime * s_frequency;
00128 }
00129 
00130 bool ModPlugin::audioSetSample( long sample, int )
00131 {
00132     float position = ( sample / s_frequency ) * m_maxPosition / m_songTime;
00133     SetCurrentPos( (int)position );
00134     return true;
00135 }
00136 
00137 long ModPlugin::audioGetSample( int )
00138 {
00139     return GetCurrentPos() * s_frequency;
00140 }
00141 
00142 bool ModPlugin::audioReadSamples( short *output, int /*channels*/, long samples,
00143                                         long &samplesRead, int )
00144 {
00145     unsigned long totalAmountInBytes = samples * s_bytesPerSample * s_channels;
00146     samplesRead = Read( output, totalAmountInBytes );
00147     // it can happen that our prediction about the total amount of samples
00148     // is wrong. The mediaplayer can't handle the situation of returning 0 read bytes
00149     // very well. So instead let's fill up the remaining bytes with zeroes.
00150     if ( samplesRead == 0 ) 
00151     {
00152         memset( reinterpret_cast<char *>( output ), 0, totalAmountInBytes );
00153         samplesRead = samples;
00154     }
00155 
00156     return true;
00157 }
00158 
00159 int ModPlugin::videoStreams()
00160 {
00161     return 0;
00162 }
00163 
00164 int ModPlugin::videoWidth( int )
00165 {
00166     return 0;
00167 }
00168 
00169 int ModPlugin::videoHeight( int )
00170 {
00171     return 0;
00172 }
00173 
00174 double ModPlugin::videoFrameRate( int )
00175 {
00176     return 0;
00177 }
00178 
00179 int ModPlugin::videoFrames( int )
00180 {
00181     return 0;
00182 }
00183 
00184 bool ModPlugin::videoSetFrame( long, int )
00185 {
00186     return 0;
00187 }
00188 
00189 long ModPlugin::videoGetFrame( int )
00190 {
00191     return 0;
00192 }
00193 
00194 bool ModPlugin::videoReadFrame( unsigned char **, int, int, int, int, 
00195                                       ColorFormat, int )
00196 {
00197     return false;
00198 }
00199 
00200 bool ModPlugin::videoReadScaledFrame( unsigned char **, int, int, int, int, 
00201                                             int, int, ColorFormat, int )
00202 {
00203     return false;
00204 }
00205 
00206 bool ModPlugin::videoReadYUVFrame( char *, char *, char *, int, int, int, 
00207                                          int, int )
00208 {
00209     return false;
00210 }
00211 
00212 double ModPlugin::getTime()
00213 {
00214     return 0.0; // ###
00215 }
00216 
00217 bool ModPlugin::setSMP( int )
00218 {
00219     return false;
00220 }
00221 
00222 bool ModPlugin::setMMX( bool )
00223 {
00224     return false;
00225 }
00226 
00227 bool ModPlugin::supportsAudio()
00228 {
00229     return true;
00230 }
00231 
00232 bool ModPlugin::supportsVideo()
00233 {
00234     return false;
00235 }
00236 
00237 bool ModPlugin::supportsYUV()
00238 {
00239     return false;
00240 }
00241 
00242 bool ModPlugin::supportsMMX()
00243 {
00244     return false;
00245 }
00246 
00247 bool ModPlugin::supportsSMP()
00248 {
00249     return false;
00250 }
00251 
00252 bool ModPlugin::supportsStereo()
00253 {
00254     return true;
00255 }
00256 
00257 bool ModPlugin::supportsScaling()
00258 {
00259     return false;
00260 }
00261 
00262 /* vim: et sw=4
00263  */

Generated on Sat Nov 5 16:15:41 2005 for OPIE by  doxygen 1.4.2