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.

652 lines
31KB

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