From: <sag...@us...> - 2010-12-19 17:50:47
|
Revision: 775 http://modplug.svn.sourceforge.net/modplug/?rev=775&view=rev Author: saga-games Date: 2010-12-19 17:50:40 +0000 (Sun, 19 Dec 2010) Log Message: ----------- [New] Sample Editor: The new "sample grid" feature can create equally-sized sample selections, so it is f.e. easy to split a sample into four equally-sized samples. Modified Paths: -------------- trunk/OpenMPT/mptrack/Mainfrm.h trunk/OpenMPT/mptrack/View_smp.cpp trunk/OpenMPT/mptrack/View_smp.h trunk/OpenMPT/mptrack/dlg_misc.cpp trunk/OpenMPT/mptrack/dlg_misc.h trunk/OpenMPT/mptrack/mptrack.rc trunk/OpenMPT/mptrack/res/smptoolb.bmp trunk/OpenMPT/mptrack/resource.h Modified: trunk/OpenMPT/mptrack/Mainfrm.h =================================================================== --- trunk/OpenMPT/mptrack/Mainfrm.h 2010-12-18 19:08:08 UTC (rev 774) +++ trunk/OpenMPT/mptrack/Mainfrm.h 2010-12-19 17:50:40 UTC (rev 775) @@ -298,6 +298,7 @@ SIMAGE_DRAW, SIMAGE_RESIZE, SIMAGE_GENERATE, + SIMAGE_GRID, }; Modified: trunk/OpenMPT/mptrack/View_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_smp.cpp 2010-12-18 19:08:08 UTC (rev 774) +++ trunk/OpenMPT/mptrack/View_smp.cpp 2010-12-19 17:50:40 UTC (rev 775) @@ -31,7 +31,7 @@ // trimming will be done. This is the minimum value for // selection difference, so the minimum length of result // of trimming is nTrimLengthMin + 1. -const uint8 nTrimLengthMin = 16; +#define MIN_TRIM_LENGTH 16 const UINT cLeftBarButtons[SMP_LEFTBAR_BUTTONS] = { @@ -40,6 +40,9 @@ ID_SEPARATOR, ID_SAMPLE_DRAW, ID_SAMPLE_ADDSILENCE, + ID_SEPARATOR, + ID_SAMPLE_GRID, + ID_SEPARATOR, }; @@ -88,6 +91,7 @@ ON_COMMAND(ID_SAMPLE_ZOOMDOWN, OnZoomDown) ON_COMMAND(ID_SAMPLE_DRAW, OnDrawingToggle) ON_COMMAND(ID_SAMPLE_ADDSILENCE, OnAddSilence) + ON_COMMAND(ID_SAMPLE_GRID, OnChangeGridSize) ON_MESSAGE(WM_MOD_MIDIMSG, OnMidiMsg) ON_MESSAGE(WM_MOD_KEYCOMMAND, OnCustomKeyMsg) //rewbs.customKeys //}}AFX_MSG_MAP @@ -100,6 +104,7 @@ CViewSample::CViewSample() //------------------------ { + m_nGridSegments = 0; m_nSample = 1; m_nZoom = 0; m_nScrollPos = 0; @@ -225,12 +230,23 @@ void CViewSample::SetCurSel(DWORD nBegin, DWORD nEnd) //--------------------------------------------------- { + CSoundFile *pSndFile = (GetDocument()) ? GetDocument()->GetSoundFile() : nullptr; + if(pSndFile == nullptr) + return; + + // Snap to grid + if(m_nGridSegments > 0) + { + const float sampsPerSegment = (float)(pSndFile->Samples[m_nSample].nLength / m_nGridSegments); + nBegin = (DWORD)(floor((float)(nBegin / sampsPerSegment) + 0.5f) * sampsPerSegment); + nEnd = (DWORD)(floor((float)(nEnd / sampsPerSegment) + 0.5f) * sampsPerSegment); + } + if (nBegin > nEnd) { - DWORD tmp = nBegin; - nBegin = nEnd; - nEnd = tmp; + std::swap(nBegin, nEnd); } + if ((nBegin != m_dwBeginSel) || (nEnd != m_dwEndSel)) { RECT rect; @@ -272,23 +288,18 @@ s[0] = 0; if (m_dwEndSel > m_dwBeginSel) { - CModDoc *pModDoc = GetDocument(); wsprintf(s, "[%d,%d]", m_dwBeginSel, m_dwEndSel); - if (pModDoc) + LONG lSampleRate = pSndFile->Samples[m_nSample].nC5Speed; + if (pSndFile->m_nType & (MOD_TYPE_MOD|MOD_TYPE_XM)) { - CSoundFile *pSndFile = pModDoc->GetSoundFile(); - LONG lSampleRate = pSndFile->Samples[m_nSample].nC5Speed; - if (pSndFile->m_nType & (MOD_TYPE_MOD|MOD_TYPE_XM)) - { - lSampleRate = CSoundFile::TransposeToFrequency(pSndFile->Samples[m_nSample].RelativeTone, pSndFile->Samples[m_nSample].nFineTune); - } - if (!lSampleRate) lSampleRate = 8363; - ULONG msec = ((ULONG)(m_dwEndSel - m_dwBeginSel) * 1000) / lSampleRate; - if (msec < 1000) - wsprintf(s+strlen(s), " (%lums)", msec); - else - wsprintf(s+strlen(s), " (%lu.%lus)", msec/1000, (msec/100) % 10); + lSampleRate = CSoundFile::TransposeToFrequency(pSndFile->Samples[m_nSample].RelativeTone, pSndFile->Samples[m_nSample].nFineTune); } + if (!lSampleRate) lSampleRate = 8363; + ULONG msec = ((ULONG)(m_dwEndSel - m_dwBeginSel) * 1000) / lSampleRate; + if (msec < 1000) + wsprintf(s+strlen(s), " (%lums)", msec); + else + wsprintf(s+strlen(s), " (%lu.%lus)", msec/1000, (msec/100) % 10); } pMainFrm->SetInfoText(s); } @@ -1009,6 +1020,7 @@ case ID_SAMPLE_ZOOMDOWN: nImage = SIMAGE_ZOOMDOWN; break; case ID_SAMPLE_DRAW: nImage = (dwStyle & NCBTNS_DISABLED) ? SIMAGE_NODRAW : SIMAGE_DRAW; break; case ID_SAMPLE_ADDSILENCE: nImage = SIMAGE_RESIZE; break; + case ID_SAMPLE_GRID: nImage = SIMAGE_GRID; break; } pDC->Draw3dRect(rect.left-1, rect.top-1, SMP_LEFTBAR_CXBTN+2, SMP_LEFTBAR_CYBTN+2, c3, c4); pDC->Draw3dRect(rect.left, rect.top, SMP_LEFTBAR_CXBTN, SMP_LEFTBAR_CYBTN, c1, c2); @@ -1481,7 +1493,7 @@ // "Trim" menu item is responding differently if there's no selection, // but a loop present: "trim around loop point"! (jojo in topic 2258) std::string sTrimMenuText = "Trim"; - bool bIsGrayed = ( (m_dwEndSel<=m_dwBeginSel) || (m_dwEndSel - m_dwBeginSel < nTrimLengthMin) + bool bIsGrayed = ( (m_dwEndSel<=m_dwBeginSel) || (m_dwEndSel - m_dwBeginSel < MIN_TRIM_LENGTH) || (m_dwEndSel - m_dwBeginSel == pSmp->nLength) ); @@ -1491,7 +1503,7 @@ sTrimMenuText += " around loop points"; // Check whether trim menu item can be enabled (loop not too short or long for trimming). if( (pSmp->nLoopEnd <= pSmp->nLength) && - (pSmp->nLoopEnd - pSmp->nLoopStart >= nTrimLengthMin) && + (pSmp->nLoopEnd - pSmp->nLoopStart >= MIN_TRIM_LENGTH) && (pSmp->nLoopEnd - pSmp->nLoopStart < pSmp->nLength) ) bIsGrayed = false; } @@ -2055,7 +2067,7 @@ UINT nStart = m_dwBeginSel; UINT nEnd = m_dwEndSel - m_dwBeginSel; - if ((pSmp->pSample) && (nStart+nEnd <= pSmp->nLength) && (nEnd >= nTrimLengthMin)) + if ((pSmp->pSample) && (nStart+nEnd <= pSmp->nLength) && (nEnd >= MIN_TRIM_LENGTH)) { pModDoc->GetSampleUndo()->PrepareUndo(m_nSample, sundo_replace); BEGIN_CRITICAL(); @@ -2355,7 +2367,7 @@ if(pSmp->uFlags & CHN_LOOP) { /* only update sample buffer if the loop is actually enabled - (resets sound without any reason otherwise) - bug report 1874 */ + (resets sound without any reason otherwise) - http://forum.openmpt.org/index.php?topic=1874.0 */ pModDoc->AdjustEndOfSample(m_nSample); } pModDoc->UpdateAllViews(NULL, (m_nSample << HINT_SHIFT_SMP) | HINT_SAMPLEINFO | HINT_SAMPLEDATA, NULL); @@ -2380,7 +2392,7 @@ if(pSmp->uFlags & CHN_LOOP) { /* only update sample buffer if the loop is actually enabled - (resets sound without any reason otherwise) - bug report 1874 */ + (resets sound without any reason otherwise) - http://forum.openmpt.org/index.php?topic=1874.0 */ pModDoc->AdjustEndOfSample(m_nSample); } pModDoc->UpdateAllViews(NULL, (m_nSample << HINT_SHIFT_SMP) | HINT_SAMPLEINFO | HINT_SAMPLEDATA, NULL); @@ -2703,3 +2715,15 @@ return CModScrollView::OnMouseWheel(nFlags, zDelta, pt); } + + +void CViewSample::OnChangeGridSize() +//---------------------------------- +{ + CSampleGridDlg dlg(this, m_nGridSegments, GetDocument()->GetSoundFile()->Samples[m_nSample].nLength); + if(dlg.DoModal() == IDOK) + { + m_nGridSegments = dlg.m_nSegments; + InvalidateSample(); + } +} Modified: trunk/OpenMPT/mptrack/View_smp.h =================================================================== --- trunk/OpenMPT/mptrack/View_smp.h 2010-12-18 19:08:08 UTC (rev 774) +++ trunk/OpenMPT/mptrack/View_smp.h 2010-12-19 17:50:40 UTC (rev 775) @@ -5,7 +5,7 @@ #define SMPSTATUS_KEYDOWN 0x02 #define SMPSTATUS_NCLBTNDOWN 0x04 -#define SMP_LEFTBAR_BUTTONS 5 +#define SMP_LEFTBAR_BUTTONS 8 //====================================== class CViewSample: public CModScrollView @@ -21,6 +21,7 @@ DWORD m_dwMenuParam; DWORD m_NcButtonState[SMP_LEFTBAR_BUTTONS]; DWORD m_dwNotifyPos[MAX_CHANNELS]; + int m_nGridSegments; bool m_bDrawingEnabled; // sample drawing mode enabled? CPoint m_lastDrawPoint; // for drawing horizontal lines @@ -123,6 +124,7 @@ afx_msg void OnZoomDown(); afx_msg void OnDrawingToggle(); afx_msg void OnAddSilence(); + afx_msg void OnChangeGridSize(); afx_msg LRESULT OnMidiMsg(WPARAM, LPARAM); afx_msg LRESULT OnCustomKeyMsg(WPARAM, LPARAM); //rewbs.customKeys afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); Modified: trunk/OpenMPT/mptrack/dlg_misc.cpp =================================================================== --- trunk/OpenMPT/mptrack/dlg_misc.cpp 2010-12-18 19:08:08 UTC (rev 774) +++ trunk/OpenMPT/mptrack/dlg_misc.cpp 2010-12-19 17:50:40 UTC (rev 775) @@ -526,7 +526,7 @@ strTipText = "Gxx and Exx/Fxx won't share effect memory. Gxx resets instrument envelopes."; break; case IDC_CHECK5: - strTipText = "The resonant filter's frequency range is incresed from about 4KHz to 10KHz."; + strTipText = "The resonant filter's frequency range is increased from about 4KHz to 10KHz."; break; case IDC_CHECK6: strTipText = "The instrument settings of the external ITI files will be ignored."; @@ -1873,6 +1873,39 @@ } +void CSampleGridDlg::DoDataExchange(CDataExchange* pDX) +//----------------------------------------------------- +{ + CDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CSampleGridDlg) + DDX_Control(pDX, IDC_EDIT1, m_EditSegments); + DDX_Control(pDX, IDC_SPIN1, m_SpinSegments); + //}}AFX_DATA_MAP +} + + +BOOL CSampleGridDlg::OnInitDialog() +//--------------------------------- +{ + CDialog::OnInitDialog(); + m_SpinSegments.SetRange32(0, m_nMaxSegments); + m_SpinSegments.SetPos(m_nSegments); + SetDlgItemInt(IDC_EDIT1, m_nSegments, FALSE); + GetDlgItem(IDC_EDIT1)->SetFocus(); + return TRUE; +} + + +void CSampleGridDlg::OnOK() +//------------------------- +{ + m_nSegments = GetDlgItemInt(IDC_EDIT1, NULL, FALSE); + CDialog::OnOK(); +} + + + + //////////////////////////////////////////////////////////////////////////////// // Sound Bank Information Modified: trunk/OpenMPT/mptrack/dlg_misc.h =================================================================== --- trunk/OpenMPT/mptrack/dlg_misc.h 2010-12-18 19:08:08 UTC (rev 774) +++ trunk/OpenMPT/mptrack/dlg_misc.h 2010-12-19 17:50:40 UTC (rev 775) @@ -447,7 +447,28 @@ }; +//================================== +class CSampleGridDlg: public CDialog +//================================== +{ +public: + int m_nSegments, m_nMaxSegments; +protected: + CEdit m_EditSegments; + CSpinButtonCtrl m_SpinSegments; + +public: + CSampleGridDlg(CWnd *parent, int nSegments, int nMaxSegments) : CDialog(IDD_SAMPLE_GRID_SIZE, parent) { m_nSegments = nSegments; m_nMaxSegments = nMaxSegments; }; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); + virtual BOOL OnInitDialog(); + virtual void OnOK(); +}; + + + //////////////////////////////////////////////////////////////////////// // Sound Banks Modified: trunk/OpenMPT/mptrack/mptrack.rc =================================================================== --- trunk/OpenMPT/mptrack/mptrack.rc 2010-12-18 19:08:08 UTC (rev 774) +++ trunk/OpenMPT/mptrack/mptrack.rc 2010-12-19 17:50:40 UTC (rev 775) @@ -160,7 +160,20 @@ LTEXT "",IDC_TOTAL_EDIT_TIME,60,165,192,15 END +IDD_SAMPLE_GRID_SIZE DIALOGEX 0, 0, 154, 71 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Sample Grid Size" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + EDITTEXT IDC_EDIT1,66,6,42,12,ES_AUTOHSCROLL | ES_NUMBER + CONTROL "",IDC_SPIN1,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | UDS_NOTHOUSANDS,102,6,11,14 + DEFPUSHBUTTON "&OK",IDOK,42,48,50,14 + PUSHBUTTON "&Cancel",IDCANCEL,96,48,50,14 + LTEXT "Input the number of grid segments, or input ""0"" to disable the grid.",IDC_STATIC,6,24,138,24 + LTEXT "Grid Segments:",IDC_STATIC,6,8,60,8 +END + ///////////////////////////////////////////////////////////////////////////// // // DESIGNINFO @@ -224,6 +237,14 @@ TOPMARGIN, 7 BOTTOMMARGIN, 178 END + + IDD_SAMPLE_GRID_SIZE, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 147 + TOPMARGIN, 7 + BOTTOMMARGIN, 64 + END END #endif // APSTUDIO_INVOKED @@ -415,7 +436,7 @@ END IDD_OPTIONS_MIDI DIALOGEX 0, 0, 272, 281 -STYLE DS_SETFONT | DS_3DLOOK | WS_CHILD | WS_DISABLED | WS_CAPTION +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD | WS_DISABLED | WS_CAPTION CAPTION "MIDI" FONT 8, "MS Shell Dlg", 0, 0, 0x0 BEGIN @@ -435,7 +456,7 @@ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,140,226,9 CONTROL "Pass MIDI to active instrument plugin (experimental)",IDC_MIDI_TO_PLUGIN, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,155,180,9 - CONTROL "Respond to play/continue/stop song messages (untested)",IDC_MIDIPLAYCONTROL, + CONTROL "Respond to play/continue/stop song messages",IDC_MIDIPLAYCONTROL, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,170,200,9 CONTROL "Continue song as soon as MIDI notes are being received",IDC_MIDIPLAYPATTERNONMIDIIN, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,185,195,10 Modified: trunk/OpenMPT/mptrack/res/smptoolb.bmp =================================================================== (Binary files differ) Modified: trunk/OpenMPT/mptrack/resource.h =================================================================== --- trunk/OpenMPT/mptrack/resource.h 2010-12-18 19:08:08 UTC (rev 774) +++ trunk/OpenMPT/mptrack/resource.h 2010-12-19 17:50:40 UTC (rev 775) @@ -136,6 +136,7 @@ #define IDD_SAMPLE_GENERATOR 524 #define IDD_SAMPLE_GENERATOR_PRESETS 525 #define IDD_EDITHISTORY 526 +#define IDD_SAMPLE_GRID_SIZE 527 #define IDC_BUTTON1 1001 #define IDC_BUTTON2 1002 #define IDC_BUTTON3 1003 @@ -1185,14 +1186,15 @@ #define ID_ENVELOPE_ZOOM_OUT 60450 #define ID_PANIC 60451 #define ID_VIEW_EDITHISTORY 60452 +#define ID_SAMPLE_GRID 60453 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_3D_CONTROLS 1 -#define _APS_NEXT_RESOURCE_VALUE 527 -#define _APS_NEXT_COMMAND_VALUE 60453 +#define _APS_NEXT_RESOURCE_VALUE 528 +#define _APS_NEXT_COMMAND_VALUE 60454 #define _APS_NEXT_CONTROL_VALUE 2433 #define _APS_NEXT_SYMED_VALUE 901 #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |