From: <sag...@us...> - 2009-07-25 15:39:29
|
Revision: 303 http://modplug.svn.sourceforge.net/modplug/?rev=303&view=rev Author: saga-games Date: 2009-07-25 15:39:19 +0000 (Sat, 25 Jul 2009) Log Message: ----------- [Imp] General tab: "Modtype" dialog will revert mod flags to previous values if user presses the Cancel button [Imp] Sample tab: It is now possible to resize samples to a given sample size. You can do this using the already existing "add silence" dialog. [Fix] S3M loader: Samples with very short loops (2 bytes) will now load correctly. This fixes for example 94hitmix.s3m and spectral.s3m. After using this patch for a long time, it seems to not break anything else. Modified Paths: -------------- trunk/OpenMPT/mptrack/View_smp.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_s3m.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/modsmp_ctrl.cpp trunk/OpenMPT/soundlib/modsmp_ctrl.h Modified: trunk/OpenMPT/mptrack/View_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_smp.cpp 2009-07-25 13:27:30 UTC (rev 302) +++ trunk/OpenMPT/mptrack/View_smp.cpp 2009-07-25 15:39:19 UTC (rev 303) @@ -2415,14 +2415,14 @@ void CViewSample::OnAddSilence() //------------------------------ { - CAddSilenceDlg dlg(this); - if (dlg.DoModal() != IDOK) return; - CModDoc *pModDoc = GetDocument(); if (!pModDoc) return; CSoundFile *pSndFile = pModDoc->GetSoundFile(); if (!pSndFile) return; + CAddSilenceDlg dlg(this, 32, pSndFile->Ins[m_nSample].nLength); + if (dlg.DoModal() != IDOK) return; + const ctrlSmp::SmpLength nOldLength = pSndFile->Ins[m_nSample].nLength; if( MAX_SAMPLE_LENGTH - nOldLength < dlg.m_nSamples ) @@ -2432,7 +2432,16 @@ return; } - ctrlSmp::InsertSilence(pSndFile->Ins[m_nSample], dlg.m_nSamples, (dlg.m_bAddAtEnd) ? pSndFile->Ins[m_nSample].nLength : 0, pSndFile); + if(dlg.m_nEditOption == 3) + { + // resize + ctrlSmp::ResizeSample(pSndFile->Ins[m_nSample], dlg.m_nSamples, pSndFile); + } + else + { + // add silence + ctrlSmp::InsertSilence(pSndFile->Ins[m_nSample], dlg.m_nSamples, (dlg.m_nEditOption == 2) ? pSndFile->Ins[m_nSample].nLength : 0, pSndFile); + } if(nOldLength != pSndFile->Ins[m_nSample].nLength) { Modified: trunk/OpenMPT/mptrack/dlg_misc.cpp =================================================================== --- trunk/OpenMPT/mptrack/dlg_misc.cpp 2009-07-25 13:27:30 UTC (rev 302) +++ trunk/OpenMPT/mptrack/dlg_misc.cpp 2009-07-25 15:39:19 UTC (rev 303) @@ -138,6 +138,7 @@ CDialog::OnInitDialog(); m_nType = m_pSndFile->m_nType; m_nChannels = m_pSndFile->m_nChannels; + m_dwSongFlags = m_pSndFile->m_dwSongFlags; SetDlgItemInt(IDC_ROWSPERBEAT, m_pSndFile->m_nRowsPerBeat); SetDlgItemInt(IDC_ROWSPERMEASURE, m_pSndFile->m_nRowsPerMeasure); @@ -489,7 +490,15 @@ CDialog::OnOK(); } +void CModTypeDlg::OnCancel() +//-------------------------- +{ + // Reset mod flags + m_pSndFile->m_dwSongFlags = m_dwSongFlags; + CDialog::OnCancel(); +} + ////////////////////////////////////////////////////////////////////////////// // CShowLogDlg @@ -1568,19 +1577,45 @@ // Add silence to a sample +BEGIN_MESSAGE_MAP(CAddSilenceDlg, CDialog) + ON_COMMAND(IDC_RADIO_ADDSILENCE_BEGIN, OnEditModeChanged) + ON_COMMAND(IDC_RADIO_ADDSILENCE_END, OnEditModeChanged) + ON_COMMAND(IDC_RADIO_RESIZETO, OnEditModeChanged) +END_MESSAGE_MAP() + + BOOL CAddSilenceDlg::OnInitDialog() //--------------------------------- { CDialog::OnInitDialog(); - CSpinButtonCtrl *spin = (CSpinButtonCtrl *)GetDlgItem(IDC_SPIN1); + + CSpinButtonCtrl *spin = (CSpinButtonCtrl *)GetDlgItem(IDC_SPIN_ADDSILENCE); if (spin) { spin->SetRange(0, int16_max); spin->SetPos(m_nSamples); } - CButton *radio2 = (CButton *)GetDlgItem(IDC_RADIO2); - radio2->SetCheck(m_bAddAtEnd); - SetDlgItemInt(IDC_EDIT1, m_nSamples); + + int iRadioButton; + switch(m_nEditOption) + { + case 1: + iRadioButton = IDC_RADIO_ADDSILENCE_BEGIN; + break; + case 2: + default: + iRadioButton = IDC_RADIO_ADDSILENCE_END; + break; + case 3: + iRadioButton = IDC_RADIO_RESIZETO; + break; + + } + CButton *radioEnd = (CButton *)GetDlgItem(iRadioButton); + radioEnd->SetCheck(true); + + SetDlgItemInt(IDC_EDIT_ADDSILENCE, (m_nEditOption == 3) ? m_nLength : m_nSamples); + return TRUE; } @@ -1588,12 +1623,39 @@ void CAddSilenceDlg::OnOK() //------------------------- { - m_nSamples = GetDlgItemInt(IDC_EDIT1); - m_bAddAtEnd = (IsDlgButtonChecked(IDC_RADIO2) != 0); + m_nSamples = GetDlgItemInt(IDC_EDIT_ADDSILENCE); + m_nEditOption = GetEditMode(); CDialog::OnOK(); } +void CAddSilenceDlg::OnEditModeChanged() +//------------------------------------------------ +{ + char cNewEditOption = GetEditMode(); + if(cNewEditOption != 3 && m_nEditOption == 3) + { + m_nLength = GetDlgItemInt(IDC_EDIT_ADDSILENCE); + SetDlgItemInt(IDC_EDIT_ADDSILENCE, m_nSamples); + } + else if(cNewEditOption == 3 && m_nEditOption != 3) + { + m_nSamples = GetDlgItemInt(IDC_EDIT_ADDSILENCE); + SetDlgItemInt(IDC_EDIT_ADDSILENCE, m_nLength); + } + m_nEditOption = cNewEditOption; +} + + +char CAddSilenceDlg::GetEditMode() +{ + if(IsDlgButtonChecked(IDC_RADIO_ADDSILENCE_BEGIN)) return 1; + else if(IsDlgButtonChecked(IDC_RADIO_ADDSILENCE_END)) return 2; + else if(IsDlgButtonChecked(IDC_RADIO_RESIZETO)) return 3; + return 0; +} + + //////////////////////////////////////////////////////////////////////////////// // Sound Bank Information Modified: trunk/OpenMPT/mptrack/dlg_misc.h =================================================================== --- trunk/OpenMPT/mptrack/dlg_misc.h 2009-07-25 13:27:30 UTC (rev 302) +++ trunk/OpenMPT/mptrack/dlg_misc.h 2009-07-25 15:39:19 UTC (rev 303) @@ -15,6 +15,7 @@ CEdit m_EditFlag; CSoundFile *m_pSndFile; UINT m_nChannels, m_nType; + DWORD m_dwSongFlags; // -> CODE#0023 // -> DESC="IT project files (.itp)" @@ -36,6 +37,7 @@ virtual void DoDataExchange(CDataExchange* pDX); virtual BOOL OnInitDialog(); virtual void OnOK(); + virtual void OnCancel(); //}}AFX_VIRTUAL //{{AFX_MSG(CModTypeDlg) @@ -346,12 +348,18 @@ class CAddSilenceDlg: public CDialog //=========================== { +protected: + char GetEditMode(); + afx_msg void OnEditModeChanged(); + DECLARE_MESSAGE_MAP() + public: UINT m_nSamples; - bool m_bAddAtEnd; + UINT m_nLength; + char m_nEditOption; //0 = add at beginning, 1 = add at end, 2 = resize public: - CAddSilenceDlg(CWnd *parent, UINT nSamples=32):CDialog(IDD_ADDSILENCE, parent) { m_nSamples = nSamples; m_bAddAtEnd = true; } + CAddSilenceDlg(CWnd *parent, UINT nSamples = 32, UINT nOrigLength = 1024):CDialog(IDD_ADDSILENCE, parent) { m_nSamples = nSamples; m_nLength = nOrigLength; m_nEditOption = 2; } virtual BOOL OnInitDialog(); virtual void OnOK(); }; Modified: trunk/OpenMPT/mptrack/mptrack.rc =================================================================== --- trunk/OpenMPT/mptrack/mptrack.rc 2009-07-25 13:27:30 UTC (rev 302) +++ trunk/OpenMPT/mptrack/mptrack.rc 2009-07-25 15:39:19 UTC (rev 303) @@ -1482,19 +1482,21 @@ LTEXT "around current",IDC_STATIC,156,84,49,8 END -IDD_ADDSILENCE DIALOGEX 0, 0, 175, 71 +IDD_ADDSILENCE DIALOGEX 0, 0, 184, 82 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Insert Silence" +CAPTION "Add Silence / Resize" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN - GROUPBOX "",IDC_STATIC,6,6,108,60 - DEFPUSHBUTTON "OK",IDOK,120,12,50,14 - PUSHBUTTON "Cancel",IDCANCEL,120,30,50,14 - EDITTEXT IDC_EDIT1,12,18,40,14,ES_AUTOHSCROLL | ES_NUMBER - CONTROL "",IDC_SPIN1,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | UDS_NOTHOUSANDS,44,18,11,14 - LTEXT "samples",IDC_STATIC,59,21,35,8 - CONTROL "At beginning of sample",IDC_RADIO1,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,12,36,97,10 - CONTROL "At end of sample",IDC_RADIO2,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,12,48,97,10 + GROUPBOX "",IDC_STATIC,6,6,114,72 + DEFPUSHBUTTON "OK",IDOK,126,12,50,14 + PUSHBUTTON "Cancel",IDCANCEL,126,30,50,14 + EDITTEXT IDC_EDIT_ADDSILENCE,12,18,60,14,ES_AUTOHSCROLL | ES_NUMBER + CONTROL "",IDC_SPIN_ADDSILENCE,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | UDS_NOTHOUSANDS,60,18,11,14 + LTEXT "samples",IDC_STATIC,78,21,35,8 + CONTROL "Add a beginning of sample",IDC_RADIO_ADDSILENCE_BEGIN, + "Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,12,36,102,12 + CONTROL "Add at end of sample",IDC_RADIO_ADDSILENCE_END,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,12,48,102,12 + CONTROL "Resize to",IDC_RADIO_RESIZETO,"Button",BS_AUTORADIOBUTTON,12,60,102,12 END IDD_PATTERNRANDOMIZER_EFFECT DIALOGEX 0, 0, 235, 172 @@ -1790,9 +1792,9 @@ IDD_ADDSILENCE, DIALOG BEGIN LEFTMARGIN, 7 - RIGHTMARGIN, 168 + RIGHTMARGIN, 177 TOPMARGIN, 7 - BOTTOMMARGIN, 64 + BOTTOMMARGIN, 75 END IDD_PATTERNRANDOMIZER_EFFECT, DIALOG Modified: trunk/OpenMPT/mptrack/resource.h =================================================================== --- trunk/OpenMPT/mptrack/resource.h 2009-07-25 13:27:30 UTC (rev 302) +++ trunk/OpenMPT/mptrack/resource.h 2009-07-25 15:39:19 UTC (rev 303) @@ -869,6 +869,12 @@ #define IDC_EDIT_SAVEDWITH 2375 #define IDC_FRAME_MODFLAGS 2376 #define IDC_FRAME_MODTYPE 2377 +#define IDC_EDIT_ADDSILENCE 2378 +#define IDC_EDIT_RESIZESAMPLE 2379 +#define IDC_RADIO_ADDSILENCE_BEGIN 2380 +#define IDC_RADIO_ADDSILENCE_END 2381 +#define IDC_SPIN_ADDSILENCE 2382 +#define IDC_RADIO_RESIZETO 2384 #define ID_FILE_NEWMOD 32771 #define ID_FILE_NEWXM 32772 #define ID_FILE_NEWS3M 32773 @@ -1108,7 +1114,7 @@ #define _APS_3D_CONTROLS 1 #define _APS_NEXT_RESOURCE_VALUE 518 #define _APS_NEXT_COMMAND_VALUE 59227 -#define _APS_NEXT_CONTROL_VALUE 2378 +#define _APS_NEXT_CONTROL_VALUE 2385 #define _APS_NEXT_SYMED_VALUE 901 #endif #endif Modified: trunk/OpenMPT/soundlib/Load_s3m.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_s3m.cpp 2009-07-25 13:27:30 UTC (rev 302) +++ trunk/OpenMPT/soundlib/Load_s3m.cpp 2009-07-25 15:39:19 UTC (rev 303) @@ -370,9 +370,8 @@ if ((Ins[iSmp].nLoopStart >= Ins[iSmp].nLoopEnd) || (Ins[iSmp].nLoopEnd - Ins[iSmp].nLoopStart < 1)) Ins[iSmp].nLoopStart = Ins[iSmp].nLoopEnd = 0; UINT iLooplength = Ins[iSmp].nLoopEnd - Ins[iSmp].nLoopStart; - if(iLooplength > 0 && iLooplength < 8) Ins[iSmp].nLoopEnd = Ins[iSmp].nLoopStart + 8; Ins[iSmp].nPan = 0x80; - // ASSERT(iLooplength == 0 || iLooplength > 10); + //ASSERT(iLooplength == 0 || iLooplength > 4); } } // Reading patterns Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2009-07-25 13:27:30 UTC (rev 302) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2009-07-25 15:39:19 UTC (rev 303) @@ -650,7 +650,7 @@ if (pins->pSample) { if (pins->nLoopEnd > pins->nLength) pins->nLoopEnd = pins->nLength; - if (pins->nLoopStart + 3 >= pins->nLoopEnd) + if (pins->nLoopStart >= pins->nLoopEnd) { pins->nLoopStart = 0; pins->nLoopEnd = 0; @@ -2447,7 +2447,7 @@ { if ((!pIns->pSample) || (!pIns->nLength)) return; if (pIns->nLoopEnd > pIns->nLength) pIns->nLoopEnd = pIns->nLength; - if (pIns->nLoopStart+2 >= pIns->nLoopEnd) + if (pIns->nLoopStart >= pIns->nLoopEnd) { pIns->nLoopStart = pIns->nLoopEnd = 0; pIns->uFlags &= ~CHN_LOOP; Modified: trunk/OpenMPT/soundlib/modsmp_ctrl.cpp =================================================================== --- trunk/OpenMPT/soundlib/modsmp_ctrl.cpp 2009-07-25 13:27:30 UTC (rev 302) +++ trunk/OpenMPT/soundlib/modsmp_ctrl.cpp 2009-07-25 15:39:19 UTC (rev 303) @@ -23,7 +23,7 @@ } -SmpLength InsertSilence(MODINSTRUMENT& smp, const SmpLength nSilenceLength, const SmpLength nStartFrom, CSoundFile* pSndFile) +SmpLength InsertSilence(MODINSTRUMENT& smp, const SmpLength nSilenceLength, const SmpLength nStartFrom, CSoundFile* pSndFile) //---------------------------------------------------------------------------------------------------------------------------- { if(nSilenceLength == 0 || nSilenceLength >= MAX_SAMPLE_LENGTH || smp.nLength > MAX_SAMPLE_LENGTH - nSilenceLength) @@ -66,6 +66,49 @@ return smp.nLength; } +SmpLength ResizeSample(MODINSTRUMENT& smp, const SmpLength nNewLength, CSoundFile* pSndFile) +//---------------------------------------------------------------------------------------- +{ + // Invalid sample size + if(nNewLength > MAX_SAMPLE_LENGTH || nNewLength == smp.nLength) + return smp.nLength; + + // New sample will be bigger so we'll just use "InsertSilence" as it's already there. + if(nNewLength > smp.nLength) + return InsertSilence(smp, nNewLength - smp.nLength, smp.nLength, pSndFile); + + // Else: Shrink sample + + const SmpLength nNewSmpBytes = nNewLength * smp.GetElementarySampleSize() * smp.GetNumChannels(); + + LPSTR pNewSmp = 0; + pNewSmp = CSoundFile::AllocateSample(nNewSmpBytes); + if(pNewSmp == 0) + return smp.nLength; //Sample allocation failed. + + // Copy over old data and replace sample by the new one + memcpy(pNewSmp, smp.pSample, nNewSmpBytes); + ReplaceSample(smp, pNewSmp, nNewLength); + + // Adjust loops + if(smp.nLoopStart > nNewLength) + { + smp.nLoopStart = smp.nLoopEnd = 0; + smp.uFlags &= ~CHN_LOOP; + } + if(smp.nLoopEnd > nNewLength) smp.nLoopEnd = nNewLength; + if(smp.nSustainStart > nNewLength) + { + smp.nSustainStart = smp.nSustainEnd = 0; + smp.uFlags &= ~CHN_SUSTAINLOOP; + } + if(smp.nSustainEnd > nNewLength) smp.nSustainEnd = nNewLength; + + AdjustEndOfSample(smp, pSndFile); + + return smp.nLength; +} + namespace // Unnamed namespace for local implementation functions. { Modified: trunk/OpenMPT/soundlib/modsmp_ctrl.h =================================================================== --- trunk/OpenMPT/soundlib/modsmp_ctrl.h 2009-07-25 13:27:30 UTC (rev 302) +++ trunk/OpenMPT/soundlib/modsmp_ctrl.h 2009-07-25 15:39:19 UTC (rev 303) @@ -20,8 +20,13 @@ // Insert silence to given location. // Note: Is currently implemented only for inserting silence to the beginning and to the end of the sample. // Return: Length of the new sample. -SmpLength InsertSilence(MODINSTRUMENT& smp, const SmpLength nSilenceLength, const SmpLength nStartFrom, CSoundFile* pSndFile = 0); +SmpLength InsertSilence(MODINSTRUMENT& smp, const SmpLength nSilenceLength, const SmpLength nStartFrom, CSoundFile* pSndFile = nullptr); +// Change sample size. +// Note: If resized sample is bigger, silence will be added to the sample's tail. +// Return: Length of the new sample. +SmpLength ResizeSample(MODINSTRUMENT& smp, const SmpLength nNewLength, CSoundFile* pSndFile = nullptr); + // Replaces sample in 'smp' with given sample and frees the old sample. void ReplaceSample(MODINSTRUMENT& smp, const LPSTR pNewSample, const SmpLength nNewLength); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |