Audio plugin host https://kx.studio/carla
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.

214 lines
5.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. namespace water {
  24. //==============================================================================
  25. NamedValueSet::NamedValueSet() noexcept
  26. {
  27. }
  28. NamedValueSet::NamedValueSet (const NamedValueSet& other)
  29. : values (other.values)
  30. {
  31. }
  32. NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other)
  33. {
  34. clear();
  35. values = other.values;
  36. return *this;
  37. }
  38. #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  39. NamedValueSet::NamedValueSet (NamedValueSet&& other) noexcept
  40. : values (static_cast<Array<NamedValue>&&> (other.values))
  41. {
  42. }
  43. NamedValueSet& NamedValueSet::operator= (NamedValueSet&& other) noexcept
  44. {
  45. other.values.swapWith (values);
  46. return *this;
  47. }
  48. #endif
  49. NamedValueSet::~NamedValueSet() noexcept
  50. {
  51. }
  52. void NamedValueSet::clear()
  53. {
  54. values.clear();
  55. }
  56. bool NamedValueSet::operator== (const NamedValueSet& other) const
  57. {
  58. return values == other.values;
  59. }
  60. bool NamedValueSet::operator!= (const NamedValueSet& other) const
  61. {
  62. return ! operator== (other);
  63. }
  64. int NamedValueSet::size() const noexcept
  65. {
  66. return values.size();
  67. }
  68. bool NamedValueSet::isEmpty() const noexcept
  69. {
  70. return values.isEmpty();
  71. }
  72. static const var& getNullVarRef() noexcept
  73. {
  74. static var nullVar;
  75. return nullVar;
  76. }
  77. const var& NamedValueSet::operator[] (const Identifier& name) const noexcept
  78. {
  79. if (const var* v = getVarPointer (name))
  80. return *v;
  81. return getNullVarRef();
  82. }
  83. var NamedValueSet::getWithDefault (const Identifier& name, const var& defaultReturnValue) const
  84. {
  85. if (const var* const v = getVarPointer (name))
  86. return *v;
  87. return defaultReturnValue;
  88. }
  89. var* NamedValueSet::getVarPointer (const Identifier& name) const noexcept
  90. {
  91. for (NamedValue* e = values.end(), *i = values.begin(); i != e; ++i)
  92. if (i->name == name)
  93. return &(i->value);
  94. return nullptr;
  95. }
  96. #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  97. bool NamedValueSet::set (const Identifier& name, var&& newValue)
  98. {
  99. if (var* const v = getVarPointer (name))
  100. {
  101. if (v->equalsWithSameType (newValue))
  102. return false;
  103. *v = static_cast<var&&> (newValue);
  104. return true;
  105. }
  106. values.add (NamedValue (name, static_cast<var&&> (newValue)));
  107. return true;
  108. }
  109. #endif
  110. bool NamedValueSet::set (const Identifier& name, const var& newValue)
  111. {
  112. if (var* const v = getVarPointer (name))
  113. {
  114. if (v->equalsWithSameType (newValue))
  115. return false;
  116. *v = newValue;
  117. return true;
  118. }
  119. values.add (NamedValue (name, newValue));
  120. return true;
  121. }
  122. bool NamedValueSet::contains (const Identifier& name) const noexcept
  123. {
  124. return getVarPointer (name) != nullptr;
  125. }
  126. int NamedValueSet::indexOf (const Identifier& name) const noexcept
  127. {
  128. const int numValues = values.size();
  129. for (int i = 0; i < numValues; ++i)
  130. if (values.getReference(i).name == name)
  131. return i;
  132. return -1;
  133. }
  134. bool NamedValueSet::remove (const Identifier& name)
  135. {
  136. const int numValues = values.size();
  137. for (int i = 0; i < numValues; ++i)
  138. {
  139. if (values.getReference(i).name == name)
  140. {
  141. values.remove (i);
  142. return true;
  143. }
  144. }
  145. return false;
  146. }
  147. Identifier NamedValueSet::getName (const int index) const noexcept
  148. {
  149. if (isPositiveAndBelow (index, values.size()))
  150. return values.getReference (index).name;
  151. jassertfalse;
  152. return Identifier();
  153. }
  154. const var& NamedValueSet::getValueAt (const int index) const noexcept
  155. {
  156. if (isPositiveAndBelow (index, values.size()))
  157. return values.getReference (index).value;
  158. jassertfalse;
  159. return getNullVarRef();
  160. }
  161. var* NamedValueSet::getVarPointerAt (int index) const noexcept
  162. {
  163. if (isPositiveAndBelow (index, values.size()))
  164. return &(values.getReference (index).value);
  165. return nullptr;
  166. }
  167. }