From: Joe E. <jo...@em...> - 2005-03-17 00:27:54
|
Brian wrote: > My gut reaction to how to fix it would be to create a method in the > base class for models and senders that does nothing called setPatch > (Patch p). This would be called automatically by addWidget > on the Model and Sender sent to it. Well, here's the "grand design" of what I'm thinking of: - Patch data would be given only to one of the items (widget, param-model, or sender) and the others would get it from that. My inclination would be that the param-model would house the patch data, since there are possible scenarios in which we might want to adjust parameters *outside* of the context of a graphical widget (ie, cross-breeding, or cut "Master Volume" by 90% in all patches in a bank). ParamModel would have a method for widgets to get the patch data... which Widget would use to obtain it, and then give it to Sender, if there is one. - I think parameter name should also be in ParamModel, for the same reasons (and obtained by Widget in the same way) - Lastly, I'd like for DataModel to be worked into this somehow. Like I mentioned before, the driver I'm working on now requires tat 7-bit bytes be decoded into 8-bit bytes, and it's easier to do this to the entire sysex message and than it would be for individual ParamModels to try to convert just the part they're interested in. Instead, by using a DataModel class (which holds the actual Patch object and handles all translation to/from Ints/Longs/Strings), the ParamModels would be given the DataModel object and would access the data they wanted via methods like getInt(offset). The ultimate result of this would be to stop writing things like this: addWidget(leftPane, new CheckBoxWidget("Midi Pitch Bend", patch, new MKSBitModel(patch, 16, 5), new MKSBitSender(patch, 16, 5, 9)) , 0, 10, 1, 1, -3); and start writing them like this: SingleSysexDataModel datamodel = new SingleSysexDataModel(patch); .... addWidget(leftPane, new CheckBoxWidget(new MKSBitModel("Midi Pitch Bend", datamodel, 16, 5), new MKSBitSender(16, 5, 9)) , 0, 10, 1, 1, -3); It doesn't look *that* much cleaner, but at least the patch data is only passed once. This could be cleaned up even more if ParamModels use interfaces or superclasses that define them as either BooleanParamModel, NumericParamModel, or EnumParamModel. Then, addWidget could discover what kind of parameter a ParamModel is and automatically give it the correct widget (ie, BooleanParamModel gets a CheckBoxWidget, NumericParamModel might get a spinner, EnumParamModel would get a ComboBoxWidget, etc). Then, you could use things like: addWidget(leftPane, new MKSBitModel("Midi Pitch Bend", datamodel, 16, 5), new MKSBitSender(16, 5, 9), 0, 10, 1, 1, -3); Of course, you could always do things the old way if this didn't give you the flexibility you needed. But I think that this would clean things up in the general cases. Give it some thought, if you will. - Joe |