DualFilterControls.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * DualFilterControls.cpp - controls for dual filter effect
  3. *
  4. * Copyright (c) 2014 Vesa Kivimäki <contact/dot/diizy/at/nbl/dot/fi>
  5. * Copyright (c) 2008-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  6. *
  7. * This file is part of LMMS - https://lmms.io
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public
  20. * License along with this program (see COPYING); if not, write to the
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301 USA.
  23. *
  24. */
  25. #include <QDomElement>
  26. #include "BasicFilters.h"
  27. #include "DualFilterControls.h"
  28. #include "DualFilter.h"
  29. #include "embed.h"
  30. #include "Engine.h"
  31. #include "Song.h"
  32. #include "stdshims.h"
  33. DualFilterControls::DualFilterControls( DualFilterEffect* effect ) :
  34. EffectControls( effect ),
  35. m_effect( effect ),
  36. m_enabled1Model( true, this, tr( "Filter 1 enabled" ) ),
  37. m_filter1Model( this, tr( "Filter 1 type" ) ),
  38. m_cut1Model( 7000.0f, 1.0f, 20000.0f, 1.0f, this, tr( "Cutoff frequency 1" ) ),
  39. m_res1Model( 0.5, BasicFilters<>::minQ(), 10.0, 0.01, this, tr( "Q/Resonance 1" ) ),
  40. m_gain1Model( 100.0f, 0.0f, 200.0f, 0.1f, this, tr( "Gain 1" ) ),
  41. m_mixModel( 0.0f, -1.0f, 1.0f, 0.01f, this, tr( "Mix" ) ),
  42. m_enabled2Model( true, this, tr( "Filter 2 enabled" ) ),
  43. m_filter2Model( this, tr( "Filter 2 type" ) ),
  44. m_cut2Model( 7000.0f, 1.0f, 20000.0f, 1.0f, this, tr( "Cutoff frequency 2" ) ),
  45. m_res2Model( 0.5, BasicFilters<>::minQ(), 10.0, 0.01, this, tr( "Q/Resonance 2" ) ),
  46. m_gain2Model( 100.0f, 0.0f, 200.0f, 0.1f, this, tr( "Gain 2" ) )
  47. {
  48. m_filter1Model.addItem( tr( "Low-pass" ), make_unique<PixmapLoader>( "filter_lp" ) );
  49. m_filter1Model.addItem( tr( "Hi-pass" ), make_unique<PixmapLoader>( "filter_hp" ) );
  50. m_filter1Model.addItem( tr( "Band-pass csg" ), make_unique<PixmapLoader>( "filter_bp" ) );
  51. m_filter1Model.addItem( tr( "Band-pass czpg" ), make_unique<PixmapLoader>( "filter_bp" ) );
  52. m_filter1Model.addItem( tr( "Notch" ), make_unique<PixmapLoader>( "filter_notch" ) );
  53. m_filter1Model.addItem( tr( "All-pass" ), make_unique<PixmapLoader>( "filter_ap" ) );
  54. m_filter1Model.addItem( tr( "Moog" ), make_unique<PixmapLoader>( "filter_lp" ) );
  55. m_filter1Model.addItem( tr( "2x Low-pass" ), make_unique<PixmapLoader>( "filter_2lp" ) );
  56. m_filter1Model.addItem( tr( "RC Low-pass 12 dB/oct" ), make_unique<PixmapLoader>( "filter_lp" ) );
  57. m_filter1Model.addItem( tr( "RC Band-pass 12 dB/oct" ), make_unique<PixmapLoader>( "filter_bp" ) );
  58. m_filter1Model.addItem( tr( "RC High-pass 12 dB/oct" ), make_unique<PixmapLoader>( "filter_hp" ) );
  59. m_filter1Model.addItem( tr( "RC Low-pass 24 dB/oct" ), make_unique<PixmapLoader>( "filter_lp" ) );
  60. m_filter1Model.addItem( tr( "RC Band-pass 24 dB/oct" ), make_unique<PixmapLoader>( "filter_bp" ) );
  61. m_filter1Model.addItem( tr( "RC High-pass 24 dB/oct" ), make_unique<PixmapLoader>( "filter_hp" ) );
  62. m_filter1Model.addItem( tr( "Vocal Formant" ), make_unique<PixmapLoader>( "filter_hp" ) );
  63. m_filter1Model.addItem( tr( "2x Moog" ), make_unique<PixmapLoader>( "filter_2lp" ) );
  64. m_filter1Model.addItem( tr( "SV Low-pass" ), make_unique<PixmapLoader>( "filter_lp" ) );
  65. m_filter1Model.addItem( tr( "SV Band-pass" ), make_unique<PixmapLoader>( "filter_bp" ) );
  66. m_filter1Model.addItem( tr( "SV High-pass" ), make_unique<PixmapLoader>( "filter_hp" ) );
  67. m_filter1Model.addItem( tr( "SV Notch" ), make_unique<PixmapLoader>( "filter_notch" ) );
  68. m_filter1Model.addItem( tr( "Fast Formant" ), make_unique<PixmapLoader>( "filter_hp" ) );
  69. m_filter1Model.addItem( tr( "Tripole" ), make_unique<PixmapLoader>( "filter_lp" ) );
  70. m_filter2Model.addItem( tr( "Low-pass" ), make_unique<PixmapLoader>( "filter_lp" ) );
  71. m_filter2Model.addItem( tr( "Hi-pass" ), make_unique<PixmapLoader>( "filter_hp" ) );
  72. m_filter2Model.addItem( tr( "Band-pass csg" ), make_unique<PixmapLoader>( "filter_bp" ) );
  73. m_filter2Model.addItem( tr( "Band-pass czpg" ), make_unique<PixmapLoader>( "filter_bp" ) );
  74. m_filter2Model.addItem( tr( "Notch" ), make_unique<PixmapLoader>( "filter_notch" ) );
  75. m_filter2Model.addItem( tr( "All-pass" ), make_unique<PixmapLoader>( "filter_ap" ) );
  76. m_filter2Model.addItem( tr( "Moog" ), make_unique<PixmapLoader>( "filter_lp" ) );
  77. m_filter2Model.addItem( tr( "2x Low-pass" ), make_unique<PixmapLoader>( "filter_2lp" ) );
  78. m_filter2Model.addItem( tr( "RC Low-pass 12 dB/oct" ), make_unique<PixmapLoader>( "filter_lp" ) );
  79. m_filter2Model.addItem( tr( "RC Band-pass 12 dB/oct" ), make_unique<PixmapLoader>( "filter_bp" ) );
  80. m_filter2Model.addItem( tr( "RC High-pass 12 dB/oct" ), make_unique<PixmapLoader>( "filter_hp" ) );
  81. m_filter2Model.addItem( tr( "RC Low-pass 24 dB/oct" ), make_unique<PixmapLoader>( "filter_lp" ) );
  82. m_filter2Model.addItem( tr( "RC Band-pass 24 dB/oct" ), make_unique<PixmapLoader>( "filter_bp" ) );
  83. m_filter2Model.addItem( tr( "RC High-pass 24 dB/oct" ), make_unique<PixmapLoader>( "filter_hp" ) );
  84. m_filter2Model.addItem( tr( "Vocal Formant" ), make_unique<PixmapLoader>( "filter_hp" ) );
  85. m_filter2Model.addItem( tr( "2x Moog" ), make_unique<PixmapLoader>( "filter_2lp" ) );
  86. m_filter2Model.addItem( tr( "SV Low-pass" ), make_unique<PixmapLoader>( "filter_lp" ) );
  87. m_filter2Model.addItem( tr( "SV Band-pass" ), make_unique<PixmapLoader>( "filter_bp" ) );
  88. m_filter2Model.addItem( tr( "SV High-pass" ), make_unique<PixmapLoader>( "filter_hp" ) );
  89. m_filter2Model.addItem( tr( "SV Notch" ), make_unique<PixmapLoader>( "filter_notch" ) );
  90. m_filter2Model.addItem( tr( "Fast Formant" ), make_unique<PixmapLoader>( "filter_hp" ) );
  91. m_filter2Model.addItem( tr( "Tripole" ), make_unique<PixmapLoader>( "filter_lp" ) );
  92. connect( Engine::mixer(), SIGNAL( sampleRateChanged() ), this, SLOT( updateFilters() ) );
  93. }
  94. void DualFilterControls::updateFilters()
  95. {
  96. // swap filters to new ones
  97. delete m_effect->m_filter1;
  98. delete m_effect->m_filter2;
  99. m_effect->m_filter1 = new BasicFilters<2>( Engine::mixer()->processingSampleRate() );
  100. m_effect->m_filter2 = new BasicFilters<2>( Engine::mixer()->processingSampleRate() );
  101. // flag filters as needing recalculation
  102. m_effect->m_filter1changed = true;
  103. m_effect->m_filter2changed = true;
  104. }
  105. void DualFilterControls::loadSettings( const QDomElement& _this )
  106. {
  107. m_enabled1Model.loadSettings( _this, "enabled1" );
  108. m_filter1Model.loadSettings( _this, "filter1" );
  109. m_cut1Model.loadSettings( _this, "cut1" );
  110. m_res1Model.loadSettings( _this, "res1" );
  111. m_gain1Model.loadSettings( _this, "gain1" );
  112. m_mixModel.loadSettings( _this, "mix" );
  113. m_enabled2Model.loadSettings( _this, "enabled2" );
  114. m_filter2Model.loadSettings( _this, "filter2" );
  115. m_cut2Model.loadSettings( _this, "cut2" );
  116. m_res2Model.loadSettings( _this, "res2" );
  117. m_gain2Model.loadSettings( _this, "gain2" );
  118. }
  119. void DualFilterControls::saveSettings( QDomDocument& _doc, QDomElement& _this )
  120. {
  121. m_enabled1Model.saveSettings( _doc, _this, "enabled1" );
  122. m_filter1Model.saveSettings( _doc, _this, "filter1" );
  123. m_cut1Model.saveSettings( _doc, _this, "cut1" );
  124. m_res1Model.saveSettings( _doc, _this, "res1" );
  125. m_gain1Model.saveSettings( _doc, _this, "gain1" );
  126. m_mixModel.saveSettings( _doc, _this, "mix" );
  127. m_enabled2Model.saveSettings( _doc, _this, "enabled2" );
  128. m_filter2Model.saveSettings( _doc, _this, "filter2" );
  129. m_cut2Model.saveSettings( _doc, _this, "cut2" );
  130. m_res2Model.saveSettings( _doc, _this, "res2" );
  131. m_gain2Model.saveSettings( _doc, _this, "gain2" );
  132. }