From: <man...@us...> - 2013-09-01 08:50:25
|
Revision: 2625 http://sourceforge.net/p/modplug/code/2625 Author: manxorist Date: 2013-09-01 08:50:08 +0000 (Sun, 01 Sep 2013) Log Message: ----------- [New] libopenmpt: Add heuristic to detect the used charset based on module type. [Mod] OpenMPT: Version is now 1.22.05.01 Modified Paths: -------------- trunk/OpenMPT/common/versionNumber.h trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp trunk/OpenMPT/soundlib/Snd_defs.h trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/soundlib/Tables.cpp Modified: trunk/OpenMPT/common/versionNumber.h =================================================================== --- trunk/OpenMPT/common/versionNumber.h 2013-09-01 08:32:23 UTC (rev 2624) +++ trunk/OpenMPT/common/versionNumber.h 2013-09-01 08:50:08 UTC (rev 2625) @@ -17,7 +17,7 @@ #define VER_MAJORMAJOR 1 #define VER_MAJOR 22 #define VER_MINOR 05 -#define VER_MINORMINOR 00 +#define VER_MINORMINOR 01 //Version string. For example "1.17.02.28" #define MPT_VERSION_STR VER_STRINGIZE(VER_MAJORMAJOR) "." VER_STRINGIZE(VER_MAJOR) "." VER_STRINGIZE(VER_MINOR) "." VER_STRINGIZE(VER_MINORMINOR) Modified: trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-09-01 08:32:23 UTC (rev 2624) +++ trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-09-01 08:50:08 UTC (rev 2625) @@ -786,17 +786,22 @@ std::vector<std::string> module_impl::get_ctls() const { std::vector<std::string> retval; + retval.push_back( "charset" ); return retval; } std::string module_impl::ctl_get( const std::string & ctl ) const { if ( ctl == "" ) { throw openmpt::exception("unknown ctl"); + } else if ( ctl == "charset" ) { + return m_sndFile->GetCharset().second; } throw openmpt::exception("unknown ctl"); } void module_impl::ctl_set( const std::string & ctl, const std::string & value ) { if ( ctl == "" ) { throw openmpt::exception("unknown ctl: " + ctl + " := " + value); + } else if ( ctl == "charset" ) { + throw openmpt::exception("ctl is read-only: " + ctl); } throw openmpt::exception("unknown ctl: " + ctl + " := " + value); } Modified: trunk/OpenMPT/soundlib/Snd_defs.h =================================================================== --- trunk/OpenMPT/soundlib/Snd_defs.h 2013-09-01 08:32:23 UTC (rev 2624) +++ trunk/OpenMPT/soundlib/Snd_defs.h 2013-09-01 08:50:08 UTC (rev 2625) @@ -113,6 +113,14 @@ DECLARE_FLAGSET(MODTYPE) +enum MOD_CHARSET_CERTAINTY +{ + MOD_CHARSET_UNKNOWN, + MOD_CHARSET_MAYBE, + MOD_CHARSET_IS, +}; + + // For compatibility mode #define TRK_IMPULSETRACKER (MOD_TYPE_IT | MOD_TYPE_MPT) #define TRK_FASTTRACKER2 (MOD_TYPE_XM) Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-09-01 08:32:23 UTC (rev 2624) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-09-01 08:50:08 UTC (rev 2625) @@ -447,6 +447,9 @@ bool TypeIsIT_MPT_XM() const { return (m_nType & (MOD_TYPE_IT | MOD_TYPE_MPT | MOD_TYPE_XM)) != 0; } bool TypeIsS3M_IT_MPT() const { return (m_nType & (MOD_TYPE_S3M | MOD_TYPE_IT | MOD_TYPE_MPT)) != 0; } + // rough heuristic, could be improved + std::pair<MOD_CHARSET_CERTAINTY, std::string> GetCharset() const { return GetCharsetFromModType(GetType()); } + void SetPreAmp(UINT vol); UINT GetPreAmp() const { return m_MixerSettings.m_nPreAmp; } @@ -542,6 +545,7 @@ bool ReadMID(const LPCBYTE lpStream, DWORD dwMemLength, ModLoadingFlags loadFlags = loadCompleteModule); static std::vector<const char *> GetSupportedExtensions(bool otherFormats); + static std::pair<MOD_CHARSET_CERTAINTY, std::string> GetCharsetFromModType(MODTYPE modtype); static const char * ModTypeToString(MODTYPE modtype); static std::string ModTypeToTracker(MODTYPE modtype); Modified: trunk/OpenMPT/soundlib/Tables.cpp =================================================================== --- trunk/OpenMPT/soundlib/Tables.cpp 2013-09-01 08:32:23 UTC (rev 2624) +++ trunk/OpenMPT/soundlib/Tables.cpp 2013-09-01 08:50:08 UTC (rev 2625) @@ -121,6 +121,69 @@ #endif +struct ModCharsetInfo { + MODTYPE type; + MOD_CHARSET_CERTAINTY certainty; + const char *charset; +}; + +static const ModCharsetInfo ModCharsetInfos[] = +{ + // Amiga + { MOD_TYPE_OKT , MOD_CHARSET_IS , "Amiga-1251" }, + { MOD_TYPE_DBM , MOD_CHARSET_IS , "Amiga-1251" }, + { MOD_TYPE_DIGI, MOD_CHARSET_IS , "Amiga-1251" }, + // Amiga // DOS + { MOD_TYPE_MOD , MOD_CHARSET_MAYBE , "Amiga-1251" }, + { MOD_TYPE_MED , MOD_CHARSET_MAYBE , "Amiga-1251" }, + // DOS + { MOD_TYPE_S3M , MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_XM , MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_MTM , MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_IT , MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_669 , MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_STM , MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_FAR , MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_AMF , MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_AMF0, MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_MDL , MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_DMF , MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_PTM , MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_PSM , MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_J2B , MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_IMF , MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_ULT , MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_AMS , MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_AMS2, MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_DSM , MOD_CHARSET_IS , "cp437" }, + // Windows + { MOD_TYPE_MT2 , MOD_CHARSET_MAYBE , "Windows-1252"}, + { MOD_TYPE_MPT , MOD_CHARSET_MAYBE , "Windows-1252"}, + // random stuff + { MOD_TYPE_MID , MOD_CHARSET_IS , "US-ASCII" }, + { MOD_TYPE_WAV , MOD_CHARSET_MAYBE , "US-ASCII" }, + // end + { MOD_TYPE_NONE, MOD_CHARSET_UNKNOWN, "" } +}; + + +std::pair<MOD_CHARSET_CERTAINTY, std::string> CSoundFile::GetCharsetFromModType(MODTYPE modtype) +//---------------------------------------------------------------------------------------------- +{ + // This is just a rough heuristic. + // It could be improved by adjusting the charset according to the tracker that had been used to save the file. + for(const ModCharsetInfo *charsetInfoIt = ModCharsetInfos; charsetInfoIt->type != MOD_TYPE_NONE; ++charsetInfoIt) + { + if(charsetInfoIt->type == modtype) + { + return std::make_pair(charsetInfoIt->certainty, charsetInfoIt->charset); + } + } + // fallback + return std::make_pair(MOD_CHARSET_UNKNOWN, ""); +} + + std::vector<const char *> CSoundFile::GetSupportedExtensions(bool otherFormats) //----------------------------------------------------------------------------- { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |