TuttleOFX
1
|
00001 #include "OfxhParameterSuite.hpp" 00002 #include "attribute/OfxhParam.hpp" 00003 #include "attribute/OfxhParamSet.hpp" 00004 #include "attribute/OfxhParamSetDescriptor.hpp" 00005 #include "attribute/OfxhKeyframeParam.hpp" 00006 00007 namespace tuttle { 00008 namespace host { 00009 namespace ofx { 00010 namespace attribute { 00011 00012 namespace { 00013 00014 OfxStatus paramDefine( OfxParamSetHandle paramSet, 00015 const char* paramType, 00016 const char* name, 00017 OfxPropertySetHandle* propertySet ) 00018 { 00019 try 00020 { 00021 OfxhParamSetDescriptor* paramSetDescriptor = reinterpret_cast<OfxhParamSetDescriptor*>( paramSet ); 00022 if( !paramSetDescriptor ) 00023 return kOfxStatErrBadHandle; 00024 00025 OfxhParamDescriptor* desc = paramSetDescriptor->paramDefine( paramType, name ); 00026 if( !desc ) 00027 return kOfxStatErrUnsupported; 00028 00029 *propertySet = desc->getPropHandle(); 00030 00031 return kOfxStatOK; 00032 } 00033 catch( OfxhException& e ) 00034 { 00035 return e.getStatus(); 00036 } 00037 catch(... ) 00038 { 00039 return kOfxStatErrUnknown; 00040 } 00041 } 00042 00043 OfxStatus paramGetHandle( OfxParamSetHandle paramSet, 00044 const char* name, 00045 OfxParamHandle* param, 00046 OfxPropertySetHandle* propertySet ) 00047 { 00048 try 00049 { 00050 OfxhParamSetAccessor* baseSet = reinterpret_cast<OfxhParamSetAccessor*>( paramSet ); 00051 if( !baseSet ) 00052 return kOfxStatErrBadHandle; 00053 00054 OfxhParamSet* setInstance = dynamic_cast<OfxhParamSet*>( baseSet ); 00055 if( setInstance ) 00056 { 00057 const std::map<std::string, OfxhParam*>& params = setInstance->getParamsByName(); 00058 std::map<std::string, OfxhParam*>::const_iterator it = params.find( name ); 00059 00060 // if we can't find it return an error... 00061 if( it == params.end() ) 00062 { 00063 BOOST_THROW_EXCEPTION( OfxhException( kOfxStatErrUnknown, std::string( "Can't find parameter : " ) + name ) ); 00064 } 00065 00066 // get the param 00067 *param = ( it->second )->getParamHandle(); 00068 00069 // get the param property set 00070 if( propertySet ) 00071 *propertySet = ( it->second )->getPropHandle(); 00072 00073 return kOfxStatOK; 00074 } 00075 00076 OfxhParamSetDescriptor* setDescriptor = dynamic_cast<OfxhParamSetDescriptor*>( baseSet ); 00077 if( setDescriptor ) 00078 { 00079 const std::map<std::string, OfxhParamDescriptor*>& params = setDescriptor->getParams(); 00080 std::map<std::string, OfxhParamDescriptor*>::const_iterator it = params.find( name ); 00081 00082 // if we can't find it return an error... 00083 if( it == params.end() ) 00084 return kOfxStatErrUnknown; 00085 00086 // get the param 00087 *param = ( it->second )->getParamHandle(); 00088 00089 // get the param property set 00090 if( propertySet ) 00091 *propertySet = ( it->second )->getPropHandle(); 00092 00093 return kOfxStatOK; 00094 } 00095 00096 return kOfxStatErrBadHandle; 00097 } 00098 catch( OfxhException& e ) 00099 { 00100 TUTTLE_LOG_EXCEPTION( e ); 00101 return e.getStatus(); 00102 } 00103 catch(... ) 00104 { 00105 return kOfxStatErrUnknown; 00106 } 00107 } 00108 00109 OfxStatus paramSetGetPropertySet( OfxParamSetHandle paramSet, 00110 OfxPropertySetHandle* propHandle ) 00111 { 00112 try 00113 { 00114 OfxhParamSetAccessor* baseSet = reinterpret_cast<OfxhParamSetAccessor*>( paramSet ); 00115 if( !baseSet ) 00116 return kOfxStatErrBadHandle; 00117 00118 *propHandle = baseSet->getParamSetProps().getHandle(); 00119 00120 return kOfxStatOK; 00121 } 00122 catch( OfxhException& e ) 00123 { 00124 return e.getStatus(); 00125 } 00126 catch(... ) 00127 { 00128 return kOfxStatErrUnknown; 00129 } 00130 } 00131 00132 OfxStatus paramGetPropertySet( OfxParamHandle param, 00133 OfxPropertySetHandle* propHandle ) 00134 { 00135 try 00136 { 00137 attribute::OfxhParam* paramInstance = reinterpret_cast<attribute::OfxhParam*>( param ); 00138 if( !paramInstance || !paramInstance->verifyMagic() ) 00139 return kOfxStatErrBadHandle; 00140 00141 // get the param property set 00142 *propHandle = paramInstance->getPropHandle(); 00143 00144 return kOfxStatOK; 00145 } 00146 catch( OfxhException& e ) 00147 { 00148 return e.getStatus(); 00149 } 00150 catch(... ) 00151 { 00152 return kOfxStatErrUnknown; 00153 } 00154 } 00155 00156 /** 00157 * get the current param value 00158 */ 00159 OfxStatus paramGetValue( OfxParamHandle paramHandle, ... ) 00160 { 00161 try 00162 { 00163 OfxhParam* paramInstance = reinterpret_cast<OfxhParam*>( paramHandle ); 00164 if( !paramInstance || !paramInstance->verifyMagic() ) 00165 return kOfxStatErrBadHandle; 00166 00167 va_list ap; 00168 va_start( ap, paramHandle ); 00169 OfxStatus stat = kOfxStatOK; 00170 00171 try 00172 { 00173 paramInstance->getV( ap ); 00174 } 00175 catch( OfxhException& e ) 00176 { 00177 stat = e.getStatus(); 00178 } 00179 catch(... ) 00180 { 00181 stat = kOfxStatErrUnknown; 00182 } 00183 00184 va_end( ap ); 00185 00186 return stat; 00187 } 00188 catch( OfxhException& e ) 00189 { 00190 return e.getStatus(); 00191 } 00192 catch(... ) 00193 { 00194 return kOfxStatErrUnknown; 00195 } 00196 } 00197 00198 /** 00199 * get the param value at a time 00200 */ 00201 OfxStatus paramGetValueAtTime( OfxParamHandle paramHandle, 00202 OfxTime time, 00203 ... ) 00204 { 00205 try 00206 { 00207 OfxhParam* paramInstance = reinterpret_cast<OfxhParam*>( paramHandle ); 00208 if( !paramInstance || !paramInstance->verifyMagic() ) 00209 return kOfxStatErrBadHandle; 00210 00211 va_list ap; 00212 va_start( ap, time ); 00213 OfxStatus stat = kOfxStatOK; 00214 00215 try 00216 { 00217 paramInstance->getV( time, ap ); 00218 } 00219 catch( OfxhException& e ) 00220 { 00221 stat = e.getStatus(); 00222 } 00223 catch(... ) 00224 { 00225 stat = kOfxStatErrUnknown; 00226 } 00227 00228 va_end( ap ); 00229 00230 return stat; 00231 } 00232 catch( OfxhException& e ) 00233 { 00234 return e.getStatus(); 00235 } 00236 catch(... ) 00237 { 00238 return kOfxStatErrUnknown; 00239 } 00240 } 00241 00242 /** 00243 * get the param's derivative at the given time 00244 */ 00245 OfxStatus paramGetDerivative( OfxParamHandle paramHandle, 00246 OfxTime time, 00247 ... ) 00248 { 00249 try 00250 { 00251 OfxhParam* paramInstance = reinterpret_cast<OfxhParam*>( paramHandle ); 00252 if( !paramInstance || !paramInstance->verifyMagic() ) 00253 return kOfxStatErrBadHandle; 00254 00255 va_list ap; 00256 va_start( ap, time ); 00257 OfxStatus stat = kOfxStatOK; 00258 00259 try 00260 { 00261 paramInstance->deriveV( time, ap ); 00262 } 00263 catch( OfxhException& e ) 00264 { 00265 stat = e.getStatus(); 00266 } 00267 catch(... ) 00268 { 00269 stat = kOfxStatErrUnknown; 00270 } 00271 00272 va_end( ap ); 00273 00274 return stat; 00275 } 00276 catch( OfxhException& e ) 00277 { 00278 return e.getStatus(); 00279 } 00280 catch(... ) 00281 { 00282 return kOfxStatErrUnknown; 00283 } 00284 } 00285 00286 OfxStatus paramGetIntegral( OfxParamHandle paramHandle, 00287 OfxTime time1, OfxTime time2, 00288 ... ) 00289 { 00290 try 00291 { 00292 OfxhParam* paramInstance = reinterpret_cast<OfxhParam*>( paramHandle ); 00293 if( !paramInstance || !paramInstance->verifyMagic() ) 00294 return kOfxStatErrBadHandle; 00295 00296 va_list ap; 00297 va_start( ap, time2 ); 00298 OfxStatus stat = kOfxStatOK; 00299 00300 try 00301 { 00302 paramInstance->integrateV( time1, time2, ap ); 00303 } 00304 catch( OfxhException& e ) 00305 { 00306 stat = e.getStatus(); 00307 } 00308 catch(... ) 00309 { 00310 stat = kOfxStatErrUnknown; 00311 } 00312 00313 va_end( ap ); 00314 00315 return stat; 00316 } 00317 catch( OfxhException& e ) 00318 { 00319 return e.getStatus(); 00320 } 00321 catch(... ) 00322 { 00323 return kOfxStatErrUnknown; 00324 } 00325 } 00326 00327 /** 00328 * set the param's value at the 'current' time 00329 */ 00330 OfxStatus paramSetValue( OfxParamHandle paramHandle, 00331 ... ) 00332 { 00333 try 00334 { 00335 OfxhParam* paramInstance = reinterpret_cast<OfxhParam*>( paramHandle ); 00336 if( !paramInstance || !paramInstance->verifyMagic() ) 00337 return kOfxStatErrBadHandle; 00338 00339 va_list ap; 00340 va_start( ap, paramHandle ); 00341 OfxStatus stat = kOfxStatOK; 00342 00343 try 00344 { 00345 paramInstance->setV( ap, eChangePluginEdited ); 00346 } 00347 catch( OfxhException& e ) 00348 { 00349 stat = e.getStatus(); 00350 } 00351 catch(... ) 00352 { 00353 stat = kOfxStatErrUnknown; 00354 } 00355 00356 va_end( ap ); 00357 00358 return stat; 00359 } 00360 catch( OfxhException& e ) 00361 { 00362 return e.getStatus(); 00363 } 00364 catch(... ) 00365 { 00366 return kOfxStatErrUnknown; 00367 } 00368 } 00369 00370 /** 00371 * set the param's value at the indicated time, and set a key 00372 */ 00373 OfxStatus paramSetValueAtTime( OfxParamHandle paramHandle, 00374 OfxTime time, // time in frames 00375 ... ) 00376 { 00377 try 00378 { 00379 OfxhParam* paramInstance = reinterpret_cast<OfxhParam*>( paramHandle ); 00380 if( !paramInstance || !paramInstance->verifyMagic() ) 00381 return kOfxStatErrBadHandle; 00382 00383 va_list ap; 00384 va_start( ap, time ); 00385 OfxStatus stat = kOfxStatOK; 00386 00387 try 00388 { 00389 paramInstance->setV( time, ap, eChangePluginEdited ); 00390 } 00391 catch( OfxhException& e ) 00392 { 00393 stat = e.getStatus(); 00394 } 00395 catch(... ) 00396 { 00397 stat = kOfxStatErrUnknown; 00398 } 00399 00400 va_end( ap ); 00401 00402 return stat; 00403 } 00404 catch( OfxhException& e ) 00405 { 00406 return e.getStatus(); 00407 } 00408 catch(... ) 00409 { 00410 return kOfxStatErrUnknown; 00411 } 00412 } 00413 00414 OfxStatus paramGetNumKeys( OfxParamHandle paramHandle, 00415 unsigned int* numberOfKeys ) 00416 { 00417 try 00418 { 00419 attribute::OfxhParam* pInstance = reinterpret_cast<attribute::OfxhParam*>( paramHandle ); 00420 if( !pInstance || !pInstance->verifyMagic() ) 00421 return kOfxStatErrBadHandle; 00422 00423 OfxhKeyframeParam* paramInstance = dynamic_cast<OfxhKeyframeParam*>( pInstance ); 00424 if( !paramInstance ) 00425 return kOfxStatErrBadHandle; 00426 00427 paramInstance->getNumKeys( *numberOfKeys ); 00428 00429 return kOfxStatOK; 00430 } 00431 catch( OfxhException& e ) 00432 { 00433 return e.getStatus(); 00434 } 00435 catch(... ) 00436 { 00437 return kOfxStatErrUnknown; 00438 } 00439 } 00440 00441 OfxStatus paramGetKeyTime( OfxParamHandle paramHandle, 00442 unsigned int nthKey, 00443 OfxTime* time ) 00444 { 00445 try 00446 { 00447 attribute::OfxhParam* pInstance = reinterpret_cast<attribute::OfxhParam*>( paramHandle ); 00448 if( !pInstance || !pInstance->verifyMagic() ) 00449 return kOfxStatErrBadHandle; 00450 00451 OfxhKeyframeParam* paramInstance = dynamic_cast<OfxhKeyframeParam*>( pInstance ); 00452 if( !paramInstance ) 00453 return kOfxStatErrBadHandle; 00454 00455 paramInstance->getKeyTime( nthKey, *time ); 00456 00457 return kOfxStatOK; 00458 } 00459 catch( OfxhException& e ) 00460 { 00461 return e.getStatus(); 00462 } 00463 catch(... ) 00464 { 00465 return kOfxStatErrUnknown; 00466 } 00467 } 00468 00469 OfxStatus paramGetKeyIndex( OfxParamHandle paramHandle, 00470 OfxTime time, 00471 int direction, 00472 int* index ) 00473 { 00474 try 00475 { 00476 if( index == NULL ) 00477 return kOfxStatErrBadHandle; 00478 00479 attribute::OfxhParam* pInstance = reinterpret_cast<attribute::OfxhParam*>( paramHandle ); 00480 if( pInstance == NULL || !pInstance->verifyMagic() ) 00481 return kOfxStatErrBadHandle; 00482 00483 OfxhKeyframeParam* paramInstance = dynamic_cast<OfxhKeyframeParam*>( pInstance ); 00484 if( paramInstance == NULL ) 00485 return kOfxStatErrBadHandle; 00486 00487 paramInstance->getKeyIndex( time, direction, *index ); 00488 00489 return kOfxStatOK; 00490 } 00491 catch( OfxhException& e ) 00492 { 00493 return e.getStatus(); 00494 } 00495 catch(... ) 00496 { 00497 return kOfxStatErrUnknown; 00498 } 00499 } 00500 00501 OfxStatus paramDeleteKey( OfxParamHandle paramHandle, 00502 OfxTime time ) 00503 { 00504 try 00505 { 00506 attribute::OfxhParam* pInstance = reinterpret_cast<attribute::OfxhParam*>( paramHandle ); 00507 if( !pInstance || !pInstance->verifyMagic() ) 00508 return kOfxStatErrBadHandle; 00509 00510 OfxhKeyframeParam* paramInstance = dynamic_cast<OfxhKeyframeParam*>( pInstance ); 00511 if( !paramInstance ) 00512 return kOfxStatErrBadHandle; 00513 00514 paramInstance->deleteKey( time ); 00515 00516 return kOfxStatOK; 00517 } 00518 catch( OfxhException& e ) 00519 { 00520 return e.getStatus(); 00521 } 00522 catch(... ) 00523 { 00524 return kOfxStatErrUnknown; 00525 } 00526 } 00527 00528 OfxStatus paramDeleteAllKeys( OfxParamHandle paramHandle ) 00529 { 00530 try 00531 { 00532 attribute::OfxhParam* pInstance = reinterpret_cast<attribute::OfxhParam*>( paramHandle ); 00533 if( !pInstance || !pInstance->verifyMagic() ) 00534 return kOfxStatErrBadHandle; 00535 00536 OfxhKeyframeParam* paramInstance = dynamic_cast<OfxhKeyframeParam*>( pInstance ); 00537 if( !paramInstance ) 00538 return kOfxStatErrBadHandle; 00539 00540 paramInstance->deleteAllKeys(); 00541 00542 return kOfxStatOK; 00543 } 00544 catch( OfxhException& e ) 00545 { 00546 return e.getStatus(); 00547 } 00548 catch(... ) 00549 { 00550 return kOfxStatErrUnknown; 00551 } 00552 } 00553 00554 OfxStatus paramCopy( OfxParamHandle paramTo, 00555 OfxParamHandle paramFrom, 00556 OfxTime dstOffset, OfxRangeD* frameRange ) 00557 { 00558 try 00559 { 00560 OfxhParam* paramInstanceTo = reinterpret_cast<OfxhParam*>( paramTo ); 00561 if( !paramInstanceTo || !paramInstanceTo->verifyMagic() ) 00562 return kOfxStatErrBadHandle; 00563 00564 OfxhParam* paramInstanceFrom = reinterpret_cast<OfxhParam*>( paramFrom ); 00565 if( !paramInstanceFrom || !paramInstanceFrom->verifyMagic() ) 00566 return kOfxStatErrBadHandle; 00567 00568 if( !frameRange ) 00569 paramInstanceTo->copy( *paramInstanceFrom, dstOffset ); 00570 else 00571 paramInstanceTo->copy( *paramInstanceFrom, dstOffset, *frameRange ); 00572 00573 return kOfxStatOK; 00574 } 00575 catch( OfxhException& e ) 00576 { 00577 return e.getStatus(); 00578 } 00579 catch(... ) 00580 { 00581 return kOfxStatErrUnknown; 00582 } 00583 } 00584 00585 OfxStatus paramEditBegin( OfxParamSetHandle paramSet, const char* name ) 00586 { 00587 try 00588 { 00589 OfxhParamSet* setInstance = reinterpret_cast<OfxhParamSet*>( paramSet ); 00590 if( !setInstance ) 00591 return kOfxStatErrBadHandle; 00592 00593 setInstance->editBegin( std::string( name ) ); 00594 return kOfxStatOK; 00595 } 00596 catch( OfxhException& e ) 00597 { 00598 return e.getStatus(); 00599 } 00600 catch(... ) 00601 { 00602 return kOfxStatErrUnknown; 00603 } 00604 } 00605 00606 OfxStatus paramEditEnd( OfxParamSetHandle paramSet ) 00607 { 00608 try 00609 { 00610 OfxhParamSet* setInstance = reinterpret_cast<OfxhParamSet*>( paramSet ); 00611 if( !setInstance ) 00612 return kOfxStatErrBadHandle; 00613 00614 setInstance->editEnd(); 00615 00616 return kOfxStatOK; 00617 } 00618 catch( OfxhException& e ) 00619 { 00620 return e.getStatus(); 00621 } 00622 catch(... ) 00623 { 00624 return kOfxStatErrUnknown; 00625 } 00626 } 00627 00628 OfxParameterSuiteV1 gParamSuiteV1 = { 00629 paramDefine, 00630 paramGetHandle, 00631 paramSetGetPropertySet, 00632 paramGetPropertySet, 00633 paramGetValue, 00634 paramGetValueAtTime, 00635 paramGetDerivative, 00636 paramGetIntegral, 00637 paramSetValue, 00638 paramSetValueAtTime, 00639 paramGetNumKeys, 00640 paramGetKeyTime, 00641 paramGetKeyIndex, 00642 paramDeleteKey, 00643 paramDeleteAllKeys, 00644 paramCopy, 00645 paramEditBegin, 00646 paramEditEnd 00647 }; 00648 00649 } 00650 00651 void* getParameterSuite( const int version ) 00652 { 00653 if( version == 1 ) 00654 return &gParamSuiteV1; 00655 return NULL; 00656 } 00657 00658 } 00659 } 00660 } 00661 }