[Clam-devel] TypedControls: asking for advice and opinions

Pau Arumí Albó parumi at iua.upf.edu
Fri Jun 27 02:50:35 PDT 2008


El dv 27 de 06 de 2008 a les 00:18 -0300, en/na Hernán Ordiales va
escriure:
> Hi gang,
> 
> First, some context, Francisco was working in a new typedcontrols
> patch and an issue arose that I would like to share and ask for
> opinions.
> Since the last work regarding to get a common interface for
> registering controls with the same interface (i.e.BaseTypedControls)
> this ended up requiring a dynamic_cast in every DoControl() call in
> the processing code because now the signature of GetInControl (at
> Processing class) is like:
>   BaseTypedInControl & GetInControl( const std::string & name )
> 
> for example, now is required:
> 		dynamic_cast<TypedInControl<float>*>(&(mPitchShift.GetInControl("PitchSteps")))->DoControl(amount);
> instead of
> 		mPitchShift.GetInControl("PitchSteps").DoControl(amount);


Yep! this is a conceptual problem.
With typed controls (or ports) the GetInControl(...) interface should
not be used by client classes.
One should only use typed controls in three ways
      * From within the concrete class: _myOutControl.Send(myObject);
      * Connecting out->in ports from two processings.
      * From outside the class (a client class) : 
                OutControl<Foo> controlSender;
                controlSender.LinkTo( targetProcessing.GetInControl(..) );
                controlSernder.SendControl( foo );

                I'm writing by heart, so not sure about the interface.
                LinkTo, etc.
                Note that the LinkTo can launch an exception -- which is
                something wanted.

Does it makes sense to you?

Pau



> (btw, DoControl() is not defined in BaseTypedControl since should be
> templatized too)
> 
> Well, so now I'm asking for opinions on the best way to avoid this
> (since i think is to much overhead for a framework code), I have some
> ideas, but let me know if you have new/better ones or what you think
> is best.
> 
> What i thought:
> 
> * Make the Processing class templatized and do the dynamic cast inside
> the get function and returning a TypednControl
> 
> * Make templatized the TypedInControlRegistry and do something like:
> mPitchShift.GetInControls().Get("PitchSteps").DoControl(amount);
> (with Get() returning a TypednControl)
> 
> * Add a virtual DoControl in BaseTypedInControl and in TypedInControl
> something like:
> template<class TypedControlData>
> void TypedInControl<TypedControlData>::DoControl(void* val)
> {
> 	try {
> 		TypedControlData* data = reinterpret_cast<TypedControlData*>(val);
> 		this->DoControl(*data);
> 	}
> 	catch(...)
> 	{
> 		CLAM_ASSERT( false, "DoControl could not cast to TypedControlData*" );
> 	}
> }
> (or directly mLastValue = *data instead of this->DoControl(*data) to
> avoid another function call)
> 
> * Some macro (#define ...)?
> 
> * Put your idea here :-D
> 
> note: I'm not sending the current francisco's patch because is a
> little big (the idea is to reduce it, but is not so simple) and is not
> ready for commitment either (has some minor problems and is full of
> needed dynamic castings related with DoControl() which i'd like to
> avoid as i previously told)
> 
> Cheers!





More information about the clam-devel mailing list