|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Alf mapping functions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "alf/alfmappingfunctions.h" |
|
22 #include "alf/alfgencomponent.h" |
|
23 #include "alf/alfconstants.h" |
|
24 #include "alflogger.h" |
|
25 |
|
26 #include <uiacceltk/HuiUtil.h> |
|
27 |
|
28 #include <e32math.h> |
|
29 #include <e32std.h> |
|
30 |
|
31 |
|
32 // CONSTANT MAPPING FUNCTION |
|
33 |
|
34 struct CAlfConstantMappingFunction::TPrivateData |
|
35 { |
|
36 CAlfGenComponent* iComms; |
|
37 TReal32 iValue; |
|
38 }; |
|
39 |
|
40 EXPORT_C CAlfConstantMappingFunction* CAlfConstantMappingFunction::NewL( |
|
41 CAlfEnv& aEnv, |
|
42 TReal32 aValue ) __SOFTFP |
|
43 { |
|
44 CAlfConstantMappingFunction* self = new (ELeave) CAlfConstantMappingFunction; |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL( aEnv, aValue ); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 CAlfConstantMappingFunction::CAlfConstantMappingFunction() |
|
52 { |
|
53 } |
|
54 |
|
55 void CAlfConstantMappingFunction::ConstructL( CAlfEnv& aEnv, TReal32 aValue ) |
|
56 { |
|
57 iData = new (ELeave) TPrivateData; |
|
58 |
|
59 iData->iComms = NULL; |
|
60 |
|
61 TPckgC<TReal32> paramsPckg( aValue ); |
|
62 |
|
63 iData->iComms = CAlfGenComponent::NewL(aEnv, |
|
64 EAlfMappingFunctionConstantCreate, |
|
65 0, |
|
66 paramsPckg); |
|
67 |
|
68 iData->iValue = aValue; |
|
69 } |
|
70 |
|
71 |
|
72 EXPORT_C CAlfConstantMappingFunction::~CAlfConstantMappingFunction() |
|
73 { |
|
74 if ( iData ) |
|
75 { |
|
76 delete iData->iComms; |
|
77 iData->iComms = NULL; |
|
78 } |
|
79 delete iData; |
|
80 iData = NULL; |
|
81 } |
|
82 |
|
83 TReal32 CAlfConstantMappingFunction::MapValue(TReal32 /*aValue*/, TInt /*aComponent*/) const __SOFTFP |
|
84 { |
|
85 return iData->iValue; |
|
86 } |
|
87 |
|
88 TInt CAlfConstantMappingFunction::MappingFunctionIdentifier() const |
|
89 { |
|
90 return iData->iComms->Identifier(); |
|
91 } |
|
92 |
|
93 EXPORT_C void CAlfConstantMappingFunction::SetValue( TReal32 aValue ) __SOFTFP |
|
94 { |
|
95 TPckgC<TReal32> paramsPckg( aValue ); |
|
96 |
|
97 TInt err = iData->iComms->DoCmdNoReply( |
|
98 EAlfConstantMappingFunctionSetValue, |
|
99 paramsPckg ); |
|
100 |
|
101 if ( err ) |
|
102 { |
|
103 __ALFLOGSTRING1( "CAlfConstantMappingFunction::SetValue panic error %d", err ) |
|
104 USER_INVARIANT(); |
|
105 } |
|
106 |
|
107 iData->iValue = aValue; |
|
108 } |
|
109 |
|
110 EXPORT_C TReal32 CAlfConstantMappingFunction::Value() const __SOFTFP |
|
111 { |
|
112 return iData->iValue; |
|
113 } |
|
114 |
|
115 // LINEAR MAPPING FUNCTION |
|
116 |
|
117 struct CAlfLinearMappingFunction::TPrivateData |
|
118 { |
|
119 CAlfGenComponent* iComms; |
|
120 TReal32 iFactor; |
|
121 TReal32 iOffset; |
|
122 }; |
|
123 |
|
124 EXPORT_C CAlfLinearMappingFunction* CAlfLinearMappingFunction::NewL( |
|
125 CAlfEnv& aEnv, |
|
126 TReal32 aFactor, |
|
127 TReal32 aOffset) __SOFTFP |
|
128 { |
|
129 CAlfLinearMappingFunction* self = new (ELeave) CAlfLinearMappingFunction; |
|
130 CleanupStack::PushL( self ); |
|
131 self->ConstructL( aEnv, aFactor, aOffset ); |
|
132 CleanupStack::Pop( self ); |
|
133 return self; |
|
134 } |
|
135 |
|
136 CAlfLinearMappingFunction::CAlfLinearMappingFunction() |
|
137 { |
|
138 } |
|
139 |
|
140 void CAlfLinearMappingFunction::ConstructL( CAlfEnv& aEnv, TReal32 aFactor, TReal32 aOffset ) |
|
141 { |
|
142 iData = new (ELeave) TPrivateData; |
|
143 |
|
144 iData->iComms = NULL; |
|
145 |
|
146 TReal2 params( aFactor, aOffset ); |
|
147 TPckgC<TReal2> paramsPckg( params ); |
|
148 |
|
149 iData->iComms = CAlfGenComponent::NewL(aEnv, |
|
150 EAlfMappingFunctionLinearCreate, |
|
151 0, |
|
152 paramsPckg); |
|
153 |
|
154 iData->iFactor = aFactor; |
|
155 iData->iOffset = aOffset; |
|
156 } |
|
157 |
|
158 EXPORT_C CAlfLinearMappingFunction::~CAlfLinearMappingFunction() |
|
159 { |
|
160 if ( iData ) |
|
161 { |
|
162 delete iData->iComms; |
|
163 iData->iComms = NULL; |
|
164 } |
|
165 delete iData; |
|
166 iData = NULL; |
|
167 } |
|
168 |
|
169 TReal32 CAlfLinearMappingFunction::MapValue(TReal32 aValue, TInt /*aComponent*/) const __SOFTFP |
|
170 { |
|
171 return aValue * iData->iFactor + iData->iOffset; |
|
172 } |
|
173 |
|
174 TInt CAlfLinearMappingFunction::MappingFunctionIdentifier() const |
|
175 { |
|
176 return iData->iComms->Identifier(); |
|
177 } |
|
178 |
|
179 EXPORT_C void CAlfLinearMappingFunction::SetFactor( TReal32 aFactor ) __SOFTFP |
|
180 { |
|
181 TPckgC<TReal32> paramsPckg( aFactor ); |
|
182 |
|
183 TInt err = iData->iComms->DoCmdNoReply( |
|
184 EAlfLinearMappingFunctionSetFactor, |
|
185 paramsPckg ); |
|
186 |
|
187 if ( err ) |
|
188 { |
|
189 __ALFLOGSTRING1( "CAlfLinearMappingFunction::SetFactor panic error %d", err ) |
|
190 USER_INVARIANT(); |
|
191 } |
|
192 |
|
193 iData->iFactor = aFactor; |
|
194 } |
|
195 |
|
196 EXPORT_C TReal32 CAlfLinearMappingFunction::Factor() const __SOFTFP |
|
197 { |
|
198 return iData->iFactor; |
|
199 } |
|
200 |
|
201 EXPORT_C void CAlfLinearMappingFunction::SetOffset( TReal32 aOffset ) __SOFTFP |
|
202 { |
|
203 TPckgC<TReal32> paramsPckg( aOffset ); |
|
204 |
|
205 TInt err = iData->iComms->DoCmdNoReply( |
|
206 EAlfLinearMappingFunctionSetOffset, |
|
207 paramsPckg ); |
|
208 |
|
209 if ( err ) |
|
210 { |
|
211 __ALFLOGSTRING1( "CAlfLinearMappingFunction::SetOffset panic error %d", err ) |
|
212 USER_INVARIANT(); |
|
213 } |
|
214 |
|
215 iData->iOffset = aOffset; |
|
216 } |
|
217 |
|
218 EXPORT_C TReal32 CAlfLinearMappingFunction::Offset() const __SOFTFP |
|
219 { |
|
220 return iData->iOffset; |
|
221 } |
|
222 |
|
223 // SINE MAPPING FUNCTION |
|
224 |
|
225 struct CAlfSineMappingFunction::TPrivateData |
|
226 { |
|
227 CAlfGenComponent* iComms; |
|
228 TReal32 iFactor; |
|
229 TReal32 iOffset; |
|
230 }; |
|
231 |
|
232 EXPORT_C CAlfSineMappingFunction* CAlfSineMappingFunction::NewL( |
|
233 CAlfEnv& aEnv, |
|
234 TReal32 aFactor, |
|
235 TReal32 aOffset) __SOFTFP |
|
236 { |
|
237 CAlfSineMappingFunction* self = new (ELeave) CAlfSineMappingFunction; |
|
238 CleanupStack::PushL( self ); |
|
239 self->ConstructL( aEnv, aFactor,aOffset ); |
|
240 CleanupStack::Pop( self ); |
|
241 return self; |
|
242 } |
|
243 |
|
244 CAlfSineMappingFunction::CAlfSineMappingFunction() |
|
245 { |
|
246 } |
|
247 |
|
248 void CAlfSineMappingFunction::ConstructL( CAlfEnv& aEnv, TReal32 aFactor, TReal32 aOffset ) |
|
249 { |
|
250 iData = new (ELeave) TPrivateData; |
|
251 |
|
252 iData->iComms = NULL; |
|
253 |
|
254 TReal2 params( aFactor, aOffset ); |
|
255 TPckgC<TReal2> paramsPckg( params ); |
|
256 |
|
257 iData->iComms = CAlfGenComponent::NewL(aEnv, |
|
258 EAlfMappingFunctionSineCreate, |
|
259 0, |
|
260 paramsPckg); |
|
261 |
|
262 iData->iFactor = aFactor; |
|
263 iData->iOffset = aOffset; |
|
264 } |
|
265 |
|
266 EXPORT_C CAlfSineMappingFunction::~CAlfSineMappingFunction() |
|
267 { |
|
268 if ( iData ) |
|
269 { |
|
270 delete iData->iComms; |
|
271 iData->iComms = NULL; |
|
272 } |
|
273 delete iData; |
|
274 iData = NULL; |
|
275 } |
|
276 |
|
277 TReal32 CAlfSineMappingFunction::MapValue(TReal32 aValue, TInt /*aComponent*/) const __SOFTFP |
|
278 { |
|
279 TReal mapped = 0; |
|
280 Math::Sin(mapped, aValue); |
|
281 return mapped * iData->iFactor + iData->iOffset; |
|
282 } |
|
283 |
|
284 TInt CAlfSineMappingFunction::MappingFunctionIdentifier() const |
|
285 { |
|
286 return iData->iComms->Identifier(); |
|
287 } |
|
288 |
|
289 EXPORT_C void CAlfSineMappingFunction::SetFactor( TReal32 aFactor ) __SOFTFP |
|
290 { |
|
291 TPckgC<TReal32> paramsPckg( aFactor ); |
|
292 |
|
293 TInt err = iData->iComms->DoCmdNoReply( |
|
294 EAlfSineMappingFunctionSetFactor, |
|
295 paramsPckg ); |
|
296 |
|
297 if ( err ) |
|
298 { |
|
299 __ALFLOGSTRING1( "CAlfSineMappingFunction::SetFactor panic error %d", err ) |
|
300 USER_INVARIANT(); |
|
301 } |
|
302 |
|
303 iData->iFactor = aFactor; |
|
304 } |
|
305 |
|
306 EXPORT_C TReal32 CAlfSineMappingFunction::Factor() const __SOFTFP |
|
307 { |
|
308 return iData->iFactor; |
|
309 } |
|
310 |
|
311 EXPORT_C void CAlfSineMappingFunction::SetOffset( TReal32 aOffset ) __SOFTFP |
|
312 { |
|
313 TPckgC<TReal32> paramsPckg( aOffset ); |
|
314 |
|
315 TInt err = iData->iComms->DoCmdNoReply( |
|
316 EAlfSineMappingFunctionSetOffset, |
|
317 paramsPckg ); |
|
318 |
|
319 if ( err ) |
|
320 { |
|
321 __ALFLOGSTRING1( "CAlfSineMappingFunction::SetOffset panic error %d", err ) |
|
322 USER_INVARIANT(); |
|
323 } |
|
324 |
|
325 iData->iOffset = aOffset; |
|
326 } |
|
327 |
|
328 EXPORT_C TReal32 CAlfSineMappingFunction::Offset() const __SOFTFP |
|
329 { |
|
330 return iData->iOffset; |
|
331 } |
|
332 |
|
333 // COSINE MAPPING FUNCTION |
|
334 |
|
335 struct CAlfCosineMappingFunction::TPrivateData |
|
336 { |
|
337 CAlfGenComponent* iComms; |
|
338 TReal32 iFactor; |
|
339 TReal32 iOffset; |
|
340 }; |
|
341 |
|
342 EXPORT_C CAlfCosineMappingFunction* CAlfCosineMappingFunction::NewL( |
|
343 CAlfEnv& aEnv, |
|
344 TReal32 aFactor, |
|
345 TReal32 aOffset) __SOFTFP |
|
346 { |
|
347 CAlfCosineMappingFunction* self = new (ELeave) CAlfCosineMappingFunction; |
|
348 CleanupStack::PushL( self ); |
|
349 self->ConstructL( aEnv, aFactor,aOffset ); |
|
350 CleanupStack::Pop( self ); |
|
351 return self; |
|
352 } |
|
353 |
|
354 CAlfCosineMappingFunction::CAlfCosineMappingFunction() |
|
355 { |
|
356 } |
|
357 |
|
358 void CAlfCosineMappingFunction::ConstructL( CAlfEnv& aEnv, TReal32 aFactor, TReal32 aOffset ) |
|
359 { |
|
360 iData = new (ELeave) TPrivateData; |
|
361 |
|
362 iData->iComms = NULL; |
|
363 |
|
364 TReal2 params( aFactor, aOffset ); |
|
365 TPckgC<TReal2> paramsPckg( params ); |
|
366 |
|
367 iData->iComms = CAlfGenComponent::NewL(aEnv, |
|
368 EAlfMappingFunctionCosineCreate, |
|
369 0, |
|
370 paramsPckg); |
|
371 |
|
372 iData->iFactor = aFactor; |
|
373 iData->iOffset = aOffset; |
|
374 } |
|
375 |
|
376 EXPORT_C CAlfCosineMappingFunction::~CAlfCosineMappingFunction() |
|
377 { |
|
378 if ( iData ) |
|
379 { |
|
380 delete iData->iComms; |
|
381 iData->iComms = NULL; |
|
382 } |
|
383 delete iData; |
|
384 iData = NULL; |
|
385 } |
|
386 |
|
387 TReal32 CAlfCosineMappingFunction::MapValue(TReal32 aValue, TInt /*aComponent*/) const __SOFTFP |
|
388 { |
|
389 TReal mapped = 0; |
|
390 Math::Cos(mapped, aValue); |
|
391 return mapped * iData->iFactor + iData->iOffset; |
|
392 } |
|
393 |
|
394 TInt CAlfCosineMappingFunction::MappingFunctionIdentifier() const |
|
395 { |
|
396 return iData->iComms->Identifier(); |
|
397 } |
|
398 |
|
399 EXPORT_C void CAlfCosineMappingFunction::SetFactor( TReal32 aFactor ) __SOFTFP |
|
400 { |
|
401 TPckgC<TReal32> paramsPckg( aFactor ); |
|
402 |
|
403 TInt err = iData->iComms->DoCmdNoReply( |
|
404 EAlfCosineMappingFunctionSetFactor, |
|
405 paramsPckg ); |
|
406 |
|
407 if ( err ) |
|
408 { |
|
409 __ALFLOGSTRING1( "CAlfCosineMappingFunction::SetFactor panic error %d", err ) |
|
410 USER_INVARIANT(); |
|
411 } |
|
412 |
|
413 iData->iFactor = aFactor; |
|
414 } |
|
415 |
|
416 EXPORT_C TReal32 CAlfCosineMappingFunction::Factor() const __SOFTFP |
|
417 { |
|
418 return iData->iFactor; |
|
419 } |
|
420 |
|
421 EXPORT_C void CAlfCosineMappingFunction::SetOffset( TReal32 aOffset ) __SOFTFP |
|
422 { |
|
423 TPckgC<TReal32> paramsPckg( aOffset ); |
|
424 |
|
425 TInt err = iData->iComms->DoCmdNoReply( |
|
426 EAlfCosineMappingFunctionSetOffset, |
|
427 paramsPckg ); |
|
428 |
|
429 if ( err ) |
|
430 { |
|
431 __ALFLOGSTRING1( "CAlfCosineMappingFunction::SetOffset panic error %d", err ) |
|
432 USER_INVARIANT(); |
|
433 } |
|
434 |
|
435 iData->iOffset = aOffset; |
|
436 } |
|
437 |
|
438 EXPORT_C TReal32 CAlfCosineMappingFunction::Offset() const __SOFTFP |
|
439 { |
|
440 return iData->iOffset; |
|
441 } |
|
442 |
|
443 // AVERAGE MAPPING FUNCTION |
|
444 |
|
445 struct CAlfAverageMappingFunction::TPrivateData |
|
446 { |
|
447 CAlfGenComponent* iComms; |
|
448 }; |
|
449 |
|
450 |
|
451 EXPORT_C CAlfAverageMappingFunction* CAlfAverageMappingFunction::NewL( |
|
452 CAlfEnv& aEnv, |
|
453 MAlfMappingFunction* aFunc1, |
|
454 MAlfMappingFunction* aFunc2 ) |
|
455 { |
|
456 CAlfAverageMappingFunction* self = new (ELeave)CAlfAverageMappingFunction(); |
|
457 CleanupStack::PushL( self ); |
|
458 self->ConstructL( aEnv, aFunc1, aFunc2 ); |
|
459 CleanupStack::Pop( self ); |
|
460 return self; |
|
461 } |
|
462 |
|
463 CAlfAverageMappingFunction::CAlfAverageMappingFunction() |
|
464 { |
|
465 } |
|
466 |
|
467 void CAlfAverageMappingFunction::ConstructL( |
|
468 CAlfEnv& aEnv, |
|
469 MAlfMappingFunction* aFunc1, |
|
470 MAlfMappingFunction* aFunc2 |
|
471 ) |
|
472 { |
|
473 iData = new (ELeave) TPrivateData; |
|
474 |
|
475 iData->iComms = NULL; |
|
476 |
|
477 TInt2 functions( |
|
478 aFunc1 ? aFunc1->MappingFunctionIdentifier() : 0, |
|
479 aFunc2 ? aFunc2->MappingFunctionIdentifier() : 0 ); |
|
480 TPckgC<TInt2> functionsPckg( functions ); |
|
481 |
|
482 iData->iComms = CAlfGenComponent::NewL(aEnv, |
|
483 EAlfMappingFunctionAverageCreate, |
|
484 0, |
|
485 functionsPckg); |
|
486 } |
|
487 |
|
488 EXPORT_C CAlfAverageMappingFunction::~CAlfAverageMappingFunction() |
|
489 { |
|
490 if ( iData ) |
|
491 { |
|
492 delete iData->iComms; |
|
493 iData->iComms = NULL; |
|
494 } |
|
495 delete iData; |
|
496 iData = NULL; |
|
497 } |
|
498 |
|
499 TReal32 CAlfAverageMappingFunction::MapValue(TReal32 aValue, TInt aComponent) const __SOFTFP |
|
500 { |
|
501 TIntTReal mapValues( aComponent, aValue ); |
|
502 TPckgC<TIntTReal> mapValuesPckg( mapValues ); |
|
503 |
|
504 TReal32 returnValue = aValue; |
|
505 TPckg<TReal32> returnBuf(returnValue); |
|
506 |
|
507 TInt err = iData->iComms->DoSynchronousCmd( |
|
508 EAlfMappingFunctionMapValue, |
|
509 mapValuesPckg, |
|
510 returnBuf ); |
|
511 |
|
512 if ( err ) |
|
513 { |
|
514 __ALFLOGSTRING1( "CAlfAverageMappingFunction::MapValue panic error %d", err ) |
|
515 USER_INVARIANT(); |
|
516 } |
|
517 |
|
518 return returnValue; |
|
519 } |
|
520 |
|
521 TInt CAlfAverageMappingFunction::MappingFunctionIdentifier() const |
|
522 { |
|
523 return iData->iComms->Identifier(); |
|
524 } |
|
525 |
|
526 EXPORT_C void CAlfAverageMappingFunction::SetMappingFunction1( MAlfMappingFunction* aFunction1 ) |
|
527 { |
|
528 TInt function = aFunction1 ? aFunction1->MappingFunctionIdentifier() : 0; |
|
529 TPckgC<TInt> functionPckg( function ); |
|
530 |
|
531 TInt err = iData->iComms->DoCmdNoReply( |
|
532 EAlfAverageMappingFunctionSetFunction1, |
|
533 functionPckg ); |
|
534 |
|
535 if ( err ) |
|
536 { |
|
537 __ALFLOGSTRING1( "CAlfAverageMappingFunction::SetMappingFunction1 panic error %d", err ) |
|
538 USER_INVARIANT(); |
|
539 } |
|
540 } |
|
541 |
|
542 EXPORT_C void CAlfAverageMappingFunction::SetMappingFunction2( MAlfMappingFunction* aFunction2 ) |
|
543 { |
|
544 TInt function = aFunction2 ? aFunction2->MappingFunctionIdentifier() : 0; |
|
545 TPckgC<TInt> functionPckg( function ); |
|
546 TBuf8<1> outDum; |
|
547 |
|
548 TInt err = iData->iComms->DoCmdNoReply( |
|
549 EAlfAverageMappingFunctionSetFunction2, |
|
550 functionPckg ); |
|
551 |
|
552 if ( err ) |
|
553 { |
|
554 __ALFLOGSTRING1( "CAlfAverageMappingFunction::SetMappingFunction2 panic error %d", err ) |
|
555 USER_INVARIANT(); |
|
556 } |
|
557 } |
|
558 |
|
559 EXPORT_C void CAlfAverageMappingFunction::SetMappingFunctions( |
|
560 MAlfMappingFunction* aFunction1, |
|
561 MAlfMappingFunction* aFunction2 ) |
|
562 { |
|
563 TInt2 functions( |
|
564 aFunction1 ? aFunction1->MappingFunctionIdentifier() : 0, |
|
565 aFunction2 ? aFunction2->MappingFunctionIdentifier() : 0 ); |
|
566 TPckgC<TInt2> functionsPckg( functions ); |
|
567 TBuf8<1> outDum; |
|
568 |
|
569 TInt err = iData->iComms->DoCmdNoReply( |
|
570 EAlfAverageMappingFunctionSetFunctions, |
|
571 functionsPckg ); |
|
572 |
|
573 if ( err ) |
|
574 { |
|
575 __ALFLOGSTRING1( "CAlfAverageMappingFunction::SetMappingFunctions panic error %d", err ) |
|
576 USER_INVARIANT(); |
|
577 } |
|
578 } |
|
579 |
|
580 EXPORT_C void CAlfAverageMappingFunction::SetWeight( |
|
581 const TAlfTimedValue& aWeight ) |
|
582 { |
|
583 TPckgC<TAlfTimedValue> buf(aWeight); |
|
584 |
|
585 TInt err = iData->iComms->DoCmdNoReply( |
|
586 EAlfAverageMappingFunctionSetWeight, |
|
587 buf); |
|
588 |
|
589 if ( err ) |
|
590 { |
|
591 __ALFLOGSTRING1( "CAlfAverageMappingFunction::SetWeight panic error %d", err ) |
|
592 USER_INVARIANT(); |
|
593 } |
|
594 } |
|
595 struct CAlfTableMappingFunction::TPrivateData |
|
596 { |
|
597 CAlfGenComponent* iComms; |
|
598 TAlfTableMappingFunctionParams iParams; |
|
599 MAlfTableMappingFunctionDataProvider* iLastFunction; |
|
600 TReal32 iLastStart; |
|
601 TReal32 iLastEnd; |
|
602 }; |
|
603 |
|
604 |
|
605 |
|
606 EXPORT_C CAlfTableMappingFunction* CAlfTableMappingFunction::NewL( |
|
607 CAlfEnv& aEnv) |
|
608 { |
|
609 CAlfTableMappingFunction* self = new (ELeave)CAlfTableMappingFunction(); |
|
610 CleanupStack::PushL( self ); |
|
611 self->ConstructL( aEnv ); |
|
612 CleanupStack::Pop( self ); |
|
613 return self; |
|
614 } |
|
615 |
|
616 CAlfTableMappingFunction::CAlfTableMappingFunction() |
|
617 { |
|
618 } |
|
619 |
|
620 void CAlfTableMappingFunction::ConstructL(CAlfEnv& aEnv) |
|
621 { |
|
622 iData = new (ELeave) TPrivateData; |
|
623 |
|
624 iData->iComms = NULL; |
|
625 Mem::FillZ(&iData->iParams, sizeof(iData->iParams)); |
|
626 iData->iLastStart = 0; |
|
627 iData->iLastEnd = 0; |
|
628 iData->iLastFunction = NULL; |
|
629 |
|
630 TReal2 param(0.f, 0.f); |
|
631 TPckgC<TReal2> paramPckg( param ); |
|
632 iData->iComms = CAlfGenComponent::NewL(aEnv, |
|
633 EAlfMappingFunctionTableCreate, |
|
634 0, |
|
635 paramPckg); |
|
636 } |
|
637 |
|
638 EXPORT_C CAlfTableMappingFunction::~CAlfTableMappingFunction() |
|
639 { |
|
640 if ( iData ) |
|
641 { |
|
642 delete iData->iComms; |
|
643 iData->iComms = NULL; |
|
644 } |
|
645 delete iData; |
|
646 iData = NULL; |
|
647 } |
|
648 |
|
649 TReal32 CAlfTableMappingFunction::MapValue(TReal32 aValue, TInt /*aComponent*/) const __SOFTFP |
|
650 { |
|
651 // For performance resons, this same function exist both client and serverside |
|
652 TReal32 retVal = aValue; |
|
653 |
|
654 TBool inverted = EFalse; |
|
655 |
|
656 if (iData->iParams.iValues[KAlfTableMappingNumberOfMappedValues - 1] < iData->iParams.iValues[0]) |
|
657 { |
|
658 inverted = ETrue; |
|
659 } |
|
660 |
|
661 TInt i = 0; |
|
662 |
|
663 if (!inverted) |
|
664 { |
|
665 // Find closest pre-calculated value... |
|
666 for (i=0; i<KAlfTableMappingNumberOfMappedValues;i++) |
|
667 { |
|
668 if ((!inverted && aValue < iData->iParams.iValues[i]) || |
|
669 inverted && (aValue > iData->iParams.iValues[i])) |
|
670 { |
|
671 retVal = iData->iParams.iMappedValues[i]; |
|
672 break; |
|
673 } |
|
674 retVal = iData->iParams.iMappedValues[i]; |
|
675 } |
|
676 |
|
677 // ...do approximation, real value is between pre-calculated values |
|
678 if (i != 0) |
|
679 { |
|
680 TReal32 valueDelta = iData->iParams.iValues[i] - aValue; |
|
681 if (inverted) |
|
682 { |
|
683 valueDelta = -valueDelta; |
|
684 } |
|
685 |
|
686 TReal32 valueStep = iData->iParams.iValues[i] - iData->iParams.iValues[i-1]; |
|
687 TReal32 mappedValueStep = iData->iParams.iMappedValues[i] - iData->iParams.iMappedValues[i-1]; |
|
688 TReal32 fix = (valueDelta/valueStep) * mappedValueStep; |
|
689 retVal -= fix; |
|
690 } |
|
691 } |
|
692 |
|
693 return retVal; |
|
694 } |
|
695 |
|
696 TInt CAlfTableMappingFunction::MappingFunctionIdentifier() const |
|
697 { |
|
698 return iData->iComms->Identifier(); |
|
699 } |
|
700 |
|
701 EXPORT_C void CAlfTableMappingFunction::SetMappingTableValues(TReal32 aStart, TReal32 aEnd, MAlfTableMappingFunctionDataProvider* aFunction) __SOFTFP |
|
702 { |
|
703 TBool valuesChanged = (iData->iLastStart != aStart || iData->iLastEnd != aEnd); |
|
704 TBool functionChanged = (aFunction != iData->iLastFunction); |
|
705 |
|
706 if (aFunction && (valuesChanged || functionChanged)) |
|
707 { |
|
708 TReal32 step = (aEnd - aStart)/(KAlfTableMappingNumberOfMappedValues - 1); |
|
709 TReal32 value = aStart; |
|
710 for (TInt i=0; i<KAlfTableMappingNumberOfMappedValues;i++) |
|
711 { |
|
712 iData->iParams.iValues[i] = value; |
|
713 iData->iParams.iMappedValues[i] = aFunction->MapValue(value, 0); |
|
714 value += step; |
|
715 } |
|
716 |
|
717 iData->iParams.iValues[KAlfTableMappingNumberOfMappedValues -1] = aEnd; |
|
718 iData->iParams.iMappedValues[KAlfTableMappingNumberOfMappedValues -1] = |
|
719 aFunction->MapValue(aEnd, 0); |
|
720 |
|
721 TPckgC<TAlfTableMappingFunctionParams> mapValuesPckg( iData->iParams ); |
|
722 |
|
723 TInt err = iData->iComms->DoCmdNoReply( |
|
724 EAlfMappingFunctionTableSetValues, |
|
725 mapValuesPckg ); |
|
726 __ASSERT_ALWAYS( err == KErrNone, USER_INVARIANT() ); |
|
727 |
|
728 iData->iLastStart = aStart; |
|
729 iData->iLastEnd = aEnd; |
|
730 iData->iLastFunction = aFunction; |
|
731 } |
|
732 } |
|
733 |