From: Joe E. <jo...@em...> - 2005-03-11 19:46:54
|
Bill Zwicky wrote: > Joe Emenaker wrote: > >> I made a "DataModel" interface. The idea behind it is that it handles >> all of the nuisance of stripping off leading bytes (ie, F0, manufID, >> devID, etc) and trailing F0 and it handles any conversion to/from >> 8-bit bytes or whatnot. >> >> Then, I made a new ParamModel which, when it needs data, asks the >> DataModel for it. So, the ParamModel and addWidget never need to see >> the actual Patch. > > > So did I, good job. :) I think DataModel might be the next stage in the evolution. ParamModels alone won't really cut it (in my case anyway) because I'm having to do a 7-bit-to-8-bit conversion on the whole patch before I do anything with it. If I did this in each ParamModel, there'd be a conversion happening for *every* Widget in my editor which, potentially, could lead to long delays for the editor to load. Also, because the 7-to-8 encoding "intermingles" the bits of each byte with neighboring ones, it'd be very tricky to try to have each ParamModel try to sneak its param data into the undecoded patch data itself. > Two things to watch out for: > * In Java, bytes are signed. So if the range is 0..255 before, > casting it to a (Byte) will change that to -128..127. Thus, reading > patch.sysex[index] may yield negative numbers. I had to compensate in > my CZModel.getByte. Yeah... I've hit this kinda thing before. Most-recently, it was when doing right-shifting of bits. If you do ( 0x80 >> 1 ), you don't get 0x40, you get 0xC0 because Java figures that the high-bit was on, and needs to stay that way. Uh... okay. > * Java ints are only 4 bytes, so you can't grab any more than that at > once. Ints are also signed, so if you grab 4 bytes, you'll get > negative numbers again. Longs are 8 bytes. Right! Well, here's where things can get really fun with DataModels. Some synths (like the Alesis I'm working on) use 8-bit bytes for the actual patch data, some use 7-bit. The DataModel would be aware of this. Part of the interaction between ParamModel and DataModel could be one where ParamModel declares to DataModel how many bytes it wants, and what the highest value it expects to be able to use with it. Then, the DataModel would do the calculations to make sure that it was possible. For example, suppose DataModel has a method called isInRange(int bytes, long highest value)... For a DataModel which used 7-bit bytes, isInRange(1,127) returns true isInRange(1,128) returns false isInRange(2 16383) returns true isInRange(2,16384) returns false Meanwhile, for a DataModel which uses 8-bit bytes, isInRange(1,128) would return true.... Maybe this is overkill... but I like the encapsulation of it.... and I'm an encapsulation whore. - Joe |