Jamoma API  0.6.0.a19
TTClassWrapperMax.h
1 /*
2  * TTClassWrapperMax
3  * An automated class wrapper to make Jamoma object's available as objects for Max/MSP
4  * Copyright © 2008 by Timothy Place
5  *
6  * License: This code is licensed under the terms of the "New BSD License"
7  * http://creativecommons.org/licenses/BSD/
8  */
9 
10 #ifndef __TT_CLASS_WRAPPER_MAX_H__
11 #define __TT_CLASS_WRAPPER_MAX_H__
12 
13 #include "ext.h" // Max Header
14 #include "z_dsp.h" // MSP Header
15 #include "ext_strings.h" // String Functions
16 #include "commonsyms.h" // Common symbols used by the Max 4.5 API
17 #include "ext_obex.h" // Max Object Extensions (attributes) Header
18 #include "TTFoundationAPI.h" // Jamoma Foundation API
19 #include "TTDSP.h" // Jamoma DSP API
20 
21 // TYPE DEFINITIONS
22 
23 typedef TTErr (*TTValidityCheckFunction)(const TTPtr data); ///< A type that can be used to store a pointer to a validity checking function.
24 
25 
26 #ifndef SELF
27 #define SELF ((t_object*)self)
28 #endif
29 
30 
31 class WrappedClassOptions;
32 
33 typedef struct _wrappedClass {
34  t_class* maxClass; ///< The Max class pointer.
35  t_symbol* maxClassName; ///< The name to give the Max class.
36  TTSymbol ttblueClassName; ///< The name of the class as registered with the TTBlue framework.
37  TTValidityCheckFunction validityCheck; ///< A function to call to validate the context for an object before it is instantiated.
38  TTPtr validityCheckArgument; ///< An argument to pass to the validityCheck function when it is called.
39  WrappedClassOptions* options; ///< Additional configuration options specified for the class.
40  t_hashtab* maxNamesToTTNames; ///< names may not be direct mappings, as we downcase the first letter.
41 
42  void* specificities; ///< anything needed to deal with somes specificities of the class...
43 } WrappedClass;
44 
45 
46 
47 class WrappedClassOptions {
48 protected:
49  TTHash* options;
50 
51 public:
52  WrappedClassOptions()
53  {
54  options = new TTHash;
55  }
56 
57  virtual ~WrappedClassOptions()
58  {
59  delete options;
60  }
61 
62  TTErr append(const TTSymbol& optionName, const TTValue& optionValue)
63  {
64  return options->append(optionName, optionValue);
65  }
66 
67  /** Returns an error if the requested option doesn't exist. */
68  TTErr lookup(const TTSymbol& optionName, TTValue& optionValue)
69  {
70  return options->lookup(optionName, optionValue);
71  }
72 
73 };
74 
75 
76 typedef WrappedClass* WrappedClassPtr; ///< A pointer to a WrappedClass.
77 typedef WrappedClassOptions* WrappedClassOptionsPtr; ///< A pointer to WrappedClassOptions.
78 
79 
80 
81 
82 // Data Structure for this object
83 typedef struct _wrappedInstance {
84  t_pxobject obj; ///< Max audio object header
85  WrappedClassPtr wrappedClassDefinition; ///< A pointer to the class definition
86  TTAudioObject* wrappedObject; ///< The instance of the TTBlue object we are wrapping
87  TTAudio* audioIn; ///< Audio input signal
88  TTAudio* audioOut; ///< Audio output signal
89  TTUInt16 vs;
90  TTUInt16 maxNumChannels; ///< The number of channels for which this object is initialized to operate upon
91  TTUInt16 numChannels; ///< The actual number of channels in use
92  TTUInt16 numInputs;
93  TTUInt16 numOutputs;
94  TTUInt16 numControlSignals; ///< What number, a subset of numInputs, of signals are for controlling attributes?
95  TTSymbol* controlSignalNames; ///< An array of attribute names for the control signals.
96 
97  TTPtr controlOutlet; ///< for output from a notification
98  TTObject* controlCallback; ///< for output from a notification
99 
100  t_bool signals_connected[256]; ///< which inlets and outlets are actually connected to audio signals
101 } WrappedInstance;
102 
103 typedef WrappedInstance* WrappedInstancePtr; ///< Pointer to a wrapped instance of our object.
104 
105 
106 
107 
108 
109 // FUNCTIONS
110 
111 
112 // private:
113 // self has to be TTPtr because different wrappers (such as the ui wrapper) have different implementations.
114 t_max_err wrappedClass_attrGet(TTPtr self, t_object* attr, long* argc, t_atom** argv);
115 t_max_err wrappedClass_attrSet(TTPtr self, t_object* attr, long argc, t_atom* argv);
116 void wrappedClass_anything(TTPtr self, t_symbol* s, long argc, t_atom* argv);
117 void wrappedClass_assist(WrappedInstancePtr self, void *b, long msg, long arg, char *dst);
118 
119 
120 
121 
122 // public:
123 
124 // Wrap a Jamoma class as a Max class.
125 TTErr wrapTTClassAsMaxClass(TTSymbol ttblueClassName, const char* maxClassName, WrappedClassPtr* c);
126 
127 // This version can be passed a method that is called to make sure it is legit to instantiate the class.
128 TTErr wrapTTClassAsMaxClass(TTSymbol ttblueClassName, const char* maxClassName, WrappedClassPtr* c, TTValidityCheckFunction validityCheck);
129 
130 // This version can be passed a method that is called to make sure it is legit to instantiate the class.
131 TTErr wrapTTClassAsMaxClass(TTSymbol ttblueClassName, const char* maxClassName, WrappedClassPtr* c, TTValidityCheckFunction validityCheck, TTPtr validityCheckArgument);
132 
133 
134 // These are versions of the above, but for which additional options can be specified.
135 TTErr wrapTTClassAsMaxClass(TTSymbol ttblueClassName, const char* maxClassName, WrappedClassPtr* c, WrappedClassOptionsPtr options);
136 TTErr wrapTTClassAsMaxClass(TTSymbol ttblueClassName, const char* maxClassName, WrappedClassPtr* c, TTValidityCheckFunction validityCheck, WrappedClassOptionsPtr options);
137 TTErr wrapTTClassAsMaxClass(TTSymbol ttblueClassName, const char* maxClassName, WrappedClassPtr* c, TTValidityCheckFunction validityCheck, TTPtr validityCheckArgument, WrappedClassOptionsPtr options);
138 
139 TTErr TTValueFromAtoms(TTValue& v, long ac, t_atom* av);
140 TTErr TTAtomsFromValue(const TTValue& v, long* ac, t_atom** av); // NOTE: allocates memory
141 
142 long TTMatrixReferenceJitterMatrix(TTMatrix aMatrix, TTPtr aJitterMatrix, TTBoolean copy = true);
143 TTErr TTMatrixCopyDataFromJitterMatrix(TTMatrix aMatrix, TTPtr aJitterMatrix);
144 TTErr TTMatrixCopyDataToJitterMatrix(TTMatrix aMatrix, TTPtr aJitterMatrix);
145 
146 #endif // __TT_CLASS_WRAPPER_MAX_H__
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
TTErr lookup(const TTSymbol key, TTValue &value)
Find the value for the given key.
Definition: TTHash.cpp:76
Create and use Jamoma object instances.
Definition: TTObject.h:29
Wrap audio objects for convenience.
Jamoma DSP Library.
Maintain a collection of TTValue objects indexed by TTSymbol pointers.
Definition: TTHash.h:36
WrappedInstance * WrappedInstancePtr
Pointer to a wrapped instance of our object.
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
TTErr(* TTValidityCheckFunction)(const TTPtr data)
A type that can be used to store a pointer to a validity checking function.
Definition: MaxAudioGraph.h:36
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTErr append(const TTSymbol key, const TTValue &value)
Insert an item into the hash table.
Definition: TTHash.cpp:70
Wrap TTMatrixBase instances.
Definition: TTMatrix.h:27
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
Wrap TTAudioSignal instances for convenience.
Definition: TTAudioObject.h:25