From: <man...@us...> - 2013-04-18 21:21:45
|
Revision: 1913 http://sourceforge.net/p/modplug/code/1913 Author: manxorist Date: 2013-04-18 21:21:33 +0000 (Thu, 18 Apr 2013) Log Message: ----------- [Ref] Move Reporting.* from common/ to mptrack/. [Ref] Add common/Logging.h and class ILog. [Ref] Route all user messages from soundlib via CModDoc->AddToLog(). [Ref] Handle displaying of the message log via a class ScopedLogCapturer which ensures that no messages are lost. [Ref] Optionally route user messages via a custom ILog set via SetLog in CSoundFile. Modified Paths: -------------- trunk/OpenMPT/mptrack/CleanupSong.cpp trunk/OpenMPT/mptrack/CommandSet.cpp trunk/OpenMPT/mptrack/MIDIMacroDialog.cpp trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/Moddoc.h trunk/OpenMPT/mptrack/Mptrack.h trunk/OpenMPT/mptrack/mptrack_08.vcproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters trunk/OpenMPT/sounddev/SoundDevice.cpp trunk/OpenMPT/soundlib/ITCompression.cpp trunk/OpenMPT/soundlib/Mmx_mix.cpp trunk/OpenMPT/soundlib/ModSequence.cpp trunk/OpenMPT/soundlib/SampleFormats.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/soundlib/modsmp_ctrl.cpp trunk/OpenMPT/soundlib/patternContainer.cpp trunk/OpenMPT/soundlib/tuning.cpp Added Paths: ----------- trunk/OpenMPT/common/Logging.h trunk/OpenMPT/mptrack/Reporting.cpp trunk/OpenMPT/mptrack/Reporting.h Removed Paths: ------------- trunk/OpenMPT/common/Reporting.cpp trunk/OpenMPT/common/Reporting.h Added: trunk/OpenMPT/common/Logging.h =================================================================== --- trunk/OpenMPT/common/Logging.h (rev 0) +++ trunk/OpenMPT/common/Logging.h 2013-04-18 21:21:33 UTC (rev 1913) @@ -0,0 +1,42 @@ +/* + * Logging.h + * --------- + * Purpose: General logging and user confirmation support + * Notes : (currently none) + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + +#pragma once + + +enum LogLevel +{ + /*LogDebug = 1,*/ + LogNotification = 2, + LogInformation = 3, + LogWarning = 4, + LogError = 5, +}; + + +inline std::string LogLevelToString(LogLevel level) +{ + switch(level) + { + case LogError: return "error"; break; + case LogWarning: return "warning"; break; + case LogInformation: return "info"; break; + case LogNotification: return "notify"; break; + } + return "unknown"; +} + + +class ILog +{ +public: + virtual void AddToLog(const std::string &text) const { AddToLog(LogInformation, text); } + virtual void AddToLog(LogLevel level, const std::string &text) const = 0; +}; + Property changes on: trunk/OpenMPT/common/Logging.h ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-chdr \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Deleted: trunk/OpenMPT/common/Reporting.cpp =================================================================== --- trunk/OpenMPT/common/Reporting.cpp 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/common/Reporting.cpp 2013-04-18 21:21:33 UTC (rev 1913) @@ -1,149 +0,0 @@ -/* - * Reporting.cpp - * ------------- - * Purpose: A class for showing notifications, prompts, etc... - * Notes : (currently none) - * Authors: OpenMPT Devs - * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. - */ - - -#include "Stdafx.h" -#include "Reporting.h" -#ifdef MODPLUG_TRACKER -#include "../mptrack/Mainfrm.h" -#else -#include <iostream> -#endif // MODPLUG_TRACKER - - -UINT Reporting::ShowNotification(const char *text, const char *caption, UINT flags, const CWnd *parent) -//----------------------------------------------------------------------------------------------------- -{ -#ifdef MODPLUG_TRACKER - CMainFrame *pMainFrm = CMainFrame::GetMainFrame(); - - if(pMainFrm != nullptr && pMainFrm->GetInputHandler() != nullptr) - { - pMainFrm->GetInputHandler()->Bypass(true); - } - - if(parent == nullptr) - { - parent = pMainFrm; - } - UINT result = ::MessageBox((parent ? parent->m_hWnd : NULL), text, caption, flags); - - if(pMainFrm != nullptr && pMainFrm->GetInputHandler() != nullptr) - { - pMainFrm->GetInputHandler()->Bypass(false); - } - - return result; -#else - std::clog << caption << std::endl << text << std::endl; - return 0; -#endif // MODPLUG_TRACKER -} - - -void Reporting::Notification(const char *text, const CWnd *parent) -//---------------------------------------------------------------- -{ - Notification(text, MAINFRAME_TITLE, parent); -} - - -void Reporting::Notification(const char *text, const char *caption, const CWnd *parent) -//------------------------------------------------------------------------------------- -{ - ShowNotification(text, caption, MB_OK, parent); -} - - -void Reporting::Information(const char *text, const CWnd *parent) -//--------------------------------------------------------------- -{ - Information(text, MAINFRAME_TITLE, parent); -} - - -void Reporting::Information(const char *text, const char *caption, const CWnd *parent) -//------------------------------------------------------------------------------------ -{ - ShowNotification(text, caption, MB_OK | MB_ICONINFORMATION, parent); -} - - -void Reporting::Warning(const char *text, const CWnd *parent) -//----------------------------------------------------------- -{ - Warning(text, MAINFRAME_TITLE " - Warning", parent); -} - - -void Reporting::Warning(const char *text, const char *caption, const CWnd *parent) -//-------------------------------------------------------------------------------- -{ - ShowNotification(text, caption, MB_OK | MB_ICONWARNING, parent); -} - - -void Reporting::Error(const char *text, const CWnd *parent) -//--------------------------------------------------------- -{ - Error(text, MAINFRAME_TITLE " - Error", parent); -} - - -void Reporting::Error(const char *text, const char *caption, const CWnd *parent) -//------------------------------------------------------------------------------ -{ - ShowNotification(text, caption, MB_OK | MB_ICONERROR, parent); -} - - -ConfirmAnswer Reporting::Confirm(const char *text, bool showCancel, bool defaultNo, const CWnd *parent) -//----------------------------------------------------------------------------------------------------- -{ - return Confirm(text, MAINFRAME_TITLE " - Confirmation", showCancel, defaultNo, parent); -} - - -ConfirmAnswer Reporting::Confirm(const char *text, const char *caption, bool showCancel, bool defaultNo, const CWnd *parent) -//-------------------------------------------------------------------------------------------------------------------------- -{ - UINT result = ShowNotification(text, caption, (showCancel ? MB_YESNOCANCEL : MB_YESNO) | MB_ICONQUESTION | (defaultNo ? MB_DEFBUTTON2 : 0), parent); - switch(result) - { - case IDYES: - return cnfYes; - case IDNO: - return cnfNo; - default: - case IDCANCEL: - return cnfCancel; - } -} - - -RetryAnswer Reporting::RetryCancel(const char *text, const CWnd *parent) -//---------------------------------------------------------------------- -{ - return RetryCancel(text, MAINFRAME_TITLE, parent); -} - - -RetryAnswer Reporting::RetryCancel(const char *text, const char *caption, const CWnd *parent) -//------------------------------------------------------------------------------------------- -{ - UINT result = ShowNotification(text, caption, MB_RETRYCANCEL, parent); - switch(result) - { - case IDRETRY: - return rtyRetry; - default: - case IDCANCEL: - return rtyCancel; - } -} Deleted: trunk/OpenMPT/common/Reporting.h =================================================================== --- trunk/OpenMPT/common/Reporting.h 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/common/Reporting.h 2013-04-18 21:21:33 UTC (rev 1913) @@ -1,66 +0,0 @@ -/* - * Reporting.h - * ----------- - * Purpose: A class for showing notifications, prompts, etc... - * Notes : (currently none) - * Authors: OpenMPT Devs - * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. - */ - - -#pragma once - -enum ConfirmAnswer -{ - cnfYes, - cnfNo, - cnfCancel, -}; - -enum RetryAnswer -{ - rtyRetry, - rtyCancel, -}; - -//============= -class Reporting -//============= -{ - -protected: - - static UINT ShowNotification(const char *text, const char *caption, UINT flags, const CWnd *parent); - -public: - -#ifdef MODPLUG_TRACKER - // TODO Quick'n'dirty workaround for MsgBox(). Shouldn't be public. - static UINT CustomNotification(const char *text, const char *caption, UINT flags, const CWnd *parent) { return ShowNotification(text, caption, flags, parent); }; -#endif // MODPLUG_TRACKER - - // Show a simple notification - static void Notification(const char *text, const CWnd *parent = nullptr); - static void Notification(const char *text, const char *caption, const CWnd *parent = nullptr); - - // Show a simple information - static void Information(const char *text, const CWnd *parent = nullptr); - static void Information(const char *text, const char *caption, const CWnd *parent = nullptr); - - // Show a simple warning - static void Warning(const char *text, const CWnd *parent = nullptr); - static void Warning(const char *text, const char *caption, const CWnd *parent = nullptr); - - // Show an error box. - static void Error(const char *text, const CWnd *parent = nullptr); - static void Error(const char *text, const char *caption, const CWnd *parent = nullptr); - - // Show a confirmation dialog. - static ConfirmAnswer Confirm(const char *text, bool showCancel = false, bool defaultNo = false, const CWnd *parent = nullptr); - static ConfirmAnswer Confirm(const char *text, const char *caption, bool showCancel = false, bool defaultNo = false, const CWnd *parent = nullptr); - - // Show a confirmation dialog. - static RetryAnswer RetryCancel(const char *text, const CWnd *parent = nullptr); - static RetryAnswer RetryCancel(const char *text, const char *caption, const CWnd *parent = nullptr); - -}; Modified: trunk/OpenMPT/mptrack/CleanupSong.cpp =================================================================== --- trunk/OpenMPT/mptrack/CleanupSong.cpp 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/mptrack/CleanupSong.cpp 2013-04-18 21:21:33 UTC (rev 1913) @@ -120,13 +120,13 @@ void CModCleanupDlg::OnOK() //------------------------- { + ScopedLogCapturer logcapturer(modDoc, "cleanup", this); for(int i = 0; i < CU_MAX_CLEANUP_OPTIONS; i++) { m_bCheckBoxes[i] = IsDlgButtonChecked(m_nCleanupIDtoDlgID[i]) != BST_UNCHECKED; } bool bModified = false; - modDoc.ClearLog(); // Orders if(m_bCheckBoxes[CU_MERGE_SEQUENCES]) bModified |= MergeSequences(); @@ -162,7 +162,7 @@ if(bModified) modDoc.SetModified(); modDoc.UpdateAllViews(NULL, HINT_MODTYPE | HINT_MODSEQUENCE | HINT_MODGENERAL | HINT_SMPNAMES | HINT_INSNAMES); - modDoc.ShowLog("Cleanup", this); + logcapturer.ShowLog(true); CDialog::OnOK(); } Modified: trunk/OpenMPT/mptrack/CommandSet.cpp =================================================================== --- trunk/OpenMPT/mptrack/CommandSet.cpp 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/mptrack/CommandSet.cpp 2013-04-18 21:21:33 UTC (rev 1913) @@ -13,7 +13,7 @@ #include "resource.h" #include "Mptrack.h" // For MsgBox #include "../soundlib/mod_specifications.h" -#include "../common/Reporting.h" +#include "../mptrack/Reporting.h" #include <stdio.h> #include <stdlib.h> #include <fstream> Modified: trunk/OpenMPT/mptrack/MIDIMacroDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/MIDIMacroDialog.cpp 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/mptrack/MIDIMacroDialog.cpp 2013-04-18 21:21:33 UTC (rev 1913) @@ -9,7 +9,7 @@ #include "stdafx.h" -#include "../common/Reporting.h" +#include "../mptrack/Reporting.h" #include "../common/StringFixer.h" #include "Mainfrm.h" #include "mptrack.h" Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2013-04-18 21:21:33 UTC (rev 1913) @@ -118,8 +118,8 @@ ///////////////////////////////////////////////////////////////////////////// // CModDoc construction/destruction -CModDoc::CModDoc() : m_PatternUndo(*this), m_SampleUndo(*this) -//------------------------------------------------------------ +CModDoc::CModDoc() : m_LogMode(LogModeInstantReporting), m_PatternUndo(*this), m_SampleUndo(*this) +//------------------------------------------------------------------------------------------------ { m_bHasValidPath = false; m_hWndFollow = NULL; @@ -201,6 +201,8 @@ BOOL bModified = TRUE; CMappedFile f; + ScopedLogCapturer logcapturer(*this); + if (!lpszPathName) return OnNewDocument(); BeginWaitCursor(); if (f.Open(lpszPathName)) @@ -220,14 +222,12 @@ EndWaitCursor(); - // Show log messages from loaders. - 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, GetLogString().c_str()); - Reporting::Information(sTemp); - ClearLog(); - } + std::ostringstream str; + str + << "File: " << lpszPathName << std::endl + << "Last saved with: " << MptVersion::ToStr(m_SndFile.m_dwLastSavedWithVersion) << ", your version is " << MptVersion::str << std::endl + << std::endl; + logcapturer.ShowLog(str.str()); if ((m_SndFile.m_nType == MOD_TYPE_NONE) || (!m_SndFile.GetNumChannels())) return FALSE; // Midi Import @@ -428,6 +428,7 @@ BOOL CModDoc::OnSaveDocument(LPCTSTR lpszPathName, const bool bTemplateFile) //-------------------------------------------------------------------------- { + ScopedLogCapturer logcapturer(*this); static int greccount = 0; BOOL bOk = FALSE; m_SndFile.m_dwLastSavedWithVersion = MptVersion::num; @@ -443,7 +444,6 @@ return bOk; } BeginWaitCursor(); - ClearLog(); FixNullStrings(); switch(type) { @@ -461,7 +461,7 @@ // Set new path for this file, unless we are saving a template, in which case we want to keep the old file path. SetPathName(lpszPathName); } - ShowLog(); + logcapturer.ShowLog(true); if (bTemplateFile) { // Update template menu. @@ -808,25 +808,88 @@ } -void CModDoc::AddToLog(const std::string &text) -//--------------------------------------------- +ScopedLogCapturer::ScopedLogCapturer(CModDoc &modDoc, const std::string &title, CWnd *parent) : +m_modDoc(modDoc), m_oldLogMode(m_modDoc.GetLogMode()), m_title(title), m_pParent(parent) +//--------------------------------------------------------------------------------------------- { - m_Log.push_back(text); + m_modDoc.SetLogMode(LogModeGather); } +void ScopedLogCapturer::ShowLog(bool force) +//---------------------------------------- +{ + if(force || m_oldLogMode == LogModeInstantReporting) + { + m_modDoc.ShowLog(m_title, m_pParent); + m_modDoc.ClearLog(); + } +} + + +void ScopedLogCapturer::ShowLog(const std::string &preamble, bool force) +//---------------------------------------------------------------------- +{ + if(force || m_oldLogMode == LogModeInstantReporting) + { + m_modDoc.ShowLog(preamble, m_title, m_pParent); + m_modDoc.ClearLog(); + } +} + + +ScopedLogCapturer::~ScopedLogCapturer() +//------------------------------------- +{ + ShowLog(); + m_modDoc.SetLogMode(m_oldLogMode); +} + + +void CModDoc::AddToLog(LogLevel level, const std::string &text) const +//------------------------------------------------------------------- +{ + if(m_LogMode == LogModeGather) + { + m_Log.push_back(LogEntry(level, text)); + } else + { + switch(level) + { + case LogError: Reporting::Error(text.c_str()); break; + case LogWarning: Reporting::Warning(text.c_str()); break; + case LogInformation: Reporting::Information(text.c_str()); break; + case LogNotification: Reporting::Notification(text.c_str()); break; + default: Reporting::Information(text.c_str()); break; + } + } +} + + std::string CModDoc::GetLogString() const //--------------------------------------- { std::ostringstream ret; - for(std::vector<std::string>::const_iterator i=m_Log.begin(); i!=m_Log.end(); ++i) + for(std::vector<LogEntry>::const_iterator i=m_Log.begin(); i!=m_Log.end(); ++i) { - ret << *i << std::endl; + ret << (*i).message << "\r\n";//std::endl; } return ret.str(); } +LogLevel CModDoc::GetMaxLogLevel() const +//-------------------------------------- +{ + LogLevel retval = LogNotification; + for(std::vector<LogEntry>::const_iterator i=m_Log.begin(); i!=m_Log.end(); ++i) + { + retval = std::max(retval, i->level); + } + return retval; +} + + void CModDoc::ClearLog() //---------------------- { @@ -834,13 +897,22 @@ } -UINT CModDoc::ShowLog(LPCSTR lpszTitle, CWnd *parent) -//--------------------------------------------------- +UINT CModDoc::ShowLog(const std::string &preamble, const std::string &title, CWnd *parent) +//---------------------------------------------------------------------------------------- { - if(!lpszTitle) lpszTitle = MAINFRAME_TITLE; + if(!parent) parent = CMainFrame::GetMainFrame(); if(GetLog().size() > 0) { - Reporting::Information(GetLogString().c_str(), lpszTitle, parent); + std::string text = preamble + GetLogString(); + std::string actualTitle = (title.length() == 0) ? std::string(MAINFRAME_TITLE) : title; + switch(GetMaxLogLevel()) + { + case LogError: Reporting::Error(text.c_str(), actualTitle.c_str(), parent); break; + case LogWarning: Reporting::Warning(text.c_str(), actualTitle.c_str(), parent); break; + case LogInformation: Reporting::Information(text.c_str(), actualTitle.c_str(), parent); break; + case LogNotification: Reporting::Notification(text.c_str(), actualTitle.c_str(), parent); break; + default: Reporting::Information(text.c_str(), actualTitle.c_str(), parent); break; + } return IDOK; } return IDCANCEL; @@ -1899,7 +1971,7 @@ FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(false, ext, filename, pattern, TrackerSettings::Instance().GetWorkingDirectory(DIR_MODS)); if(files.abort) return; - ClearLog(); + ScopedLogCapturer logcapturer(*this); FixNullStrings(); switch (type) { @@ -1910,7 +1982,6 @@ m_SndFile.SaveIT(files.first_file.c_str(), true); break; } - ShowLog(); } @@ -2480,12 +2551,11 @@ void CModDoc::OnViewMPTHacks() //---------------------------- { + ScopedLogCapturer logcapturer(*this); if(!HasMPTHacks()) { AddToLog("No hacks found."); } - ShowLog(); - ClearLog(); } @@ -2676,8 +2746,8 @@ CModTypeDlg dlg(m_SndFile, CMainFrame::GetMainFrame()); if (dlg.DoModal() == IDOK) { + ScopedLogCapturer logcapturer(*this, "Conversion Status"); bool bShowLog = false; - ClearLog(); if(dlg.m_nType) { if (!ChangeModType(dlg.m_nType)) return; @@ -2697,7 +2767,6 @@ SetModified(); - if (bShowLog) ShowLog("Conversion Status", CMainFrame::GetMainFrame()); } } Modified: trunk/OpenMPT/mptrack/Moddoc.h =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.h 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/mptrack/Moddoc.h 2013-04-18 21:21:33 UTC (rev 1913) @@ -14,6 +14,7 @@ #include "../common/misc_util.h" #include "Undo.h" #include "Notification.h" +#include "../common/Logging.h" #include <time.h> @@ -139,12 +140,46 @@ enum InputTargetContext; + +struct LogEntry +{ + LogLevel level; + std::string message; + LogEntry() : level(LogInformation) {} + LogEntry(LogLevel l, const std::string &m) : level(l), message(m) {} +}; + + +enum LogMode +{ + LogModeInstantReporting, + LogModeGather, +}; + + +class ScopedLogCapturer +{ +private: + CModDoc &m_modDoc; + LogMode m_oldLogMode; + std::string m_title; + CWnd *m_pParent; +public: + ScopedLogCapturer(CModDoc &modDoc, const std::string &title = "", CWnd *parent = nullptr); + ~ScopedLogCapturer(); + void ShowLog(bool force = false); + void ShowLog(const std::string &preamble, bool force = false); +}; + + //============================= class CModDoc: public CDocument //============================= { protected: - std::vector<std::string> m_Log; + friend ScopedLogCapturer; + mutable std::vector<LogEntry> m_Log; + LogMode m_LogMode; CSoundFile m_SndFile; HWND m_hWndFollow; @@ -190,11 +225,21 @@ SAMPLEINDEX GetNumSamples() const { return m_SndFile.m_nSamples; } // Logging for general progress and error events. - void AddToLog(const std::string &text); - const std::vector<std::string> & GetLog() const { return m_Log; } + void AddToLog(LogLevel level, const std::string &text) const; + void AddToLog(const std::string &text) const { AddToLog(LogInformation, text); } + + const std::vector<LogEntry> & GetLog() const { return m_Log; } std::string GetLogString() const; + LogLevel GetMaxLogLevel() const; +protected: + LogMode GetLogMode() const { return m_LogMode; } + void SetLogMode(LogMode mode) { m_LogMode = mode; } void ClearLog(); - UINT ShowLog(LPCSTR lpszTitle=NULL, CWnd *parent=NULL); + UINT ShowLog(const std::string &preamble, const std::string &title = "", CWnd *parent = nullptr); + UINT ShowLog(const std::string &title = "", CWnd *parent = nullptr) { return ShowLog("", title, parent); } + +public: + void ClearFilePath() { m_strPathName.Empty(); } void ViewPattern(UINT nPat, UINT nOrd); Modified: trunk/OpenMPT/mptrack/Mptrack.h =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.h 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/mptrack/Mptrack.h 2013-04-18 21:21:33 UTC (rev 1913) @@ -13,7 +13,7 @@ #include "resource.h" // main symbols #include "ACMConvert.h" #include <windows.h> -#include "../common/Reporting.h" +#include "../mptrack/Reporting.h" #include "../soundlib/MIDIMacros.h" #include "../soundlib/modcommand.h" #include <vector> Added: trunk/OpenMPT/mptrack/Reporting.cpp =================================================================== --- trunk/OpenMPT/mptrack/Reporting.cpp (rev 0) +++ trunk/OpenMPT/mptrack/Reporting.cpp 2013-04-18 21:21:33 UTC (rev 1913) @@ -0,0 +1,140 @@ +/* + * Reporting.cpp + * ------------- + * Purpose: A class for showing notifications, prompts, etc... + * Notes : (currently none) + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + + +#include "Stdafx.h" +#include "Reporting.h" +#include "../mptrack/Mainfrm.h" + + +UINT Reporting::ShowNotification(const char *text, const char *caption, UINT flags, const CWnd *parent) +//----------------------------------------------------------------------------------------------------- +{ + CMainFrame *pMainFrm = CMainFrame::GetMainFrame(); + + if(pMainFrm != nullptr && pMainFrm->GetInputHandler() != nullptr) + { + pMainFrm->GetInputHandler()->Bypass(true); + } + + if(parent == nullptr) + { + parent = pMainFrm; + } + UINT result = ::MessageBox((parent ? parent->m_hWnd : NULL), text, caption, flags); + + if(pMainFrm != nullptr && pMainFrm->GetInputHandler() != nullptr) + { + pMainFrm->GetInputHandler()->Bypass(false); + } + + return result; +} + + +void Reporting::Notification(const char *text, const CWnd *parent) +//---------------------------------------------------------------- +{ + Notification(text, MAINFRAME_TITLE, parent); +} + + +void Reporting::Notification(const char *text, const char *caption, const CWnd *parent) +//------------------------------------------------------------------------------------- +{ + ShowNotification(text, caption, MB_OK, parent); +} + + +void Reporting::Information(const char *text, const CWnd *parent) +//--------------------------------------------------------------- +{ + Information(text, MAINFRAME_TITLE, parent); +} + + +void Reporting::Information(const char *text, const char *caption, const CWnd *parent) +//------------------------------------------------------------------------------------ +{ + ShowNotification(text, caption, MB_OK | MB_ICONINFORMATION, parent); +} + + +void Reporting::Warning(const char *text, const CWnd *parent) +//----------------------------------------------------------- +{ + Warning(text, MAINFRAME_TITLE " - Warning", parent); +} + + +void Reporting::Warning(const char *text, const char *caption, const CWnd *parent) +//-------------------------------------------------------------------------------- +{ + ShowNotification(text, caption, MB_OK | MB_ICONWARNING, parent); +} + + +void Reporting::Error(const char *text, const CWnd *parent) +//--------------------------------------------------------- +{ + Error(text, MAINFRAME_TITLE " - Error", parent); +} + + +void Reporting::Error(const char *text, const char *caption, const CWnd *parent) +//------------------------------------------------------------------------------ +{ + ShowNotification(text, caption, MB_OK | MB_ICONERROR, parent); +} + + +ConfirmAnswer Reporting::Confirm(const char *text, bool showCancel, bool defaultNo, const CWnd *parent) +//----------------------------------------------------------------------------------------------------- +{ + return Confirm(text, MAINFRAME_TITLE " - Confirmation", showCancel, defaultNo, parent); +} + + +ConfirmAnswer Reporting::Confirm(const char *text, const char *caption, bool showCancel, bool defaultNo, const CWnd *parent) +//-------------------------------------------------------------------------------------------------------------------------- +{ + UINT result = ShowNotification(text, caption, (showCancel ? MB_YESNOCANCEL : MB_YESNO) | MB_ICONQUESTION | (defaultNo ? MB_DEFBUTTON2 : 0), parent); + switch(result) + { + case IDYES: + return cnfYes; + case IDNO: + return cnfNo; + default: + case IDCANCEL: + return cnfCancel; + } +} + + +RetryAnswer Reporting::RetryCancel(const char *text, const CWnd *parent) +//---------------------------------------------------------------------- +{ + return RetryCancel(text, MAINFRAME_TITLE, parent); +} + + +RetryAnswer Reporting::RetryCancel(const char *text, const char *caption, const CWnd *parent) +//------------------------------------------------------------------------------------------- +{ + UINT result = ShowNotification(text, caption, MB_RETRYCANCEL, parent); + switch(result) + { + case IDRETRY: + return rtyRetry; + default: + case IDCANCEL: + return rtyCancel; + } +} Property changes on: trunk/OpenMPT/mptrack/Reporting.cpp ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-c++src \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: trunk/OpenMPT/mptrack/Reporting.h =================================================================== --- trunk/OpenMPT/mptrack/Reporting.h (rev 0) +++ trunk/OpenMPT/mptrack/Reporting.h 2013-04-18 21:21:33 UTC (rev 1913) @@ -0,0 +1,67 @@ +/* + * Reporting.h + * ----------- + * Purpose: A class for showing notifications, prompts, etc... + * Notes : (currently none) + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + + +#pragma once + + +enum ConfirmAnswer +{ + cnfYes, + cnfNo, + cnfCancel, +}; + + +enum RetryAnswer +{ + rtyRetry, + rtyCancel, +}; + + +//============= +class Reporting +//============= +{ + +protected: + + static UINT ShowNotification(const char *text, const char *caption, UINT flags, const CWnd *parent); + +public: + + // TODO Quick'n'dirty workaround for MsgBox(). Shouldn't be public. + static UINT CustomNotification(const char *text, const char *caption, UINT flags, const CWnd *parent) { return ShowNotification(text, caption, flags, parent); }; + + // Show a simple notification + static void Notification(const char *text, const CWnd *parent = nullptr); + static void Notification(const char *text, const char *caption, const CWnd *parent = nullptr); + + // Show a simple information + static void Information(const char *text, const CWnd *parent = nullptr); + static void Information(const char *text, const char *caption, const CWnd *parent = nullptr); + + // Show a simple warning + static void Warning(const char *text, const CWnd *parent = nullptr); + static void Warning(const char *text, const char *caption, const CWnd *parent = nullptr); + + // Show an error box. + static void Error(const char *text, const CWnd *parent = nullptr); + static void Error(const char *text, const char *caption, const CWnd *parent = nullptr); + + // Show a confirmation dialog. + static ConfirmAnswer Confirm(const char *text, bool showCancel = false, bool defaultNo = false, const CWnd *parent = nullptr); + static ConfirmAnswer Confirm(const char *text, const char *caption, bool showCancel = false, bool defaultNo = false, const CWnd *parent = nullptr); + + // Show a confirmation dialog. + static RetryAnswer RetryCancel(const char *text, const CWnd *parent = nullptr); + static RetryAnswer RetryCancel(const char *text, const char *caption, const CWnd *parent = nullptr); + +}; Property changes on: trunk/OpenMPT/mptrack/Reporting.h ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-chdr \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/OpenMPT/mptrack/mptrack_08.vcproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-04-18 21:21:33 UTC (rev 1913) @@ -481,7 +481,7 @@ > </File> <File - RelativePath="..\common\Reporting.cpp" + RelativePath="..\mptrack\Reporting.cpp" > </File> <File @@ -1023,10 +1023,14 @@ > </File> <File - RelativePath="..\common\Reporting.h" + RelativePath="..\common\Logging.h" > </File> <File + RelativePath="..\mptrack\Reporting.h" + > + </File> + <File RelativePath="..\soundlib\Resampler.h" > </File> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-04-18 21:21:33 UTC (rev 1913) @@ -248,7 +248,6 @@ <ClCompile Include="..\common\misc_util.cpp" /> <ClCompile Include="..\common\mptString.cpp" /> <ClCompile Include="..\common\Profiler.cpp" /> - <ClCompile Include="..\common\Reporting.cpp" /> <ClCompile Include="..\common\serialization_utils.cpp" /> <ClCompile Include="..\common\typedefs.cpp" /> <ClCompile Include="..\sounddev\SoundDevice.cpp" /> @@ -338,6 +337,7 @@ <ClCompile Include="PatternEditorDialogs.cpp" /> <ClCompile Include="PatternGotoDialog.cpp" /> <ClCompile Include="PSRatioCalc.cpp" /> + <ClCompile Include="Reporting.cpp" /> <ClCompile Include="SampleEditorDialogs.cpp" /> <ClCompile Include="ScaleEnvPointsDlg.cpp" /> <ClCompile Include="..\common\stdafx.cpp"> @@ -402,11 +402,11 @@ <ItemGroup> <ClInclude Include="..\common\AudioCriticalSection.h" /> <ClInclude Include="..\common\FlagSet.h" /> + <ClInclude Include="..\common\Logging.h" /> <ClInclude Include="..\common\misc_util.h" /> <ClInclude Include="..\common\mptString.h" /> <ClInclude Include="..\common\mutex.h" /> <ClInclude Include="..\common\Profiler.h" /> - <ClInclude Include="..\common\Reporting.h" /> <ClInclude Include="..\common\serialization_utils.h" /> <ClInclude Include="..\common\StringFixer.h" /> <ClInclude Include="..\common\typedefs.h" /> @@ -484,6 +484,7 @@ <ClInclude Include="Notification.h" /> <ClInclude Include="PatternClipboard.h" /> <ClInclude Include="PatternCursor.h" /> + <ClInclude Include="Reporting.h" /> <ClInclude Include="SelectPluginDialog.h" /> <ClInclude Include="ChannelManagerDlg.h" /> <ClInclude Include="CloseMainDialog.h" /> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-04-18 21:21:33 UTC (rev 1913) @@ -277,9 +277,6 @@ <ClCompile Include="..\common\Profiler.cpp"> <Filter>Source Files\common</Filter> </ClCompile> - <ClCompile Include="..\common\Reporting.cpp"> - <Filter>Source Files\common</Filter> - </ClCompile> <ClCompile Include="AbstractVstEditor.cpp"> <Filter>Source Files\mptrack</Filter> </ClCompile> @@ -436,6 +433,9 @@ <ClCompile Include="..\common\typedefs.cpp"> <Filter>Source Files\common</Filter> </ClCompile> + <ClCompile Include="Reporting.cpp"> + <Filter>Source Files\mptrack</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\soundlib\Loaders.h"> @@ -648,9 +648,6 @@ <ClInclude Include="..\common\Profiler.h"> <Filter>Header Files\common</Filter> </ClInclude> - <ClInclude Include="..\common\Reporting.h"> - <Filter>Header Files\common</Filter> - </ClInclude> <ClInclude Include="..\common\serialization_utils.h"> <Filter>Header Files\common</Filter> </ClInclude> @@ -798,6 +795,12 @@ <ClInclude Include="Vstplug.h"> <Filter>Header Files\mptrack</Filter> </ClInclude> + <ClInclude Include="..\common\Logging.h"> + <Filter>Header Files\common</Filter> + </ClInclude> + <ClInclude Include="Reporting.h"> + <Filter>Header Files\mptrack</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="res\bitmap1.bmp"> Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-04-18 21:21:33 UTC (rev 1913) @@ -14,7 +14,7 @@ #include "SoundDevice.h" #include "SoundDevices.h" #include "../common/misc_util.h" -#include "../common/Reporting.h" +#include "../mptrack/Reporting.h" #include "../common/StringFixer.h" Modified: trunk/OpenMPT/soundlib/ITCompression.cpp =================================================================== --- trunk/OpenMPT/soundlib/ITCompression.cpp 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/soundlib/ITCompression.cpp 2013-04-18 21:21:33 UTC (rev 1913) @@ -12,6 +12,9 @@ #include <stdafx.h> #include "ITCompression.h" #include "../common/misc_util.h" +#ifdef MODPLUG_TRACKER +#include "../mptrack/Reporting.h" +#endif // Algorithm parameters for 16-Bit samples struct IT16BitParams Modified: trunk/OpenMPT/soundlib/Mmx_mix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Mmx_mix.cpp 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/soundlib/Mmx_mix.cpp 2013-04-18 21:21:33 UTC (rev 1913) @@ -22,7 +22,6 @@ #include "stdafx.h" #include "sndfile.h" -#include "../common/Reporting.h" DWORD CSoundFile::GetSysInfo() Modified: trunk/OpenMPT/soundlib/ModSequence.cpp =================================================================== --- trunk/OpenMPT/soundlib/ModSequence.cpp 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/soundlib/ModSequence.cpp 2013-04-18 21:21:33 UTC (rev 1913) @@ -13,10 +13,10 @@ #include "ModSequence.h" #ifdef MODPLUG_TRACKER #include "../mptrack/moddoc.h" +#include "../mptrack/Reporting.h" #endif // MODPLUG_TRACKER #include "../common/version.h" #include "../common/serialization_utils.h" -#include "../common/Reporting.h" #include "FileReader.h" #include <functional> @@ -444,8 +444,13 @@ bool modified = false; if(hasSepPatterns && +#ifdef MODPLUG_TRACKER Reporting::Confirm("The order list contains separator items.\nThe new format supports multiple sequences, do you want to convert those separate tracks into multiple song sequences?", - "Order list conversion", false, true) == cnfYes) + "Order list conversion", false, true) == cnfYes +#else + false +#endif + ) { SetSequence(0); Modified: trunk/OpenMPT/soundlib/SampleFormats.cpp =================================================================== --- trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-04-18 21:21:33 UTC (rev 1913) @@ -14,13 +14,13 @@ #ifdef MODPLUG_TRACKER #include "../mptrack/Moddoc.h" #include "../mptrack/Mainfrm.h" // For ini settings +#include "../mptrack/Reporting.h" #endif //MODPLUG_TRACKER #include "../common/AudioCriticalSection.h" #include "Wav.h" #include "ITTools.h" #include "XMTools.h" #include "WAVTools.h" -#include "../common/Reporting.h" #include "../common/version.h" #include "ChunkReader.h" Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-04-18 21:21:33 UTC (rev 1913) @@ -13,6 +13,7 @@ #ifdef MODPLUG_TRACKER #include "../mptrack/mainfrm.h" #include "../mptrack/moddoc.h" +#include "../mptrack/Reporting.h" #endif // MODPLUG_TRACKER #include "../common/version.h" #include "../common/serialization_utils.h" @@ -20,6 +21,7 @@ #include "tuningcollection.h" #include "../common/StringFixer.h" #include "FileReader.h" +#include <iostream> #ifndef NO_ARCHIVE_SUPPORT #include "../unarchiver/unarchiver.h" @@ -386,7 +388,8 @@ Order(*this), m_pModSpecs(&ModSpecs::itEx), m_MIDIMapper(*this), - visitedSongRows(*this) + visitedSongRows(*this), + m_pCustomLog(nullptr) #pragma warning(default : 4355) // "'this' : used in base member initializer list" //---------------------- { @@ -452,14 +455,16 @@ } -void CSoundFile::AddToLog(const std::string &text) const -//------------------------------------------------------ +void CSoundFile::AddToLog(LogLevel level, const std::string &text) const +//---------------------------------------------------------------------- { -#ifdef MODPLUG_TRACKER - if(GetpModDoc()) GetpModDoc()->AddToLog(text); -#else - Reporting::Warning(text.c_str()); -#endif + if(m_pCustomLog) + return m_pCustomLog->AddToLog(level, text); + #ifdef MODPLUG_TRACKER + if(GetpModDoc()) GetpModDoc()->AddToLog(level, text); + #else + std::clog << "openmpt: " << LogLevelToString(level) << ": " << text << std::endl; + #endif } @@ -1480,12 +1485,12 @@ bool CSoundFile::SaveStaticTunings() //---------------------------------- { - if(s_pTuningsSharedLocal->Serialize()) + if(s_pTuningsSharedLocal->Serialize() != CTuningCollection::SERIALIZATION_SUCCESS) { - ErrorBox(IDS_ERR_TUNING_SERIALISATION, NULL); - return true; + AddToLog(LogError, "Static tuning serialisation failed"); + return false; } - return false; + return true; } #endif Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-04-18 21:21:33 UTC (rev 1913) @@ -14,6 +14,7 @@ #include "../soundlib/SoundFilePlayConfig.h" #include "../soundlib/MixerSettings.h" #include "../common/misc_util.h" +#include "../common/Logging.h" #include "mod_specifications.h" #include <vector> #include <bitset> @@ -130,6 +131,7 @@ class CModDoc; #endif // MODPLUG_TRACKER + //============== class CSoundFile //============== @@ -173,7 +175,7 @@ public: #ifdef MODPLUG_TRACKER static bool LoadStaticTunings(); - static bool SaveStaticTunings(); + bool SaveStaticTunings(); static void DeleteStaticdata(); static CTuningCollection& GetBuiltInTunings() {return *s_pTuningsSharedBuiltIn;} static CTuningCollection& GetLocalTunings() {return *s_pTuningsSharedLocal;} @@ -335,13 +337,21 @@ bool m_bIsRendering; bool m_bPatternTransitionOccurred; +private: + // logging and user interaction + ILog *m_pCustomLog; + public: CSoundFile(); ~CSoundFile(); public: + // logging and user interaction + void SetCustomLog(ILog *pLog) { m_pCustomLog = pLog; } + void AddToLog(LogLevel level, const std::string &text) const; + void AddToLog(const std::string &text) const { AddToLog(LogInformation, text); } - void AddToLog(const std::string &text) const; +public: #ifdef MODPLUG_TRACKER BOOL Create(LPCBYTE lpStream, CModDoc *pModDoc, DWORD dwMemLength=0); Modified: trunk/OpenMPT/soundlib/modsmp_ctrl.cpp =================================================================== --- trunk/OpenMPT/soundlib/modsmp_ctrl.cpp 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/soundlib/modsmp_ctrl.cpp 2013-04-18 21:21:33 UTC (rev 1913) @@ -11,7 +11,6 @@ #include "stdafx.h" #include "modsmp_ctrl.h" #include "../common/AudioCriticalSection.h" -#include "../common/Reporting.h" #include "Sndfile.h" #define new DEBUG_NEW @@ -55,7 +54,7 @@ #if 0 if( GetSampleCapacity(smp) >= nNewSmpBytes ) // If sample has room to expand. { - Reporting::Notification("Not implemented: GetSampleCapacity(smp) >= nNewSmpBytes"); + sndFile.AddToLog(LogNotification, "Not implemented: GetSampleCapacity(smp) >= nNewSmpBytes"); // Not implemented, GetSampleCapacity() currently always returns length based value // even if there is unused space in the sample. } @@ -74,7 +73,7 @@ memcpy(pNewSmp, smp.pSample, nOldBytes); } else - Reporting::Notification(TEXT("Unsupported start position in InsertSilence.")); + sndFile.AddToLog(LogNotification, TEXT("Unsupported start position in InsertSilence.")); } // Set loop points automatically Modified: trunk/OpenMPT/soundlib/patternContainer.cpp =================================================================== --- trunk/OpenMPT/soundlib/patternContainer.cpp 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/soundlib/patternContainer.cpp 2013-04-18 21:21:33 UTC (rev 1913) @@ -64,9 +64,7 @@ m_Patterns.push_back(MODPATTERN(*this)); else { -#ifdef MODPLUG_TRACKER - ErrorBox(IDS_ERR_TOOMANYPAT, CMainFrame::GetMainFrame()); -#endif // MODPLUG_TRACKER + GetSoundFile().AddToLog(LogError, "Too many patterns!"); return true; } } Modified: trunk/OpenMPT/soundlib/tuning.cpp =================================================================== --- trunk/OpenMPT/soundlib/tuning.cpp 2013-04-18 20:23:43 UTC (rev 1912) +++ trunk/OpenMPT/soundlib/tuning.cpp 2013-04-18 21:21:33 UTC (rev 1913) @@ -12,7 +12,9 @@ #include "tuning.h" #include "../common/serialization_utils.h" -#include "../common/Reporting.h" +#ifdef MODPLUG_TRACKER +#include "../mptrack/Reporting.h" +#endif #include <string> typedef CTuningRTI::RATIOTYPE RATIOTYPE; @@ -399,7 +401,13 @@ pTuning->m_EditMask = EM_ALLOWALL; //Allowing all while processing data. if (pTuning->ProProcessUnserializationdata()) { - Reporting::Error(("Processing loaded data for tuning \"" + pTuning->GetName() + "\" failed.").c_str(), "Tuning load failure"); +#ifdef MODPLUG_TRACKER + Reporting::Error( +#else + Log("%s (%s)\n", +#endif + ("Processing loaded data for tuning \"" + pTuning->GetName() + "\" failed.").c_str(), "Tuning load failure" + ); delete pTuning; pTuning = nullptr; } else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |