TuttleOFX
1
|
00001 /* 00002 * OFX Support Library, a library that skins the OFX plug-in API with C++ classes. 00003 * Copyright (C) 2004-2005 The Open Effects Association Ltd 00004 * Author Bruno Nicoletti bruno@thefoundry.co.uk 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * 00009 * Redistributions of source code must retain the above copyright notice, 00010 * this list of conditions and the following disclaimer. 00011 * Redistributions in binary form must reproduce the above copyright notice, 00012 * this list of conditions and the following disclaimer in the documentation 00013 * and/or other materials provided with the distribution. 00014 * Neither the name The Open Effects Association Ltd, nor the names of its 00015 * contributors may be used to endorse or promote products derived from this 00016 * software without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00019 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00020 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00021 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 00022 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00023 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00024 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00025 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00026 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00027 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00028 * 00029 * The Open Effects Association Ltd 00030 * 1 Wardour St 00031 * London W1D 6PA 00032 * England 00033 * 00034 * 00035 * 00036 */ 00037 00038 #ifndef _ofxsSupportPrivate_H_ 00039 #define _ofxsSupportPrivate_H_ 00040 00041 #include "ofxsInteract.h" 00042 #include "ofxsImageEffect.h" 00043 #include "ofxsLog.h" 00044 #include "ofxsMultiThread.h" 00045 00046 /** @brief Namespace private to the ofx support library. 00047 */ 00048 namespace OFX { 00049 00050 /** @brief turns a field string into and enum */ 00051 EField mapFieldStringToEnum( const std::string& str ); 00052 00053 /** @brief map a std::string to a context enum */ 00054 EContext mapContextStringToEnum( const std::string& s ); 00055 00056 //////////////////////////////////////////////////////////////////////////////// 00057 00058 namespace Private { 00059 /** @brief Pointer to the host */ 00060 extern OfxHost* gHost; 00061 00062 /** @brief Pointer to the effect suite */ 00063 extern OfxImageEffectSuiteV1* gEffectSuite; 00064 00065 /** @brief Pointer to the property suite */ 00066 extern OfxPropertySuiteV1* gPropSuite; 00067 00068 /** @brief Pointer to the interact suite */ 00069 extern OfxInteractSuiteV1* gInteractSuite; 00070 00071 /** @brief Pointer to the parameter suite */ 00072 extern OfxParameterSuiteV1* gParamSuite; 00073 00074 /** @brief Pointer to the general memory suite */ 00075 extern OfxMemorySuiteV1* gMemorySuite; 00076 00077 /** @brief Pointer to the threading suite */ 00078 extern OfxMultiThreadSuiteV1* gThreadSuite; 00079 00080 /** @brief Pointer to the message suite */ 00081 extern OfxMessageSuiteV1* gMessageSuite; 00082 00083 /** @brief Pointer to the optional progress suite */ 00084 extern OfxProgressSuiteV1* gProgressSuite; 00085 00086 /** @brief Pointer to the optional progress suite */ 00087 extern OfxTimeLineSuiteV1* gTimeLineSuite; 00088 00089 /** @brief Pointer to the parametric parameter suite */ 00090 extern OfxParametricParameterSuiteV1* gParametricParameterSuite; 00091 00092 /** @brief Pointer to the camera parameter suite (nuke ofx extension) */ 00093 extern NukeOfxCameraSuiteV1* gCameraParameterSuite; 00094 00095 /** @brief Support lib function called on an ofx load action */ 00096 void loadAction( void ); 00097 00098 /** @brief Support lib function called on an ofx unload action */ 00099 void unloadAction( void ); 00100 00101 /** @brief The plugin function that gets passed the host structure. 00102 */ 00103 void setHost( OfxHost* host ); 00104 00105 /** @brief fetches our pointer out of the props on the handle */ 00106 ImageEffect* retrieveImageEffectPointer( OfxImageEffectHandle handle ); 00107 00108 /** @brief fetch the prop set from the effect handle */ 00109 OFX::PropertySet fetchEffectProps( OfxImageEffectHandle handle ); 00110 00111 /** @brief the set of descriptors, one per context used by kOfxActionDescribeInContext, 'eContextNone' is the one used by the kOfxActionDescribe */ 00112 typedef std::map<EContext, ImageEffectDescriptor*> EffectContextMap; 00113 typedef std::map<std::string, EffectContextMap> EffectDescriptorMap; 00114 extern EffectDescriptorMap gEffectDescriptors; 00115 }; 00116 00117 /** @brief The validation code has its own namespace */ 00118 namespace Validation { 00119 00120 /** @brief This is uses to hold a property value, used by the property checking classes. 00121 * 00122 * Could have been a union, but std::string can't be in one. 00123 */ 00124 struct ValueHolder 00125 { 00126 std::string vString; 00127 int vInt; 00128 double vDouble; 00129 void* vPointer; 00130 00131 ValueHolder( void ) {} 00132 ValueHolder( char* s ) : vString( s ) {} 00133 ValueHolder( const std::string& s ) : vString( s ) {} 00134 ValueHolder( int i ) : vInt( i ) {} 00135 ValueHolder( double d ) : vDouble( d ) {} 00136 ValueHolder( void* p ) : vPointer( p ) {} 00137 00138 ValueHolder& operator =( char* v ) { vString = v; return *this; } 00139 ValueHolder& operator =( std::string v ) { vString = v; return *this; } 00140 ValueHolder& operator =( void* v ) { vPointer = v; return *this; } 00141 ValueHolder& operator =( int v ) { vInt = v; return *this; } 00142 ValueHolder& operator =( double v ) { vDouble = v; return *this; } 00143 00144 operator const char* () { return vString.c_str(); } 00145 operator std::string& () { return vString; } 00146 operator int& () { return vInt; } 00147 operator double& () { return vDouble; } 00148 operator void*& ( ) { return vPointer; } 00149 }; 00150 00151 /** @brief Enum used in the varargs list of the PropertyDescription constructor */ 00152 enum DescriptionTag 00153 { 00154 eDescDefault, /** @brief following values are the default to check against */ 00155 eDescFinished /** @brief we have finished the description */ 00156 }; 00157 00158 /** @brief class to describe properties, check their default and set their values */ 00159 class PropertyDescription 00160 { 00161 public: 00162 /** @brief name of the property */ 00163 std::string _name; 00164 00165 /** @brief Was it validated */ 00166 bool _exists; 00167 00168 /** @brief dimension of the property */ 00169 int _dimension; 00170 00171 /** @brief What type of property is it */ 00172 OFX::PropertyTypeEnum _ilk; 00173 00174 /** @brief The default value that this property should have. Empty implies no default (eg: a host name has no default). */ 00175 std::vector<ValueHolder> _defaultValue; 00176 00177 public: 00178 /** @brief var args constructor that is use to describe properties */ 00179 PropertyDescription( const char* name, OFX::PropertyTypeEnum ilk, int dimension, ... ); 00180 00181 /** @brief Die! Die! Die! */ 00182 virtual ~PropertyDescription( void ) {} 00183 00184 /** @brief See if the property exists in the containing property set and has the correct dimension */ 00185 void validate( bool checkDefaults, PropertySet& propSet ); 00186 }; 00187 00188 /** @brief Describes a set of properties */ 00189 class PropertySetDescription 00190 { 00191 protected: 00192 /** @brief name of the property set */ 00193 std::string _setName; 00194 00195 /** @brief the descriptions of each property */ 00196 std::vector<PropertyDescription*> _descriptions; 00197 00198 /** @brief The descriptions of each property */ 00199 std::vector<PropertyDescription*> _deleteThese; 00200 00201 public: 00202 /** @brief constructor. 00203 * 00204 * The varargs zero terminated are made from pairs of PropertyDescription * and ints indicating the number of properties pointed to. 00205 * These are to come from static arrays and need not be deleted 00206 */ 00207 PropertySetDescription( const char* setName, ... ); // [PropertyDescription *v, int nSetToThese] 00208 00209 /** @brief destructor */ 00210 virtual ~PropertySetDescription(); 00211 00212 /** @brief add another property in */ 00213 void addProperty( PropertyDescription* desc, bool deleteOnDestruction = true ); 00214 00215 /** @brief See if all properties exist and have the correct dimensions */ 00216 void validate( OFX::PropertySet& propSet, bool checkDefaults = true, bool logOrdinaryMessages = false ); 00217 }; 00218 00219 /** @brief Validates the host structure and property handle */ 00220 void validateHostProperties( OfxHost* host ); 00221 00222 /** @brief Validates the effect descriptor properties */ 00223 void validatePluginDescriptorProperties( PropertySet props ); 00224 00225 /** @brief Validates the effect instance properties */ 00226 void validatePluginInstanceProperties( PropertySet props ); 00227 00228 /** @brief validates a clip descriptor */ 00229 void validateClipDescriptorProperties( PropertySet props ); 00230 00231 /** @brief validates a clip instance */ 00232 void validateClipInstanceProperties( PropertySet props ); 00233 00234 /** @brief validates a clip descriptor */ 00235 void validateImageProperties( PropertySet props ); 00236 00237 /** @brief Validates action in/out arguments */ 00238 void validateActionArgumentsProperties( const std::string& action, PropertySet inArgs, PropertySet outArgs ); 00239 00240 /** @brief Validates parameter properties */ 00241 void validateParameterProperties( ParamTypeEnum paramType, 00242 OFX::PropertySet& paramProps, 00243 bool checkDefaults ); 00244 00245 /** @brief initialises the validation code, call this in on load */ 00246 void initialise( void ); 00247 }; 00248 00249 }; 00250 00251 #endif