SaControls.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * SaControls.cpp - definition of SaControls class.
  3. *
  4. * Copyright (c) 2019 Martin Pavelek <he29/dot/HS/at/gmail/dot/com>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #include "SaControls.h"
  25. #include <QtXml/QDomElement>
  26. #include "Analyzer.h"
  27. #include "SaControlsDialog.h"
  28. SaControls::SaControls(Analyzer *effect) :
  29. EffectControls(effect),
  30. m_effect(effect),
  31. // initialize bool models and set default values
  32. m_pauseModel(false, this, tr("Pause")),
  33. m_refFreezeModel(false, this, tr("Reference freeze")),
  34. m_waterfallModel(false, this, tr("Waterfall")),
  35. m_smoothModel(false, this, tr("Averaging")),
  36. m_stereoModel(false, this, tr("Stereo")),
  37. m_peakHoldModel(false, this, tr("Peak hold")),
  38. m_logXModel(true, this, tr("Logarithmic frequency")),
  39. m_logYModel(true, this, tr("Logarithmic amplitude")),
  40. // default values of combo boxes are set after they are populated
  41. m_freqRangeModel(this, tr("Frequency range")),
  42. m_ampRangeModel(this, tr("Amplitude range")),
  43. m_blockSizeModel(this, tr("FFT block size")),
  44. m_windowModel(this, tr("FFT window type"))
  45. {
  46. // Frequency and amplitude ranges; order must match
  47. // FREQUENCY_RANGES and AMPLITUDE_RANGES defined in SaControls.h
  48. m_freqRangeModel.addItem(tr("Full (auto)"));
  49. m_freqRangeModel.addItem(tr("Audible"));
  50. m_freqRangeModel.addItem(tr("Bass"));
  51. m_freqRangeModel.addItem(tr("Mids"));
  52. m_freqRangeModel.addItem(tr("High"));
  53. m_freqRangeModel.setValue(m_freqRangeModel.findText(tr("Full (auto)")));
  54. m_ampRangeModel.addItem(tr("Extended"));
  55. m_ampRangeModel.addItem(tr("Default"));
  56. m_ampRangeModel.addItem(tr("Audible"));
  57. m_ampRangeModel.addItem(tr("Noise"));
  58. m_ampRangeModel.setValue(m_ampRangeModel.findText(tr("Default")));
  59. // FFT block size labels are generated automatically, based on
  60. // FFT_BLOCK_SIZES vector defined in fft_helpers.h
  61. for (unsigned int i = 0; i < FFT_BLOCK_SIZES.size(); i++)
  62. {
  63. if (i == 0)
  64. {
  65. m_blockSizeModel.addItem((std::to_string(FFT_BLOCK_SIZES[i]) + " ").c_str() + tr("(High time res.)"));
  66. }
  67. else if (i == FFT_BLOCK_SIZES.size() - 1)
  68. {
  69. m_blockSizeModel.addItem((std::to_string(FFT_BLOCK_SIZES[i]) + " ").c_str() + tr("(High freq. res.)"));
  70. }
  71. else
  72. {
  73. m_blockSizeModel.addItem(std::to_string(FFT_BLOCK_SIZES[i]).c_str());
  74. }
  75. }
  76. m_blockSizeModel.setValue(m_blockSizeModel.findText("2048"));
  77. // Window type order must match FFT_WINDOWS defined in fft_helpers.h
  78. m_windowModel.addItem(tr("Rectangular (Off)"));
  79. m_windowModel.addItem(tr("Blackman-Harris (Default)"));
  80. m_windowModel.addItem(tr("Hamming"));
  81. m_windowModel.addItem(tr("Hanning"));
  82. m_windowModel.setValue(m_windowModel.findText(tr("Blackman-Harris (Default)")));
  83. // Colors
  84. // Background color is defined by Qt / theme.
  85. // Make sure the sum of colors for L and R channel stays lower or equal
  86. // to 255. Otherwise the Waterfall pixels may overflow back to 0 even when
  87. // the input signal isn't clipping (over 1.0).
  88. m_colorL = QColor(51, 148, 204, 135);
  89. m_colorR = QColor(204, 107, 51, 135);
  90. m_colorMono = QColor(51, 148, 204, 204);
  91. m_colorBG = QColor(7, 7, 7, 255); // ~20 % gray (after gamma correction)
  92. m_colorGrid = QColor(30, 34, 38, 255); // ~40 % gray (slightly cold / blue)
  93. m_colorLabels = QColor(192, 202, 212, 255); // ~90 % gray (slightly cold / blue)
  94. }
  95. // Create the SaControlDialog widget which handles display of GUI elements.
  96. EffectControlDialog* SaControls::createView()
  97. {
  98. return new SaControlsDialog(this, m_effect->getProcessor());
  99. }
  100. void SaControls::loadSettings(const QDomElement &_this)
  101. {
  102. m_waterfallModel.loadSettings(_this, "Waterfall");
  103. m_smoothModel.loadSettings(_this, "Smooth");
  104. m_stereoModel.loadSettings(_this, "Stereo");
  105. m_peakHoldModel.loadSettings(_this, "PeakHold");
  106. m_logXModel.loadSettings(_this, "LogX");
  107. m_logYModel.loadSettings(_this, "LogY");
  108. m_freqRangeModel.loadSettings(_this, "RangeX");
  109. m_ampRangeModel.loadSettings(_this, "RangeY");
  110. m_blockSizeModel.loadSettings(_this, "BlockSize");
  111. m_windowModel.loadSettings(_this, "WindowType");
  112. }
  113. void SaControls::saveSettings(QDomDocument &doc, QDomElement &parent)
  114. {
  115. m_waterfallModel.saveSettings(doc, parent, "Waterfall");
  116. m_smoothModel.saveSettings(doc, parent, "Smooth");
  117. m_stereoModel.saveSettings(doc, parent, "Stereo");
  118. m_peakHoldModel.saveSettings(doc, parent, "PeakHold");
  119. m_logXModel.saveSettings(doc, parent, "LogX");
  120. m_logYModel.saveSettings(doc, parent, "LogY");
  121. m_freqRangeModel.saveSettings(doc, parent, "RangeX");
  122. m_ampRangeModel.saveSettings(doc, parent, "RangeY");
  123. m_blockSizeModel.saveSettings(doc, parent, "BlockSize");
  124. m_windowModel.saveSettings(doc, parent, "WindowType");
  125. }