From: Steven S. <ste...@co...> - 2005-03-29 01:27:00
|
Methinks this went to the wrong list _____ From: Steven Schmidt [mailto:ste...@co...] Sent: Monday, March 28, 2005 10:36 AM To: 'jsy...@li...' Subject: Re: What is the JSL way to deal with negative param values? 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. 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. |
From: Bill Z. <wrz...@po...> - 2005-04-01 03:38:02
|
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. > You realize that "the math" prints get()+max-max, which is the same as rawval? So if rawval has the right value, then you don't have a problem. What is the value for min and max? If max is less than zero but the spinner control itself won't go negative, then we have a bug. Try using a SliderWidget, I know those work. -Bill |
From: Steven S. <ste...@co...> - 2005-04-01 22:25:30
|
Bill Zwicky wrote: > 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. > > You realize that "the math" prints get()+max-max, which is the same as > rawval? So if rawval has the right value, then you don't have a > problem. What is the value for min and max? If max is less than zero > but the spinner control itself won't go negative, then we have a bug. > Try using a SliderWidget, I know those work. > > -Bill Yes - min val is less than zero and the spinner won't go negative, although it does go negative in other instances. This: addWidget(p21_osc18va, new SpinnerWidget("**Tune", patch, -1200, +1200, -128, new TritonMultiCompModel(patch, 311, 1,1200), new TritonSender(311)), 3, 8, 1, 1, 15); displays the correct value of -5 for the MSB/LSB combo of 7f 7b (I haven't looked at why I had to subtact 128 (base val) to get it right, but that's a suspiciously even number) So, have we a bug? I'll try a slider and see if I have the same problem and report back. |
From: Bill Z. <wrz...@po...> - 2005-04-02 05:08:34
|
Steven Schmidt wrote: > displays the correct value of -5 for the MSB/LSB combo of 7f 7b > (I haven't looked at why I had to subtact 128 (base val) to get it > right, but that's a suspiciously even number) > So, have we a bug? I'll try a slider and see if I have the same > problem and report back. > Are the bytes still correct when the spinner reads -129? In a sysex message, the high bit must always be zero, and (I'm guessing) your synth simply sticks the remaining 14 bits together to form a number. 7f 7b is 0111 1111 0111 1011 and if we drop the high bits and regroup the nybbles, we get 11 1111 1111 1011 If you add 5 to that, you get zero. So 7f 7b is exactly -5 in 14 bits. (If you're running Microsoft Windows, you can try this with the included calculator; it can handle both hex and binary.) -Bill |
From: Steven S. <ste...@co...> - 2005-04-02 18:58:40
|
Bill Zwicky wrote: > Steven Schmidt wrote: > >> displays the correct value of -5 for the MSB/LSB combo of 7f 7b >> (I haven't looked at why I had to subtact 128 (base val) to get it >> right, but that's a suspiciously even number) >> So, have we a bug? I'll try a slider and see if I have the same >> problem and report back. >> > Are the bytes still correct when the spinner reads -129? > > In a sysex message, the high bit must always be zero, and (I'm > guessing) your synth simply sticks the remaining 14 bits together to > form a number. 7f 7b is > 0111 1111 0111 1011 > and if we drop the high bits and regroup the nybbles, we get > 11 1111 1111 1011 > If you add 5 to that, you get zero. So 7f 7b is exactly -5 in 14 > bits. (If you're running Microsoft Windows, you can try this with the > included calculator; it can handle both hex and binary.) Do you know of an existing editor that works in this manner? |
From: Bill Z. <wrz...@po...> - 2005-04-02 20:23:11
|
Steven Schmidt wrote: > Do you know of an existing editor that works in this manner? What part is giving you trouble? Are you familiar enough with binary and boolean math to work through this? Here are some links with an excessive amount of detail: http://mathforum.org/dr.math/faq/faq.bases.html http://mathforum.org/library/drmath/view/54311.html http://mathforum.org/library/drmath/sets/select/dm_twos_complement.html The "twos complement" link is most relevant, as it explains how negative numbers work. I can't find a good, decisive tutorial on binary math, but if you search around that site, you should be able to find answers. Anyway, to answer your question, my own Casio CZ editor is reasonably similar. You need to chop your numbers into 7-bit chunks, and the CZ works with 4-bit chunks. The math is the same, only the constants differ. I've pulled all the code into a common superclass: synthdrivers/CasioCZ1000/CZModel.java -Bill |
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. > |