[Clam-devel] TypedConrols questions -- was: <something very long>

Francisco Tufró nictuku at gmail.com
Fri Jul 18 06:07:07 PDT 2008


Oh, i've sent the patch before reading this, but i'll change the static
casts to dynamic for next patch

On Thu, Jul 17, 2008 at 2:56 PM, Pau Arumí <parumi at iua.upf.edu> wrote:

>
> > My previously mentioned mail:
> >
> > Hi all,
> >
> > On Fri, Jul 11, 2008 at 3:12 PM, Francisco Tufró <nictuku at gmail.com>
> wrote:
> > > Hi, I've been trying to do the migration to TypedControls and we've
> some
> > > problems.
> > > Since the *ControlRegistry now is defined as
> std::list<BaseTyped*Control*>
> > > the functions Get() and GetByNumber now return a BaseTyped*Control
> instead
> > > of a *Control.
> > > The same is happening with Get*Controls() which now returns a
> list<Base..>
> > > instead of a list<*Control *>
> > > So, every single code line using Get*Controls as well as Get() and
> > > GetByNumber() has to be replaced.
> > > As Pau proposed i wrote the function that connected a In to a temporary
> out
> > > and sends the value, but that was just one of the appearances of the
> > > problem.
> > [snip]
> > >  - For the already known problem (the one of this thread) i wrote the
> > > following function
> > > (i made also a version where an int is passed instead of the name, but
> is
> > > essentially the same, for those places where GetByNumber was used):
> > >     void SendFloatToInControl(Processing & receiver, const std::string
> &
> > > inControlName, float value){
> > >         TypedOutControl<float> controlSender;
> > >
> controlSender.AddLink(receiver.GetInControls().Get(inControlName));
> > >         controlSender.SendControl(value);
> > >     }
> >
> > > I tried to solve every one of these problems with the better solution i
> > > thought, now i present these solutions:
> >
> > I'll reorder the problems you exposed and proposed solutions:
> >
> > > Those functiones were used in other circumstances:
> > >   - Assignations: MIDIIO/MIDIKeyboard.cxx:        OutControl&
> outVelocity =
> > > mNoteIn.GetOutControls().GetByNumber(2);
> >
> > > The first i had to do a static cast, i don't like this solution, but
> the
> > > code needs to be rewritten to avoid it, this happends also in
> NetworkEditor
> > > and Annotator.
> >
> > This seems the more ugly...
>
> First, avoid "static" casts. "dynamic" casts are preferable.
>
> We could do the casts, or encapsulate the ugliness in a function.
> OutControl & outVelocity = getOutControlAsFloatControl(mNoteIn, 2)
>
> Note this is very similar to another shortcut function I proposed (it
> was something like sendFloatControl(...)
>
> >
> > >   - To access in controls defined in parent classes:
> > > SpectralSpread.hxx:
> > > GetInControl("Amount").DoControl(100);
> >
> > > The second was solved with this function also, but passed *this as
> argument.
> >
> > ok, but if controls are protected (or public) i think you can use the
> > var name instead (like third case) and if not, i think they should...
>
> The GetInControl(..) interface is public regardless if the control
> member is public or not.
> The solution of using the function and "*this" is nice.
>
>
> >
> > >   - also (don't know why) in the Initialization function of some
> processings
> > > (where the controls were accesible by its own variable name, but
> anyways
> > > they were referenced with Get*Controls:
> > > FrameTransformation.hxx:
> > > GetInControl("Amount").DoControl(0.);
> >
> > > The third was solved replacing the lines using the variable name.
> >
> > ok for me.
>
> Ok++
>
> >
> > > Another of these problems was that GetInControl was used to ask for
> > > GetLastValue of an InControl, for this i wrote:
> > > float GetFloatFromInControl(Processing & proc, const std::string &
> > > inControlName){
> > >         InControl& in = (InControl&)(proc.GetInControl(inControlName));
> > >         return in.GetLastValue();
> > >     }
> > > This needed a typecast, but static. I'm not so sure about this
> solution.
> > > This was needed in the SMSDeesser lines 44-47.
> >
> > ok
>
> Ok++, but dynamic_cast<InControl&> please
>
> >
> > > Also there were some places that used GetOutControl to do a
> SendControl,
> > > with these i used this function:
> > >
> > >     void SendFloatToOutControl(Processing & sender, int inControlIndex,
> > > float value){
> > >         OutControl& out =
> > > (OutControl&)(sender.GetOutControls().GetByNumber(inControlIndex));
> > >         out.SendControl(value);
> > >     }
> > > Again, a cast was needed, used in MIDIInControl.hxx.
> >
> > ok
>
> Idem
>
> Hope that helps. Sorry for not answering earlier.
>
> P
>
>
> _______________________________________________
> Clam-devel mailing list
> Clam-devel at llistes.projectes.lafarga.org
> https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.clam-project.org/pipermail/clam-devel-clam-project.org/attachments/20080718/7f133794/attachment-0004.htm>


More information about the clam-devel mailing list