Jamoma API  0.6.0.a19
j.midi.format.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup implementationMaxExternalsGraph
4  *
5  * @brief j.midi.format# - Format MIDI message as 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 MidiFormat {
22  Object obj;
23  TTGraphObjectBasePtr graphObject;
24  TTPtr graphOutlets[16]; // this _must_ be third (for the setup call)
25 };
26 typedef MidiFormat* MidiFormatPtr;
27 
28 
29 // Prototypes for methods
30 MidiFormatPtr MidiFormatNew (t_symbol* msg, long argc, t_atom* argv);
31 void MidiFormatFree (MidiFormatPtr self);
32 void MidiFormatAssist (MidiFormatPtr self, void* b, long msg, long arg, char* dst);
33 
34 
35 // Globals
36 static t_class* sMidiFormatClass;
37 
38 
39 /************************************************************************************/
40 // Main() Function
41 
42 int C74_EXPORT main(void)
43 {
44  t_class* c;
45 
46  TTGraphInit();
47  common_symbols_init();
48 
49  c = class_new("j.midi.format-", (method)MidiFormatNew, (method)MidiFormatFree, sizeof(MidiFormat), (method)0L, A_GIMME, 0);
50 
51  class_addmethod(c, (method)MaxGraphReset, "graph.reset", A_CANT, 0);
52  class_addmethod(c, (method)MaxGraphSetup, "graph.setup", A_CANT, 0);
53  class_addmethod(c, (method)MaxGraphConnect, "graph.connect", A_OBJ, A_LONG, 0);
54  class_addmethod(c, (method)MaxGraphDrop, "graph.drop", A_CANT, 0);
55  class_addmethod(c, (method)MaxGraphObject, "graph.object", A_CANT, 0);
56 
57  class_addmethod(c, (method)MidiFormatAssist, "assist", A_CANT, 0);
58  class_addmethod(c, (method)object_obex_dumpout, "dumpout", A_CANT, 0);
59 
60  class_register(_sym_box, c);
61  sMidiFormatClass = c;
62  return 0;
63 }
64 
65 
66 /************************************************************************************/
67 // Object Creation Method
68 
69 MidiFormatPtr MidiFormatNew(t_symbol* msg, long argc, t_atom* argv)
70 {
71  MidiFormatPtr self;
72  TTValue v;
73  TTErr err;
74 
75  self = MidiFormatPtr(object_alloc(sMidiFormatClass));
76  if (self) {
77  object_obex_store((void*)self, _sym_dumpout, (t_object*)outlet_new(self, NULL)); // dumpout
78  self->graphOutlets[0] = outlet_new(self, "graph.connect");
79 
80  v.resize(2);
81  v[0] = "midi.format";
82  v[1] = 1;
83  err = TTObjectBaseInstantiate(TT("graph.object"), (TTObjectBasePtr*)&self->graphObject, v);
84 
85  if (!self->graphObject->mKernel.valid()) {
86  object_error(SELF, "cannot load Jamoma object");
87  return NULL;
88  }
89 
90  attr_args_process(self, argc, argv);
91  }
92  return self;
93 }
94 
95 
96 // Memory Deallocation
97 void MidiFormatFree(MidiFormatPtr self)
98 {
99  TTObjectBaseRelease((TTObjectBasePtr*)&self->graphObject);
100 }
101 
102 
103 /************************************************************************************/
104 // Methods bound to input/inlets
105 
106 // Method for Assistance Messages
107 void MidiFormatAssist(MidiFormatPtr self, void* b, long msg, long arg, char* dst)
108 {
109  if (msg==1) // Inlets
110  strcpy (dst, "dictionary input and control messages");
111  else if (msg==2) { // Outlets
112  if (arg == 0)
113  strcpy(dst, "dictionary output");
114  else
115  strcpy(dst, "dumpout");
116  }
117 }
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
void resize(size_type n)
Change the number of elements.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
int C74_EXPORT main(void)
Set up this class as a Max external the first time an object of this kind is instantiated.