Jamoma API  0.6.0.a19
PureData/source/j.node/j.node.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup implementationPdExternals
4  *
5  * @brief j.node : edit priority, tag and description for a node that doesn't refer to any parameter, message or return
6  *
7  * @details
8  *
9  * @authors Théo de la Hogue, Antoine Villeret
10  *
11  * @copyright © 2014 by Théo 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 
18 
19 #define dump_out 0
20 
21 // Definitions
22 void WrapTTNodeInfoClass(WrappedClassPtr c);
23 void WrappedNodeInfoClass_new(TTPtr self, long argc, t_atom* argv);
24 void WrappedNodeInfoClass_free(TTPtr self);
25 
26 
27 /** Provide assistance on input and output while patching.
28  @param self The node instance.
29  @param b
30  @param msg Determines if assistance is requested for an input or output.
31  @param arg Determines what input/output assistance is requested for.
32  @param dst Destination address that assistance string is copied to.
33  */
34 void node_assist(TTPtr self, TTPtr b, long msg, long arg, char *dst);
35 
36 /** Subscribe the j.node into the directory.
37  @param self The node instance.
38  @param relativeAddres where to subscribe the node relatively into the tree structure.
39  @param argc useless
40  @param argv useless
41  */
42 void node_subscribe(TTPtr self, t_symbol* relativeAddress, long argc, t_atom* argv);
43 
44 extern "C" void JAMOMA_EXPORT_MAXOBJ setup_j0x2enode(void)
45 {
46  ModularSpec *spec = new ModularSpec;
47  spec->_wrap = &WrapTTNodeInfoClass;
48  spec->_new = &WrappedNodeInfoClass_new;
49  spec->_free = NULL;
50  spec->_any = NULL;
51 
52  return (void)wrapTTModularClassAsPdClass(kTTSym_NodeInfo, "j.node", NULL, spec);
53 }
54 
55 
56 void WrapTTNodeInfoClass(WrappedClassPtr c)
57 {
58  eclass_addmethod(c->pdClass, (method)node_assist, "assist", A_CANT, 0L);
59 }
60 
61 
62 void WrappedNodeInfoClass_new(TTPtr self, long argc, t_atom* argv)
63 {
65  t_symbol *relativeAddress;
66  long attrstart = attr_args_offset(argc, argv); // support normal arguments
67 
68  // check address argument
69  relativeAddress = _sym_nothing;
70  if (attrstart && argv)
71  if (atom_gettype(argv) == A_SYM)
72  relativeAddress = atom_getsym(argv);
73 
74  if (relativeAddress == _sym_nothing) {
75  pd_error((t_object*)x, "needs a name as first argument");
76  return;
77  }
78 
79  // check for reserved address
80  if (relativeAddress == gensym("data/mute") ||
81  relativeAddress == gensym("data/bypass") ||
82  relativeAddress == gensym("data/freeze") ||
83  relativeAddress == gensym("data/preview") ||
84  relativeAddress == gensym("audio/mute") ||
85  relativeAddress == gensym("audio/bypass") ||
86  relativeAddress == gensym("audio/mix") ||
87  relativeAddress == gensym("audio/gain") ||
88  relativeAddress == gensym("model") ||
89  relativeAddress == gensym("preset") ) {
90 
91  pd_error((t_object*)x, "%s address is reserved by j.model", relativeAddress->s_name);
92  return;
93  }
94 
95  jamoma_node_info_create((t_object*)x, x->wrappedObject);
96 
97  if (argc && argv)
98  attr_args_process(x, argc, argv);
99 
100  // The following must be deferred because we have to interrogate our box,
101  // and our box is not yet valid until we have finished instantiating the object.
102  // Trying to use a loadbang method instead is also not fully successful (as of Max 5.0.6)
103  node_subscribe(x,relativeAddress, argc, argv);
104 // defer_low((t_object*)x, (method)node_subscribe, relativeAddress, argc, argv);
105 }
106 
107 void node_subscribe(TTPtr self, t_symbol* relativeAddress, long argc, t_atom* argv)
108 {
110  TTAddress returnedAddress;
111  TTNodePtr returnedNode = NULL;
112  TTNodePtr returnedContextNode = NULL;
113 
114  // for relative address
115  if (TTAddress(relativeAddress->s_name).getType() == kAddressRelative) {
116 
117  if(!jamoma_subscriber_create((t_eobj*)x, x->wrappedObject, TTAddress(relativeAddress->s_name), x->subscriberObject, returnedAddress, &returnedNode, &returnedContextNode))
118  pd_error((t_object*)x, "error when registering %s", relativeAddress->s_name);
119  }
120  else
121  pd_error((t_object*)x, "can't register because %s is not a relative address", relativeAddress->s_name);
122 }
123 
124 // Method for Assistance Messages
125 void node_assist(TTPtr self, TTPtr b, long msg, long arg, char *dst)
126 {
127  if (msg==1) // Inlet
128  strcpy(dst, "input");
129  else { // Outlets
130  switch(arg) {
131  case dump_out:
132  strcpy(dst, "dumpout");
133  break;
134  }
135  }
136 }
TTObject subscriberObject
The instance of a TTSubscriber object used to register the wrapped object in the tree structure...
We build a directory of TTNodes, and you can request a pointer for any TTNode, or add an observer to ...
Definition: TTNode.h:59
The TTAddress class is used to represent a string and efficiently pass and compare that string...
Definition: TTAddress.h:29
TTErr JAMOMA_EXPORT jamoma_node_info_create(t_object *x, TTObject &returnedNodeInfo)
Create a TTNodeInfo object.
this flag means that an address have no leading slash
Definition: TTAddressBase.h:64
void node_subscribe(TTPtr self, t_symbol *relativeAddress, long argc, t_atom *argv)
Subscribe the j.node into the directory.
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
void node_assist(TTPtr self, TTPtr b, long msg, long arg, char *dst)
Provide assistance on input and output while patching.
TTObject wrappedObject
The instance of the Jamoma object we are wrapping.
Wraps Jamoma Core classes as objects for PureData.
Data Structure for this object.
TTAddressType getType()
Get the type.
Definition: TTAddress.h:136
TTErr JAMOMA_EXPORT jamoma_subscriber_create(t_object *x, TTObject &anObject, TTAddress relativeAddress, TTObject &returnedSubscriber, TTSymbol &returnedAddress, TTNodePtr *returnedNode, TTNodePtr *returnedContextNode)
Create a #TTSubscriber object and register a TTObject into the tree or, if aTTObject is NULL...
WrappedModularInstance * WrappedModularInstancePtr
Pointer to a wrapped instance of our object.
TTErr wrapTTModularClassAsPdClass(TTSymbol &ttblueClassName, const char *pdClassName, WrappedClassPtr *c, ModularSpec *specificities)
Wrap a Jamoma class as a Pd class.