# Can AttachedControlBase become derivable?

**URL:** <https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159>\
**Category:** General JUCE discussion\
**Created:** [March 7, 2019, 7:09pm UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159 "2019-03-07T19:09:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [March 7, 2019, 7:09pm UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/1 "2019-03-07T19:09:52Z")

</div>

It would be great if this class was a derivable class in `juce_AudioProcessorValueTreeState.h` so we could provide our own implementation of derived classes to attach to our custom widgets that can’t really be represented as sliders, buttons, or comboBoxes.

At present, I’m using my 2D widget to modify a pair of hidden Sliders that are attached accordingly. I’d prefer to avoid doing this, but that’s what must be done to make this work.

---

<div class="post-metadata">

**Author:** ![lalala](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lalala/32/8577_2.png) [@lalala](https://forum.juce.com/u/lalala)\
**Post date:** [March 7, 2019, 7:28pm UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/2 "2019-03-07T19:28:07Z")

</div>

You can just copy it imo, its a small class.

---

<div class="post-metadata">

**Author:** ![pizzafilms](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pizzafilms/32/562_2.png) [@pizzafilms](https://forum.juce.com/u/pizzafilms)\
**Post date:** [March 7, 2019, 7:34pm UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/3 "2019-03-07T19:34:33Z")

</div>

This keeps coming up…

> [@"Double ring" slider?](https://forum.juce.com/t/double-ring-slider/31106/8):
>
> It seems that this kind of thing comes up every so often when users are creating custom controls. I know I’ve rolled my own Attachment classes a few times for my own custom controls. I usually start with either the Button or Slider Attachment class, copy it, and hack away until it fits my use case. Based on that, I’m wondering if JUCE shouldn’t have an abstract Attachment class so we could be a bit more proper and safe when attaching our own custom controls.

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [March 7, 2019, 7:52pm UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/4 "2019-03-07T19:52:27Z")

</div>

> [@lalala](#):
>
> You can just copy it imo, its a small class.

that’s not very D.R.Y. though…

---

<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:** [March 8, 2019, 8:28am UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/5 "2019-03-08T08:28:33Z")

</div>

Yeah, there’s been a few requests for it. I’ll bump its priority up.

---

<div class="post-metadata">

**Author:** ![danielrudrich](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/danielrudrich/32/3735_2.png) [@danielrudrich](https://forum.juce.com/u/danielrudrich)\
**Post date:** [July 31, 2019, 8:10am UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/6 "2019-07-31T08:10:19Z")

</div>

Can we move this or one of the other threads with same request to the Feature-Request category, so we can vote for it?

> <https://github.com/juce-framework/JUCE/issues/525>
>
> It is currently not possible to use \`SliderAttachment\` on a slider that accepts …two values. It would be nice to have some kind of \`TwoValueSliderAttachment\` class.
> 
> I started writing my own class for this outside of the Juce library, but realized that a lot of the code necessary to implement custom attachments is all tucked away into the .cpp file for \`AudioProcessorValueTreeState\`, as well as a lot of stuff is marked private which makes it really difficult to do in a clean way.
> 
> I propose two possible solutions:
> \* Implement \`TwoValueSliderAttachment\` and \`ThreeValueSliderAttachment\`
> \* Allow users to write their own attachment classes
> 
> Looking around, it seems like a common issue: https://forum.juce.com/t/using-the-slider-attachment-class-with-2-value-sliders/18411/2

> [@FR: Make AttachedControlBase in AudioProcessorValueTreeState.cpp a public facing class](https://forum.juce.com/t/fr-make-attachedcontrolbase-in-audioprocessorvaluetreestate-cpp-a-public-facing-class/26801):
>
> I have a number of custom GUI objects for my plugins, it would be very useful to be able to create an attachment to AudioProcessorValueTreeState for them, along with an attachControl method.

---

<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:** [July 31, 2019, 8:13am UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/7 "2019-07-31T08:13:42Z")

</div>

I’ve moved this thread, since you’ve helpfully linked in the others.

---

<div class="post-metadata">

**Author:** ![jrrossi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrrossi/32/140_2.png) [@jrrossi](https://forum.juce.com/u/jrrossi)\
**Post date:** [July 31, 2019, 8:25am UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/8 "2019-07-31T08:25:22Z")

</div>

Bump!!  
This would be very very useful!!

---

<div class="post-metadata">

**Author:** ![mathieudemange](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mathieudemange/32/13333_2.png) [@mathieudemange](https://forum.juce.com/u/mathieudemange)\
**Post date:** [July 31, 2019, 11:49am UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/9 "2019-07-31T11:49:08Z")

</div>

Indeed, recently had to copy it to make my own `RadioButtonGroupAttachment`.

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [July 31, 2019, 6:46pm UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/10 "2019-07-31T18:46:47Z")

</div>

Let’s all share our implementations so we can see how everyone solves the problem. I’m sure they’ll all be similar but uniquely different 🙂 I’ll go first:

```auto
#pragma once

#include "../JuceLibraryCode/JuceHeader.h"

struct GroupButton : public Button
{
    GroupButton(const String& name, int index) : Button(name), groupIndex(index) { }

    const int groupIndex;
};

struct GroupButtonParamListener : public AudioProcessorParameter::Listener, public AsyncUpdater, public Timer
{
    /*
     a group of buttons that are connected to a AudioParameterChoice
     */
    GroupButtonParamListener(Array<GroupButton*>&& bs,
                             AudioParameterChoice& choices);
    ~GroupButtonParamListener();
    void timerCallback() override;

    void handleAsyncUpdate() override;

    void parameterValueChanged(int i, float v) override;
    void parameterGestureChanged(int, bool) override { }

    juce::Atomic<int> parameterIndex;
    Array<GroupButton*> buttons;
    AudioParameterChoice& param;
    std::function<void(int,float)> parameterChanged;
};

```

```auto
#include "GroupButtonParamListener.h"

GroupButtonParamListener::GroupButtonParamListener(Array<GroupButton*>&& bs,
                                                   AudioParameterChoice& choices) :
buttons( std::move(bs) ),
param(choices)
{
    jassert( buttons.size() == param.choices.size() );
    for( auto* button : buttons )
    {
        button->onClick = [this, button]()
        {
            //all group indexes start at 1
            this->param.beginChangeGesture();
            this->param.setValueNotifyingHost( ((float)button->groupIndex-1) / float(this->param.choices.size()-1) );
            this->param.endChangeGesture();
        };
    }
    startTimer(50);
}

GroupButtonParamListener::~GroupButtonParamListener()
{
    param.removeListener(this);
}

void GroupButtonParamListener::timerCallback()
{
    stopTimer();
    param.addListener(this);
    buttons[param.getIndex()]->triggerClick();
}

void GroupButtonParamListener::handleAsyncUpdate()
{
    jassert( buttons.size() == param.choices.size() );
    auto idx = param.getIndex();
    buttons[idx]->setToggleState(true, dontSendNotification);
    //button is updated in PluginVal, but not in Logic.. hmmmm

    if( parameterChanged )
        parameterChanged(parameterIndex.get(),
                         (float)idx / float(param.choices.size() - 1) );

}
void GroupButtonParamListener::parameterValueChanged(int i, float v)
{
    parameterIndex.set(i);
    triggerAsyncUpdate();
}

```

---

<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:** [July 31, 2019, 6:56pm UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/11 "2019-07-31T18:56:03Z")

</div>

Not the most reusable nor the highest quality solution, but here’s how I was able to do a XY(Z)pad component for a plugin that uses AudioProcessorValueTreeState :

> <https://gist.github.com/Xenakios/e6db592d1a54dec0402d7f6b3f00e9b9>

---

<div class="post-metadata">

**Author:** ![JeffersonBledsoe](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@JeffersonBledsoe](https://forum.juce.com/u/JeffersonBledsoe)\
**Post date:** [October 11, 2019, 1:48pm UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/12 "2019-10-11T13:48:05Z")

</div>

Just a quick bump on this 🙂

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [February 6, 2020, 10:43am UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/13 "2020-02-06T10:43:38Z")

</div>

And another bump!

---

<div class="post-metadata">

**Author:** ![mathieudemange](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mathieudemange/32/13333_2.png) [@mathieudemange](https://forum.juce.com/u/mathieudemange)\
**Post date:** [February 6, 2020, 12:37pm UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/14 "2020-02-06T12:37:33Z")

</div>

I’m in 😉

---

<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:** [February 6, 2020, 5:20pm UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/15 "2020-02-06T17:20:17Z")

</div>

We’re working on it 🙂

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [February 6, 2020, 5:47pm UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/16 "2020-02-06T17:47:25Z")

</div>

Well, if you need any user-feedback … I have a good supply of it right now!

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [February 6, 2020, 6:17pm UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/17 "2020-02-06T18:17:11Z")

</div>

What else is involved besides moving it to the APVTS header file?

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [February 6, 2020, 6:18pm UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/18 "2020-02-06T18:18:41Z")

</div>

It’s not the nicest interface. I’m sure we can do better.

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [February 6, 2020, 6:37pm UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/19 "2020-02-06T18:37:03Z")

</div>

I don’t think anyone here would really care how nice the interface is, as long as it becomes derivable. I requested this almost a year ago. There are only a couple of other feature requests that have as many votes…

---

<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:** [February 6, 2020, 8:19pm UTC](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159/20 "2020-02-06T20:19:58Z")

</div>

> [@matkatmusic](#):
>
> I don’t think anyone here would really care how nice the interface is

I don’t think that’s true; we get a lot of feedback from the JUCE community letting us know they value our thoughtful approach to API design. We’re not going to suddenly lower our standards.

[Next page](https://forum.juce.com/t/can-attachedcontrolbase-become-derivable/32159.md?page=2)
