Jamoma API  0.6.0.a19
TTClassWrapperPd.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  * COpyright 2014 by Antoine Villeret
6  *
7  * License: This code is licensed under the terms of the "New BSD License"
8  * http://creativecommons.org/licenses/BSD/
9  */
10 
11 #ifndef __TT_CLASS_WRAPPER_MAX_H__
12 #define __TT_CLASS_WRAPPER_MAX_H__
13 
14 #include "JamomaForPd.h"
15 #include "TTFoundationAPI.h" // Jamoma Foundation API
16 #include "TTDSP.h" // Jamoma DSP API
17 #include <map>
18 
19 #ifndef t_max_err
20 #define t_max_err t_int
21 #endif
22 
23 #define JAMOMA_ATTR_MAX 256
24 
25 // TYPE DEFINITIONS
26 
27 typedef TTErr (*TTValidityCheckFunction)(const TTPtr data); ///< A type that can be used to store a pointer to a validity checking function.
28 
29 
30 #ifndef SELF
31 #define SELF ((t_object*)self)
32 #endif
33 
34 
35 class WrappedClassOptions;
36 
37 typedef struct _wrappedClass {
38  t_eclass* pdClass; ///< The Pd class pointer.
39  t_symbol* pdClassName; ///< The name to give the Pd class.
40  TTSymbol ttblueClassName; ///< The name of the class as registered with the TTBlue framework.
41  TTValidityCheckFunction validityCheck; ///< A function to call to validate the context for an object before it is instantiated.
42  TTPtr validityCheckArgument; ///< An argument to pass to the validityCheck function when it is called.
43  WrappedClassOptions* options; ///< Additional configuration options specified for the class.
44  //std::map<std::string,std::string>* pdNamesToTTNames; ///< names may not be direct mappings, as we downcase the first letter.
45  std::map<std::string,TTPtr> pdNamesToTTNames; ///< names may not be direct mappings, as we downcase the first letter.
46 
47  void* specificities; ///< anything needed to deal with somes specificities of the class...
48 } WrappedClass;
49 
50 
51 
52 class WrappedClassOptions {
53 protected:
54  TTHash* options;
55 
56 public:
57  WrappedClassOptions()
58  {
59  options = new TTHash;
60  }
61 
62  virtual ~WrappedClassOptions()
63  {
64  delete options;
65  }
66 
67  TTErr append(const TTSymbol& optionName, const TTValue& optionValue)
68  {
69  return options->append(optionName, optionValue);
70  }
71 
72  /** Returns an error if the requested option doesn't exist. */
73  TTErr lookup(const TTSymbol& optionName, TTValue& optionValue)
74  {
75  return options->lookup(optionName, optionValue);
76  }
77 
78 };
79 
80 
81 typedef WrappedClass* WrappedClassPtr; ///< A pointer to a WrappedClass.
82 typedef WrappedClassOptions* WrappedClassOptionsPtr; ///< A pointer to WrappedClassOptions.
83 
84 
85 
86 
87 // Data Structure for this object
88 typedef struct _wrappedInstance {
89  t_eobj obj; ///< Pd audio object header is the same as non-audio header
90  WrappedClassPtr wrappedClassDefinition; ///< A pointer to the class definition
91  TTAudioObject* wrappedObject; ///< The instance of the TTBlue object we are wrapping
92  TTAudio* audioIn; ///< Audio input signal
93  TTAudio* audioOut; ///< Audio output signal
94  TTUInt16 vs;
95  TTUInt16 maxNumChannels; ///< The number of channels for which this object is initialized to operate upon
96  TTUInt16 numChannels; ///< The actual number of channels in use
97  TTUInt16 numInputs;
98  TTUInt16 numOutputs;
99  TTUInt16 numControlSignals; ///< What number, a subset of numInputs, of signals are for controlling attributes?
100  TTSymbol* controlSignalNames; ///< An array of attribute names for the control signals.
101 
102  TTPtr controlOutlet; ///< for output from a notification
103  TTObject* controlCallback; ///< for output from a notification
104 
105  bool signals_connected[256]; ///< which inlets and outlets are actually connected to audio signals
106  t_outlet* dumpOut; ///< Dump output for attributes
107  t_inlet** inlets; ///< Array of inlets
108  t_outlet** outlets; ///< Array of outlets
109 } WrappedInstance;
110 
111 typedef WrappedInstance* WrappedInstancePtr; ///< Pointer to a wrapped instance of our object.
112 
113 
114 
115 
116 
117 // FUNCTIONS
118 
119 
120 // private:
121 // self has to be TTPtr because different wrappers (such as the ui wrapper) have different implementations.
122 t_max_err wrappedClass_attrGet(TTPtr self, t_object* attr, long* argc, t_atom** argv);
123 t_max_err wrappedClass_attrSet(TTPtr self, t_object* attr, long argc, t_atom* argv);
124 void wrappedClass_anything(TTPtr self, t_symbol* s, long argc, t_atom* argv);
125 void wrappedClass_assist(WrappedInstancePtr self, void *b, long msg, long arg, char *dst);
126 
127 
128 
129 
130 // public:
131 
132 // Wrap a Jamoma class as a Pd class.
133 TTErr wrapTTClassAsPdClass(TTSymbol ttblueClassName, const char* pdClassName, WrappedClassPtr* c);
134 
135 // This version can be passed a method that is called to make sure it is legit to instantiate the class.
136 TTErr wrapTTClassAsPdClass(TTSymbol ttblueClassName, const char* pdClassName, WrappedClassPtr* c, TTValidityCheckFunction validityCheck);
137 
138 // This version can be passed a method that is called to make sure it is legit to instantiate the class.
139 TTErr wrapTTClassAsPdClass(TTSymbol ttblueClassName, const char* pdClassName, WrappedClassPtr* c, TTValidityCheckFunction validityCheck, TTPtr validityCheckArgument);
140 
141 
142 // These are versions of the above, but for which additional options can be specified.
143 TTErr wrapTTClassAsPdClass(TTSymbol ttblueClassName, const char* pdClassName, WrappedClassPtr* c, WrappedClassOptionsPtr options);
144 TTErr wrapTTClassAsPdClass(TTSymbol ttblueClassName, const char* pdClassName, WrappedClassPtr* c, TTValidityCheckFunction validityCheck, WrappedClassOptionsPtr options);
145 TTErr wrapTTClassAsPdClass(TTSymbol ttblueClassName, const char* pdClassName, WrappedClassPtr* c, TTValidityCheckFunction validityCheck, TTPtr validityCheckArgument, WrappedClassOptionsPtr options);
146 
147 TTErr TTValueFromAtoms(TTValue& v, long ac, t_atom* av);
148 TTErr TTAtomsFromValue(const TTValue& v, long* ac, t_atom** av); // NOTE: allocates memory
149 
150 long TTMatrixReferenceJitterMatrix(TTMatrix aMatrix, TTPtr aJitterMatrix, TTBoolean copy = true);
151 TTErr TTMatrixCopyDataFromJitterMatrix(TTMatrix aMatrix, TTPtr aJitterMatrix);
152 TTErr TTMatrixCopyDataToJitterMatrix(TTMatrix aMatrix, TTPtr aJitterMatrix);
153 
154 #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
Various utilities for interfacing with Pd that are not specific to JamomaModular as such...
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