From: <man...@us...> - 2013-04-11 14:29:19
|
Revision: 1834 http://sourceforge.net/p/modplug/code/1834 Author: manxorist Date: 2013-04-11 14:29:08 +0000 (Thu, 11 Apr 2013) Log Message: ----------- [Ref] At a bunch of places in CSoundFile, #ifdef MODPLUG_TRACKER was checked in case where log message were to be added to the CModDoc log. Add an AddToLog function directly to CSoundFile and do the #ifdef MODPLUG_TRACKER check there. Log to std::clog otherwise. [Ref] Replace the open-coded strcpy'ing and reallocating of the log in CModDoc with a straigt std::vector<std::string> instead. [Ref] Remove AddLogEvent and convert its single usage site to AddToLog. [Ref] Make log messages consistent, they should not contain a \n at the end. Modified Paths: -------------- trunk/OpenMPT/common/Reporting.cpp trunk/OpenMPT/common/misc_util.cpp trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/mptrack/CleanupSong.cpp trunk/OpenMPT/mptrack/MPTHacks.cpp trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/Moddoc.h trunk/OpenMPT/soundlib/Load_it.cpp trunk/OpenMPT/soundlib/Load_mo3.cpp trunk/OpenMPT/soundlib/Load_mod.cpp trunk/OpenMPT/soundlib/Load_s3m.cpp trunk/OpenMPT/soundlib/Load_xm.cpp trunk/OpenMPT/soundlib/ModSequence.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/Sndfile.h Modified: trunk/OpenMPT/common/Reporting.cpp =================================================================== --- trunk/OpenMPT/common/Reporting.cpp 2013-04-11 10:40:13 UTC (rev 1833) +++ trunk/OpenMPT/common/Reporting.cpp 2013-04-11 14:29:08 UTC (rev 1834) @@ -41,7 +41,7 @@ return result; #else - std::cout << caption << std::endl << text << std::endl; + std::clog << caption << std::endl << text << std::endl; return 0; #endif // MODPLUG_TRACKER } Modified: trunk/OpenMPT/common/misc_util.cpp =================================================================== --- trunk/OpenMPT/common/misc_util.cpp 2013-04-11 10:40:13 UTC (rev 1833) +++ trunk/OpenMPT/common/misc_util.cpp 2013-04-11 14:29:08 UTC (rev 1834) @@ -65,13 +65,6 @@ #endif // MODPLUG_TRACKER -std::basic_string<TCHAR> Util::sdTime::GetDateTimeStr() -{ - time_t t; - std::time(&t); - return _tctime(&t); -} - time_t Util::sdTime::MakeGmTime(tm& timeUtc) { return _mkgmtime(&timeUtc); Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2013-04-11 10:40:13 UTC (rev 1833) +++ trunk/OpenMPT/common/misc_util.h 2013-04-11 14:29:08 UTC (rev 1834) @@ -355,8 +355,6 @@ #ifdef MODPLUG_TRACKER namespace Util { namespace sdTime { - // Returns string containing date and time ended with newline. - std::basic_string<TCHAR> GetDateTimeStr(); time_t MakeGmTime(tm& timeUtc); Modified: trunk/OpenMPT/mptrack/CleanupSong.cpp =================================================================== --- trunk/OpenMPT/mptrack/CleanupSong.cpp 2013-04-11 10:40:13 UTC (rev 1833) +++ trunk/OpenMPT/mptrack/CleanupSong.cpp 2013-04-11 14:29:08 UTC (rev 1834) @@ -505,7 +505,7 @@ modDoc.GetPatternUndo().ClearUndo(); if (nPatRemoved) { - wsprintf(s, "%d pattern%s removed.\n", nPatRemoved, (nPatRemoved == 1) ? "" : "s"); + wsprintf(s, "%d pattern%s removed.", nPatRemoved, (nPatRemoved == 1) ? "" : "s"); modDoc.AddToLog(s); } return true; @@ -555,7 +555,7 @@ if(nRemoved > 0) { - wsprintf(s, "%d unused sample%s removed\n" , nRemoved, (nRemoved == 1) ? "" : "s"); + wsprintf(s, "%d unused sample%s removed" , nRemoved, (nRemoved == 1) ? "" : "s"); modDoc.AddToLog(s); } @@ -622,7 +622,7 @@ } } } - wsprintf(s, "%d sample loop%s optimized\n" ,numLoopOpt, (numLoopOpt == 1) ? "" : "s"); + wsprintf(s, "%d sample loop%s optimized" ,numLoopOpt, (numLoopOpt == 1) ? "" : "s"); modDoc.AddToLog(s); return true; } @@ -734,7 +734,7 @@ EndWaitCursor(); char s[64]; - wsprintf(s, "%d unused instrument%s removed\n", numRemoved, (numRemoved == 1) ? "" : "s"); + wsprintf(s, "%d unused instrument%s removed", numRemoved, (numRemoved == 1) ? "" : "s"); modDoc.AddToLog(s); return true; } Modified: trunk/OpenMPT/mptrack/MPTHacks.cpp =================================================================== --- trunk/OpenMPT/mptrack/MPTHacks.cpp 2013-04-11 10:40:13 UTC (rev 1833) +++ trunk/OpenMPT/mptrack/MPTHacks.cpp 2013-04-11 14:29:08 UTC (rev 1834) @@ -175,7 +175,7 @@ } bool foundHacks = false, foundHere = false; - CString message; + mpt::String message; ClearLog(); // Check for plugins @@ -190,7 +190,7 @@ // REQUIRES AUTOFIX } if(foundHere) - AddToLog("Found plugins\n"); + AddToLog("Found plugins"); // Check for invalid order items for(ORDERINDEX i = m_SndFile.Order.GetLengthTailTrimmed(); i > 0; i--) @@ -198,7 +198,7 @@ if(m_SndFile.Order[i - 1] == m_SndFile.Order.GetIgnoreIndex() && !originalSpecs->hasIgnoreIndex) { foundHacks = true; - AddToLog("This format does not support separator (+++) patterns\n"); + AddToLog("This format does not support separator (+++) patterns"); if(autofix) { @@ -212,7 +212,7 @@ if((m_SndFile.GetType() & (MOD_TYPE_MOD | MOD_TYPE_XM)) && m_SndFile.Order.GetLengthFirstEmpty() != m_SndFile.Order.GetLengthTailTrimmed()) { foundHacks = true; - AddToLog("The pattern sequence should end after the first stop (---) index in this format.\n"); + AddToLog("The pattern sequence should end after the first stop (---) index in this format."); if(autofix) { @@ -234,7 +234,7 @@ // Pattern count if(m_SndFile.Patterns.GetNumPatterns() > originalSpecs->patternsMax) { - message.Format("Found too many patterns (%d allowed)\n", originalSpecs->patternsMax); + message.Format("Found too many patterns (%d allowed)", originalSpecs->patternsMax); AddToLog(message); foundHacks = true; // REQUIRES (INTELLIGENT) AUTOFIX @@ -273,7 +273,7 @@ } if(foundHere) { - message.Format("Found incompatible pattern lengths (must be between %d and %d rows)\n", originalSpecs->patternRowsMin, originalSpecs->patternRowsMax); + message.Format("Found incompatible pattern lengths (must be between %d and %d rows)", originalSpecs->patternRowsMin, originalSpecs->patternRowsMax); AddToLog(message); } @@ -282,14 +282,14 @@ m_SndFile.Patterns.ForEachModCommand(FixHackedPatterns(originalSpecs, m_SndFile.GetType(), autofix, &foundHere)); if(foundHere) { - AddToLog("Found invalid pattern commands\n"); + AddToLog("Found invalid pattern commands"); foundHacks = true; } // Check for pattern names if(m_SndFile.Patterns.GetNumNamedPatterns() > 0 && !originalSpecs->hasPatternNames) { - AddToLog("Found pattern names\n"); + AddToLog("Found pattern names"); foundHacks = true; if(autofix) { @@ -303,7 +303,7 @@ // Check for too many channels if(m_SndFile.GetNumChannels() > originalSpecs->channelsMax || m_SndFile.GetNumChannels() < originalSpecs->channelsMin) { - message.Format("Found incompatible channel count (must be between %d and %d channels)\n", originalSpecs->channelsMin, originalSpecs->channelsMax); + message.Format("Found incompatible channel count (must be between %d and %d channels)", originalSpecs->channelsMin, originalSpecs->channelsMax); AddToLog(message); foundHacks = true; if(autofix) @@ -329,12 +329,12 @@ } } if(foundHere) - AddToLog("Found channel names\n"); + AddToLog("Found channel names"); // Check for too many samples if(m_SndFile.GetNumSamples() > originalSpecs->samplesMax) { - message.Format("Found too many samples (%d allowed)\n", originalSpecs->samplesMax); + message.Format("Found too many samples (%d allowed)", originalSpecs->samplesMax); AddToLog(message); foundHacks = true; // REQUIRES (INTELLIGENT) AUTOFIX @@ -358,12 +358,12 @@ } } if(foundHere) - AddToLog("Stereo samples are not supported in the original XM format\n"); + AddToLog("Stereo samples are not supported in the original XM format"); // Check for too many instruments if(m_SndFile.GetNumInstruments() > originalSpecs->instrumentsMax) { - message.Format("Found too many instruments (%d allowed)\n", originalSpecs->instrumentsMax); + message.Format("Found too many instruments (%d allowed)", originalSpecs->instrumentsMax); AddToLog(message); foundHacks = true; // REQUIRES (INTELLIGENT) AUTOFIX @@ -407,14 +407,14 @@ foundHacks |= foundEnvelopes; } if(foundHere) - AddToLog("Found MPT instrument extensions\n"); + AddToLog("Found MPT instrument extensions"); if(foundEnvelopes) - AddToLog("Two envelope points may not share the same tick.\n"); + AddToLog("Two envelope points may not share the same tick."); // Check for too many orders if(m_SndFile.Order.GetLengthTailTrimmed() > originalSpecs->ordersMax) { - message.Format("Found too many orders (%d allowed)\n", originalSpecs->ordersMax); + message.Format("Found too many orders (%d allowed)", originalSpecs->ordersMax); AddToLog(message); foundHacks = true; // REQUIRES (INTELLIGENT) AUTOFIX @@ -423,7 +423,7 @@ // Check for invalid default tempo if(m_SndFile.m_nDefaultTempo > originalSpecs->tempoMax || m_SndFile.m_nDefaultTempo < originalSpecs->tempoMin) { - message.Format("Found incompatible default tempo (must be between %d and %d)\n", originalSpecs->tempoMin, originalSpecs->tempoMax); + message.Format("Found incompatible default tempo (must be between %d and %d)", originalSpecs->tempoMin, originalSpecs->tempoMax); AddToLog(message); foundHacks = true; if(autofix) @@ -433,7 +433,7 @@ // Check for invalid default speed if(m_SndFile.m_nDefaultSpeed > originalSpecs->speedMax || m_SndFile.m_nDefaultSpeed < originalSpecs->speedMin) { - message.Format("Found incompatible default speed (must be between %d and %d)\n", originalSpecs->speedMin, originalSpecs->speedMax); + message.Format("Found incompatible default speed (must be between %d and %d)", originalSpecs->speedMin, originalSpecs->speedMax); AddToLog(message); foundHacks = true; if(autofix) @@ -443,7 +443,7 @@ // Check for invalid rows per beat / measure values if(m_SndFile.m_nDefaultRowsPerBeat >= originalSpecs->patternRowsMax || m_SndFile.m_nDefaultRowsPerMeasure >= originalSpecs->patternRowsMax) { - AddToLog("Found incompatible rows per beat / measure\n"); + AddToLog("Found incompatible rows per beat / measure"); foundHacks = true; if(autofix) { @@ -461,7 +461,7 @@ if(m_SndFile.Patterns[i].GetOverrideSignature()) { if(!foundHere) - AddToLog("Found pattern-specific time signatures\n"); + AddToLog("Found pattern-specific time signatures"); if(autofix) m_SndFile.Patterns[i].RemoveSignature(); @@ -476,7 +476,7 @@ // Check for new tempo modes if(m_SndFile.m_nTempoMode != tempo_mode_classic) { - AddToLog("Found incompatible tempo mode (only classic tempo mode allowed)\n"); + AddToLog("Found incompatible tempo mode (only classic tempo mode allowed)"); foundHacks = true; if(autofix) m_SndFile.m_nTempoMode = tempo_mode_classic; @@ -485,7 +485,7 @@ // Check for extended filter range flag if(m_SndFile.m_SongFlags[SONG_EXFILTERRANGE]) { - AddToLog("Found extended filter range\n"); + AddToLog("Found extended filter range"); foundHacks = true; if(autofix) m_SndFile.m_SongFlags.reset(SONG_EXFILTERRANGE); @@ -494,7 +494,7 @@ // Embedded MIDI configuration in XM files if(m_SndFile.m_SongFlags[SONG_EMBEDMIDICFG] != 0 && m_SndFile.GetType() == MOD_TYPE_XM) { - AddToLog("Found embedded MIDI macros\n"); + AddToLog("Found embedded MIDI macros"); foundHacks = true; if(autofix) { @@ -506,7 +506,7 @@ // Player flags if((m_SndFile.GetType() & (MOD_TYPE_XM|MOD_TYPE_IT)) && !m_SndFile.GetModFlag(MSF_COMPATIBLE_PLAY)) { - AddToLog("Compatible play is deactivated\n"); + AddToLog("Compatible play is deactivated"); foundHacks = true; if(autofix) m_SndFile.SetModFlag(MSF_COMPATIBLE_PLAY, true); @@ -515,7 +515,7 @@ // Check for restart position where it should not be if(m_SndFile.m_nRestartPos > 0 && !originalSpecs->hasRestartPos) { - AddToLog("Found restart position\n"); + AddToLog("Found restart position"); foundHacks = true; if(autofix) { @@ -525,7 +525,7 @@ if(m_SndFile.m_nMixLevels != mixLevels_compatible) { - AddToLog("Found incorrect mix levels (only compatible mix levels allowed)\n"); + AddToLog("Found incorrect mix levels (only compatible mix levels allowed)"); foundHacks = true; if(autofix) m_SndFile.m_nMixLevels = mixLevels_compatible; Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2013-04-11 10:40:13 UTC (rev 1833) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2013-04-11 14:29:08 UTC (rev 1834) @@ -122,7 +122,6 @@ //------------------------------------------------------------ { m_bHasValidPath = false; - m_lpszLog = NULL; m_hWndFollow = NULL; m_notifyType = Notification::Default; @@ -222,10 +221,10 @@ EndWaitCursor(); // Show log messages from loaders. - if (GetLog() != nullptr) + if (GetLog().size() > 0) { CString sTemp; - sTemp.Format("File: %s\nLast saved with: %s, your version is %s\n\n%s", lpszPathName, (LPCTSTR)MptVersion::ToStr(m_SndFile.m_dwLastSavedWithVersion), MptVersion::str, GetLog()); + sTemp.Format("File: %s\nLast saved with: %s, your version is %s\n\n%s", lpszPathName, (LPCTSTR)MptVersion::ToStr(m_SndFile.m_dwLastSavedWithVersion), MptVersion::str, GetLogString()); Reporting::Information(sTemp); ClearLog(); } @@ -810,72 +809,40 @@ } -void CModDoc::AddLogEvent(LogEventType eventType, LPCTSTR pszFuncName, LPCTSTR pszFormat, ...) -//-------------------------------------------------------------------------------------------- +void CModDoc::AddToLog(const std::string &text) +//--------------------------------------------- { - CString strMsg; - va_list args; - va_start(args, pszFormat); - strMsg.FormatV(pszFormat, args); - va_end(args); - - m_logEvents << Util::sdTime::GetDateTimeStr() - << _T("Event type: ") << eventType << std::endl - << _T("Function: ") << pszFuncName << std::endl - << _T("Message: ") << strMsg << std::endl << std::endl; + m_Log.push_back(text); } -BOOL CModDoc::AddToLog(LPCSTR lpszLog) -//------------------------------------ +std::string CModDoc::GetLogString() const +//--------------------------------------- { - UINT len; - if ((!lpszLog) || (!lpszLog[0])) return FALSE; - len = strlen(lpszLog); - if (m_lpszLog) + std::ostringstream ret; + for(std::vector<std::string>::const_iterator i=m_Log.begin(); i!=m_Log.end(); ++i) { - LPSTR p = new CHAR[strlen(m_lpszLog)+len+2]; - if (p) - { - strcpy(p, m_lpszLog); - strcat(p, lpszLog); - delete[] m_lpszLog; - m_lpszLog = p; - } - } else - { - m_lpszLog = new CHAR[len+2]; - if (m_lpszLog) strcpy(m_lpszLog, lpszLog); + ret << *i << std::endl; } - return TRUE; + return ret.str(); } -BOOL CModDoc::ClearLog() +void CModDoc::ClearLog() //---------------------- { - if (m_lpszLog) - { - delete[] m_lpszLog; - m_lpszLog = NULL; - } - return TRUE; + m_Log.clear(); } UINT CModDoc::ShowLog(LPCSTR lpszTitle, CWnd *parent) //--------------------------------------------------- { - if (!lpszTitle) lpszTitle = MAINFRAME_TITLE; - if (m_lpszLog) + if(!lpszTitle) lpszTitle = MAINFRAME_TITLE; + if(GetLog().size() > 0) { -#if 0 - CShowLogDlg dlg(parent); - return dlg.ShowLog(m_lpszLog, lpszTitle); -#else - Reporting::Information(m_lpszLog, lpszTitle, parent); + Reporting::Information(GetLogString().c_str(), lpszTitle, parent); return IDOK; -#endif } return IDCANCEL; } @@ -2530,7 +2497,7 @@ { if(!HasMPTHacks()) { - AddToLog("No hacks found.\n"); + AddToLog("No hacks found."); } ShowLog(); ClearLog(); Modified: trunk/OpenMPT/mptrack/Moddoc.h =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.h 2013-04-11 10:40:13 UTC (rev 1833) +++ trunk/OpenMPT/mptrack/Moddoc.h 2013-04-11 14:29:08 UTC (rev 1834) @@ -137,11 +137,6 @@ } }; -enum LogEventType -{ - LogEventUnexpectedError -}; - enum InputTargetContext; //============================= @@ -149,8 +144,7 @@ //============================= { protected: - LPSTR m_lpszLog; - std::basic_ostringstream<TCHAR> m_logEvents; // Log for general progress and error events. + std::vector<std::string> m_Log; CSoundFile m_SndFile; HWND m_hWndFollow; @@ -194,15 +188,15 @@ MODTYPE GetModType() const { return m_SndFile.m_nType; } INSTRUMENTINDEX GetNumInstruments() const { return m_SndFile.m_nInstruments; } SAMPLEINDEX GetNumSamples() const { return m_SndFile.m_nSamples; } - BOOL AddToLog(LPCSTR lpszLog); - LPCSTR GetLog() const { return m_lpszLog; } - BOOL ClearLog(); + + // Logging for general progress and error events. + void AddToLog(const std::string &text); + const std::vector<std::string> & GetLog() const { return m_Log; } + std::string GetLogString() const; + void ClearLog(); UINT ShowLog(LPCSTR lpszTitle=NULL, CWnd *parent=NULL); void ClearFilePath() { m_strPathName.Empty(); } - // Logging for general progress and error events. - void AddLogEvent(LogEventType eventType, LPCTSTR pszFuncName, LPCTSTR pszFormat, ...); - void ViewPattern(UINT nPat, UINT nOrd); void ViewSample(UINT nSmp); void ViewInstrument(UINT nIns); Modified: trunk/OpenMPT/soundlib/Load_it.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_it.cpp 2013-04-11 10:40:13 UTC (rev 1833) +++ trunk/OpenMPT/soundlib/Load_it.cpp 2013-04-11 14:29:08 UTC (rev 1834) @@ -22,10 +22,10 @@ #define str_tooMuchPatternData (GetStrI18N((_TEXT("Warning: File format limit was reached. Some pattern data may not get written to file.")))) #define str_pattern (GetStrI18N((_TEXT("pattern")))) -#define str_PatternSetTruncationNote (GetStrI18N((_TEXT("The module contains %u patterns but only %u patterns can be loaded in this OpenMPT version.\n")))) -#define str_SequenceTruncationNote (GetStrI18N((_TEXT("Module has sequence of length %u; it will be truncated to maximum supported length, %u.\n")))) -#define str_LoadingIncompatibleVersion TEXT("The file informed that it is incompatible with this version of OpenMPT. Loading was terminated.\n") -#define str_LoadingMoreRecentVersion TEXT("The loaded file was made with a more recent OpenMPT version and this version may not be able to load all the features or play the file correctly.\n") +#define str_PatternSetTruncationNote (GetStrI18N((_TEXT("The module contains %u patterns but only %u patterns can be loaded in this OpenMPT version.")))) +#define str_SequenceTruncationNote (GetStrI18N((_TEXT("Module has sequence of length %u; it will be truncated to maximum supported length, %u.")))) +#define str_LoadingIncompatibleVersion TEXT("The file informed that it is incompatible with this version of OpenMPT. Loading was terminated.") +#define str_LoadingMoreRecentVersion TEXT("The loaded file was made with a more recent OpenMPT version and this version may not be able to load all the features or play the file correctly.") const uint16 verMptFileVer = 0x891; const uint16 verMptFileVerLoadLimit = 0x1000; // If cwtv-field is greater or equal to this value, @@ -109,10 +109,7 @@ TNTS_MAP_ITER iter = tNameToShort_Map.find(sf.Instruments[i]->pTuning); if(iter == tNameToShort_Map.end()) //Should never happen { -#ifdef MODPLUG_TRACKER - if(sf.GetpModDoc()) - sf.GetpModDoc()->AddToLog(_T("Error: 210807_1\n")); -#endif // MODPLUG_TRACKER + sf.AddToLog("Error: 210807_1"); return; } srlztn::Binarywrite(oStrm, iter->second); @@ -198,11 +195,11 @@ if(iter == notFoundTunings.end()) { notFoundTunings.push_back(str); + std::string erm = std::string("Tuning ") + str + std::string(" used by the module was not found."); + csf.AddToLog(erm); #ifdef MODPLUG_TRACKER if(csf.GetpModDoc() != nullptr) { - string erm = string("Tuning ") + str + string(" used by the module was not found.\n"); - csf.GetpModDoc()->AddToLog(erm.c_str()); csf.GetpModDoc()->SetModified(); //The tuning is changed so the modified flag is set. } #endif // MODPLUG_TRACKER @@ -361,14 +358,12 @@ { if (fileHeader.cwtv >= verMptFileVerLoadLimit) { - if(GetpModDoc()) - GetpModDoc()->AddToLog(str_LoadingIncompatibleVersion); + AddToLog(str_LoadingIncompatibleVersion); return false; } else if (fileHeader.cwtv > verMptFileVer) { - if(GetpModDoc()) - GetpModDoc()->AddToLog(str_LoadingMoreRecentVersion); + AddToLog(str_LoadingMoreRecentVersion); } } } @@ -431,11 +426,9 @@ ORDERINDEX ordSize = fileHeader.ordnum; if(fileHeader.ordnum > GetModSpecifications().ordersMax) { -#ifdef MODPLUG_TRACKER - CString str; + mpt::String str; str.Format(str_SequenceTruncationNote, fileHeader.ordnum, GetModSpecifications().ordersMax); - if(GetpModDoc() != nullptr) GetpModDoc()->AddToLog(str); -#endif // MODPLUG_TRACKER + AddToLog(str); ordSize = GetModSpecifications().ordersMax; } @@ -663,14 +656,9 @@ if(numPats != patPos.size()) { // Hack: Notify user here if file contains more patterns than what can be read. -#ifdef MODPLUG_TRACKER - if(GetpModDoc() != nullptr) - { - CString str; - str.Format(str_PatternSetTruncationNote, patPos.size(), numPats); - GetpModDoc()->AddToLog(str); - } -#endif // MODPLUG_TRACKER + mpt::String str; + str.Format(str_PatternSetTruncationNote, patPos.size(), numPats); + AddToLog(str); } // Checking for number of used channels, which is not explicitely specified in the file. @@ -743,11 +731,9 @@ // Empty 64-row pattern if(Patterns.Insert(pat, 64)) { -#ifdef MODPLUG_TRACKER - CString s; - s.Format(TEXT("Allocating patterns failed starting from pattern %u\n"), pat); - if(GetpModDoc() != nullptr) GetpModDoc()->AddToLog(s); -#endif // MODPLUG_TRACKER + mpt::String s; + s.Format("Allocating patterns failed starting from pattern %u", pat); + AddToLog(s); break; } // Now (after the Insert() call), we can read the pattern name. @@ -937,17 +923,13 @@ if(ssb.m_Status & srlztn::SNT_FAILURE) { -#ifdef MODPLUG_TRACKER - if(GetpModDoc() != nullptr) GetpModDoc()->AddToLog(_T("Unknown error occured while deserializing file.\n")); -#endif // MODPLUG_TRACKER + AddToLog("Unknown error occured while deserializing file."); } } else //Loading for older files. { if(GetTuneSpecificTunings().Deserialize(iStrm)) { -#ifdef MODPLUG_TRACKER - if(GetpModDoc() != nullptr) GetpModDoc()->AddToLog(_T("Error occured - loading failed while trying to load tune specific tunings.\n")); -#endif // MODPLUG_TRACKER + AddToLog("Error occured - loading failed while trying to load tune specific tunings."); } else { ReadTuningMap(iStrm, *this); @@ -1004,9 +986,7 @@ if (p != nullptr) mptHistory.loadDate = *p; else if (pSndFile->GetpModDoc() != nullptr) - pSndFile->GetpModDoc()->AddLogEvent(LogEventUnexpectedError, - __FUNCTION__, - _T("localtime() returned nullptr.")); + pSndFile->AddToLog("localtime() returned nullptr."); mptHistory.openTime = (uint32)(difftime(time(nullptr), creationTime) * (double)HISTORY_TIMER_PRECISION); } @@ -1460,14 +1440,9 @@ buf[len++] = 0; if(patinfo[0] > uint16_max - len) { -#ifdef MODPLUG_TRACKER - if(GetpModDoc()) - { - CString str; - str.Format("%s (%s %u)\n", str_tooMuchPatternData, str_pattern, pat); - GetpModDoc()->AddToLog(str); - } -#endif // MODPLUG_TRACKER + mpt::String str; + str.Format("%s (%s %u)", str_tooMuchPatternData, str_pattern, pat); + AddToLog(str); break; } else { @@ -1551,10 +1526,7 @@ if(ssb.m_Status & srlztn::SNT_FAILURE) { -#ifdef MODPLUG_TRACKER - if(GetpModDoc()) - GetpModDoc()->AddToLog("Error occured in writing MPTM extensions.\n"); -#endif // MODPLUG_TRACKER + AddToLog("Error occured in writing MPTM extensions."); } //Last 4 bytes should tell where the hack mpt things begin. @@ -1979,10 +1951,7 @@ const size_t objectsize = GetMIDIMapper().GetSerializationSize(); if(objectsize > size_t(int16_max)) { -#ifdef MODPLUG_TRACKER - if(GetpModDoc()) - GetpModDoc()->AddToLog("Datafield overflow with MIDI to plugparam mappings; data won't be written.\n"); -#endif // MODPLUG_TRACKER + AddToLog("Datafield overflow with MIDI to plugparam mappings; data won't be written."); } else { Modified: trunk/OpenMPT/soundlib/Load_mo3.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mo3.cpp 2013-04-11 10:40:13 UTC (rev 1833) +++ trunk/OpenMPT/soundlib/Load_mo3.cpp 2013-04-11 14:29:08 UTC (rev 1834) @@ -38,9 +38,7 @@ return false; } -#ifdef MODPLUG_TRACKER - if(GetpModDoc() != nullptr) GetpModDoc()->AddToLog(GetStrI18N(_TEXT("The file appears to be a MO3 file, but this OpenMPT build does not support loading MO3 files."))); -#endif // MODPLUG_TRACKER + AddToLog(GetStrI18N(_TEXT("The file appears to be a MO3 file, but this OpenMPT build does not support loading MO3 files."))); return false; #else @@ -58,9 +56,7 @@ #endif // MODPLUG_TRACKER if(unmo3 == nullptr) // Didn't succeed. { -#ifdef MODPLUG_TRACKER - if(GetpModDoc() != nullptr) GetpModDoc()->AddToLog(GetStrI18N(_TEXT("Loading MO3 file failed because unmo3.dll could not be loaded."))); -#endif // MODPLUG_TRACKER + AddToLog(GetStrI18N(_TEXT("Loading MO3 file failed because unmo3.dll could not be loaded."))); } else // case: dll loaded succesfully. { Modified: trunk/OpenMPT/soundlib/Load_mod.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mod.cpp 2013-04-11 10:40:13 UTC (rev 1833) +++ trunk/OpenMPT/soundlib/Load_mod.cpp 2013-04-11 14:29:08 UTC (rev 1834) @@ -1181,19 +1181,14 @@ } //Check for unsaved patterns -#ifdef MODPLUG_TRACKER - if(GetpModDoc() != nullptr) + for(PATTERNINDEX pat = writePatterns; pat < Patterns.Size(); pat++) { - for(PATTERNINDEX pat = writePatterns; pat < Patterns.Size(); pat++) + if(Patterns.IsValidPat(pat)) { - if(Patterns.IsValidPat(pat)) - { - GetpModDoc()->AddToLog(_T("Warning: This track contains at least one pattern after the highest pattern number referred to in the sequence. Such patterns are not saved in the .mod format.\n")); - break; - } + AddToLog("Warning: This track contains at least one pattern after the highest pattern number referred to in the sequence. Such patterns are not saved in the .mod format."); + break; } } -#endif // Writing samples for(SAMPLEINDEX smp = 1; smp <= 31; smp++) Modified: trunk/OpenMPT/soundlib/Load_s3m.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_s3m.cpp 2013-04-11 10:40:13 UTC (rev 1833) +++ trunk/OpenMPT/soundlib/Load_s3m.cpp 2013-04-11 14:29:08 UTC (rev 1834) @@ -597,12 +597,10 @@ } } -#ifdef MODPLUG_TRACKER - if(hasAdlibPatches && GetpModDoc() != nullptr) + if(hasAdlibPatches) { - GetpModDoc()->AddToLog("This track uses Adlib instruments, which are not supported by OpenMPT."); + AddToLog("This track uses Adlib instruments, which are not supported by OpenMPT."); } -#endif // MODPLUG_TRACKER // Try to find out if Zxx commands are supposed to be panning commands (PixPlay). Modified: trunk/OpenMPT/soundlib/Load_xm.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_xm.cpp 2013-04-11 10:40:13 UTC (rev 1833) +++ trunk/OpenMPT/soundlib/Load_xm.cpp 2013-04-11 14:29:08 UTC (rev 1834) @@ -557,8 +557,8 @@ \ if((len > uint16_max - (UINT)x) && GetpModDoc()) /*Reaching the limits of file format?*/ \ { \ - mpt::String str; str.Format("%s (%s %u)\n", str_tooMuchPatternData, str_pattern, pat); \ - GetpModDoc()->AddToLog(str); \ + mpt::String str; str.Format("%s (%s %u)", str_tooMuchPatternData, str_pattern, pat); \ + AddToLog(str); \ break; \ } Modified: trunk/OpenMPT/soundlib/ModSequence.cpp =================================================================== --- trunk/OpenMPT/soundlib/ModSequence.cpp 2013-04-11 10:40:13 UTC (rev 1833) +++ trunk/OpenMPT/soundlib/ModSequence.cpp 2013-04-11 14:29:08 UTC (rev 1834) @@ -120,10 +120,7 @@ std::fill(iter, end(), GetInvalidPatIndex()); if(GetLengthTailTrimmed() > specs.ordersMax) { -#ifdef MODPLUG_TRACKER - if(m_pSndFile->GetpModDoc()) - m_pSndFile->GetpModDoc()->AddToLog("WARNING: Order list has been trimmed!\n"); -#endif // MODPLUG_TRACKER + m_pSndFile->AddToLog("WARNING: Order list has been trimmed!"); } } resize(specs.ordersMax); @@ -536,11 +533,8 @@ const ORDERINDEX nFirstOrder = GetLengthTailTrimmed() + 1; // +1 for separator item if(nFirstOrder + GetSequence(1).GetLengthTailTrimmed() > m_pSndFile->GetModSpecifications().ordersMax) { -#ifdef MODPLUG_TRACKER - wsprintf(s, "WARNING: Cannot merge Sequence %d (too long!)\n", removedSequences); - if (m_pSndFile->GetpModDoc()) - m_pSndFile->GetpModDoc()->AddToLog(s); -#endif // MODPLUG_TRACKER + wsprintf(s, "WARNING: Cannot merge Sequence %d (too long!)", removedSequences); + m_pSndFile->AddToLog(s); RemoveSequence(1); continue; } @@ -575,11 +569,8 @@ } else { // cannot create new pattern: notify the user -#ifdef MODPLUG_TRACKER wsprintf(s, "CONFLICT: Pattern break commands in Pattern %d might be broken since it has been used in several sequences!", nPat); - if (m_pSndFile->GetpModDoc()) - m_pSndFile->GetpModDoc()->AddToLog(s); -#endif // MODPLUG_TRACKER + m_pSndFile->AddToLog(s); } } m->param = static_cast<BYTE>(m->param + nFirstOrder); Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-04-11 10:40:13 UTC (rev 1833) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-04-11 14:29:08 UTC (rev 1834) @@ -470,7 +470,18 @@ } +void CSoundFile::AddToLog(const std::string &text) const +//------------------------------------------------------ +{ #ifdef MODPLUG_TRACKER + if(GetpModDoc()) GetpModDoc()->AddToLog(text); +#else + Reporting::Warning(text.c_str()); +#endif +} + + +#ifdef MODPLUG_TRACKER BOOL CSoundFile::Create(LPCBYTE lpStream, CModDoc *pModDoc, DWORD dwMemLength) //---------------------------------------------------------------------------- { Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-04-11 10:40:13 UTC (rev 1833) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-04-11 14:29:08 UTC (rev 1834) @@ -343,6 +343,8 @@ public: + void AddToLog(const std::string &text) const; + #ifdef MODPLUG_TRACKER BOOL Create(LPCBYTE lpStream, CModDoc *pModDoc, DWORD dwMemLength=0); // Get parent CModDoc. Can be nullptr if previewing from tree view, and is always nullptr if we're not actually compiling OpenMPT. @@ -351,6 +353,7 @@ BOOL Create(LPCBYTE lpStream, void *pModDoc, DWORD dwMemLength=0); void *GetpModDoc() const { return nullptr; } #endif // MODPLUG_TRACKER + BOOL Destroy(); MODTYPE GetType() const { return m_nType; } bool TypeIsIT_MPT() const { return (m_nType & (MOD_TYPE_IT | MOD_TYPE_MPT)) != 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |