Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Rounding the output value while the slider is being moved



Hey all!

I am trying to figure out how I can round the value the slider returns while it is being moved. My slider is set to continuously send the data while it's moving, it sends data to the Audio Unit plugin and also to a text box near it. While the slider is moving and is not being relesed, the Audio Unit parameter also changes continuously. Here's the code that does the job:

- (IBAction)iaParam1Changed:(id)sender {
float floatValue = [sender floatValue];
NSAssert( AUParameterSet(mParameterListener, sender, &parameter[0], (Float32)floatValue, 0) == noErr,
@"[SinevibesTransformerView iaParam1Changed:] AUParameterSet()");
if (sender == uiParam1Slider) {
[uiParam1TextField setFloatValue:floatValue];
} else {
[uiParam1Slider setFloatValue:floatValue];
}
}


Now, for some parameters, I would like to simultaneously round the value to the first or second decimal after the point, as seeing a number with 4 or 5 decimals after the dot makes no visual sense. So I changed the second line to:

float floatValue = round ([sender floatValue] * 10.0f) / 10.0f;

As the slider is being moved, parameter changes smoothly for the Audio Unit, e.g. 3.5 instead of 2.54121, but the text box shows 3.50000 or 3.49999 until the slider gets released - then it shows 3.5. How can I eliminate this issue which looks connected to calculation precision?

Any suggestions would be very welcome!



Artemiy.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.