SaControls.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. // Advanced settings knobs
  46. m_envelopeResolutionModel(0.25f, 0.1f, 3.0f, 0.05f, this, tr("Peak envelope resolution")),
  47. m_spectrumResolutionModel(1.5f, 0.1f, 3.0f, 0.05f, this, tr("Spectrum display resolution")),
  48. m_peakDecayFactorModel(0.992f, 0.95f, 0.999f, 0.001f, this, tr("Peak decay multiplier")),
  49. m_averagingWeightModel(0.15f, 0.01f, 0.5f, 0.01f, this, tr("Averaging weight")),
  50. m_waterfallHeightModel(300.0f, 50.0f, 1000.0f, 50.0f, this, tr("Waterfall history size")),
  51. m_waterfallGammaModel(0.30f, 0.10f, 1.00f, 0.05f, this, tr("Waterfall gamma correction")),
  52. m_windowOverlapModel(2.0f, 1.0f, 4.0f, 1.0f, this, tr("FFT window overlap")),
  53. m_zeroPaddingModel(2.0f, 0.0f, 4.0f, 1.0f, this, tr("FFT zero padding"))
  54. {
  55. // Frequency and amplitude ranges; order must match
  56. // FREQUENCY_RANGES and AMPLITUDE_RANGES defined in SaControls.h
  57. m_freqRangeModel.addItem(tr("Full (auto)"));
  58. m_freqRangeModel.addItem(tr("Audible"));
  59. m_freqRangeModel.addItem(tr("Bass"));
  60. m_freqRangeModel.addItem(tr("Mids"));
  61. m_freqRangeModel.addItem(tr("High"));
  62. m_freqRangeModel.setValue(m_freqRangeModel.findText(tr("Full (auto)")));
  63. m_ampRangeModel.addItem(tr("Extended"));
  64. m_ampRangeModel.addItem(tr("Audible"));
  65. m_ampRangeModel.addItem(tr("Loud"));
  66. m_ampRangeModel.addItem(tr("Silent"));
  67. m_ampRangeModel.setValue(m_ampRangeModel.findText(tr("Audible")));
  68. // FFT block size labels are generated automatically, based on
  69. // FFT_BLOCK_SIZES vector defined in fft_helpers.h
  70. for (unsigned int i = 0; i < FFT_BLOCK_SIZES.size(); i++)
  71. {
  72. if (i == 0)
  73. {
  74. m_blockSizeModel.addItem((std::to_string(FFT_BLOCK_SIZES[i]) + " ").c_str() + tr("(High time res.)"));
  75. }
  76. else if (i == FFT_BLOCK_SIZES.size() - 1)
  77. {
  78. m_blockSizeModel.addItem((std::to_string(FFT_BLOCK_SIZES[i]) + " ").c_str() + tr("(High freq. res.)"));
  79. }
  80. else
  81. {
  82. m_blockSizeModel.addItem(std::to_string(FFT_BLOCK_SIZES[i]).c_str());
  83. }
  84. }
  85. m_blockSizeModel.setValue(m_blockSizeModel.findText("2048"));
  86. // Window type order must match FFT_WINDOWS defined in fft_helpers.h
  87. m_windowModel.addItem(tr("Rectangular (Off)"));
  88. m_windowModel.addItem(tr("Blackman-Harris (Default)"));
  89. m_windowModel.addItem(tr("Hamming"));
  90. m_windowModel.addItem(tr("Hanning"));
  91. m_windowModel.setValue(m_windowModel.findText(tr("Blackman-Harris (Default)")));
  92. // Colors
  93. // Background color is defined by Qt / theme.
  94. // Make sure the sum of colors for L and R channel results into a neutral
  95. // color that has at least one component equal to 255 (i.e. ideally white).
  96. // This means the color overflows to zero exactly when signal reaches
  97. // clipping threshold, indicating the problematic frequency to user.
  98. // Mono waterfall color should have similarly at least one component at 255.
  99. m_colorL = QColor(51, 148, 204, 135);
  100. m_colorR = QColor(204, 107, 51, 135);
  101. m_colorMono = QColor(51, 148, 204, 204);
  102. m_colorMonoW = QColor(64, 185, 255, 255);
  103. m_colorBG = QColor(7, 7, 7, 255); // ~20 % gray (after gamma correction)
  104. m_colorGrid = QColor(30, 34, 38, 255); // ~40 % gray (slightly cold / blue)
  105. m_colorLabels = QColor(192, 202, 212, 255); // ~90 % gray (slightly cold / blue)
  106. }
  107. // Create the SaControlDialog widget which handles display of GUI elements.
  108. EffectControlDialog* SaControls::createView()
  109. {
  110. return new SaControlsDialog(this, m_effect->getProcessor());
  111. }
  112. void SaControls::loadSettings(const QDomElement &_this)
  113. {
  114. m_waterfallModel.loadSettings(_this, "Waterfall");
  115. m_smoothModel.loadSettings(_this, "Smooth");
  116. m_stereoModel.loadSettings(_this, "Stereo");
  117. m_peakHoldModel.loadSettings(_this, "PeakHold");
  118. m_logXModel.loadSettings(_this, "LogX");
  119. m_logYModel.loadSettings(_this, "LogY");
  120. m_freqRangeModel.loadSettings(_this, "RangeX");
  121. m_ampRangeModel.loadSettings(_this, "RangeY");
  122. m_blockSizeModel.loadSettings(_this, "BlockSize");
  123. m_windowModel.loadSettings(_this, "WindowType");
  124. m_envelopeResolutionModel.loadSettings(_this, "EnvelopeRes");
  125. m_spectrumResolutionModel.loadSettings(_this, "SpectrumRes");
  126. m_peakDecayFactorModel.loadSettings(_this, "PeakDecayFactor");
  127. m_averagingWeightModel.loadSettings(_this, "AverageWeight");
  128. m_waterfallHeightModel.loadSettings(_this, "WaterfallHeight");
  129. m_waterfallGammaModel.loadSettings(_this, "WaterfallGamma");
  130. m_windowOverlapModel.loadSettings(_this, "WindowOverlap");
  131. m_zeroPaddingModel.loadSettings(_this, "ZeroPadding");
  132. }
  133. void SaControls::saveSettings(QDomDocument &doc, QDomElement &parent)
  134. {
  135. m_waterfallModel.saveSettings(doc, parent, "Waterfall");
  136. m_smoothModel.saveSettings(doc, parent, "Smooth");
  137. m_stereoModel.saveSettings(doc, parent, "Stereo");
  138. m_peakHoldModel.saveSettings(doc, parent, "PeakHold");
  139. m_logXModel.saveSettings(doc, parent, "LogX");
  140. m_logYModel.saveSettings(doc, parent, "LogY");
  141. m_freqRangeModel.saveSettings(doc, parent, "RangeX");
  142. m_ampRangeModel.saveSettings(doc, parent, "RangeY");
  143. m_blockSizeModel.saveSettings(doc, parent, "BlockSize");
  144. m_windowModel.saveSettings(doc, parent, "WindowType");
  145. m_envelopeResolutionModel.saveSettings(doc, parent, "EnvelopeRes");
  146. m_spectrumResolutionModel.saveSettings(doc, parent, "SpectrumRes");
  147. m_peakDecayFactorModel.saveSettings(doc, parent, "PeakDecayFactor");
  148. m_averagingWeightModel.saveSettings(doc, parent, "AverageWeight");
  149. m_waterfallHeightModel.saveSettings(doc, parent, "WaterfallHeight");
  150. m_waterfallGammaModel.saveSettings(doc, parent, "WaterfallGamma");
  151. m_windowOverlapModel.saveSettings(doc, parent, "WindowOverlap");
  152. m_zeroPaddingModel.saveSettings(doc, parent, "ZeroPadding");
  153. }