The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

659 lines
32KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. /** Advanced properties of an AudioProcessorValueTreeState::Parameter.
  21. The members here have the same meaning as the similarly-named member functions of
  22. AudioParameterFloatAttributes.
  23. @see AudioParameterFloatAttributes, RangedAudioParameterAttributes
  24. */
  25. class AudioProcessorValueTreeStateParameterAttributes
  26. {
  27. using This = AudioProcessorValueTreeStateParameterAttributes;
  28. using StringFromValue = AudioParameterFloatAttributes::StringFromValue;
  29. using ValueFromString = AudioParameterFloatAttributes::ValueFromString;
  30. using Category = AudioParameterFloatAttributes::Category;
  31. public:
  32. /** @see RangedAudioParameterAttributes::withStringFromValueFunction() */
  33. [[nodiscard]] auto withStringFromValueFunction (StringFromValue x) const { return withMember (*this, &This::attributes, attributes.withStringFromValueFunction (std::move (x))); }
  34. /** @see RangedAudioParameterAttributes::withValueFromStringFunction() */
  35. [[nodiscard]] auto withValueFromStringFunction (ValueFromString x) const { return withMember (*this, &This::attributes, attributes.withValueFromStringFunction (std::move (x))); }
  36. /** @see RangedAudioParameterAttributes::withLabel() */
  37. [[nodiscard]] auto withLabel (String x) const { return withMember (*this, &This::attributes, attributes.withLabel (std::move (x))); }
  38. /** @see RangedAudioParameterAttributes::withCategory() */
  39. [[nodiscard]] auto withCategory (Category x) const { return withMember (*this, &This::attributes, attributes.withCategory (std::move (x))); }
  40. /** @see RangedAudioParameterAttributes::withMeta() */
  41. [[nodiscard]] auto withMeta (bool x) const { return withMember (*this, &This::attributes, attributes.withMeta (std::move (x))); }
  42. /** @see RangedAudioParameterAttributes::withAutomatable() */
  43. [[nodiscard]] auto withAutomatable (bool x) const { return withMember (*this, &This::attributes, attributes.withAutomatable (std::move (x))); }
  44. /** @see RangedAudioParameterAttributes::withInverted() */
  45. [[nodiscard]] auto withInverted (bool x) const { return withMember (*this, &This::attributes, attributes.withInverted (std::move (x))); }
  46. /** Pass 'true' if this parameter has discrete steps, or 'false' if the parameter is continuous.
  47. Using an AudioParameterChoice or AudioParameterInt might be a better choice than setting this flag.
  48. */
  49. [[nodiscard]] auto withDiscrete (bool x) const { return withMember (*this, &This::discrete, std::move (x)); }
  50. /** Pass 'true' if this parameter only has two valid states.
  51. Using an AudioParameterBool might be a better choice than setting this flag.
  52. */
  53. [[nodiscard]] auto withBoolean (bool x) const { return withMember (*this, &This::boolean, std::move (x)); }
  54. /** @returns all attributes that might also apply to an AudioParameterFloat */
  55. [[nodiscard]] const auto& getAudioParameterFloatAttributes() const { return attributes; }
  56. /** @returns 'true' if this parameter has discrete steps, or 'false' if the parameter is continuous. */
  57. [[nodiscard]] const auto& getDiscrete() const { return discrete; }
  58. /** @returns 'true' if this parameter only has two valid states. */
  59. [[nodiscard]] const auto& getBoolean() const { return boolean; }
  60. private:
  61. AudioParameterFloatAttributes attributes;
  62. bool discrete = false, boolean = false;
  63. };
  64. /**
  65. This class contains a ValueTree that is used to manage an AudioProcessor's entire state.
  66. It has its own internal class of parameter object that is linked to values
  67. within its ValueTree, and which are each identified by a string ID.
  68. You can get access to the underlying ValueTree object via the state member variable,
  69. so you can add extra properties to it as necessary.
  70. It also provides some utility child classes for connecting parameters directly to
  71. GUI controls like sliders.
  72. The favoured constructor of this class takes a collection of RangedAudioParameters or
  73. AudioProcessorParameterGroups of RangedAudioParameters and adds them to the attached
  74. AudioProcessor directly.
  75. The deprecated way of using this class is as follows:
  76. 1) Create an AudioProcessorValueTreeState, and give it some parameters using createAndAddParameter().
  77. 2) Initialise the state member variable with a type name.
  78. The deprecated constructor will be removed from the API in a future version of JUCE!
  79. @tags{Audio}
  80. */
  81. class JUCE_API AudioProcessorValueTreeState : private Timer,
  82. private ValueTree::Listener
  83. {
  84. public:
  85. //==============================================================================
  86. /** A class to contain a set of RangedAudioParameters and AudioProcessorParameterGroups
  87. containing RangedAudioParameters.
  88. This class is used in the AudioProcessorValueTreeState constructor to allow
  89. arbitrarily grouped RangedAudioParameters to be passed to an AudioProcessor.
  90. */
  91. class JUCE_API ParameterLayout final
  92. {
  93. private:
  94. //==============================================================================
  95. template <typename It>
  96. using ValidIfIterator = decltype (std::next (std::declval<It>()));
  97. public:
  98. //==============================================================================
  99. template <typename... Items>
  100. ParameterLayout (std::unique_ptr<Items>... items) { add (std::move (items)...); }
  101. template <typename It, typename = ValidIfIterator<It>>
  102. ParameterLayout (It begin, It end) { add (begin, end); }
  103. template <typename... Items>
  104. void add (std::unique_ptr<Items>... items)
  105. {
  106. parameters.reserve (parameters.size() + sizeof... (items));
  107. (parameters.push_back (makeParameterStorage (std::move (items))), ...);
  108. }
  109. template <typename It, typename = ValidIfIterator<It>>
  110. void add (It begin, It end)
  111. {
  112. parameters.reserve (parameters.size() + std::size_t (std::distance (begin, end)));
  113. std::transform (std::make_move_iterator (begin),
  114. std::make_move_iterator (end),
  115. std::back_inserter (parameters),
  116. [] (auto item) { return makeParameterStorage (std::move (item)); });
  117. }
  118. ParameterLayout (const ParameterLayout& other) = delete;
  119. ParameterLayout (ParameterLayout&& other) noexcept { swap (other); }
  120. ParameterLayout& operator= (const ParameterLayout& other) = delete;
  121. ParameterLayout& operator= (ParameterLayout&& other) noexcept { swap (other); return *this; }
  122. void swap (ParameterLayout& other) noexcept { std::swap (other.parameters, parameters); }
  123. private:
  124. //==============================================================================
  125. struct Visitor
  126. {
  127. virtual ~Visitor() = default;
  128. // If you have a compiler error telling you that there is no matching
  129. // member function to call for 'visit', then you are probably attempting
  130. // to add a parameter that is not derived from RangedAudioParameter to
  131. // the AudioProcessorValueTreeState.
  132. virtual void visit (std::unique_ptr<RangedAudioParameter>) const = 0;
  133. virtual void visit (std::unique_ptr<AudioProcessorParameterGroup>) const = 0;
  134. };
  135. struct ParameterStorageBase
  136. {
  137. virtual ~ParameterStorageBase() = default;
  138. virtual void accept (const Visitor& visitor) = 0;
  139. };
  140. template <typename Contents>
  141. struct ParameterStorage : ParameterStorageBase
  142. {
  143. explicit ParameterStorage (std::unique_ptr<Contents> input) : contents (std::move (input)) {}
  144. void accept (const Visitor& visitor) override { visitor.visit (std::move (contents)); }
  145. std::unique_ptr<Contents> contents;
  146. };
  147. template <typename Contents>
  148. static std::unique_ptr<ParameterStorage<Contents>> makeParameterStorage (std::unique_ptr<Contents> contents)
  149. {
  150. return std::make_unique<ParameterStorage<Contents>> (std::move (contents));
  151. }
  152. void add() {}
  153. friend class AudioProcessorValueTreeState;
  154. std::vector<std::unique_ptr<ParameterStorageBase>> parameters;
  155. };
  156. //==============================================================================
  157. /** Creates a state object for a given processor, and sets up all the parameters
  158. that will control that processor.
  159. You should *not* assign a new ValueTree to the state, or call
  160. createAndAddParameter, after using this constructor.
  161. Note that each AudioProcessorValueTreeState should be attached to only one
  162. processor, and must have the same lifetime as the processor, as they will
  163. have dependencies on each other.
  164. The ParameterLayout parameter has a set of constructors that allow you to
  165. add multiple RangedAudioParameters and AudioProcessorParameterGroups containing
  166. RangedAudioParameters to the AudioProcessorValueTreeState inside this constructor.
  167. @code
  168. YourAudioProcessor()
  169. : apvts (*this, &undoManager, "PARAMETERS",
  170. { std::make_unique<AudioParameterFloat> ("a", "Parameter A", NormalisableRange<float> (-100.0f, 100.0f), 0),
  171. std::make_unique<AudioParameterInt> ("b", "Parameter B", 0, 5, 2) })
  172. @endcode
  173. To add parameters programmatically you can call `add` repeatedly on a
  174. ParameterLayout instance:
  175. @code
  176. AudioProcessorValueTreeState::ParameterLayout createParameterLayout()
  177. {
  178. AudioProcessorValueTreeState::ParameterLayout layout;
  179. for (int i = 1; i < 9; ++i)
  180. layout.add (std::make_unique<AudioParameterInt> (String (i), String (i), 0, i, 0));
  181. return layout;
  182. }
  183. YourAudioProcessor()
  184. : apvts (*this, &undoManager, "PARAMETERS", createParameterLayout())
  185. {
  186. }
  187. @endcode
  188. @param processorToConnectTo The Processor that will be managed by this object
  189. @param undoManagerToUse An optional UndoManager to use; pass nullptr if no UndoManager is required
  190. @param valueTreeType The identifier used to initialise the internal ValueTree
  191. @param parameterLayout An object that holds all parameters and parameter groups that the
  192. AudioProcessor should use.
  193. */
  194. AudioProcessorValueTreeState (AudioProcessor& processorToConnectTo,
  195. UndoManager* undoManagerToUse,
  196. const Identifier& valueTreeType,
  197. ParameterLayout parameterLayout);
  198. /** This constructor is discouraged and will be deprecated in a future version of JUCE!
  199. Use the other constructor instead.
  200. Creates a state object for a given processor.
  201. The UndoManager is optional and can be a nullptr. After creating your state object,
  202. you should add parameters with the createAndAddParameter() method. Note that each
  203. AudioProcessorValueTreeState should be attached to only one processor, and must have
  204. the same lifetime as the processor, as they will have dependencies on each other.
  205. */
  206. AudioProcessorValueTreeState (AudioProcessor& processorToConnectTo, UndoManager* undoManagerToUse);
  207. /** Destructor. */
  208. ~AudioProcessorValueTreeState() override;
  209. //==============================================================================
  210. #ifndef DOXYGEN
  211. /** Previous calls to
  212. @code
  213. createAndAddParameter (paramID1, paramName1, ...);
  214. @endcode
  215. can be replaced with
  216. @code
  217. using Parameter = AudioProcessorValueTreeState::Parameter;
  218. createAndAddParameter (std::make_unique<Parameter> (paramID1, paramName1, ...));
  219. @endcode
  220. However, a much better approach is to use the AudioProcessorValueTreeState
  221. constructor directly
  222. @code
  223. using Parameter = AudioProcessorValueTreeState::Parameter;
  224. YourAudioProcessor()
  225. : apvts (*this, &undoManager, "PARAMETERS", { std::make_unique<Parameter> (paramID1, paramName1, ...),
  226. std::make_unique<Parameter> (paramID2, paramName2, ...),
  227. ... })
  228. @endcode
  229. @see AudioProcessorValueTreeState::AudioProcessorValueTreeState
  230. This function creates and returns a new parameter object for controlling a
  231. parameter with the given ID.
  232. Calling this will create and add a special type of AudioProcessorParameter to the
  233. AudioProcessor to which this state is attached.
  234. */
  235. [[deprecated ("This function is deprecated and will be removed in a future version of JUCE! "
  236. "See the method docs for a code example of the replacement methods.")]]
  237. RangedAudioParameter* createAndAddParameter (const String& parameterID,
  238. const String& parameterName,
  239. const String& labelText,
  240. NormalisableRange<float> valueRange,
  241. float defaultValue,
  242. std::function<String (float)> valueToTextFunction,
  243. std::function<float (const String&)> textToValueFunction,
  244. bool isMetaParameter = false,
  245. bool isAutomatableParameter = true,
  246. bool isDiscrete = false,
  247. AudioProcessorParameter::Category parameterCategory = AudioProcessorParameter::genericParameter,
  248. bool isBoolean = false);
  249. #endif
  250. /** This function adds a parameter to the attached AudioProcessor and that parameter will
  251. be managed by this AudioProcessorValueTreeState object.
  252. */
  253. RangedAudioParameter* createAndAddParameter (std::unique_ptr<RangedAudioParameter> parameter);
  254. //==============================================================================
  255. /** Returns a parameter by its ID string. */
  256. RangedAudioParameter* getParameter (StringRef parameterID) const noexcept;
  257. /** Returns a pointer to a floating point representation of a particular parameter which a realtime
  258. process can read to find out its current value.
  259. Note that calling this method from within AudioProcessorValueTreeState::Listener::parameterChanged()
  260. is not guaranteed to return an up-to-date value for the parameter.
  261. */
  262. std::atomic<float>* getRawParameterValue (StringRef parameterID) const noexcept;
  263. //==============================================================================
  264. /** A listener class that can be attached to an AudioProcessorValueTreeState.
  265. Use AudioProcessorValueTreeState::addParameterListener() to register a callback.
  266. */
  267. struct JUCE_API Listener
  268. {
  269. virtual ~Listener() = default;
  270. /** This callback method is called by the AudioProcessorValueTreeState when a parameter changes.
  271. Within this call, retrieving the value of the parameter that has changed via the getRawParameterValue()
  272. or getParameter() methods is not guaranteed to return the up-to-date value. If you need this you should
  273. instead use the newValue parameter.
  274. */
  275. virtual void parameterChanged (const String& parameterID, float newValue) = 0;
  276. };
  277. /** Attaches a callback to one of the parameters, which will be called when the parameter changes. */
  278. void addParameterListener (StringRef parameterID, Listener* listener);
  279. /** Removes a callback that was previously added with addParameterCallback(). */
  280. void removeParameterListener (StringRef parameterID, Listener* listener);
  281. //==============================================================================
  282. /** Returns a Value object that can be used to control a particular parameter. */
  283. Value getParameterAsValue (StringRef parameterID) const;
  284. /** Returns the range that was set when the given parameter was created. */
  285. NormalisableRange<float> getParameterRange (StringRef parameterID) const noexcept;
  286. //==============================================================================
  287. /** Returns a copy of the state value tree.
  288. The AudioProcessorValueTreeState's ValueTree is updated internally on the
  289. message thread, but there may be cases when you may want to access the state
  290. from a different thread (getStateInformation is a good example). This method
  291. flushes all pending audio parameter value updates and returns a copy of the
  292. state in a thread safe way.
  293. Note: This method uses locks to synchronise thread access, so whilst it is
  294. thread-safe, it is not realtime-safe. Do not call this method from within
  295. your audio processing code!
  296. */
  297. ValueTree copyState();
  298. /** Replaces the state value tree.
  299. The AudioProcessorValueTreeState's ValueTree is updated internally on the
  300. message thread, but there may be cases when you may want to modify the state
  301. from a different thread (setStateInformation is a good example). This method
  302. allows you to replace the state in a thread safe way.
  303. Note: This method uses locks to synchronise thread access, so whilst it is
  304. thread-safe, it is not realtime-safe. Do not call this method from within
  305. your audio processing code!
  306. */
  307. void replaceState (const ValueTree& newState);
  308. //==============================================================================
  309. /** A reference to the processor with which this state is associated. */
  310. AudioProcessor& processor;
  311. /** The state of the whole processor.
  312. This must be initialised after all calls to createAndAddParameter().
  313. You can replace this with your own ValueTree object, and can add properties and
  314. children to the tree. This class will automatically add children for each of the
  315. parameter objects that are created by createAndAddParameter().
  316. */
  317. ValueTree state;
  318. /** Provides access to the undo manager that this object is using. */
  319. UndoManager* const undoManager;
  320. private:
  321. //==============================================================================
  322. class ParameterAdapter;
  323. public:
  324. //==============================================================================
  325. /** A parameter class that maintains backwards compatibility with deprecated
  326. AudioProcessorValueTreeState functionality.
  327. Previous calls to
  328. @code
  329. createAndAddParameter (paramID1, paramName1, ...);
  330. @endcode
  331. can be replaced with
  332. @code
  333. using Parameter = AudioProcessorValueTreeState::Parameter;
  334. createAndAddParameter (std::make_unique<Parameter> (paramID1, paramName1, ...));
  335. @endcode
  336. However, a much better approach is to use the AudioProcessorValueTreeState
  337. constructor directly
  338. @code
  339. using Parameter = AudioProcessorValueTreeState::Parameter;
  340. YourAudioProcessor()
  341. : apvts (*this, &undoManager, "PARAMETERS", { std::make_unique<Parameter> (paramID1, paramName1, ...),
  342. std::make_unique<Parameter> (paramID2, paramName2, ...),
  343. ... })
  344. @endcode
  345. */
  346. class Parameter final : public AudioParameterFloat
  347. {
  348. public:
  349. /** Constructs a parameter instance.
  350. Example usage:
  351. @code
  352. using Parameter = AudioProcessorValueTreeState::Parameter;
  353. using Attributes = AudioProcessorValueTreeStateParameterAttributes;
  354. auto parameter = std::make_unique<Parameter> (ParameterID { "uniqueID", 1 },
  355. "Name",
  356. NormalisableRange<float> { 0.0f, 100.0f },
  357. 50.0f,
  358. Attributes().withStringFromValueFunction (myStringFromValueFunction)
  359. .withValueFromStringFunction (myValueFromStringFunction)
  360. .withLabel ("%"));
  361. @endcode
  362. @param parameterID The globally-unique identifier of this parameter
  363. @param parameterName The user-facing name of this parameter
  364. @param valueRange The valid range of values for this parameter
  365. @param defaultValue The initial parameter value
  366. @param attributes Further advanced settings to customise the behaviour of this parameter
  367. */
  368. Parameter (const ParameterID& parameterID,
  369. const String& parameterName,
  370. NormalisableRange<float> valueRange,
  371. float defaultValue,
  372. const AudioProcessorValueTreeStateParameterAttributes& attributes = {});
  373. [[deprecated ("Prefer the signature taking an Attributes argument")]]
  374. Parameter (const ParameterID& parameterID,
  375. const String& parameterName,
  376. const String& labelText,
  377. NormalisableRange<float> valueRange,
  378. float defaultParameterValue,
  379. std::function<String (float)> valueToTextFunction,
  380. std::function<float (const String&)> textToValueFunction,
  381. bool isMetaParameter = false,
  382. bool isAutomatableParameter = true,
  383. bool isDiscrete = false,
  384. AudioProcessorParameter::Category parameterCategory = AudioProcessorParameter::genericParameter,
  385. bool isBoolean = false)
  386. : Parameter (parameterID,
  387. parameterName,
  388. valueRange,
  389. defaultParameterValue,
  390. AudioProcessorValueTreeStateParameterAttributes().withLabel (labelText)
  391. .withStringFromValueFunction (adaptSignature (std::move (valueToTextFunction)))
  392. .withValueFromStringFunction (std::move (textToValueFunction))
  393. .withMeta (isMetaParameter)
  394. .withAutomatable (isAutomatableParameter)
  395. .withDiscrete (isDiscrete)
  396. .withCategory (parameterCategory)
  397. .withBoolean (isBoolean))
  398. {
  399. }
  400. float getDefaultValue() const override;
  401. int getNumSteps() const override;
  402. bool isDiscrete() const override;
  403. bool isBoolean() const override;
  404. private:
  405. static std::function<String (float, int)> adaptSignature (std::function<String (float)> func)
  406. {
  407. if (func == nullptr)
  408. return nullptr;
  409. return [func = std::move (func)] (float v, int) { return func (v); };
  410. }
  411. void valueChanged (float) override;
  412. std::function<void()> onValueChanged;
  413. const float unsnappedDefault;
  414. const bool discrete, boolean;
  415. std::atomic<float> lastValue { -1.0f };
  416. friend class AudioProcessorValueTreeState::ParameterAdapter;
  417. };
  418. //==============================================================================
  419. /** An object of this class maintains a connection between a Slider and a parameter
  420. in an AudioProcessorValueTreeState.
  421. During the lifetime of this SliderAttachment object, it keeps the two things in
  422. sync, making it easy to connect a slider to a parameter. When this object is
  423. deleted, the connection is broken. Make sure that your AudioProcessorValueTreeState
  424. and Slider aren't deleted before this object!
  425. */
  426. class JUCE_API SliderAttachment
  427. {
  428. public:
  429. SliderAttachment (AudioProcessorValueTreeState& stateToUse,
  430. const String& parameterID,
  431. Slider& slider);
  432. private:
  433. std::unique_ptr<SliderParameterAttachment> attachment;
  434. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SliderAttachment)
  435. };
  436. //==============================================================================
  437. /** An object of this class maintains a connection between a ComboBox and a parameter
  438. in an AudioProcessorValueTreeState.
  439. Combobox items will be spaced linearly across the range of the parameter. For
  440. example if the range is specified by NormalisableRange<float> (-0.5f, 0.5f, 0.5f)
  441. and you add three items then the first will be mapped to a value of -0.5, the
  442. second to 0, and the third to 0.5.
  443. During the lifetime of this ComboBoxAttachment object, it keeps the two things in
  444. sync, making it easy to connect a combo box to a parameter. When this object is
  445. deleted, the connection is broken. Make sure that your AudioProcessorValueTreeState
  446. and ComboBox aren't deleted before this object!
  447. */
  448. class JUCE_API ComboBoxAttachment
  449. {
  450. public:
  451. ComboBoxAttachment (AudioProcessorValueTreeState& stateToUse,
  452. const String& parameterID,
  453. ComboBox& combo);
  454. private:
  455. std::unique_ptr<ComboBoxParameterAttachment> attachment;
  456. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComboBoxAttachment)
  457. };
  458. //==============================================================================
  459. /** An object of this class maintains a connection between a Button and a parameter
  460. in an AudioProcessorValueTreeState.
  461. During the lifetime of this ButtonAttachment object, it keeps the two things in
  462. sync, making it easy to connect a button to a parameter. When this object is
  463. deleted, the connection is broken. Make sure that your AudioProcessorValueTreeState
  464. and Button aren't deleted before this object!
  465. */
  466. class JUCE_API ButtonAttachment
  467. {
  468. public:
  469. ButtonAttachment (AudioProcessorValueTreeState& stateToUse,
  470. const String& parameterID,
  471. Button& button);
  472. private:
  473. std::unique_ptr<ButtonParameterAttachment> attachment;
  474. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ButtonAttachment)
  475. };
  476. private:
  477. //==============================================================================
  478. /** Code that looks like this:
  479. @code
  480. auto paramA = apvts.createParameter ("a", "Parameter A", {}, { -100, 100 }, ...);
  481. auto paramB = apvts.createParameter ("b", "Parameter B", {}, { 0, 5 }, ...);
  482. addParameterGroup (std::make_unique<AudioProcessorParameterGroup> ("g1", "Group 1", " | ", std::move (paramA), std::move (paramB)));
  483. apvts.state = ValueTree (Identifier ("PARAMETERS"));
  484. @endcode
  485. can instead create the APVTS like this, avoiding the two-step initialization process and leveraging one of JUCE's
  486. pre-built parameter types (or your own custom type derived from RangedAudioParameter):
  487. @code
  488. using Parameter = AudioProcessorValueTreeState::Parameter;
  489. YourAudioProcessor()
  490. : apvts (*this, &undoManager, "PARAMETERS",
  491. { std::make_unique<AudioProcessorParameterGroup> ("g1", "Group 1", " | ",
  492. std::make_unique<Parameter> ("a", "Parameter A", "", NormalisableRange<float> (-100, 100), ...),
  493. std::make_unique<Parameter> ("b", "Parameter B", "", NormalisableRange<float> (0, 5), ...)) })
  494. @endcode
  495. */
  496. [[deprecated ("This method was introduced to allow you to use AudioProcessorValueTreeState parameters in "
  497. "an AudioProcessorParameterGroup, but there is now a much nicer way to achieve this. See the "
  498. "method docs for a code example.")]]
  499. std::unique_ptr<RangedAudioParameter> createParameter (const String&, const String&, const String&, NormalisableRange<float>,
  500. float, std::function<String (float)>, std::function<float (const String&)>,
  501. bool, bool, bool, AudioProcessorParameter::Category, bool);
  502. //==============================================================================
  503. #if JUCE_UNIT_TESTS
  504. friend struct ParameterAdapterTests;
  505. #endif
  506. void addParameterAdapter (RangedAudioParameter&);
  507. ParameterAdapter* getParameterAdapter (StringRef) const;
  508. bool flushParameterValuesToValueTree();
  509. void setNewState (ValueTree);
  510. void timerCallback() override;
  511. void valueTreePropertyChanged (ValueTree&, const Identifier&) override;
  512. void valueTreeChildAdded (ValueTree&, ValueTree&) override;
  513. void valueTreeRedirected (ValueTree&) override;
  514. void updateParameterConnectionsToChildTrees();
  515. const Identifier valueType { "PARAM" }, valuePropertyID { "value" }, idPropertyID { "id" };
  516. struct StringRefLessThan final
  517. {
  518. bool operator() (StringRef a, StringRef b) const noexcept { return a.text.compare (b.text) < 0; }
  519. };
  520. std::map<StringRef, std::unique_ptr<ParameterAdapter>, StringRefLessThan> adapterTable;
  521. CriticalSection valueTreeChanging;
  522. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioProcessorValueTreeState)
  523. };
  524. } // namespace juce