From: Bill Z. <wrz...@in...> - 2007-05-02 19:18:25
|
I apologize for the ridiculous lateness of this; I just discovered it had never been sent. I hope it's useful to someone. Steven Schmidt wrote: > I've been casting it as a byte and while it seems to work up to a point -- I'm not getting the negative values to display. > I thought it should work the way I'm doing it, but it stops at zero. Please have a look at this snippet and make recommendations if you can: > The purpose of this method is to subtract the max value for the widget if the param value is greater than the max value. Why would you do that? I'm having trouble figuring out what your code sample is doing, so I'll pull some explanations out of thin air, and hope something applies. There are *three* data formats you need to think about when building your editor: 1. The GUI format. What is the range you want to present to the user? For example, my Casio CZ has a detune parameter that ranges from -47 to +47, so I use a slider with exactly that range. 2. The binary format. How does your synth represent a value as bits? For the detune parameter, the CZ uses one bit to represent sign, and 7 bits for the absolute value. 3. The sysex format. The upper bit of each byte in a sysex cannot be used, so usually there's an extra encoding applyed to expand the binary format so that it skips those useless bits. The CZ simply uses the lowest 4 bits of each byte, so after step two, I chop the data into two nybbles, and store them in consecutive locations in the sysex. When we say "bytes are signed numbers", we're talking about the sysex format (level 3), and the tricks involved in getting data into and out of the sysex byte array. The IParamModel, on the other hand, converts between levels 1 and 2. To use my CZ example again, DetuneModel.get() returns an integer in the range -47 to +47, and DetuneModel.set() accepts the same. http://mathforum.org/library/drmath/sets/select/dm_twos_complement.html > > public static SpinnerWidget dynaSpinner(String label, IPatch patch, int min, int max, int base, > IParamModel pmodel, ISender sender) { > String pt = patch.getByteArray().toString(); > > int rawval = pmodel.get(); > int prelimval = (byte)pmodel.get()+ max & 0x7F; > System.out.println("rawval:"+ rawval+" prelimval:"+prelimval); > if (rawval > max) { > base = -max; > System.out.println(" BASE:"+base + " The math:"+(prelimval + base)); > SpinnerWidget spinner = new SpinnerWidget (label, patch, min, max, base, pmodel, sender); > } > SpinnerWidget spinner = new SpinnerWidget (label, patch, min, max, base, pmodel, sender); > > return spinner; > } > > } > This outputs: > > rawval:126 prelimval:10 > > BASE:-12 The math:-2 > -2 is the correct value, but the spinner widget actually displays a '0' -- apparently getting stuck at 0. > Help!!! > > Bill Zwicky wrote: > > Note that this goofiness is on top of the fact that your synth has > > probably scrambled the bytes a little to get around the restrictions of > > the sysex message. So you need to deal with that, on top of dealing > > with signed bytes. > |