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