1
0

SampleEditorDialogs.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * SampleEditorDialogs.h
  3. * ---------------------
  4. * Purpose: Code for various dialogs that are used in the sample editor.
  5. * Notes : (currently none)
  6. * Authors: Olivier Lapicque
  7. * OpenMPT Devs
  8. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  9. */
  10. #pragma once
  11. #include "openmpt/all/BuildSettings.hpp"
  12. #include "../common/FileReaderFwd.h"
  13. #include "../soundlib/SampleIO.h"
  14. #include "../tracklib/FadeLaws.h"
  15. #include "CDecimalSupport.h"
  16. OPENMPT_NAMESPACE_BEGIN
  17. //////////////////////////////////////////////////////////////////////////
  18. // Sample amplification dialog
  19. class CAmpDlg: public CDialog
  20. {
  21. public:
  22. struct AmpSettings
  23. {
  24. Fade::Law fadeLaw;
  25. int fadeInStart, fadeOutEnd;
  26. int16 factor;
  27. bool fadeIn, fadeOut;
  28. };
  29. AmpSettings &m_settings;
  30. int16 m_nFactorMin, m_nFactorMax;
  31. protected:
  32. CComboBoxEx m_fadeBox;
  33. CImageList m_list;
  34. CNumberEdit m_edit, m_editFadeIn, m_editFadeOut;
  35. bool m_locked = true;
  36. public:
  37. CAmpDlg(CWnd *parent, AmpSettings &settings, int16 factorMin = int16_min, int16 factorMax = int16_max);
  38. protected:
  39. void DoDataExchange(CDataExchange* pDX) override;
  40. BOOL OnInitDialog() override;
  41. void OnOK() override;
  42. void OnDestroy();
  43. afx_msg void EnableFadeIn() { if(!m_locked) CheckDlgButton(IDC_CHECK1, BST_CHECKED); }
  44. afx_msg void EnableFadeOut() { if(!m_locked) CheckDlgButton(IDC_CHECK2, BST_CHECKED); }
  45. DECLARE_MESSAGE_MAP()
  46. };
  47. //////////////////////////////////////////////////////////////////////////
  48. // Sample import dialog
  49. class CRawSampleDlg: public CDialog
  50. {
  51. friend class AutodetectFormatDlg;
  52. protected:
  53. static SampleIO m_format;
  54. static SmpLength m_offset;
  55. CSpinButtonCtrl m_SpinOffset;
  56. FileReader &m_file;
  57. bool m_rememberFormat = false;
  58. public:
  59. SampleIO GetSampleFormat() const { return m_format; }
  60. void SetSampleFormat(SampleIO nFormat) { m_format = nFormat; }
  61. bool GetRemeberFormat() const { return m_rememberFormat; };
  62. void SetRememberFormat(bool remember) { m_rememberFormat = remember; };
  63. SmpLength GetOffset() const { return m_offset; }
  64. void SetOffset(SmpLength offset) { m_offset = offset; }
  65. public:
  66. CRawSampleDlg(FileReader &file, CWnd *parent = nullptr)
  67. : CDialog(IDD_LOADRAWSAMPLE, parent)
  68. , m_file(file) {}
  69. protected:
  70. void DoDataExchange(CDataExchange *pDX) override;
  71. BOOL OnInitDialog() override;
  72. void OnOK() override;
  73. void UpdateDialog();
  74. void OnBitDepthChanged(UINT id);
  75. void OnEncodingChanged(UINT id);
  76. void OnAutodetectFormat();
  77. DECLARE_MESSAGE_MAP()
  78. };
  79. /////////////////////////////////////////////////////////////////////////
  80. // Add silence dialog - add silence to a sample
  81. class AddSilenceDlg: public CDialog
  82. {
  83. public:
  84. enum AddSilenceOptions
  85. {
  86. kSilenceAtBeginning, // Add at beginning of sample
  87. kSilenceAtEnd, // Add at end of sample
  88. kResize, // Resize sample
  89. kOPLInstrument, // Initialize as OPL instrument
  90. };
  91. enum Unit
  92. {
  93. kSamples = 0,
  94. kMilliseconds,
  95. };
  96. SmpLength m_numSamples; // Add x samples (also containes the return value in all cases)
  97. SmpLength m_length; // Set size to x samples (init value: current sample size)
  98. AddSilenceOptions m_editOption; // See above
  99. protected:
  100. static SmpLength m_addSamples;
  101. static SmpLength m_createSamples;
  102. uint32 m_sampleRate;
  103. Unit m_unit = kSamples;
  104. bool m_allowOPL;
  105. public:
  106. AddSilenceDlg(CWnd *parent, SmpLength origLength, uint32 sampleRate, bool allowOPL);
  107. BOOL OnInitDialog() override;
  108. void OnOK() override;
  109. protected:
  110. AddSilenceOptions GetEditMode() const;
  111. afx_msg void OnEditModeChanged();
  112. afx_msg void OnUnitChanged();
  113. DECLARE_MESSAGE_MAP()
  114. };
  115. /////////////////////////////////////////////////////////////////////////
  116. // Sample grid dialog
  117. class CSampleGridDlg: public CDialog
  118. {
  119. public:
  120. SmpLength m_nSegments, m_nMaxSegments;
  121. protected:
  122. CEdit m_EditSegments;
  123. CSpinButtonCtrl m_SpinSegments;
  124. public:
  125. CSampleGridDlg(CWnd *parent, SmpLength nSegments, SmpLength nMaxSegments) : CDialog(IDD_SAMPLE_GRID_SIZE, parent) { m_nSegments = nSegments; m_nMaxSegments = nMaxSegments; };
  126. protected:
  127. void DoDataExchange(CDataExchange* pDX) override;
  128. BOOL OnInitDialog() override;
  129. void OnOK() override;
  130. };
  131. /////////////////////////////////////////////////////////////////////////
  132. // Sample cross-fade dialog
  133. class CSampleXFadeDlg: public CDialog
  134. {
  135. public:
  136. static uint32 m_fadeLength;
  137. static uint32 m_fadeLaw;
  138. static bool m_afterloopFade;
  139. static bool m_useSustainLoop;
  140. SmpLength m_loopLength = 0, m_maxLength = 0;
  141. protected:
  142. CSliderCtrl m_SliderLength, m_SliderFadeLaw;
  143. CEdit m_EditSamples;
  144. CSpinButtonCtrl m_SpinSamples;
  145. CButton m_RadioNormalLoop, m_RadioSustainLoop;
  146. ModSample &m_sample;
  147. bool m_editLocked = true;
  148. public:
  149. CSampleXFadeDlg(CWnd *parent, ModSample &sample)
  150. : CDialog(IDD_SAMPLE_XFADE, parent)
  151. , m_sample(sample) {}
  152. SmpLength PercentToSamples(uint32 percent) const { return Util::muldivr_unsigned(percent, m_loopLength, 100000); }
  153. uint32 SamplesToPercent(SmpLength samples) const { return Util::muldivr_unsigned(samples, 100000, m_loopLength); }
  154. protected:
  155. void DoDataExchange(CDataExchange* pDX) override;
  156. BOOL OnInitDialog() override;
  157. void OnOK() override;
  158. afx_msg void OnLoopTypeChanged();
  159. afx_msg void OnFadeLengthChanged();
  160. afx_msg void OnHScroll(UINT, UINT, CScrollBar *);
  161. afx_msg BOOL OnToolTipText(UINT, NMHDR *pNMHDR, LRESULT *pResult);
  162. DECLARE_MESSAGE_MAP()
  163. };
  164. /////////////////////////////////////////////////////////////////////////
  165. // Resampling dialog
  166. class CResamplingDlg: public CDialog
  167. {
  168. public:
  169. enum ResamplingOption
  170. {
  171. Upsample,
  172. Downsample,
  173. Custom
  174. };
  175. protected:
  176. ResamplingMode m_srcMode;
  177. uint32 m_frequency;
  178. bool m_resampleAll;
  179. static uint32 m_lastFrequency;
  180. static ResamplingOption m_lastChoice;
  181. static bool m_updatePatterns;
  182. public:
  183. CResamplingDlg(CWnd *parent, uint32 frequency, ResamplingMode srcMode, bool resampleAll) : CDialog(IDD_RESAMPLE, parent), m_srcMode(srcMode), m_frequency(frequency), m_resampleAll(resampleAll) { };
  184. uint32 GetFrequency() const { return m_frequency; }
  185. ResamplingMode GetFilter() const { return m_srcMode; }
  186. static ResamplingOption GetResamplingOption() { return m_lastChoice; }
  187. static bool UpdatePatternCommands() { return m_updatePatterns; }
  188. protected:
  189. BOOL OnInitDialog() override;
  190. void OnOK() override;
  191. afx_msg void OnFocusEdit() { CheckRadioButton(IDC_RADIO1, IDC_RADIO3, IDC_RADIO3); }
  192. DECLARE_MESSAGE_MAP()
  193. };
  194. /////////////////////////////////////////////////////////////////////////
  195. // Sample mix dialog
  196. class CMixSampleDlg: public CDialog
  197. {
  198. protected:
  199. // Dialog controls
  200. CEdit m_EditOffset;
  201. CNumberEdit m_EditVolOriginal, m_EditVolMix;
  202. CSpinButtonCtrl m_SpinOffset, m_SpinVolOriginal, m_SpinVolMix;
  203. public:
  204. static SmpLength sampleOffset;
  205. static int amplifyOriginal;
  206. static int amplifyMix;
  207. public:
  208. CMixSampleDlg(CWnd *parent);
  209. protected:
  210. void DoDataExchange(CDataExchange* pDX) override;
  211. BOOL OnInitDialog() override;
  212. void OnOK() override;
  213. };
  214. OPENMPT_NAMESPACE_END