Extending Component


#1

I'd like to extend those sub-classes of components into a new set of classes, and be able to extend the features with another couple of useful generic functions.  

So I've created another base class XmlSupportingObject which I want to use to extend the framework classes into new sub-classes, e.g. 

MyNewSliderWithXmlFeatures : public Slider, public XmlSupportingObject { … };

Now I want to make a generator routine which returns a pointer to the base class(es):  I want to use with this point features from Component as well as XmlSupportingObject class.  

Is returning a component and typecasting when I want to call the XmlSupportingObject features the right solution? It seems ugly!

Thoughts?  This is part of a master plan for managing parameters.

I could just edit the Component base class, but that doesn't seem like the right solution either!


#2

You could try a templated approach with something like this:

template<class WrappedJuceComp, class WrappedJuceCompXmlHandler>

class MyXmlComp : public Component, public XmlSupportingObject {

WrappedJuceComp juceComp;

WrappedJuceCompXmlHandler xmlHandler;

}

MyXmlComp<Slider, SliderXmlHandler> mySlider;

 

Or non templated with the same MyXmlComp and then subclass for each juce component type.


#3

Definitely encapsulating was the way to go.  My dynamic_casting solution was core dumping all over the place, so taking some of your suggestion I re-wrote the thing (again) this morning and now it works. 

I can take my XML and build my GUI automatically, as well as all the parameter handling :)  Yippee!

<root>

<container name="WIDTH" gui="panel" baseid="0"> 

        <location x="10" y="10" />

        <autosize />

        <parameter name="Width" gui="knob" id="0">

            <location x="0" y="20" />

            <max>3.0</max>

            <min>1.0</min>

        </parameter>

        <parameter name="Delay" gui="knob" id="1">

            <location x="72" y="20"/>

            <max>20.0</max>

            <min>-20.0</min>

            <midpoint /> 

            <units>ms</units>

        </parameter>

</container>

And so on ... magically replaces  a few hundred lines of code.  And I can tweak the positions of things without recompiling which is nice:)

I'm still undecided on the best way of handling these autogenerated things in the processor.  At the moment I've been giving each parameter an ID in the XML, which I'm later just indexing into a big array for speed and convenience:  value[id].  But it'd be nice to refer to them by name.  So I either have to do a slower lookup based on the parameter name value["frequency"], or just build a big enum automatically from the XML as part of the build process value[AutoBuiltEnum::frequency]. 

Any one else have a good solution?

 


#4

juce Identifiers would work well for that.  I've actually built a similar gui system.  It's modelled after HTML and CSS and uses Lua for scripting.  You may want to consider doing something similar.  It might not fit what you're attempting to do but using an already proven system as a guideline greatly reduces the brain power required to get all aspects working right.