Jamoma API  0.6.0.a19
Max/source/j.node/j.node.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup implementationMaxExternals
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
10  *
11  * @copyright © 2014 by Théo 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 
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 int C74_EXPORT main(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 wrapTTModularClassAsMaxClass(kTTSym_NodeInfo, "j.node", NULL, spec);
53 }
54 
55 
56 void WrapTTNodeInfoClass(WrappedClassPtr c)
57 {
58  class_addmethod(c->maxClass, (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  object_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  object_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  defer_low((t_object*)x, (method)node_subscribe, relativeAddress, argc, argv);
104 }
105 
106 void node_subscribe(TTPtr self, t_symbol* relativeAddress, long argc, t_atom* argv)
107 {
109  TTAddress returnedAddress;
110  TTNodePtr returnedNode = NULL;
111  TTNodePtr returnedContextNode = NULL;
112 
113  // for relative address
114  if (TTAddress(relativeAddress->s_name).getType() == kAddressRelative) {
115 
116  jamoma_subscriber_create((t_object*)x, x->wrappedObject, TTAddress(jamoma_parse_dieze((t_object*)x, relativeAddress)->s_name), x->subscriberObject, returnedAddress, &returnedNode, &returnedContextNode);
117  }
118  else
119  object_error((t_object*)x, "can't register because %s is not a relative address", relativeAddress->s_name);
120 }
121 
122 // Method for Assistance Messages
123 void node_assist(TTPtr self, TTPtr b, long msg, long arg, char *dst)
124 {
125  if (msg==1) // Inlet
126  strcpy(dst, "input");
127  else { // Outlets
128  switch(arg) {
129  case dump_out:
130  strcpy(dst, "dumpout");
131  break;
132  }
133  }
134 }
TTObject subscriberObject
The instance of a TTSubscriber object used to register the wrapped object in the tree structure...
TTErr wrapTTModularClassAsMaxClass(TTSymbol &ttblueClassName, const char *maxClassName, WrappedClassPtr *c, ModularSpec *specificities)
Wrap a Jamoma class as a Max class.
t_symbol JAMOMA_EXPORT * jamoma_parse_dieze(t_object *x, t_symbol *address)
Parse #N inside address and replace them by parent patcher arguments if there are.
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_assist(TTPtr self, TTPtr b, long msg, long arg, char *dst)
Provide assistance on input and output while patching.
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
TTObject wrappedObject
The instance of the Jamoma object we are wrapping.
Data Structure for this object.
TTAddressType getType()
Get the type.
Definition: TTAddress.h:136
Wraps Jamoma Core classes as objects for Max/MSP.
void node_subscribe(TTPtr self, t_symbol *relativeAddress, long argc, t_atom *argv)
Subscribe the j.node into the directory.
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...
int C74_EXPORT main(void)
Set up this class as a Max external the first time an object of this kind is instantiated.
WrappedModularInstance * WrappedModularInstancePtr
Pointer to a wrapped instance of our object.