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