imacarthur wrote:
> On 13 Jun 2008, at 20:53, [EMAIL PROTECTED] wrote:
> 
>>> Then your set_widget(130, 50); would perhaps become something like...
>>>
>>> set_widget(int id, float val) {
>>>   widget_array[id]->value(val);
>>> }
>> But Fl_Widget doesn't have a value() method.  Keeping an array of
>> Fl_Valuator* might work, but might get messy because it's value()
>> is non-virtual; you'd have to research whether or not the base class
>> value() does what you want in all cases.  Unfortunately fltk
>> doesn't do polymorphism very well.
> 
> Yes, fair point Stan.
> It (the pseudo code) was more conceptual than practical.
> I guess for a synth system all the valuator widgets would have  
> essentially similar value methods however, so picking an appropriate  
> base class could work? Dunno...

        If the situation is MIDI ID events come streaming in,
        and these ID's need to be quickly routed to the widget
        assigned to that ID, if any.

        So assuming the app has some way to map IDs to widgets,
        there's a lot of ways to 'route' the IDs to invoke the
        set/get functions for the appropriate type of widget.

        One easy way might be to make arrays of the various kinds
        of widgets:

Fl_Inputs *inputs[256];
Fl_Dials  *dials[256];
Fl_Slider *sliders[256];

        ..and assuming these arrays are all NULLs unless assigned
        to an ID, an incoming event could then be quickly routed
        to the correct widget via:

void ProcessMIDIEvent(int id, float val) {
    if ( id < 0 || id >= 256 ) return;          // out of range

    // QUICKLY ROUTE EVENT TO PROPER WIDGET
         if ( inputs[id]  ) {  inputs[id]->SetValue(val); }
    else if ( dials[id]   ) {   dials[id]->SetValue(val); }
    else if ( sliders[id] ) { sliders[id]->SetValue(val); }
}

        There's probably cleaner ways than that from a C++ point of view,
        but if you're more C oriented, that might be most straightforward
        way for you, rather then creating a wrapper class that encapsulates
        all the different types of widgets you need, and thus make a single
        array of that wrapper class, letting logic in the wrapper class
        determine which kind of widget to invoke. Basically the same
        as the above, just arranged in a more 'encapsulated' way.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to