# AudioUnit wrapper issue with discrete parameters

**URL:** <https://forum.juce.com/t/audiounit-wrapper-issue-with-discrete-parameters/33792>\
**Category:** Audio Plugins\
**Created:** [June 7, 2019, 5:04pm UTC](https://forum.juce.com/t/audiounit-wrapper-issue-with-discrete-parameters/33792 "2019-06-07T17:04:56Z")\
**Posts on this page:** 3\
**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:** [June 7, 2019, 5:04pm UTC](https://forum.juce.com/t/audiounit-wrapper-issue-with-discrete-parameters/33792/1 "2019-06-07T17:04:56Z")

</div>

We have an AudioUnit plugin that is behaving badly at initialization time. The issue is caused by this code in the wrapper’s addParameters() function:

```
                for (int i = 0; i < numSteps; ++i)
            {
                auto value = (float) i / maxValue;

                // Once legacy parameters are deprecated this can be replaced by getText
                param->setValue (value);
                stringValues->add (CFStringCreateCopy (nullptr, (param->getCurrentValueAsText().toCFString())));
            }
        }

        param->setValue (initialValue);

```

The problem arises because several of the parameters are attached to push-style buttons, which trigger a change in our plugin data when set to 1 (pressed). The changes that are triggered are _not_ un-done by the buttons returning to their 0 (unpressed) state. That leaves our plugin no longer in its default state after those parameters have been set to 1, despite the code setting them back to their default (0) states.

Why is this code needed? Why does the AU wrapper need to cycle each discrete parameter through all its possible values? What would happen if we prevented that from happening?

If that code is needed, then how can I restore my plugin to its default state after this wrapper code completes? It seems to happen AFTER the plugin’s constructor runs, so I can’t do anything there to fix this.

Any ideas?

---

<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:** [June 7, 2019, 6:05pm UTC](https://forum.juce.com/t/audiounit-wrapper-issue-with-discrete-parameters/33792/2 "2019-06-07T18:05:55Z")

</div>

If I comment out that whole section of code where it fills those string arrays, and simply return kAudioUnitErr\_InvalidProperty from GetParameterValueStrings(), I don’t see any adverse affects (yet). What problems might this cause, and in which host(s)?

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [June 21, 2019, 11:13am UTC](https://forum.juce.com/t/audiounit-wrapper-issue-with-discrete-parameters/33792/3 "2019-06-21T11:13:25Z")

</div>

This might show up in things like labels for discrete levels in the automation lanes of Logic.
