Jamoma API  0.6.0.a19
j.midi.filter.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup implementationMaxExternalsGraph
4  *
5  * @brief j.midi.filter# - External object for Max to append keys to a dictionary being passed in a Jamoma Graph
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 MidiFilter {
22  t_object obj;
23  TTGraphObjectBasePtr graphObject;
24  TTPtr graphOutlets[16]; // this _must_ be third (for the setup call)
25  t_symbol* attrType;
26 };
27 typedef MidiFilter* MidiFilterPtr;
28 
29 
30 // Prototypes for methods
31 MidiFilterPtr MidiFilterNew (t_symbol* msg, long argc, t_atom* argv);
32 void MidiFilterFree (MidiFilterPtr self);
33 void MidiFilterAssist (MidiFilterPtr self, void* b, long msg, long arg, char* dst);
34 t_max_err MidiFilterSetType (MidiFilterPtr self, void* attr, long argc, t_atom* argv);
35 
36 
37 // Globals
38 static t_class* sMidiFilterClass;
39 
40 
41 /************************************************************************************/
42 // Main() Function
43 
44 int C74_EXPORT main(void)
45 {
46  t_class* c;
47 
48  TTGraphInit();
49  common_symbols_init();
50 
51  c = class_new("j.midi.filter-", (method)MidiFilterNew, (method)MidiFilterFree, sizeof(MidiFilter), (method)0L, A_GIMME, 0);
52 
53  class_addmethod(c, (method)MaxGraphReset, "graph.reset", A_CANT, 0);
54  class_addmethod(c, (method)MaxGraphSetup, "graph.setup", A_CANT, 0);
55  class_addmethod(c, (method)MaxGraphConnect, "graph.connect", A_OBJ, A_LONG, 0);
56  class_addmethod(c, (method)MaxGraphDrop, "graph.drop", A_CANT, 0);
57  class_addmethod(c, (method)MaxGraphObject, "graph.object", A_CANT, 0);
58 
59  class_addmethod(c, (method)MidiFilterAssist, "assist", A_CANT, 0);
60  class_addmethod(c, (method)object_obex_dumpout, "dumpout", A_CANT, 0);
61 
62  CLASS_ATTR_SYM(c, "type", 0, MidiFilter, attrType);
63  CLASS_ATTR_ACCESSORS(c, "type", NULL, MidiFilterSetType);
64 
65  class_register(_sym_box, c);
66  sMidiFilterClass = c;
67  return 0;
68 }
69 
70 
71 /************************************************************************************/
72 // Object Creation Method
73 
74 MidiFilterPtr MidiFilterNew(t_symbol* msg, long argc, t_atom* argv)
75 {
76  MidiFilterPtr self;
77  TTValue v;
78  TTErr err;
79 
80  self = MidiFilterPtr(object_alloc(sMidiFilterClass));
81  if (self) {
82  object_obex_store((void*)self, _sym_dumpout, (t_object*)outlet_new(self, NULL)); // dumpout
83  self->graphOutlets[0] = outlet_new(self, "graph.connect");
84 
85  v.resize(2);
86  v[0] = "midi.filter";
87  v[1] = 1;
88  err = TTObjectBaseInstantiate(TT("graph.object"), (TTObjectBasePtr*)&self->graphObject, v);
89 
90  if (!self->graphObject->mKernel.valid()) {
91  object_error(SELF, "cannot load Jamoma object");
92  return NULL;
93  }
94 
95  attr_args_process(self, argc, argv);
96  }
97  return self;
98 }
99 
100 
101 // Memory Deallocation
102 void MidiFilterFree(MidiFilterPtr self)
103 {
104  TTObjectBaseRelease((TTObjectBasePtr*)&self->graphObject);
105 }
106 
107 
108 /************************************************************************************/
109 // Methods bound to input/inlets
110 
111 // Method for Assistance Messages
112 void MidiFilterAssist(MidiFilterPtr self, void* b, long msg, long arg, char* dst)
113 {
114  if (msg==1) // Inlets
115  strcpy (dst, "dictionary input and control messages");
116  else if (msg==2) { // Outlets
117  if (arg == 0)
118  strcpy(dst, "dictionary output");
119  else
120  strcpy(dst, "dumpout");
121  }
122 }
123 
124 
125 // ATTRIBUTE SETTERS
126 
127 t_max_err MidiFilterSetType(MidiFilterPtr self, void* attr, long argc, t_atom* argv)
128 {
129  if (argc) {
130  self->attrType = atom_getsym(argv);
131  self->graphObject->mKernel.set(TT("type"), TT(self->attrType->s_name));
132  }
133  return MAX_ERR_NONE;
134 }
135 
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.
int C74_EXPORT main(void)
Set up this class as a Max external the first time an object of this kind is instantiated.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
void resize(size_type n)
Change the number of elements.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34