1
0

ScaleEnvPointsDlg.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * ScaleEnvPointsDlg.cpp
  3. * ---------------------
  4. * Purpose: Dialog for scaling instrument envelope points on x and y axis.
  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 "resource.h"
  11. #include "ModInstrument.h"
  12. #include "ScaleEnvPointsDlg.h"
  13. OPENMPT_NAMESPACE_BEGIN
  14. double CScaleEnvPointsDlg::m_factorX = 1.0;
  15. double CScaleEnvPointsDlg::m_factorY = 1.0;
  16. double CScaleEnvPointsDlg::m_offsetY = 0.0;
  17. BOOL CScaleEnvPointsDlg::OnInitDialog()
  18. {
  19. CDialog::OnInitDialog();
  20. m_EditX.SubclassDlgItem(IDC_EDIT_FACTORX, this);
  21. m_EditY.SubclassDlgItem(IDC_EDIT_FACTORY, this);
  22. m_EditOffset.SubclassDlgItem(IDC_EDIT3, this);
  23. m_EditX.AllowNegative(false);
  24. m_EditX.SetDecimalValue(m_factorX);
  25. m_EditY.SetDecimalValue(m_factorY);
  26. m_EditOffset.SetDecimalValue(m_offsetY);
  27. return TRUE; // return TRUE unless you set the focus to a control
  28. }
  29. void CScaleEnvPointsDlg::OnOK()
  30. {
  31. m_EditX.GetDecimalValue(m_factorX);
  32. m_EditY.GetDecimalValue(m_factorY);
  33. m_EditOffset.GetDecimalValue(m_offsetY);
  34. CDialog::OnOK();
  35. }
  36. void CScaleEnvPointsDlg::Apply()
  37. {
  38. if(m_factorX > 0 && m_factorX != 1)
  39. {
  40. for(uint32 i = 0; i < m_Env.size(); i++)
  41. {
  42. m_Env[i].tick = static_cast<EnvelopeNode::tick_t>(m_factorX * m_Env[i].tick);
  43. // Checking that the order of points is preserved.
  44. if(i > 0 && m_Env[i].tick <= m_Env[i - 1].tick)
  45. m_Env[i].tick = m_Env[i - 1].tick + 1;
  46. }
  47. }
  48. if(m_factorY != 1 || m_offsetY != 0)
  49. {
  50. double factor = m_factorY;
  51. bool invert = false;
  52. if(m_factorY < 0)
  53. {
  54. invert = true;
  55. factor = -factor;
  56. }
  57. for(auto &pt : m_Env)
  58. {
  59. if(invert) pt.value = ENVELOPE_MAX - pt.value;
  60. pt.value = mpt::saturate_round<EnvelopeNode::value_t>(Clamp((factor * (pt.value - m_nCenter)) + m_nCenter + m_offsetY, double(ENVELOPE_MIN), double(ENVELOPE_MAX)));
  61. }
  62. }
  63. }
  64. OPENMPT_NAMESPACE_END