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.

148 lines
4.3KB

  1. /* Copyright 2013-2019 Matt Tytel
  2. *
  3. * vital is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * vital is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with vital. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include "common.h"
  18. #include <map>
  19. #include <string>
  20. namespace vital {
  21. struct ValueDetails {
  22. enum ValueScale {
  23. kIndexed,
  24. kLinear,
  25. kQuadratic,
  26. kCubic,
  27. kQuartic,
  28. kSquareRoot,
  29. kExponential
  30. };
  31. std::string name;
  32. int version_added = 0;
  33. mono_float min = 0.0f;
  34. mono_float max = 1.0f;
  35. mono_float default_value = 0.0f;
  36. // post_offset used to offset quadratic and exponential scaling.
  37. mono_float post_offset = 0.0f;
  38. mono_float display_multiply = 1.0f;
  39. ValueScale value_scale = kLinear;
  40. bool display_invert = false;
  41. std::string display_units;
  42. std::string display_name;
  43. const std::string* string_lookup = nullptr;
  44. std::string local_description;
  45. } typedef ValueDetails;
  46. class ValueDetailsLookup {
  47. public:
  48. ValueDetailsLookup();
  49. const bool isParameter(const std::string& name) const {
  50. return details_lookup_.count(name);
  51. }
  52. const ValueDetails& getDetails(const std::string& name) const {
  53. auto details = details_lookup_.find(name);
  54. VITAL_ASSERT(details != details_lookup_.end());
  55. return details->second;
  56. }
  57. const ValueDetails* getDetails(int index) const {
  58. return details_list_[index];
  59. }
  60. std::string getDisplayName(const std::string& name) const {
  61. return getDetails(name).display_name;
  62. }
  63. int getNumParameters() const {
  64. return static_cast<int>(details_list_.size());
  65. }
  66. mono_float getParameterRange(const std::string& name) const {
  67. auto details = details_lookup_.find(name);
  68. VITAL_ASSERT(details != details_lookup_.end());
  69. return details->second.max - details->second.min;
  70. }
  71. std::map<std::string, ValueDetails> getAllDetails() const {
  72. return details_lookup_;
  73. }
  74. void addParameterGroup(const ValueDetails* list, int num_parameters, int index,
  75. std::string id_prefix, std::string name_prefix, int version = -1);
  76. void addParameterGroup(const ValueDetails* list, int num_parameters, std::string id,
  77. std::string id_prefix, std::string name_prefix, int version = -1);
  78. static const ValueDetails parameter_list[];
  79. static const ValueDetails env_parameter_list[];
  80. static const ValueDetails lfo_parameter_list[];
  81. static const ValueDetails random_lfo_parameter_list[];
  82. static const ValueDetails filter_parameter_list[];
  83. static const ValueDetails osc_parameter_list[];
  84. static const ValueDetails mod_parameter_list[];
  85. private:
  86. std::map<std::string, ValueDetails> details_lookup_;
  87. std::vector<const ValueDetails*> details_list_;
  88. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ValueDetailsLookup)
  89. };
  90. class Parameters {
  91. public:
  92. static const ValueDetails& getDetails(const std::string& name) {
  93. return lookup_.getDetails(name);
  94. }
  95. static int getNumParameters() {
  96. return lookup_.getNumParameters();
  97. }
  98. static const ValueDetails* getDetails(int index) {
  99. return lookup_.getDetails(index);
  100. }
  101. static std::string getDisplayName(const std::string& name) {
  102. return lookup_.getDisplayName(name);
  103. }
  104. static const mono_float getParameterRange(const std::string& name) {
  105. return lookup_.getParameterRange(name);
  106. }
  107. static const bool isParameter(const std::string& name) {
  108. return lookup_.isParameter(name);
  109. }
  110. static std::map<std::string, ValueDetails> getAllDetails() {
  111. return lookup_.getAllDetails();
  112. }
  113. static ValueDetailsLookup lookup_;
  114. private:
  115. Parameters() { }
  116. };
  117. } // namespace vital