SampleConfigDlg.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * SampleConfigDlg.cpp
  3. * -------------------
  4. * Purpose: Implementation of the sample/instrument editor settings dialog.
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #include "stdafx.h"
  10. #include "Mainfrm.h"
  11. #include "Moddoc.h"
  12. #include "SampleConfigDlg.h"
  13. OPENMPT_NAMESPACE_BEGIN
  14. BEGIN_MESSAGE_MAP(COptionsSampleEditor, CPropertyPage)
  15. ON_WM_HSCROLL()
  16. ON_EN_CHANGE(IDC_EDIT_UNDOSIZE, &COptionsSampleEditor::OnUndoSizeChanged)
  17. ON_EN_CHANGE(IDC_EDIT_FINETUNE, &COptionsSampleEditor::OnSettingsChanged)
  18. ON_EN_CHANGE(IDC_FLAC_COMPRESSION, &COptionsSampleEditor::OnSettingsChanged)
  19. ON_CBN_SELCHANGE(IDC_DEFAULT_FORMAT, &COptionsSampleEditor::OnSettingsChanged)
  20. ON_CBN_SELCHANGE(IDC_VOLUME_HANDLING, &COptionsSampleEditor::OnSettingsChanged)
  21. ON_COMMAND(IDC_RADIO1, &COptionsSampleEditor::OnSettingsChanged)
  22. ON_COMMAND(IDC_RADIO2, &COptionsSampleEditor::OnSettingsChanged)
  23. ON_COMMAND(IDC_RADIO3, &COptionsSampleEditor::OnSettingsChanged)
  24. ON_COMMAND(IDC_COMPRESS_ITI, &COptionsSampleEditor::OnSettingsChanged)
  25. ON_COMMAND(IDC_PREVIEW_SAMPLES, &COptionsSampleEditor::OnSettingsChanged)
  26. ON_COMMAND(IDC_NORMALIZE, &COptionsSampleEditor::OnSettingsChanged)
  27. ON_COMMAND(IDC_CURSORINHEX, &COptionsSampleEditor::OnSettingsChanged)
  28. END_MESSAGE_MAP()
  29. void COptionsSampleEditor::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CPropertyPage::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(COptionsSampleEditor)
  33. DDX_Control(pDX, IDC_DEFAULT_FORMAT, m_cbnDefaultSampleFormat);
  34. DDX_Control(pDX, IDC_VOLUME_HANDLING, m_cbnDefaultVolumeHandling);
  35. //}}AFX_DATA_MAP
  36. }
  37. BOOL COptionsSampleEditor::OnInitDialog()
  38. {
  39. CPropertyPage::OnInitDialog();
  40. SetDlgItemInt(IDC_EDIT_UNDOSIZE, TrackerSettings::Instance().m_SampleUndoBufferSize.Get().GetSizeInPercent());
  41. SetDlgItemInt(IDC_EDIT_FINETUNE, TrackerSettings::Instance().m_nFinetuneStep);
  42. static_cast<CSpinButtonCtrl *>(GetDlgItem(IDC_SPIN1))->SetRange32(0, 100);
  43. static_cast<CSpinButtonCtrl *>(GetDlgItem(IDC_SPIN2))->SetRange32(1, 200);
  44. RecalcUndoSize();
  45. m_cbnDefaultSampleFormat.SetItemData(m_cbnDefaultSampleFormat.AddString(_T("FLAC")), dfFLAC);
  46. m_cbnDefaultSampleFormat.SetItemData(m_cbnDefaultSampleFormat.AddString(_T("WAV")), dfWAV);
  47. m_cbnDefaultSampleFormat.SetItemData(m_cbnDefaultSampleFormat.AddString(_T("RAW")), dfRAW);
  48. m_cbnDefaultSampleFormat.SetItemData(m_cbnDefaultSampleFormat.AddString(_T("S3I")), dfS3I);
  49. m_cbnDefaultSampleFormat.SetCurSel(TrackerSettings::Instance().m_defaultSampleFormat);
  50. CSliderCtrl *slider = static_cast<CSliderCtrl *>(GetDlgItem(IDC_SLIDER1));
  51. slider->SetRange(0, 8);
  52. slider->SetTicFreq(1);
  53. slider->SetPos(TrackerSettings::Instance().m_FLACCompressionLevel);
  54. CheckRadioButton(IDC_RADIO1, IDC_RADIO3, IDC_RADIO1 + TrackerSettings::Instance().sampleEditorKeyBehaviour);
  55. CheckDlgButton(IDC_COMPRESS_ITI, TrackerSettings::Instance().compressITI ? BST_CHECKED : BST_UNCHECKED);
  56. m_cbnDefaultVolumeHandling.SetItemData(m_cbnDefaultVolumeHandling.AddString(_T("MIDI volume")), PLUGIN_VOLUMEHANDLING_MIDI);
  57. m_cbnDefaultVolumeHandling.SetItemData(m_cbnDefaultVolumeHandling.AddString(_T("Dry/Wet ratio")), PLUGIN_VOLUMEHANDLING_DRYWET);
  58. m_cbnDefaultVolumeHandling.SetItemData(m_cbnDefaultVolumeHandling.AddString(_T("None")), PLUGIN_VOLUMEHANDLING_IGNORE);
  59. m_cbnDefaultVolumeHandling.SetCurSel(TrackerSettings::Instance().DefaultPlugVolumeHandling);
  60. CheckDlgButton(IDC_PREVIEW_SAMPLES, TrackerSettings::Instance().previewInFileDialogs ? BST_CHECKED : BST_UNCHECKED);
  61. CheckDlgButton(IDC_NORMALIZE, TrackerSettings::Instance().m_MayNormalizeSamplesOnLoad ? BST_CHECKED : BST_UNCHECKED);
  62. CheckDlgButton(IDC_CURSORINHEX, TrackerSettings::Instance().cursorPositionInHex ? BST_CHECKED : BST_UNCHECKED);
  63. return TRUE;
  64. }
  65. void COptionsSampleEditor::OnOK()
  66. {
  67. CPropertyPage::OnOK();
  68. TrackerSettings::Instance().m_nFinetuneStep = GetDlgItemInt(IDC_EDIT_FINETUNE);
  69. TrackerSettings::Instance().m_SampleUndoBufferSize = SampleUndoBufferSize(GetDlgItemInt(IDC_EDIT_UNDOSIZE));
  70. TrackerSettings::Instance().m_defaultSampleFormat = static_cast<SampleEditorDefaultFormat>(m_cbnDefaultSampleFormat.GetItemData(m_cbnDefaultSampleFormat.GetCurSel()));
  71. TrackerSettings::Instance().m_FLACCompressionLevel = static_cast<CSliderCtrl *>(GetDlgItem(IDC_SLIDER1))->GetPos();
  72. TrackerSettings::Instance().sampleEditorKeyBehaviour = static_cast<SampleEditorKeyBehaviour>(GetCheckedRadioButton(IDC_RADIO1, IDC_RADIO3) - IDC_RADIO1);
  73. TrackerSettings::Instance().compressITI = IsDlgButtonChecked(IDC_COMPRESS_ITI) != BST_UNCHECKED;
  74. TrackerSettings::Instance().DefaultPlugVolumeHandling = static_cast<PlugVolumeHandling>(m_cbnDefaultVolumeHandling.GetItemData(m_cbnDefaultVolumeHandling.GetCurSel()));
  75. TrackerSettings::Instance().previewInFileDialogs = IsDlgButtonChecked(IDC_PREVIEW_SAMPLES) != BST_UNCHECKED;
  76. TrackerSettings::Instance().m_MayNormalizeSamplesOnLoad = IsDlgButtonChecked(IDC_NORMALIZE) != BST_UNCHECKED;
  77. TrackerSettings::Instance().cursorPositionInHex = IsDlgButtonChecked(IDC_CURSORINHEX) != BST_UNCHECKED;
  78. auto docs = theApp.GetOpenDocuments();
  79. for(auto modDoc : docs)
  80. {
  81. modDoc->GetSampleUndo().RestrictBufferSize();
  82. }
  83. }
  84. BOOL COptionsSampleEditor::OnSetActive()
  85. {
  86. CMainFrame::m_nLastOptionsPage = OPTIONS_PAGE_SAMPLEDITOR;
  87. return CPropertyPage::OnSetActive();
  88. }
  89. void COptionsSampleEditor::OnUndoSizeChanged()
  90. {
  91. RecalcUndoSize();
  92. OnSettingsChanged();
  93. }
  94. void COptionsSampleEditor::RecalcUndoSize()
  95. {
  96. UINT sizePercent = GetDlgItemInt(IDC_EDIT_UNDOSIZE);
  97. uint32 sizeMB = mpt::saturate_cast<uint32>(SampleUndoBufferSize(sizePercent).GetSizeInBytes() >> 20);
  98. CString text = _T("% of physical memory (");
  99. if(sizePercent)
  100. text.AppendFormat(_T("%u MiB)"), sizeMB);
  101. else
  102. text.Append(_T("disabled)"));
  103. SetDlgItemText(IDC_UNDOSIZE, text);
  104. }
  105. OPENMPT_NAMESPACE_END