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.

115 lines
2.7KB

  1. /*
  2. * DISTRHO Cardinal Plugin
  3. * Copyright (C) 2021-2022 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 3 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the LICENSE file.
  16. */
  17. #pragma once
  18. #include "rack.hpp"
  19. #include "engine/TerminalModule.hpp"
  20. #ifdef NDEBUG
  21. # undef DEBUG
  22. #endif
  23. using namespace rack;
  24. extern Plugin* pluginInstance;
  25. extern Model* modelAudioFile;
  26. extern Model* modelAudioToCVPitch;
  27. extern Model* modelCarla;
  28. extern Model* modelCardinalBlank;
  29. extern Model* modelExpanderInputMIDI;
  30. extern Model* modelExpanderOutputMIDI;
  31. extern Model* modelGlBars;
  32. extern Model* modelHostAudio2;
  33. extern Model* modelHostAudio8;
  34. extern Model* modelHostCV;
  35. extern Model* modelHostMIDI;
  36. extern Model* modelHostMIDICC;
  37. extern Model* modelHostMIDIGate;
  38. extern Model* modelHostMIDIMap;
  39. extern Model* modelHostParameters;
  40. extern Model* modelHostParametersMap;
  41. extern Model* modelHostTime;
  42. extern Model* modelIldaeil;
  43. extern Model* modelMPV;
  44. extern Model* modelSassyScope;
  45. extern Model* modelTextEditor;
  46. extern std::vector<Model*> hostTerminalModels;
  47. /*
  48. * Find the highest absolute and normalized value within a float array.
  49. */
  50. template<std::size_t size>
  51. static inline
  52. float d_findMaxNormalizedFloat(const float floats[size])
  53. {
  54. static constexpr const float kEmptyFloats[size] = {};
  55. if (std::memcmp(floats, kEmptyFloats, sizeof(float)*size) == 0)
  56. return 0.f;
  57. float tmp, maxf2 = std::abs(floats[0]);
  58. for (std::size_t i=1; i<size; ++i)
  59. {
  60. if (!std::isfinite(floats[i]))
  61. __builtin_unreachable();
  62. tmp = std::abs(floats[i]);
  63. if (tmp > maxf2)
  64. maxf2 = tmp;
  65. }
  66. if (maxf2 > 1.f)
  67. maxf2 = 1.f;
  68. return maxf2;
  69. }
  70. /*
  71. * Find the highest absolute and normalized value within a float array.
  72. */
  73. static inline
  74. float d_findMaxNormalizedFloat128(const float floats[128])
  75. {
  76. static constexpr const float kEmptyFloats[128] = {};
  77. if (std::memcmp(floats, kEmptyFloats, sizeof(float)*128) == 0)
  78. return 0.f;
  79. float tmp, maxf2 = std::abs(floats[0]);
  80. for (std::size_t i=1; i<128; ++i)
  81. {
  82. if (!std::isfinite(floats[i]))
  83. __builtin_unreachable();
  84. tmp = std::abs(floats[i]);
  85. if (tmp > maxf2)
  86. maxf2 = tmp;
  87. }
  88. if (maxf2 > 1.f)
  89. maxf2 = 1.f;
  90. return maxf2;
  91. }