From: <sag...@us...> - 2011-07-30 20:32:24
|
Revision: 943 http://modplug.svn.sourceforge.net/modplug/?rev=943&view=rev Author: saga-games Date: 2011-07-30 20:32:17 +0000 (Sat, 30 Jul 2011) Log Message: ----------- [Ref] Song message handling has been refactored a bit. [Mod] Debug test modules are now removed from MRU list. Modified Paths: -------------- trunk/OpenMPT/mptrack/Ctrl_com.cpp trunk/OpenMPT/mptrack/Mod2wave.cpp trunk/OpenMPT/mptrack/test/test.cpp trunk/OpenMPT/soundlib/Load_it.cpp trunk/OpenMPT/soundlib/Message.cpp trunk/OpenMPT/soundlib/Sndfile.h Modified: trunk/OpenMPT/mptrack/Ctrl_com.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_com.cpp 2011-07-30 18:54:07 UTC (rev 942) +++ trunk/OpenMPT/mptrack/Ctrl_com.cpp 2011-07-30 20:32:17 UTC (rev 943) @@ -119,9 +119,9 @@ if ((ln >= LINE_LENGTH-1) || (!*p)) { if (((BYTE)c) > ' ') s[ln++] = c; - c = 0x0D; + c = INTERNAL_LINEENDING; } - if (c == 0x0D) + if (c == INTERNAL_LINEENDING) { s[ln] = 0x0D; s[ln+1] = 0x0A; @@ -175,11 +175,16 @@ if (ln > LINE_LENGTH-1) ln = LINE_LENGTH-1; s[ln] = 0; while ((ln > 0) && (((BYTE)s[ln-1]) <= ' ')) s[--ln] = 0; - if (i+1 < n) strcat(s, "\r"); + if (i+1 < n) + { + size_t l = strlen(s); + s[l++] = INTERNAL_LINEENDING; + s[l] = '\0'; + } strcat(p, s); } UINT len = strlen(p); - while ((len > 0) && ((p[len-1] == ' ') || (p[len-1] == '\r'))) + while ((len > 0) && ((p[len-1] == ' ') || (p[len-1] == INTERNAL_LINEENDING))) { len--; p[len] = 0; Modified: trunk/OpenMPT/mptrack/Mod2wave.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mod2wave.cpp 2011-07-30 18:54:07 UTC (rev 942) +++ trunk/OpenMPT/mptrack/Mod2wave.cpp 2011-07-30 20:32:17 UTC (rev 943) @@ -560,21 +560,7 @@ if (m_pSndFile->m_lpszSongComments) { - m_FileTags.comments = m_pSndFile->m_lpszSongComments; - // convert \r to \n, remove bad characters - for(size_t i = 0; i < m_FileTags.comments.length(); i++) - { - if(m_FileTags.comments.substr(i, 1) == "\r") - m_FileTags.comments.replace(i, 1, "\n"); - if(m_FileTags.comments.substr(i, 1) < " " && m_FileTags.comments.substr(i, 1) != "\n") - m_FileTags.comments.replace(i, 1, " "); - } - - /*size_t spos; - while((spos = m_FileTags.comments.find("\r")) != string::npos) - { - m_FileTags.comments.replace(spos, 1, "\n"); - }*/ + m_FileTags.comments = m_pSndFile->GetSongMessage(leLF); } else { @@ -631,6 +617,7 @@ EndDialog(IDCANCEL); return; } + SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS); int oldVol = m_pSndFile->GetMasterVolume(); int nOldRepeat = m_pSndFile->GetRepeatCount(); Modified: trunk/OpenMPT/mptrack/test/test.cpp =================================================================== --- trunk/OpenMPT/mptrack/test/test.cpp 2011-07-30 18:54:07 UTC (rev 942) +++ trunk/OpenMPT/mptrack/test/test.cpp 2011-07-30 20:32:17 UTC (rev 943) @@ -450,11 +450,15 @@ // Test file saving pModDoc->DoSave(theFile + "saved.mptm"); pModDoc->OnCloseDocument(); - + // Reload the saved file and test if everything is still working correctly. pModDoc = (CModDoc *)theApp.OpenDocumentFile(theFile + "saved.mptm"); TestLoadFile(pModDoc); pModDoc->OnCloseDocument(); + + // Forget about the files we just loaded + theApp.RemoveMruItem(0); + theApp.RemoveMruItem(0); } Modified: trunk/OpenMPT/soundlib/Load_it.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_it.cpp 2011-07-30 18:54:07 UTC (rev 942) +++ trunk/OpenMPT/soundlib/Load_it.cpp 2011-07-30 20:32:17 UTC (rev 943) @@ -1332,8 +1332,8 @@ const tm* const p = localtime(&creationTime); if (p != nullptr) loadDate = *p; - else if (pSndFile->GetModDocPtr() != nullptr) - pSndFile->GetModDocPtr()->AddLogEvent(LogEventUnexpectedError, + else if (pSndFile->GetpModDoc() != nullptr) + pSndFile->GetpModDoc()->AddLogEvent(LogEventUnexpectedError, __FUNCTION__, _T("localtime() returned nullptr.")); openTime = (uint32)((double)difftime(time(nullptr), creationTime) * 18.2f); Modified: trunk/OpenMPT/soundlib/Message.cpp =================================================================== --- trunk/OpenMPT/soundlib/Message.cpp 2011-07-30 18:54:07 UTC (rev 942) +++ trunk/OpenMPT/soundlib/Message.cpp 2011-07-30 20:32:17 UTC (rev 943) @@ -113,14 +113,14 @@ { case '\r': if(lineEnding != leLF) - m_lpszSongComments[cpos] = '\r'; + m_lpszSongComments[cpos] = INTERNAL_LINEENDING; else m_lpszSongComments[cpos] = ' '; if(lineEnding == leCRLF) i++; // skip the LF break; case '\n': if(lineEnding != leCR && lineEnding != leCRLF) - m_lpszSongComments[cpos] = '\r'; + m_lpszSongComments[cpos] = INTERNAL_LINEENDING; else m_lpszSongComments[cpos] = ' '; break; @@ -158,7 +158,7 @@ for(size_t line = 0, fpos = 0, cpos = 0; line < num_lines; line++, fpos += (lineLength + lineEndingLength), cpos += (lineLength + 1)) { memcpy(m_lpszSongComments + cpos, data + fpos, min(lineLength, length - fpos)); - m_lpszSongComments[cpos + lineLength] = '\r'; + m_lpszSongComments[cpos + lineLength] = INTERNAL_LINEENDING; // fix weird chars for(size_t lpos = 0; lpos < lineLength; lpos++) @@ -181,73 +181,47 @@ } -// OLD and unused function. Do we still need it? -UINT CSoundFile::GetSongMessage(LPSTR s, UINT len, UINT linesize) -//--------------------------------------------------------------- +// Retrieve song message. +// [in] lineEnding: line ending formatting of the text in memory. +// [in] pTextConverter: Pointer to a callback function which can be used to post-process the written characters, if necessary (nullptr otherwise). +// [out] returns formatted song message. +CString CSoundFile::GetSongMessage(const enmLineEndings lineEnding, void (*pTextConverter)(char &)) +//------------------------------------------------------------------------------------------------- { - LPCSTR p = m_lpszSongComments; - if (!p) return 0; - UINT i = 2, ln=0; - if ((len) && (s)) s[0] = '\r'; - if ((len > 1) && (s)) s[1] = '\n'; - while ((*p) && (i+2 < len)) + CString comments; + + if(m_lpszSongComments == nullptr) { - BYTE c = (BYTE)*p++; - if ((c == 0x0D) || ((c == ' ') && (ln >= linesize))) - { if (s) { s[i++] = '\r'; s[i++] = '\n'; } else i+= 2; ln=0; } - else - if (c >= 0x20) { if (s) s[i++] = c; else i++; ln++; } + return comments; } - if (s) s[i] = 0; - return i; -} + const size_t len = strlen(m_lpszSongComments); + comments.Preallocate(len); -// OLD and unused function. Do we still need it? -UINT CSoundFile::GetRawSongMessage(LPSTR s, UINT len, UINT linesize) -//------------------------------------------------------------------ -{ - LPCSTR p = m_lpszSongComments; - if (!p) return 0; - UINT i = 0, ln=0; - while ((*p) && (i < len-1)) + for(size_t i = 0; i < len; i++) { - BYTE c = (BYTE)*p++; - if ((c == 0x0D) || (c == 0x0A)) + if(m_lpszSongComments[i] == INTERNAL_LINEENDING) { - if (ln) + switch(lineEnding) { - while (ln < linesize) { if (s) s[i] = ' '; i++; ln++; } - ln = 0; + case leCR: + default: + comments.Append("\r"); + break; + case leLF: + comments.Append("\n"); + break; + case leCRLF: + comments.Append("\r\n"); + break; } } else - if ((c == ' ') && (!ln)) - { - UINT k=0; - while ((p[k]) && (p[k] >= ' ')) k++; - if (k <= linesize) - { - if (s) s[i] = ' '; - i++; - ln++; - } - } else - { - if (s) s[i] = c; - i++; - ln++; - if (ln == linesize) ln = 0; - } - } - if (ln) - { - while ((ln < linesize) && (i < len)) { - if (s) s[i] = ' '; - i++; - ln++; + char c = m_lpszSongComments[i]; + // Pre-process text + if(pTextConverter != nullptr) pTextConverter(c); + comments.AppendChar(c); } } - if (s) s[i] = 0; - return i; + return comments; } Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2011-07-30 18:54:07 UTC (rev 942) +++ trunk/OpenMPT/soundlib/Sndfile.h 2011-07-30 20:32:17 UTC (rev 943) @@ -476,7 +476,9 @@ leAutodetect, // Detect suitable line ending }; +#define INTERNAL_LINEENDING '\r' // The character that represents line endings internally + // For WAV export (writing pattern positions to file) struct PatternCuePoint { @@ -695,7 +697,6 @@ inline bool TypeIsXM_MOD() const { return (m_nType & (MOD_TYPE_XM | MOD_TYPE_MOD)) != 0; } inline bool TypeIsMOD_S3M() const { return (m_nType & (MOD_TYPE_MOD | MOD_TYPE_S3M)) != 0; } CModDoc* GetpModDoc() const { return m_pModDoc; } - CModDoc* GetModDocPtr() const { return m_pModDoc; } void SetMasterVolume(UINT vol, bool adjustAGC = false); UINT GetMasterVolume() const { return m_nMasterVolume; } @@ -1020,6 +1021,12 @@ // Free previously allocated song message memory. void FreeMessage(); + // Retrieve song message. + // [in] lineEnding: line ending formatting of the text in memory. + // [in] pTextConverter: Pointer to a callback function which can be used to post-process the written characters, if necessary (nullptr otherwise). + // [out] returns formatted song message. + CString GetSongMessage(const enmLineEndings lineEnding, void (*pTextConverter)(char &) = nullptr); + protected: // Read song message from a mapped file. // [in] data: pointer to the data in memory that is going to be read @@ -1038,10 +1045,6 @@ // [out] returns true on success. bool ReadFixedLineLengthMessage(const BYTE *data, const size_t length, const size_t lineLength, const size_t lineEndingLength, void (*pTextConverter)(char &) = nullptr); - // Currently unused (and the code doesn't look very nice :) - UINT GetSongMessage(LPSTR s, UINT cbsize, UINT linesize=32); - UINT GetRawSongMessage(LPSTR s, UINT cbsize, UINT linesize=32); - public: int GetVolEnvValueFromPosition(int position, MODINSTRUMENT* pIns) const; void ResetChannelEnvelopes(MODCHANNEL *pChn); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |