From: <rel...@us...> - 2009-05-02 20:42:23
|
Revision: 256 http://modplug.svn.sourceforge.net/modplug/?rev=256&view=rev Author: relabsoluness Date: 2009-05-02 20:42:19 +0000 (Sat, 02 May 2009) Log Message: ----------- . (patch from Jojo, merged somewhat modified) Fixes to MOD saving: it should now be possible to create ProTracker compatible MOD files with compatibility export. + Added a few hidable usage tips. . Fix to parameter validation in ReadSample. Modified Paths: -------------- trunk/OpenMPT/mptrack/Ctrl_smp.cpp trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mainfrm.h trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/dlg_misc.cpp trunk/OpenMPT/mptrack/dlg_misc.h trunk/OpenMPT/mptrack/mptrack.rc trunk/OpenMPT/mptrack/resource.h trunk/OpenMPT/soundlib/Load_mod.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/Sndfile.h Modified: trunk/OpenMPT/mptrack/Ctrl_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2009-05-01 14:12:28 UTC (rev 255) +++ trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2009-05-02 20:42:19 UTC (rev 256) @@ -2242,9 +2242,10 @@ memset(&viewstate, 0, sizeof(viewstate)); SendViewMessage(VIEWMSG_SAVESTATE, (LPARAM)&viewstate); if ((!m_pModDoc) || (!m_pSndFile) || (!m_pSndFile->Ins[m_nSample].pSample)) return; - if( AfxMessageBox(TEXT(GetStrI18N("Apply signed/unsigned conversion(distortion)?\n\n" - "Note: in many cases this increases volume level significantly.")), MB_YESNO|MB_ICONQUESTION) == IDNO ) - return; + + if(m_pModDoc->IsNotePlaying(0, m_nSample, 0) == TRUE) + MsgBoxHidable(ConfirmSignUnsignWhenPlaying); + BeginWaitCursor(); pins = &m_pSndFile->Ins[m_nSample]; dwStart = viewstate.dwBeginSel; Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2009-05-01 14:12:28 UTC (rev 255) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2009-05-02 20:42:19 UTC (rev 256) @@ -166,6 +166,8 @@ int CMainFrame::gnPlugWindowHeight = 332; DWORD CMainFrame::gnPlugWindowLast = 0; +uint32 CMainFrame::gnMsgBoxVisiblityFlags = ~0; + CRITICAL_SECTION CMainFrame::m_csAudio; HANDLE CMainFrame::m_hPlayThread = NULL; DWORD CMainFrame::m_dwPlayThreadId = 0; @@ -391,6 +393,7 @@ gnPlugWindowWidth = GetPrivateProfileInt("Display", "PlugSelectWindowWidth", 370, iniFile); gnPlugWindowHeight = GetPrivateProfileInt("Display", "PlugSelectWindowHeight", 332, iniFile); gnPlugWindowLast = GetPrivateProfileDWord("Display", "PlugSelectWindowLast", 0, iniFile); + gnMsgBoxVisiblityFlags = GetPrivateProfileDWord("Display", "MsgBoxVisibilityFlags", ~0, iniFile); CHAR s[16]; for (int ncol=0; ncol<MAX_MODCOLORS; ncol++) { @@ -902,6 +905,7 @@ WritePrivateProfileLong("Display", "PlugSelectWindowWidth", gnPlugWindowWidth, iniFile); WritePrivateProfileLong("Display", "PlugSelectWindowHeight", gnPlugWindowHeight, iniFile); WritePrivateProfileLong("Display", "PlugSelectWindowLast", gnPlugWindowLast, iniFile); + WritePrivateProfileDWord("Display", "MsgBoxVisibilityFlags", gnMsgBoxVisiblityFlags, iniFile); CHAR s[16]; for (int ncol=0; ncol<MAX_MODCOLORS; ncol++) { Modified: trunk/OpenMPT/mptrack/Mainfrm.h =================================================================== --- trunk/OpenMPT/mptrack/Mainfrm.h 2009-05-01 14:12:28 UTC (rev 255) +++ trunk/OpenMPT/mptrack/Mainfrm.h 2009-05-02 20:42:19 UTC (rev 256) @@ -425,6 +425,8 @@ static int gnPlugWindowHeight; static DWORD gnPlugWindowLast; + static uint32 gnMsgBoxVisiblityFlags; + // Midi Input public: static HMIDIIN shMidiIn; Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2009-05-01 14:12:28 UTC (rev 255) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2009-05-02 20:42:19 UTC (rev 256) @@ -20,6 +20,12 @@ static char THIS_FILE[] = __FILE__; #endif +const TCHAR* const FileFilterMOD = TEXT("ProTracker Modules (*.mod)|*.mod||"); +const TCHAR* const FileFilterXM = TEXT("FastTracker Modules (*.xm)|*.xm||"); +const TCHAR* const FileFilterS3M = TEXT("ScreamTracker Modules (*.s3m)|*.s3m||"); +const TCHAR* const FileFilterIT = TEXT("Impulse Tracker Modules (*.it)|*.it||"); +const TCHAR* const FileFilterITP = TEXT("Impulse Tracker Projects (*.itp)|*.itp||"); +const TCHAR* const FileFilterMPT = TEXT("OpenMPT Modules (*.mptm)|*.mptm||"); ///////////////////////////////////////////////////////////////////////////// // CModDoc @@ -487,18 +493,19 @@ switch(m_SndFile.GetType()) { case MOD_TYPE_MOD: + MsgBoxHidable(ModCompatibilityExportTip); lpszDefExt = "mod"; - lpszFilter = "ProTracker Modules (*.mod)|*.mod||"; + lpszFilter = FileFilterMOD; strcpy(fext, ".mod"); break; case MOD_TYPE_S3M: lpszDefExt = "s3m"; - lpszFilter = "ScreamTracker Modules (*.s3m)|*.s3m||"; + lpszFilter = FileFilterS3M; strcpy(fext, ".s3m"); break; case MOD_TYPE_XM: lpszDefExt = "xm"; - lpszFilter = "FastTracker Modules (*.xm)|*.xm||"; + lpszFilter = FileFilterXM; strcpy(fext, ".xm"); break; case MOD_TYPE_IT: @@ -509,19 +516,21 @@ // strcpy(fext, ".it"); if(m_SndFile.m_dwSongFlags & SONG_ITPROJECT){ lpszDefExt = "itp"; - lpszFilter = "Impulse Tracker Projects (*.itp)|*.itp||"; + lpszFilter = FileFilterITP; strcpy(fext, ".itp"); } - else{ + else + { + MsgBoxHidable(ItCompatibilityExportTip); lpszDefExt = "it"; - lpszFilter = "Impulse Tracker Modules (*.it)|*.it||"; + lpszFilter = FileFilterIT; strcpy(fext, ".it"); } // -! NEW_FEATURE#0023 break; case MOD_TYPE_MPT: lpszDefExt = "mptm"; - lpszFilter = "OpenMPT Modules (*.mptm)|*.mptm||"; + lpszFilter = FileFilterMPT; strcpy(fext, ".mptm"); break; default: @@ -1561,7 +1570,7 @@ //HACK: This is a quick fix. Needs to be better integrated into player and GUI. void CModDoc::OnFileCompatibilitySave() -//------------------------------- +//------------------------------------- { CHAR path[_MAX_PATH]="", drive[_MAX_DRIVE]=""; CHAR s[_MAX_PATH], fname[_MAX_FNAME]=""; @@ -1571,21 +1580,34 @@ UINT type = m_SndFile.GetType(); if ((!pMainFrm) || (!m_SndFile.GetType())) return; - switch (type) { + switch (type) + { /*case MOD_TYPE_XM: ext = "xm"; pattern = "Fast Tracker Files (*.xm)|*.xm||"; break;*/ + case MOD_TYPE_MOD: + ext = MOD_STD_SPECS.fileExtension; + pattern = FileFilterMOD; + if( AfxMessageBox(GetStrI18N(TEXT( + "Compared to regular MOD save, compatibility export makes " + "small adjustments to the save file in order to make the file compatible with " + "ProTracker. Note that this feature is not complete and the " + "file is not guaranteed to be free of MPT-specific features.\n\n " + "Important: beginning of some samples may be adjusted in the process. Proceed?")), MB_ICONINFORMATION|MB_YESNO) != IDYES + ) + return; + break; case MOD_TYPE_IT: - ext = "it"; - pattern = "Impulse Tracker Files (*.it)|*.it||"; + ext = IT_STD_SPECS.fileExtension; + pattern = FileFilterIT; + ::MessageBox(NULL,"Warning: the exported file will not contain any of MPT's file-format hacks.", "Compatibility export warning.",MB_ICONINFORMATION | MB_OK); break; default: - ::MessageBox(NULL,"Compatibility export is currently only available the IT format.", "Can't do compatibility export.",MB_ICONINFORMATION | MB_OK); + ::MessageBox(NULL,"Compatibility export is currently only available for MOD and IT modules.", "Can't do compatibility export.",MB_ICONINFORMATION | MB_OK); return; } - ::MessageBox(NULL,"Warning: the exported file will not contain any of MPT's file-format hacks.", "Compatibility export warning.",MB_ICONINFORMATION | MB_OK); _splitpath(GetPathName(), drive, path, fname, NULL); strcpy(s, drive); strcat(s, path); @@ -1602,7 +1624,13 @@ if (dlg.DoModal() != IDOK){ return; } - switch (type) { + switch (type) + { + case MOD_TYPE_MOD: + m_SndFile.SaveMod(dlg.GetPathName(), 0, true); + SetModified(); // Compatibility save may adjust samples so set modified... + m_ShowSavedialog = true; // ...and force save dialog to appear when saving. + break; case MOD_TYPE_XM: m_SndFile.SaveCompatXM(dlg.GetPathName()); break; Modified: trunk/OpenMPT/mptrack/dlg_misc.cpp =================================================================== --- trunk/OpenMPT/mptrack/dlg_misc.cpp 2009-05-01 14:12:28 UTC (rev 255) +++ trunk/OpenMPT/mptrack/dlg_misc.cpp 2009-05-02 20:42:19 UTC (rev 256) @@ -2710,4 +2710,90 @@ CDialog::OnCancel(); } +/////////////////////////////////////////////////////////////////////////////////////// +// Messagebox with 'don't show again'-option. +//=================================== +class CMsgBoxHidable : public CDialog +//=================================== +{ +public: + CMsgBoxHidable(LPCTSTR strMsg, bool checkStatus = true, CWnd* pParent = NULL); + enum { IDD = IDD_MSGBOX_HIDABLE }; + + int m_nCheckStatus; + LPCTSTR m_StrMsg; +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL OnInitDialog(); +}; + + +struct MsgBoxHidableMessage +//========================= +{ + LPCTSTR strMsg; + uint32 nMask; + bool bDefaultDontShowAgainStatus; // true for don't show again, false for show again. +}; + +const MsgBoxHidableMessage HidableMessages[] = +{ + {TEXT("Tip: To create ProTracker compatible MOD-files, try compatibility export from File-menu."), 1, true}, + {TEXT("Tip: To create IT-files without MPT-specific extensions included, try compatibility export from File-menu."), 1 << 1, true}, + {TEXT("Press OK to apply signed/unsigned conversion\n (note: this often significantly increases volume level)"), 1 << 2, false} +}; + +STATIC_ASSERT(ARRAYELEMCOUNT(HidableMessages) == enMsgBoxHidableMessage_count); + +// Messagebox with 'don't show this again'-checkbox. Uses parameter 'enMsg' +// to get the needed information from message array, and updates the variable that +// controls the show/don't show-flags. +void MsgBoxHidable(enMsgBoxHidableMessage enMsg) +//---------------------------------------------- +{ + // Check whether the message should be shown. + if((CMainFrame::gnMsgBoxVisiblityFlags & HidableMessages[enMsg].nMask) == 0) + return; + + const LPCTSTR strMsg = HidableMessages[enMsg].strMsg; + const uint32 mask = HidableMessages[enMsg].nMask; + const bool defaulCheckStatus = HidableMessages[enMsg].bDefaultDontShowAgainStatus; + + // Show dialog. + CMsgBoxHidable dlg(strMsg, defaulCheckStatus); + dlg.DoModal(); + + // Update visibility flags. + if(dlg.m_nCheckStatus == BST_CHECKED) + CMainFrame::gnMsgBoxVisiblityFlags &= ~mask; + else + CMainFrame::gnMsgBoxVisiblityFlags |= mask; +} + + +CMsgBoxHidable::CMsgBoxHidable(LPCTSTR strMsg, bool checkStatus, CWnd* pParent) + : CDialog(CMsgBoxHidable::IDD, pParent), + m_StrMsg(strMsg), + m_nCheckStatus((checkStatus) ? BST_CHECKED : BST_UNCHECKED) +//---------------------------------------------------------------------------- +{} + +BOOL CMsgBoxHidable::OnInitDialog() +//---------------------------------- +{ + CDialog::OnInitDialog(); + SetDlgItemText(IDC_MESSAGETEXT, m_StrMsg); + SetWindowText(AfxGetAppName()); + return TRUE; +} + +void CMsgBoxHidable::DoDataExchange(CDataExchange* pDX) +//------------------------------------------------------ +{ + CDialog::DoDataExchange(pDX); + DDX_Check(pDX, IDC_DONTSHOWAGAIN, m_nCheckStatus); +} + + + Modified: trunk/OpenMPT/mptrack/dlg_misc.h =================================================================== --- trunk/OpenMPT/mptrack/dlg_misc.h 2009-05-01 14:12:28 UTC (rev 255) +++ trunk/OpenMPT/mptrack/dlg_misc.h 2009-05-02 20:42:19 UTC (rev 256) @@ -493,4 +493,18 @@ }; +///////////////////////////////////////////////////////////////////////// +// Messagebox with 'don't show again'-option. + +// Enums for message entries. See dlg_misc.cpp for the array of entries. +enum enMsgBoxHidableMessage +{ + ModCompatibilityExportTip = 0, + ItCompatibilityExportTip = 1, + ConfirmSignUnsignWhenPlaying = 2, + enMsgBoxHidableMessage_count = 3 +}; + +void MsgBoxHidable(enMsgBoxHidableMessage enMsg); + #endif Modified: trunk/OpenMPT/mptrack/mptrack.rc =================================================================== --- trunk/OpenMPT/mptrack/mptrack.rc 2009-05-01 14:12:28 UTC (rev 255) +++ trunk/OpenMPT/mptrack/mptrack.rc 2009-05-02 20:42:19 UTC (rev 256) @@ -2626,6 +2626,19 @@ // Dialog // +IDD_MSGBOX_HIDABLE DIALOGEX 0, 0, 186, 71 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | + WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + DEFPUSHBUTTON "OK",IDOK,149,50,30,14 + PUSHBUTTON "Cancel",IDCANCEL,111,49,30,14,NOT WS_VISIBLE + CONTROL "Don't show this again.",IDC_DONTSHOWAGAIN,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,7,54,90,10 + LTEXT "Static",IDC_MESSAGETEXT,7,7,172,40 +END + IDD_MIDIPARAMCONTROL DIALOGEX 0, 0, 392, 202 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU @@ -2837,6 +2850,14 @@ #ifdef APSTUDIO_INVOKED GUIDELINES DESIGNINFO BEGIN + IDD_MSGBOX_HIDABLE, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 179 + TOPMARGIN, 7 + BOTTOMMARGIN, 64 + END + IDD_MIDIPARAMCONTROL, DIALOG BEGIN RIGHTMARGIN, 388 Modified: trunk/OpenMPT/mptrack/resource.h =================================================================== --- trunk/OpenMPT/mptrack/resource.h 2009-05-01 14:12:28 UTC (rev 255) +++ trunk/OpenMPT/mptrack/resource.h 2009-05-02 20:42:19 UTC (rev 256) @@ -104,6 +104,7 @@ #define IDD_DIALOG3 513 #define IDS_ERR_TUNING_SERIALISATION 514 #define IDD_MIDIPARAMCONTROL 515 +#define IDD_MSGBOX_HIDABLE 516 #define IDC_BUTTON1 1001 #define IDC_BUTTON2 1002 #define IDC_BUTTON3 1003 @@ -825,6 +826,8 @@ #define IDC_EDIT_STRETCHPARAMS 2338 #define IDC_MIDI_MACRO_CONTROL 2339 #define IDC_MIDIPLAYPATTERNONMIDIIN 2340 +#define IDC_DONTSHOWAGAIN 2341 +#define IDC_MESSAGETEXT 2342 #define ID_FILE_NEWMOD 32771 #define ID_FILE_NEWXM 32772 #define ID_FILE_NEWS3M 32773 @@ -1057,9 +1060,9 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_3D_CONTROLS 1 -#define _APS_NEXT_RESOURCE_VALUE 516 +#define _APS_NEXT_RESOURCE_VALUE 517 #define _APS_NEXT_COMMAND_VALUE 59221 -#define _APS_NEXT_CONTROL_VALUE 2341 +#define _APS_NEXT_CONTROL_VALUE 2343 #define _APS_NEXT_SYMED_VALUE 901 #endif #endif Modified: trunk/OpenMPT/soundlib/Load_mod.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mod.cpp 2009-05-01 14:12:28 UTC (rev 255) +++ trunk/OpenMPT/soundlib/Load_mod.cpp 2009-05-02 20:42:19 UTC (rev 256) @@ -373,8 +373,8 @@ #ifndef MODPLUG_NO_FILESAVE #pragma warning(disable:4100) -BOOL CSoundFile::SaveMod(LPCSTR lpszFileName, UINT nPacking) -//---------------------------------------------------------- +BOOL CSoundFile::SaveMod(LPCSTR lpszFileName, UINT nPacking, const bool bCompatibilityExport) +//------------------------------------------------------------------------------------------- { BYTE insmap[32]; UINT inslen[32]; @@ -418,8 +418,11 @@ bTab[25] = pins->nVolume >> 2; bTab[26] = pins->nLoopStart >> 9; bTab[27] = pins->nLoopStart >> 1; - bTab[28] = (pins->nLoopEnd - pins->nLoopStart) >> 9; - bTab[29] = (pins->nLoopEnd - pins->nLoopStart) >> 1; + UINT replen = pins->nLoopEnd - pins->nLoopStart; + if(bCompatibilityExport && replen < 2) // ensure PT will load it properly + replen = 2; + bTab[28] = replen >> 9; + bTab[29] = replen >> 1; fwrite(bTab, 30, 1, f); } // Writing number of patterns @@ -501,6 +504,11 @@ for (UINT ismpd=1; ismpd<=31; ismpd++) if (inslen[ismpd]) { MODINSTRUMENT *pins = &Ins[insmap[ismpd]]; + if(bCompatibilityExport == true) + { + if(pins->nLength > 0) pins->pSample[0] = 0; + if(pins->nLength > 1) pins->pSample[1] = 0; + } UINT flags = RS_PCM8S; #ifndef NO_PACKING if (!(pins->uFlags & (CHN_16BIT|CHN_STEREO))) Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2009-05-01 14:12:28 UTC (rev 255) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2009-05-02 20:42:19 UTC (rev 256) @@ -1899,12 +1899,13 @@ UINT CSoundFile::ReadSample(MODINSTRUMENT *pIns, UINT nFlags, LPCSTR lpMemFile, DWORD dwMemLength, const WORD format) //----------------------------------------------------------------------------------------------------------------------- { + if ((!pIns) || (pIns->nLength < 4) || (!lpMemFile)) return 0; + if(pIns->nLength > MAX_SAMPLE_LENGTH) pIns->nLength = MAX_SAMPLE_LENGTH; UINT len = 0, mem = pIns->nLength+6; - if ((!pIns) || (pIns->nLength < 4) || (!lpMemFile)) return 0; pIns->uFlags &= ~(CHN_16BIT|CHN_STEREO); if (nFlags & RSF_16BIT) { Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2009-05-01 14:12:28 UTC (rev 255) +++ trunk/OpenMPT/soundlib/Sndfile.h 2009-05-02 20:42:19 UTC (rev 256) @@ -1074,7 +1074,7 @@ UINT WriteSample(FILE *f, MODINSTRUMENT *pins, UINT nFlags, UINT nMaxLen=0); BOOL SaveXM(LPCSTR lpszFileName, UINT nPacking=0); BOOL SaveS3M(LPCSTR lpszFileName, UINT nPacking=0); - BOOL SaveMod(LPCSTR lpszFileName, UINT nPacking=0); + BOOL SaveMod(LPCSTR lpszFileName, UINT nPacking=0, const bool bCompatibilityExport = false); BOOL SaveIT(LPCSTR lpszFileName, UINT nPacking=0); BOOL SaveCompatIT(LPCSTR lpszFileName); BOOL SaveCompatXM(LPCSTR lpszFileName); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |