dynamics_processor_controls.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * dynamics_processor_controls.cpp - controls for dynamics_processor-effect
  3. *
  4. * Copyright (c) 2014 Vesa Kivimäki <contact/dot/diizy/at/nbl/dot/fi>
  5. * Copyright (c) 2008 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 "dynamics_processor_controls.h"
  27. #include "dynamics_processor.h"
  28. #include "base64.h"
  29. #include "Graph.h"
  30. #include "Engine.h"
  31. #include "Song.h"
  32. #define onedB 1.1220184543019633f
  33. dynProcControls::dynProcControls( dynProcEffect * _eff ) :
  34. EffectControls( _eff ),
  35. m_effect( _eff ),
  36. m_inputModel( 1.0f, 0.0f, 5.0f, 0.01f, this, tr( "Input gain" ) ),
  37. m_outputModel( 1.0f, 0.0f, 5.0f, 0.01f, this, tr( "Output gain" ) ),
  38. m_attackModel( 10.0f, 1.0f, 500.0f, 1.0f, this, tr( "Attack time" ) ),
  39. m_releaseModel( 100.0f, 1.0f, 500.0f, 1.0f, this, tr( "Release time" ) ),
  40. m_wavegraphModel( 0.0f, 1.0f, 200, this ),
  41. m_stereomodeModel( 0, 0, 2, this, tr( "Stereo mode" ) )
  42. {
  43. connect( &m_wavegraphModel, SIGNAL( samplesChanged( int, int ) ),
  44. this, SLOT( samplesChanged( int, int ) ) );
  45. connect( Engine::mixer(), SIGNAL( sampleRateChanged() ), this, SLOT( sampleRateChanged() ) );
  46. setDefaultShape();
  47. }
  48. void dynProcControls::sampleRateChanged()
  49. {
  50. m_effect->m_needsUpdate = true;
  51. }
  52. void dynProcControls::samplesChanged( int _begin, int _end)
  53. {
  54. Engine::getSong()->setModified();
  55. }
  56. void dynProcControls::loadSettings( const QDomElement & _this )
  57. {
  58. //load knobs, stereomode
  59. m_inputModel.loadSettings( _this, "inputGain" );
  60. m_outputModel.loadSettings( _this, "outputGain" );
  61. m_attackModel.loadSettings( _this, "attack" );
  62. m_releaseModel.loadSettings( _this, "release" );
  63. m_stereomodeModel.loadSettings( _this, "stereoMode" );
  64. //load waveshape
  65. int size = 0;
  66. char * dst = 0;
  67. base64::decode( _this.attribute( "waveShape"), &dst, &size );
  68. m_wavegraphModel.setSamples( (float*) dst );
  69. delete[] dst;
  70. }
  71. void dynProcControls::saveSettings( QDomDocument & _doc,
  72. QDomElement & _this )
  73. {
  74. //save input, output knobs
  75. m_inputModel.saveSettings( _doc, _this, "inputGain" );
  76. m_outputModel.saveSettings( _doc, _this, "outputGain" );
  77. m_attackModel.saveSettings( _doc, _this, "attack" );
  78. m_releaseModel.saveSettings( _doc, _this, "release" );
  79. m_stereomodeModel.saveSettings( _doc, _this, "stereoMode" );
  80. //save waveshape
  81. QString sampleString;
  82. base64::encode( (const char *)m_wavegraphModel.samples(),
  83. m_wavegraphModel.length() * sizeof(float), sampleString );
  84. _this.setAttribute( "waveShape", sampleString );
  85. }
  86. void dynProcControls::setDefaultShape()
  87. {
  88. float shp [200] = { };
  89. for ( int i = 0; i<200; i++)
  90. {
  91. shp[i] = ((float)i + 1.0f) / 200.0f;
  92. }
  93. m_wavegraphModel.setLength( 200 );
  94. m_wavegraphModel.setSamples( (float*)&shp );
  95. }
  96. void dynProcControls::resetClicked()
  97. {
  98. setDefaultShape();
  99. Engine::getSong()->setModified();
  100. }
  101. void dynProcControls::smoothClicked()
  102. {
  103. m_wavegraphModel.smoothNonCyclic();
  104. Engine::getSong()->setModified();
  105. }
  106. void dynProcControls::addOneClicked()
  107. {
  108. for( int i=0; i<200; i++ )
  109. {
  110. m_wavegraphModel.setSampleAt( i, qBound( 0.0f, m_wavegraphModel.samples()[i] * onedB, 1.0f ) );
  111. }
  112. Engine::getSong()->setModified();
  113. }
  114. void dynProcControls::subOneClicked()
  115. {
  116. for( int i=0; i<200; i++ )
  117. {
  118. m_wavegraphModel.setSampleAt( i, qBound( 0.0f, m_wavegraphModel.samples()[i] / onedB, 1.0f ) );
  119. }
  120. Engine::getSong()->setModified();
  121. }