Jamoma API  0.6.0.a19
TTModularClassWrapperMax.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup implementationMax
4  *
5  * @brief Wraps Jamoma Core classes as objects for Max/MSP
6  *
7  * @details
8  *
9  * @authors Timothy Place, Theo de la Hogue, Trond Lossius
10  *
11  * @copyright © 2010-13 by Timothy Place, Theo de la Hogue @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 
17 #ifndef __TT_MODULAR_CLASS_WRAPPER_MAX_H__
18 #define __TT_MODULAR_CLASS_WRAPPER_MAX_H__
19 
20 #include "ext.h" // Max Header
21 #include "ext_obex.h" // Max Object Extensions (attributes) Header
22 #include "ext_user.h"
23 #include "ext_common.h"
24 #include "ext_hashtab.h"
25 
26 #ifdef UI_EXTERNAL
27 #include "jpatcher_api.h" // jpatcher_api.h must come before z_dsp.h
28 #include "jgraphics.h"
29 #endif
30 
31 #include "TTClassWrapperMax.h"
32 
33 #include "TTModular.h" // Jamoma Modular API
34 #include "JamomaForMax.h" // Jamoma for Max
35 #include "TTInputAudio.h"
36 #include "TTOutputAudio.h"
37 
38 #ifdef AUDIO_GRAPH_EXTERNAL
39 #include "TTAudioGraphAPI.h" // Definitions for Jamoma AudioGraph
40 #endif
41 
42 
43 #define selectedObject getSelectedObject(x)
44 #define selectedAddress x->cursor
45 
46 #define MAX_ARRAY_SIZE 256
47 
48 
49 /** Definition for specific TT class things. TODO: This description is non-informative.
50  @param c
51  @ingroup typedefs
52 */
53 typedef void (*Spec_WrapTTModularClass)(WrappedClassPtr c);
54 
55 
56 /** Wrapper for the new method, called when a new obejct is being instantiated.
57  @param self This object
58  @param argc t_atomarray count (length) for the array of arguments
59  @param argv Pointer to the atom array of arguments
60  @ingroup typedefs
61 */
62 typedef void (*Spec_WrappedClass_new)(TTPtr self, long argc, t_atom *argv);
63 
64 
65 /** Wrapper for the 'free' method, called when an object is being freed.
66  @details Free up memory, ensure that any events scheduled in the future are terminated, etc.
67  @param self This object
68  @ingroup typedefs
69 */
70 typedef void (*Spec_WrappedClass_free)(TTPtr self);
71 
72 
73 /** Wrapper for the method called in response to 'anything' messages.
74  @details This wrapped method catches all messages to the object that have not been declared on and associated with their own specific methods.
75  @param self This object
76  @param msg Message passed to this object
77  @param argc t_atomarray count (length) for the array of arguments
78  @param argv Pointer to the atom array of arguments
79 */
80 typedef void (*Spec_WrappedClass_anything)(TTPtr self, t_symbol *msg, long argc, t_atom *argv);
81 
82 
83 /** Wrapper for a method called when the object receives notifications.
84  @details Examples of notifications are messages sent to the node, or notifications about changes to the patcher context, e.g., that the containing patch is being deleted.
85  @param self This object
86  @param s TODO: What is this?
87  @param msg The notification message
88  @param sender Pointer to the notifier
89  @param data Additional data provided as arguments to the notification
90 */
91 typedef t_max_err (*Spec_WrappedClass_notify)(TTPtr self, t_symbol *s, t_symbol *msg, void *sender, void *data);
92 
93 
94 /**
95 */
96 typedef struct _modularSpecificities {
97 
102  Spec_WrappedClass_notify _notify;
103 
104 } ModularSpec;
105 
106 
107 /** Data Structure for this object
108 */
109 typedef struct _wrappedModularInstance {
110 #ifdef AUDIO_EXTERNAL
111  t_pxobject obj; ///< Max msp object header
112 #else
113 #ifdef UI_EXTERNAL
114  t_jbox box; ///< Max ui object header
115 #else
116  t_object obj; ///< Max control object header
117 #endif
118 #endif
119  TTHandle inlets; ///< an array of inlets
120  long index; ///< index of the inlet used
121  TTHandle outlets; ///< an array of outlet
122  t_symbol *msg;
123  long argc;
124  t_atom *argv;
125 
126  WrappedClassPtr wrappedClassDefinition; ///< A pointer to the class definition
127 
128 #ifndef ARRAY_EXTERNAL
129  TTObject wrappedObject; ///< The instance of the Jamoma object we are wrapping
130  TTObject subscriberObject; ///< The instance of a TTSubscriber object used to
131  ///< register the wrapped object in the tree structure
132 #endif
133 
134  TTBoolean useInternals; ///< The hash table can be used as an array of wrappedObject
135  TTHashPtr internals; ///< An hash table to store any internal TTObjectBases (like TTData, TTViewer, ...)
136  TTBoolean iterateInternals; ///< The flag is true when an iteration is done on the internals
137  TTSymbol cursor; ///< to select an entry in x->internals
138 
139  TTAddress address; ///< sometime external needs to store an address (e.g. send, receive, view, ...)
140 
141  t_object *patcherPtr; ///< the patcher in which the external is (ignoring subpatcher)
142  TTSymbol patcherContext; ///< the patcher context in which the external is (model, view)
143  TTSymbol patcherClass; ///< the patcher class in which the external is
144  TTSymbol patcherName; ///< the patcher name in which the external is
145  TTAddress patcherAddress; ///< the patcher address in which the external is
146 
147 #ifdef ARRAY_EXTERNAL
148  TTUInt32 arraySize; // the size of the array size for iteration
149  TTUInt32 arrayIndex; // the index number for array selection
150  TTAddress arrayAddress; // keep the address in memory to filter repetitions
151  TTValue arrayArgs; // keep attributes argument of the external for dynamic creation
152 
153  TTString arrayFormatInteger; ///< a format string to edit numeric instance
154  TTString arrayFormatString; ///< a format string to edit string instance
155 
156  t_symbol *arrayAttrFormat; // Is it 'single' format output or 'array' format output
157 #endif
158 
159  void *extra; ///< used to keep very specific things
160 
162 
163 typedef WrappedModularInstance* WrappedModularInstancePtr; ///< Pointer to a wrapped instance of our object.
164 
165 
166 
167 // FUNCTIONS
168 
169 
170 /** tools to copy msg, argc and argv into the member msg, argc and argv of the WrappedModularInstance
171 */
172 void copy_msg_argc_argv(TTPtr self, t_symbol *msg, long argc, const t_atom *argv);
173 
174 // Use internals to store several objects :
175 
176 /**
177  */
178 TTErr makeInternals_data(TTPtr self, TTAddress address, TTSymbol name, t_symbol *callbackMethod, TTPtr context, TTSymbol service, TTObject& returnedData, TTBoolean deferlow = NO);
179 TTErr makeInternals_explorer(TTPtr self, TTSymbol name, t_symbol *callbackMethod, TTObject& returnedExplorer, TTBoolean deferlow = NO);
180 
181 
182 /**
183  */
184 TTErr makeInternals_viewer(TTPtr self, TTAddress address, TTSymbol name, t_symbol *callbackMethod, TTObject& returnedViewer, TTBoolean deferlow = NO);
185 
186 
187 /**
188  */
189 TTErr makeInternals_receiver(TTPtr self, TTAddress address, TTSymbol name, t_symbol *callbackMethod, TTObject& returnedReceiver, TTBoolean deferlow = NO, TTBoolean appendNameAsAttribute = NO);
190 
191 /**
192  */
193 TTErr makeInternals_sender(TTPtr self, TTAddress address, TTSymbol name, TTObject& returnedSender, TTBoolean appendNameAsAttribute = NO);
194 
195 /**
196  */
197 TTErr removeInternals_data(TTPtr self, TTAddress address, TTSymbol name);
198 
199 
200 /** In case internals table is used as an array of wrappedObject here is a method usefull to get the selected object in both case (use wrappedObject or use internals)
201 */
203 
204 
205 /** Wrap a Jamoma class as a Max class.
206 */
207 TTErr wrapTTModularClassAsMaxClass(TTSymbol& ttblueClassName, const char* maxClassName, WrappedClassPtr* c, ModularSpec* specificities);
208 
209 
210 /** Wrapped methods ('self' has to be TTPtr because different wrappers (such as the ui wrapper) have different implementations)
211  @param name Message passed to this object
212  @param argc t_atomarray count (length)
213  @param argv Pointer to the atom array
214 */
215 t_object *wrappedModularClass_new(t_symbol *name, long argc, t_atom *argv);
216 
217 
218 /**
219 */
220 void wrappedModularClass_unregister(WrappedModularInstancePtr x);
221 
222 
223 /**
224 */
225 void wrappedModularClass_free(WrappedModularInstancePtr x);
226 
227 
228 /**
229 */
230 t_max_err wrappedModularClass_notify(TTPtr self, t_symbol *s, t_symbol *msg, void *sender, void *data);
231 
232 
233 /**
234 */
235 void wrappedModularClass_shareContextNode(TTPtr self, TTNodePtr *contextNode);
236 
237 
238 /**
239  @param self This object
240  @param s Message passed to this object
241  @param argc t_atomarray count (length)
242  @param argv Pointer to the atom array
243 */
244 t_max_err wrappedModularClass_attrGet(TTPtr self, t_object *attr, long* argc, t_atom** argv);
245 
246 
247 /**
248  @param self This object
249  @param s Message passed to this object
250  @param argc t_atomarray count (length)
251  @param argv Pointer to the atom array
252 */
253 t_max_err wrappedModularClass_attrSet(TTPtr self, t_object *attr, long argc, const t_atom *argv);
254 
255 
256 /** This method handles "anything" messages to the Max object that wraps the #TTModularClass.
257  @param self This object
258  @param s Message passed to this object
259  @param argc Number of arguments for the message.
260  @param argv The arguments of the message as a pointer to an atom array
261 */
262 void wrappedModularClass_anything(TTPtr self, t_symbol *s, long argc, t_atom *argv);
263 
264 
265 /**
266  @param self This object
267  @param s Message passed to this object
268  @param argc t_atomarray count (length)
269  @param argv Pointer to the atom array
270 */
271 TTErr wrappedModularClass_sendMessage(TTPtr self, t_symbol *s, long argc, const t_atom *argv);
272 
273 
274 /**
275  @param self This object
276  @param s Message passed to this object
277  @param argc t_atomarray count (length)
278  @param argv Pointer to the atom array
279 */
280 TTErr wrappedModularClass_setAttribute(TTPtr self, t_symbol *s, long argc, const t_atom *argv);
281 
282 
283 /**
284 */
285 void wrappedModularClass_dump(TTPtr self);
286 
287 
288 #ifdef UI_EXTERNAL
289 void wrappedModularClass_paint(WrappedModularInstancePtr x, t_object *view);
290 
291 
292 /**
293 */
294 TTPtr wrappedModularClass_oksize(TTPtr self, t_rect *newrect);
295 
296 
297 /**
298 */
299 void wrappedModularClass_mousedblclick(TTPtr self, t_object *patcherview, t_pt pt, long modifiers);
300 
301 
302 /**
303 */
304 void wrappedModularClass_mousedown(TTPtr self, t_object *patcherview, t_pt pt, long modifiers);
305 
306 
307 /**
308 */
309 void wrappedModularClass_mousedrag(TTPtr self, t_object *patcherview, t_pt pt, long modifiers);
310 
311 
312 /**
313 */
314 void wrappedModularClass_mouseup(TTPtr self, t_object *patcherview, t_pt pt, long modifiers);
315 
316 
317 /**
318 */
319 void wrappedModularClass_mouseenter(TTPtr self, t_object *patcherview, t_pt pt, long modifiers);
320 
321 
322 /**
323 */
324 void wrappedModularClass_mousemove(TTPtr self, t_object *patcherview, t_pt pt, long modifiers);
325 
326 
327 /**
328 */
329 void wrappedModularClass_mouseleave(TTPtr self, t_object *patcherview, t_pt pt, long modifiers);
330 
331 
332 /**
333 */
334 int convertModifiersFromMaxToTTGraphics(int maxModifiers);
335 #endif
336 
337 
338 #ifdef ARRAY_EXTERNAL
339 /**
340  @param attr The name of the attribute to get
341  @param s Message passed to this object
342  @param argc t_atomarray count (length)
343  @param argv Pointer to the atom array
344 */
345 t_max_err wrappedModularClass_FormatGet(TTPtr self, TTPtr attr, long *ac, t_atom **av);
346 
347 
348 /**
349  @param self This object
350  @param attr The name of the attribute to set
351  @param argc t_atomarray count (length)
352  @param argv Pointer to the atom array
353 */
354 t_max_err wrappedModularClass_FormatSet(TTPtr self, TTPtr attr, long ac, const t_atom *av);
355 
356 
357 /**
358  @param self This object
359  @param msg Message passed to this object
360  @param argc t_atomarray count (length)
361  @param argv Pointer to the atom array
362 */
363 void wrappedModularClass_ArraySelect(TTPtr self, t_symbol *msg, long ac, const t_atom *av);
364 
365 
366 /**
367 */
368 void wrappedModularClass_ArrayResize(TTPtr self, long newSize);
369 #endif
370 
371 #endif // __TT_MODULAR_CLASS_WRAPPER_MAX_H__
TTObject subscriberObject
The instance of a TTSubscriber object used to register the wrapped object in the tree structure...
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
TTHandle outlets
an array of outlet
TTErr wrapTTModularClassAsMaxClass(TTSymbol &ttblueClassName, const char *maxClassName, WrappedClassPtr *c, ModularSpec *specificities)
Wrap a Jamoma class as a Max class.
We build a directory of TTNodes, and you can request a pointer for any TTNode, or add an observer to ...
Definition: TTNode.h:59
TTAddress address
sometime external needs to store an address (e.g. send, receive, view, ...)
Provides all necessary definitions for AudioGraph API.
TTSymbol patcherClass
the patcher class in which the external is
The TTAddress class is used to represent a string and efficiently pass and compare that string...
Definition: TTAddress.h:29
Create and use Jamoma object instances.
Definition: TTObject.h:29
void * extra
used to keep very specific things
t_object * patcherPtr
the patcher in which the external is (ignoring subpatcher)
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
TTHashPtr internals
An hash table to store any internal TTObjectBases (like TTData, TTViewer, ...)
void(* Spec_WrappedClass_anything)(TTPtr self, t_symbol *msg, long argc, t_atom *argv)
Wrapper for the method called in response to 'anything' messages.
TTErr wrappedModularClass_sendMessage(TTPtr self, t_symbol *s, long argc, const t_atom *argv)
Maintain a collection of TTValue objects indexed by TTSymbol pointers.
Definition: TTHash.h:36
t_max_err wrappedModularClass_attrSet(TTPtr self, t_object *attr, long argc, const t_atom *argv)
t_max_err wrappedModularClass_attrGet(TTPtr self, t_object *attr, long *argc, t_atom **argv)
t_max_err(* Spec_WrappedClass_notify)(TTPtr self, t_symbol *s, t_symbol *msg, void *sender, void *data)
Wrapper for a method called when the object receives notifications.
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
WrappedClassPtr wrappedClassDefinition
A pointer to the class definition.
An audio output component for Jamoma models.
t_object obj
Max control object header.
void copy_msg_argc_argv(TTPtr self, t_symbol *msg, long argc, const t_atom *argv)
tools to copy msg, argc and argv into the member msg, argc and argv of the WrappedModularInstance ...
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTHandle inlets
an array of inlets
TTAddress patcherAddress
the patcher address in which the external is
Various utilities for interfacing with Max that are not specific to JamomaModular as such...
TTBoolean iterateInternals
The flag is true when an iteration is done on the internals.
TTObject wrappedObject
The instance of the Jamoma object we are wrapping.
void wrappedModularClass_anything(TTPtr self, t_symbol *s, long argc, t_atom *argv)
This method handles "anything" messages to the Max object that wraps the #TTModularClass.
void(* Spec_WrapTTModularClass)(WrappedClassPtr c)
Definition for specific TT class things.
Data Structure for this object.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
void(* Spec_WrappedClass_new)(TTPtr self, long argc, t_atom *argv)
Wrapper for the new method, called when a new obejct is being instantiated.
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
TTSymbol patcherContext
the patcher context in which the external is (model, view)
TTBoolean useInternals
The hash table can be used as an array of wrappedObject.
An audio input component for Jamoma models.
TTSymbol patcherName
the patcher name in which the external is
TTErr wrappedModularClass_setAttribute(TTPtr self, t_symbol *s, long argc, const t_atom *argv)
The TTString class is used to represent a string.
Definition: TTString.h:34
long index
index of the inlet used
TTSymbol cursor
to select an entry in x->internals
t_object * wrappedModularClass_new(t_symbol *name, long argc, t_atom *argv)
Wrapped methods ('self' has to be TTPtr because different wrappers (such as the ui wrapper) have diff...
the Modular Application Programming Interface
void(* Spec_WrappedClass_free)(TTPtr self)
Wrapper for the 'free' method, called when an object is being freed.
WrappedModularInstance * WrappedModularInstancePtr
Pointer to a wrapped instance of our object.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTObjectBasePtr getSelectedObject(WrappedModularInstancePtr x)
In case internals table is used as an array of wrappedObject here is a method usefull to get the sele...