/usr/share/faust/iOS/iOS/FIBargraph.mm is in faust-common 0.9.95~repack1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | /************************************************************************
************************************************************************
FAUST Architecture File
Copyright (C) 2003-2012 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This is sample code. This file is provided as an example of minimal
FAUST architecture file. Redistribution and use in source and binary
forms, with or without modification, in part or in full are permitted.
In particular you can create a derived work of this FAUST architecture
and distribute that work under terms of your choice.
This sample code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
************************************************************************
************************************************************************/
/************************************************************************
************************************************************************
Based on F3BarGauge - https://github.com/ChiefPilot/F3BarGauge
Copyright (c) 2011 by Brad Benson - https://github.com/ChiefPilot
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
************************************************************************
************************************************************************/
// Pick up required headers
#import "FIBargraph.h"
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//---------------| F3BarGauge class implementation |--------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//===[ Extention for private-ish stuff ]==================================
@interface FIBargraph()
{
@private
int m_iOnIdx, // Point at which segments are on
m_iOffIdx, // Point at which segments are off
m_iPeakBarIdx, // Index of peak value segment
m_iWarningBarIdx, // Index of first warning segment
m_iDangerBarIdx; // Index of first danger segment
}
// Private methods
-(void) setDefaults;
-(void) drawBar:(CGContextRef)a_ctx
withRect:(CGRect) a_rect
andColor:(UIColor *)a_clr
lit:(BOOL)a_lit;
@end
@implementation FIBargraph
//===[ Public Methods ]===================================================
//------------------------------------------------------------------------
// Method: initWithFrame:
// Designated initializer
//
-(id) initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if(self) {
// Assign default values
[self setDefaults];
}
return self;
}
//------------------------------------------------------------------------
// Method: initWithCoder:
// Initializes the instance when brought from nib, etc.
//
-(id) initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if(self) {
// Assign default values
[self setDefaults];
}
return self;
}
//------------------------------------------------------------------------
// Method: dealloc
// Clean up instance when released
//
-(void) dealloc
{
// Clean up
[m_clrBackground release];
[m_clrOuterBorder release];
[m_clrInnerBorder release];
[m_clrNormal release];
[m_clrWarning release];
[m_clrDanger release];
// Call parent
[super dealloc];
}
//------------------------------------------------------------------------
// Method: resetPeak
// Resets peak value.
//
-(void) resetPeak
{
// Reset the value and redraw
m_flPeakValue = -INFINITY;
m_iPeakBarIdx = -1;
[self setNeedsDisplay];
}
//------------------------------------------------------------------------
// Method: value accessor
//
-(CGFloat) value
{
return m_flValue;
}
//------------------------------------------------------------------------
// Method: value setter
//
-(void) setValue:(CGFloat)a_value
{
bool fRedraw = false;
// Save value
m_flValue = a_value;
// Point at which bars start lighting up
int iOnIdx = (m_flValue >= m_flMinLimit) ? 0 : m_iNumBars;
if( iOnIdx != m_iOnIdx ) {
// Changed - save it
m_iOnIdx = iOnIdx;
fRedraw = true;
}
// Point at which bars are no longer lit
int iOffIdx = ((m_flValue - m_flMinLimit) / (m_flMaxLimit - m_flMinLimit)) * m_iNumBars;
if( iOffIdx != m_iOffIdx ) {
// Changed - save it
m_iOffIdx = iOffIdx;
fRedraw = true;
}
// Are we doing peak?
if( m_fHoldPeak && a_value > m_flPeakValue ) {
// Yes, save the peak bar index
m_flPeakValue = a_value;
m_iPeakBarIdx = MIN(m_iOffIdx, m_iNumBars - 1);
}
// Redraw the display?
if( fRedraw ) {
// Do it
[self setNeedsDisplay];
}
}
//------------------------------------------------------------------------
// Method: setNumBars:
// This method sets the number of bars in the display
//
- (void) setNumBars:(int)a_iNumBars
{
// Reset peak value to force it to be updated w/new bar index
m_flPeakValue = -INFINITY;
// Save it, then update the thresholds
m_iNumBars = a_iNumBars;
[self setValue:m_flValue];
[self setWarnThreshold:m_flWarnThreshold];
[self setDangerThreshold:m_flDangerThreshold];
}
//------------------------------------------------------------------------
// Method: setWarnThreshold:
// Sets the level for which bars should be of the warning color
// (dft: yellow)
//
- (void) setWarnThreshold:(float)a_flWarnThreshold
{
// Save it and recompute values
m_flWarnThreshold = a_flWarnThreshold;
m_iWarningBarIdx = ( !isnan(a_flWarnThreshold) && a_flWarnThreshold > 0.0f ) ?
(int)( m_flWarnThreshold * (float)m_iNumBars ) :
-1;
}
//------------------------------------------------------------------------
// Method: setDangerThreshold:
// Sets the level for which bars should be of the warning color
// (dft: red).
//
- (void) setDangerThreshold:(float)a_flDangerThreshold
{
// Save it and recompute values
m_flDangerThreshold = a_flDangerThreshold;
m_iDangerBarIdx = ( !isnan(a_flDangerThreshold) && a_flDangerThreshold > 0.0f ) ?
(int)( m_flDangerThreshold * (float)m_iNumBars ) :
-1;
}
//------------------------------------------------------------------------
// Synthesized properties
//
@synthesize maxLimit = m_flMaxLimit;
@synthesize minLimit = m_flMinLimit;
@synthesize numBars = m_iNumBars;
@synthesize warnThreshold = m_flWarning;
@synthesize dangerThreshold = m_flDanger;
@synthesize holdPeak = m_fHoldPeak;
@synthesize peakValue = m_flPeakValue;
@synthesize litEffect = m_fLitEffect;
@synthesize reverse = m_fReverseDirection;
@synthesize outerBorderColor = m_clrOuterBorder;
@synthesize innerBorderColor = m_clrInnerBorder;
@synthesize backgroundColor = m_clrBackground;
@synthesize normalBarColor = m_clrNormal;
@synthesize warningBarColor = m_clrWarning;
@synthesize dangerBarColor = m_clrDanger;
@synthesize led;
@synthesize ledMinColor;
@synthesize ledMaxColor;
//===[ Private Methods ]==================================================
//------------------------------------------------------------------------
// Method: setDefaults
// Configure default settings for instance
//
-(void) setDefaults
{
// Set view background to clear
[self setBackgroundColor:[UIColor clearColor]];
// Configure limits
m_flMaxLimit = 1.0f;
m_flMinLimit = 0.0f;
m_flValue = 0.0f;
// Set defaults for bar display
m_fHoldPeak = NO;
m_iNumBars = 10;
m_iOffIdx = 0;
m_iOnIdx = 0;
m_iPeakBarIdx = -1;
m_fLitEffect = YES;
m_fReverseDirection = NO;
[self setWarnThreshold:0.60f];
[self setDangerThreshold:0.80f];
// Set default colors
m_clrBackground = [[UIColor blackColor] retain];
m_clrOuterBorder = [[UIColor grayColor] retain];
m_clrInnerBorder = [[UIColor blackColor] retain];
m_clrNormal = [[UIColor greenColor] retain];
m_clrWarning = [[UIColor yellowColor] retain];
m_clrDanger = [[UIColor redColor] retain];
// Misc.
self.clearsContextBeforeDrawing = NO;
self.opaque = NO;
self.led = NO;
self.ledMinColor = [[UIColor blackColor] retain];
self.ledMaxColor = [[UIColor redColor] retain];
}
//------------------------------------------------------------------------
// Method: drawRect:
// Draw the gauge
//
-(void) drawRect:(CGRect)rect
{
if (self.hideOnGUI) return;
if (self.led)
{
CGContextRef ctx;
CGFloat rMin = 0.f;
CGFloat gMin = 0.f;
CGFloat bMin = 0.f;
CGFloat aMin = 0.f;
CGFloat rMax = 0.f;
CGFloat gMax = 0.f;
CGFloat bMax = 0.f;
CGFloat aMax = 0.f;
UIColor* color;
float normedValue = (self.value - self.minLimit) / (self.maxLimit - self.minLimit);
if (normedValue < 0.) normedValue = 0.f;
else if (normedValue > 1.) normedValue = 1.f;
[ledMinColor getRed:&rMin green:&gMin blue:&bMin alpha:&aMin];
[ledMaxColor getRed:&rMax green:&gMax blue:&bMax alpha:&aMax];
color = [UIColor colorWithRed:rMin * (1. - normedValue) + rMax * normedValue
green:gMin * (1. - normedValue) + gMax * normedValue
blue:bMin * (1. - normedValue) + bMax * normedValue
alpha:1./*aMin * (1. - normedValue) + aMax * normedValue*/];
ctx = UIGraphicsGetCurrentContext();
CGContextClearRect(ctx, self.bounds);
CGContextSetFillColorWithColor(ctx, color.CGColor);
CGContextFillRect(ctx, rect);
}
else
{
CGContextRef ctx; // Graphics context
CGRect rectBounds, // Bounding rectangle adjusted for multiple of bar size
rectBar; // Rectangle for individual light bar
size_t iBarSize; // Size (width or height) of each LED bar
// How is the bar oriented?
rectBounds = self.bounds;
BOOL fIsVertical = (rectBounds.size.height >= rectBounds.size.width);
if(fIsVertical) {
// Adjust height to be an exact multiple of bar
iBarSize = rectBounds.size.height / m_iNumBars;
rectBounds.size.height = iBarSize * m_iNumBars;
}
else {
// Adjust width to be an exact multiple
iBarSize = rectBounds.size.width / m_iNumBars;
rectBounds.size.width = iBarSize * m_iNumBars;
}
// Compute size of bar
rectBar.size.width = (fIsVertical) ? rectBounds.size.width - 2 : iBarSize;
rectBar.size.height = (fIsVertical) ? iBarSize : rectBounds.size.height - 2;
// Get stuff needed for drawing
ctx = UIGraphicsGetCurrentContext();
CGContextClearRect(ctx, self.bounds);
// Fill background
CGContextSetFillColorWithColor(ctx, m_clrBackground.CGColor);
CGContextFillRect(ctx, rectBounds);
// Draw LED bars
CGContextSetStrokeColorWithColor(ctx, m_clrInnerBorder.CGColor);
CGContextSetLineWidth(ctx, 1.0);
for( int iX = 0; iX < m_iNumBars; ++iX ) {
// Determine position for this bar
if(m_fReverseDirection) {
// Top-to-bottom or right-to-left
rectBar.origin.x = (fIsVertical) ? rectBounds.origin.x + 1 : (CGRectGetMaxX(rectBounds) - (iX+1) * iBarSize);
rectBar.origin.y = (fIsVertical) ? (CGRectGetMinY(rectBounds) + iX * iBarSize) : rectBounds.origin.y + 1;
}
else {
// Bottom-to-top or right-to-left
rectBar.origin.x = (fIsVertical) ? rectBounds.origin.x + 1 : (CGRectGetMinX(rectBounds) + iX * iBarSize);
rectBar.origin.y = (fIsVertical) ? (CGRectGetMaxY(rectBounds) - (iX + 1) * iBarSize) : rectBounds.origin.y + 1;
}
// Draw top and bottom borders for bar
CGContextAddRect(ctx, rectBar);
CGContextStrokePath(ctx);
// Determine color of bar
UIColor *clrFill = m_clrNormal;
if( m_iDangerBarIdx >= 0 && iX >= m_iDangerBarIdx ) {
clrFill = m_clrDanger;
}
else if( m_iWarningBarIdx >= 0 && iX >= m_iWarningBarIdx ) {
clrFill = m_clrWarning;
}
// Determine if bar should be lit
BOOL fLit = ((iX >= m_iOnIdx && iX < m_iOffIdx) || iX == m_iPeakBarIdx);
// Fill the interior of the bar
CGContextSaveGState(ctx);
CGRect rectFill = CGRectInset(rectBar, 1.0, 1.0);
CGPathRef clipPath = CGPathCreateWithRect(rectFill, NULL);
CGContextAddPath(ctx, clipPath);
CGContextClip(ctx);
[self drawBar:ctx
withRect:rectFill
andColor:clrFill
lit:fLit];
CGContextRestoreGState(ctx);
CGPathRelease(clipPath);
}
// Draw border around the control
m_clrOuterBorder = [UIColor colorWithRed:0.08 green:0.08 blue:0.08 alpha:1.];
CGContextSetStrokeColorWithColor(ctx, m_clrOuterBorder.CGColor);
CGContextSetLineWidth(ctx, 2.0);
CGContextAddRect(ctx, CGRectInset(rectBounds, 1, 1));
CGContextStrokePath(ctx);
}
}
//------------------------------------------------------------------------
// Method: drawBar::::
// This method draws a bar
//
- (void) drawBar:(CGContextRef)a_ctx
withRect:(CGRect)a_rect
andColor:(UIColor *)a_clr
lit:(BOOL) a_fLit
{
// Is the bar lit?
if(a_fLit) {
// Are we doing radial gradient fills?
if(m_fLitEffect) {
// Yes, set up to draw the bar as a radial gradient
static size_t num_locations = 2;
static CGFloat locations[] = { 0.0, 0.5 };
CGFloat aComponents[8];
CGColorRef clr = a_clr.CGColor;
// Set up color components from passed UIColor object
if (CGColorGetNumberOfComponents(clr) == 4) {
// Extract the components
//
// Note that iOS 5.0 provides a nicer way to do this i.e.
// [a_clr getRed:&aComponents[0]
// green:&aComponents[1]
// blue:&aComponents[2]
// alpha:&aComponents[3] ];
memcpy(aComponents, CGColorGetComponents(clr), 4*sizeof(CGFloat));
// Calculate dark color of gradient
aComponents[4] = aComponents[0] - ((aComponents[0] > 0.3) ? 0.3 : 0.0);
aComponents[5] = aComponents[1] - ((aComponents[1] > 0.3) ? 0.3 : 0.0);
aComponents[6] = aComponents[2] - ((aComponents[2] > 0.3) ? 0.3 : 0.0);
aComponents[7] = aComponents[3];
}
// Calculate radius needed
CGFloat width = CGRectGetWidth(a_rect);
CGFloat height = CGRectGetHeight(a_rect);
CGFloat radius = sqrt( width * width + height * height );
// Draw the gradient inside the provided rectangle
CGColorSpaceRef myColorspace = CGColorSpaceCreateDeviceRGB();
CGGradientRef myGradient = CGGradientCreateWithColorComponents (myColorspace,
aComponents,
locations,
num_locations);
CGPoint myStartPoint = { CGRectGetMidX(a_rect), CGRectGetMidY(a_rect) };
CGContextDrawRadialGradient(a_ctx, myGradient, myStartPoint, 0.0, myStartPoint, radius, 0);
CGColorSpaceRelease(myColorspace);
CGGradientRelease(myGradient);
}
else {
// No, solid fill
CGContextSetFillColorWithColor(a_ctx, a_clr.CGColor);
CGContextFillRect(a_ctx, a_rect);
}
}
else {
// No, draw the bar as background color overlayed with a mostly
// ... transparent version of the passed color
CGColorRef fillClr = CGColorCreateCopyWithAlpha(a_clr.CGColor, 0.2f);
CGContextSetFillColorWithColor(a_ctx, m_clrBackground.CGColor);
CGContextFillRect(a_ctx, a_rect);
CGContextSetFillColorWithColor(a_ctx, fillClr);
CGContextFillRect(a_ctx, a_rect);
CGColorRelease(fillClr);
}
}
@end
|