DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
4.5KB

  1. /*
  2. * Simple Gain audio effect based on DISTRHO Plugin Framework (DPF)
  3. *
  4. * SPDX-License-Identifier: MIT
  5. *
  6. * Copyright (C) 2021 Jean Pierre Cimalando <jp-dev@inbox.ru>
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to
  10. * deal in the Software without restriction, including without limitation the
  11. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  12. * sell copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  23. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  24. * IN THE SOFTWARE.
  25. */
  26. #ifndef PLUGIN_SIMPLEGAIN_H
  27. #define PLUGIN_SIMPLEGAIN_H
  28. #include "DistrhoPlugin.hpp"
  29. #include "CParamSmooth.hpp"
  30. START_NAMESPACE_DISTRHO
  31. #ifndef MIN
  32. #define MIN(a,b) ( (a) < (b) ? (a) : (b) )
  33. #endif
  34. #ifndef MAX
  35. #define MAX(a,b) ( (a) > (b) ? (a) : (b) )
  36. #endif
  37. #ifndef CLAMP
  38. #define CLAMP(v, min, max) (MIN((max), MAX((min), (v))))
  39. #endif
  40. #ifndef DB_CO
  41. #define DB_CO(g) ((g) > -90.0f ? powf(10.0f, (g) * 0.05f) : 0.0f)
  42. #endif
  43. // -----------------------------------------------------------------------
  44. class PluginSimpleGain : public Plugin {
  45. public:
  46. enum Parameters {
  47. paramGain = 0,
  48. paramCount
  49. };
  50. PluginSimpleGain();
  51. ~PluginSimpleGain();
  52. protected:
  53. // -------------------------------------------------------------------
  54. // Information
  55. const char* getLabel() const noexcept override {
  56. return "SimpleGain";
  57. }
  58. const char* getDescription() const override {
  59. return "A simple audio volume gain plugin";
  60. }
  61. const char* getMaker() const noexcept override {
  62. return "example.com";
  63. }
  64. const char* getHomePage() const override {
  65. return "https://example.com/plugins/simplegain";
  66. }
  67. const char* getLicense() const noexcept override {
  68. return "https://spdx.org/licenses/MIT";
  69. }
  70. uint32_t getVersion() const noexcept override {
  71. return d_version(0, 1, 0);
  72. }
  73. // Go to:
  74. //
  75. // http://service.steinberg.de/databases/plugin.nsf/plugIn
  76. //
  77. // Get a proper plugin UID and fill it in here!
  78. int64_t getUniqueId() const noexcept override {
  79. return d_cconst('a', 'b', 'c', 'd');
  80. }
  81. // -------------------------------------------------------------------
  82. // Init
  83. void initParameter(uint32_t index, Parameter& parameter) override;
  84. void initProgramName(uint32_t index, String& programName) override;
  85. // -------------------------------------------------------------------
  86. // Internal data
  87. float getParameterValue(uint32_t index) const override;
  88. void setParameterValue(uint32_t index, float value) override;
  89. void loadProgram(uint32_t index) override;
  90. // -------------------------------------------------------------------
  91. // Optional
  92. // Optional callback to inform the plugin about a sample rate change.
  93. void sampleRateChanged(double newSampleRate) override;
  94. // -------------------------------------------------------------------
  95. // Process
  96. void activate() override;
  97. void run(const float**, float** outputs, uint32_t frames) override;
  98. // -------------------------------------------------------------------
  99. private:
  100. float fParams[paramCount];
  101. double fSampleRate;
  102. float gain;
  103. CParamSmooth *smooth_gain;
  104. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginSimpleGain)
  105. };
  106. struct Preset {
  107. const char* name;
  108. float params[PluginSimpleGain::paramCount];
  109. };
  110. const Preset factoryPresets[] = {
  111. {
  112. "Unity Gain",
  113. {0.0f}
  114. }
  115. //,{
  116. // "Another preset", // preset name
  117. // {-14.0f, ...} // array of presetCount float param values
  118. //}
  119. };
  120. const uint presetCount = sizeof(factoryPresets) / sizeof(Preset);
  121. // -----------------------------------------------------------------------
  122. END_NAMESPACE_DISTRHO
  123. #endif // #ifndef PLUGIN_SIMPLEGAIN_H