Jamoma API  0.6.0.a19
j.op-/j.op.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup implementationMaxExternalsGraph
4  *
5  * @brief j.midi.op# - Wraps the #TTOperator class as a Jamoma Graph external object for Max
6  *
7  * @details
8  *
9  * @authors Tim Place, Trond Lossius
10  *
11  * @copyright 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 Op {
22  t_object obj;
23  TTGraphObjectBasePtr graphObject;
24  TTPtr graphOutlets[16]; // this _must_ be third (for the setup call)
25  t_symbol* attrOperator;
26  TTFloat32 attrOperand;
27 };
28 typedef Op* OpPtr;
29 
30 
31 // Prototypes for methods
32 OpPtr OpNew (t_symbol* msg, long argc, t_atom* argv);
33 void OpFree (OpPtr self);
34 void OpAssist (OpPtr self, void* b, long msg, long arg, char* dst);
35 t_max_err OpSetOperator (OpPtr self, void* attr, long argc, t_atom* argv);
36 t_max_err OpSetOperand (OpPtr self, void* attr, long argc, t_atom* argv);
37 
38 
39 // Globals
40 static t_class* sOpClass;
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.op-", (method)OpNew, (method)OpFree, sizeof(Op), (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)OpAssist, "assist", A_CANT, 0);
62  class_addmethod(c, (method)object_obex_dumpout, "dumpout", A_CANT, 0);
63 
64  CLASS_ATTR_SYM(c, "operator", 0, Op, attrOperator);
65  CLASS_ATTR_ACCESSORS(c, "operator", NULL, OpSetOperator);
66  CLASS_ATTR_ENUM(c, "operator", 0, "+ - * / % > >= == != <= < abs acos asin atan ceil cos cosh exp floor log log10 sin sinh sqrt tan tanh");
67 
68  CLASS_ATTR_FLOAT(c, "operand", 0, Op, attrOperand);
69  CLASS_ATTR_ACCESSORS(c, "operand", NULL, OpSetOperand);
70 
71  class_register(_sym_box, c);
72  sOpClass = c;
73  return 0;
74 }
75 
76 
77 /************************************************************************************/
78 // Object Creation Method
79 
80 OpPtr OpNew(t_symbol* msg, long argc, t_atom* argv)
81 {
82  OpPtr self;
83  TTValue v;
84  TTErr err;
85 
86  self = OpPtr(object_alloc(sOpClass));
87  if (self) {
88  object_obex_store((void*)self, _sym_dumpout, (t_object*)outlet_new(self, NULL)); // dumpout
89  self->graphOutlets[0] = outlet_new(self, "graph.connect");
90 
91  v.resize(2);
92  v[0] = "operator";
93  v[1] = 1;
94  err = TTObjectBaseInstantiate(TT("graph.object"), (TTObjectBasePtr*)&self->graphObject, v);
95 
96  if (!self->graphObject->mKernel.valid()) {
97  object_error(SELF, "cannot load Jamoma object");
98  return NULL;
99  }
100 
101  attr_args_process(self, argc, argv);
102  }
103  return self;
104 }
105 
106 
107 // Memory Deallocation
108 void OpFree(OpPtr self)
109 {
110  TTObjectBaseRelease((TTObjectBasePtr*)&self->graphObject);
111 }
112 
113 
114 /************************************************************************************/
115 // Methods bound to input/inlets
116 
117 // Method for Assistance Messages
118 void OpAssist(OpPtr self, void* b, long msg, long arg, char* dst)
119 {
120  if (msg==1) // Inlets
121  strcpy (dst, "multichannel input and control messages");
122  else if (msg==2) { // Outlets
123  if (arg == 0)
124  strcpy(dst, "multichannel output");
125  else
126  strcpy(dst, "dumpout");
127  }
128 }
129 
130 
131 // ATTRIBUTE SETTERS
132 
133 t_max_err OpSetOperator(OpPtr self, void* attr, long argc, t_atom* argv)
134 {
135  if (argc) {
136  self->attrOperator = atom_getsym(argv);
137  self->graphObject->mKernel.set(TT("operator"), TT(self->attrOperator->s_name));
138  }
139  return MAX_ERR_NONE;
140 }
141 
142 
143 t_max_err OpSetOperand(OpPtr self, void* attr, long argc, t_atom* argv)
144 {
145  if (argc) {
146  self->attrOperand = atom_getfloat(argv);
147  self->graphObject->mKernel.set(TT("operand"), self->attrOperand);
148  }
149  return MAX_ERR_NONE;
150 }
151 
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
float TTFloat32
32 bit floating point number
Definition: TTBase.h:187
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.op-/j.op.cpp:46
void resize(size_type n)
Change the number of elements.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34