00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 ).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,
00077 true,
00078 false,
00079 true,
00080 true,
00081 true,
00082 false );
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 , long samples,
00143 long &samplesRead, int )
00144 {
00145 unsigned long totalAmountInBytes = samples * s_bytesPerSample * s_channels;
00146 samplesRead = Read( output, totalAmountInBytes );
00147
00148
00149
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
00263