Jamoma API  0.6.0.a19
j.append.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup implementationMaxExternalsGraph
4  *
5  * @brief j.append# - External object for Max to append keys to a dictionary being passed in a Jamoma Graph
6  *
7  * @details
8  *
9  * @authors Timothy Place
10  *
11  * @copyright © 2010 by Timothy Place @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 #include "maxGraph.h"
18 
19 
20 // Data Structure for this object
21 struct Append {
22  t_object obj;
23  TTGraphObjectBasePtr graphObject;
24  TTPtr graphOutlets[16]; // this _must_ be third (for the setup call)
25  t_symbol* attrKey;
26  t_symbol* attrValue;
27 };
28 typedef Append* AppendPtr;
29 
30 
31 // Prototypes for methods
32 AppendPtr AppendNew (t_symbol* msg, long argc, t_atom* argv);
33 void AppendFree (AppendPtr self);
34 void AppendAssist (AppendPtr self, void* b, long msg, long arg, char* dst);
35 t_max_err AppendSetKey (AppendPtr self, void* attr, long argc, t_atom* argv);
36 t_max_err AppendSetValue (AppendPtr self, void* attr, long argc, t_atom* argv);
37 
38 
39 // Globals
40 static t_class* sAppendClass;
41 
42 
43 /************************************************************************************/
44 // Main() Function
45 
46 int C74_EXPORT main(void)
47 {
48  t_class* c;
49 
50  TTGraphInit();
51  common_symbols_init();
52 
53  c = class_new("j.append-", (method)AppendNew, (method)AppendFree, sizeof(Append), (method)0L, A_GIMME, 0);
54 
55  class_addmethod(c, (method)MaxGraphReset, "graph.reset", A_CANT, 0);
56  class_addmethod(c, (method)MaxGraphSetup, "graph.setup", A_CANT, 0);
57  class_addmethod(c, (method)MaxGraphConnect, "graph.connect", A_OBJ, A_LONG, 0);
58  class_addmethod(c, (method)MaxGraphDrop, "graph.drop", A_CANT, 0);
59  class_addmethod(c, (method)MaxGraphObject, "graph.object", A_CANT, 0);
60 
61  class_addmethod(c, (method)AppendAssist, "assist", A_CANT, 0);
62  class_addmethod(c, (method)object_obex_dumpout, "dumpout", A_CANT, 0);
63 
64  CLASS_ATTR_SYM(c, "key", 0, Append, attrKey);
65  CLASS_ATTR_ACCESSORS(c, "key", NULL, AppendSetKey);
66 
67  CLASS_ATTR_FLOAT(c, "value", 0, Append, attrValue);
68  CLASS_ATTR_ACCESSORS(c, "value", NULL, AppendSetValue);
69 
70  class_register(_sym_box, c);
71  sAppendClass = c;
72  return 0;
73 }
74 
75 
76 /************************************************************************************/
77 // Object Creation Method
78 
79 AppendPtr AppendNew(t_symbol* msg, long argc, t_atom* argv)
80 {
81  AppendPtr self;
82  TTValue v;
83  TTErr err;
84 
85  self = AppendPtr(object_alloc(sAppendClass));
86  if (self) {
87  object_obex_store((void*)self, _sym_dumpout, (t_object*)outlet_new(self, NULL)); // dumpout
88  self->graphOutlets[0] = outlet_new(self, "graph.connect");
89 
90  v.resize(2);
91  v[0] = "dictionary.append";
92  v[1] = 1;
93  err = TTObjectBaseInstantiate(TT("graph.object"), (TTObjectBasePtr*)&self->graphObject, v);
94 
95  if (!self->graphObject->mKernel.valid()) {
96  object_error(SELF, "cannot load Jamoma object");
97  return NULL;
98  }
99 
100  attr_args_process(self, argc, argv);
101  }
102  return self;
103 }
104 
105 
106 // Memory Deallocation
107 void AppendFree(AppendPtr self)
108 {
109  TTObjectBaseRelease((TTObjectBasePtr*)&self->graphObject);
110 }
111 
112 
113 /************************************************************************************/
114 // Methods bound to input/inlets
115 
116 // Method for Assistance Messages
117 void AppendAssist(AppendPtr self, void* b, long msg, long arg, char* dst)
118 {
119  if (msg==1) // Inlets
120  strcpy (dst, "dictionary input and control messages");
121  else if (msg==2) { // Outlets
122  if (arg == 0)
123  strcpy(dst, "dictionary output");
124  else
125  strcpy(dst, "dumpout");
126  }
127 }
128 
129 
130 // ATTRIBUTE SETTERS
131 
132 t_max_err AppendSetKey(AppendPtr self, void* attr, long argc, t_atom* argv)
133 {
134  if (argc) {
135  self->attrKey = atom_getsym(argv);
136  self->graphObject->mKernel.set(TT("key"), TT(self->attrKey->s_name));
137  }
138  return MAX_ERR_NONE;
139 }
140 
141 
142 t_max_err AppendSetValue(AppendPtr self, void* attr, long argc, t_atom* argv)
143 {
144  if (argc) {
145  self->attrValue = atom_getsym(argv);
146  self->graphObject->mKernel.set(TT("value"), TT(self->attrValue->s_name));
147  }
148  return MAX_ERR_NONE;
149 }
150 
The TTGraphObjectBase wraps a TTDSP object such that it is possible to build a dynamic graph of audio...
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
TTErr TTObjectBaseInstantiate(const TTSymbol className, TTObjectBasePtr *returnedObjectPtr, const TTValue arguments)
DEPRECATED.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
int C74_EXPORT main(void)
Set up this class as a Max external the first time an object of this kind is instantiated.
Definition: j.append.cpp:46
void resize(size_type n)
Change the number of elements.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34