# How to change valueToTextFunction?

**URL:** <https://forum.juce.com/t/how-to-change-valuetotextfunction/27933>\
**Category:** General JUCE discussion\
**Created:** [May 30, 2018, 3:35pm UTC](https://forum.juce.com/t/how-to-change-valuetotextfunction/27933 "2018-05-30T15:35:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [May 30, 2018, 3:35pm UTC](https://forum.juce.com/t/how-to-change-valuetotextfunction/27933/1 "2018-05-30T15:35:37Z")

</div>

Is there any way to change the valueToTextFunction for a parameters added using createAndAddParameter?

That function pointer is a public member of AudioProcessorValueTreeState::Parameter, since it’s a struct, but the Parameter struct itself is a private definition within AudioProcessorValueTreeState, so I can’t cast the result of getParameter() to that type, and thus cannot change the function pointer.

We need to be able to provide a different set of text values depending upon the state of the Processor (specifically, the value of another parameter), but I cannot find any way to accomplish that when using the AudioProcessorValueTreeState. The callback itself does not provide an extra data pointer with which I could pass a pointer to the Processor, so I have no way to query instance data for that Processor instance in order to find out which set of data to display.

Any ideas?  
Thanks!

---

<div class="post-metadata">

**Author:** ![ImJimmi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/imjimmi/32/10843_2.png) [@ImJimmi](https://forum.juce.com/u/ImJimmi)\
**Post date:** [May 30, 2018, 3:42pm UTC](https://forum.juce.com/t/how-to-change-valuetotextfunction/27933/2 "2018-05-30T15:42:52Z")

</div>

From [https://docs.juce.com/master/tutorial\_audio\_processor\_value\_tree\_state.html](https://docs.juce.com/master/tutorial_audio_processor_value_tree_state.html) :

```auto
parameters.createAndAddParameter ("invertPhase", "Invert Phase", String(),
                                  NormalisableRange<float> (0.0f, 1.0f, 1.0f), 0.0f,
                                  [](float value)
                                  {
                                      // value to text function
                                      return value < 0.5 ? "Normal" : "Inverted";
                                  },
                                  [](const String& text)
                                  {
                                      // text to value function
                                      if (text == "Normal") return 0.0f;
                                      if (text == "Inverted") return 1.0f;
                                      return 0.0f;
                                  });

```

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [May 30, 2018, 3:52pm UTC](https://forum.juce.com/t/how-to-change-valuetotextfunction/27933/3 "2018-05-30T15:52:53Z")

</div>

Thanks, but I think you misunderstand the problem. I have three complete sets of names for the possible Keys, based on the current Scale selection. The Major and Minor scales each present a completely different set of Key names than the Chromatic (or other) scales. So the translation from the Key parameter’s value to its key name needs to be different, depending upon the Scale. For example, if the Scale is Major, the text (Key name) for the Key index 1 is “Db”, but it is “C#” if the Scale is Minor or Chromatic (or other). So I need a _different_ callback, depending upon the Scale, which is another parameter that the Key parameter has no access to. If the Parameter struct were not a _private_ member of the AudioProcessorValueTreeState class, then I could re-assign the Key parameter’s valueToTextFunction pointer when the Scale parameter changes. But it is, so I can’t. So I’m looking for another solution.

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [May 30, 2018, 3:55pm UTC](https://forum.juce.com/t/how-to-change-valuetotextfunction/27933/4 "2018-05-30T15:55:44Z")

</div>

You should be able to use the C++11 lambda using solution proposed by Im\_Jimmi. Just capture the state for the lambda (likely the “this” pointer of your AudioProcessor) you need for determining the text you need to output.

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [May 30, 2018, 4:02pm UTC](https://forum.juce.com/t/how-to-change-valuetotextfunction/27933/5 "2018-05-30T16:02:53Z")

</div>

I don’t see how I can do that. The function definition only passes a float parameter. And I cannot capture 'this" in that code block (as evidenced by the error message that appears in Xcode if you reference ‘this’ in that code block).

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [May 30, 2018, 4:05pm UTC](https://forum.juce.com/t/how-to-change-valuetotextfunction/27933/6 "2018-05-30T16:05:23Z")

</div>

Do you know how the C++11 lambda syntax works? The captures (that are not part of the lambda’s function signature) go inside the [] like [this]. Im\_Jimmi’s example was a bit misleading because it didn’t include that.

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [May 30, 2018, 4:17pm UTC](https://forum.juce.com/t/how-to-change-valuetotextfunction/27933/7 "2018-05-30T16:17:07Z")

</div>

Ah! I get you now. Thanks, that should work perfectly! And no, I am not very familiar with the C++11 lambda syntax. Dang yung’uns always tryin’ to teach us old dogs new tricks! 🙂
