Jamoma API  0.6.0.a19
j.info.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup implementationMaxExternalsAudioGraph
4  *
5  * @brief j.info= : creates an external for AudioGraph that provides information about the incoming multichannel signal
6  *
7  * @details
8  *
9  * @authors Timothy Place, Trond Lossius
10  *
11  * @copyright © 2008 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 "maxAudioGraph.h"
18 
19 
20 // Data Structure for this object
21 struct Info {
22  t_object obj;
23  TTAudioGraphObjectBasePtr audioGraphObject; // we wrap a simple 'thru' audiograph object
24  TTPtr outletSmartSignal; // outlet for passing the input to the output, and so we can be pulled
25  TTPtr unused; // this is an unused ptr, always set to NULL, to signal the end of the JAG outlets
26  TTPtr outletSampleRate;
27  TTPtr outletVectorSize;
28  TTPtr outletNumChannels;
29  long audioSourceOutlet; // number of the outlet connected to our inlet
30  long maxNumChannels; // the number of inlets or outlets, which is an argument at instantiation
31  long numChannels; // the actual number of channels to use, set by the dsp method
32  long vectorSize; // cached by the DSP method
33  TTPtr qelem; // a queue for deferring 'bang' calls
34 };
35 typedef Info* InfoPtr;
36 
37 
38 // Prototypes for methods
39 InfoPtr InfoNew(t_symbol* msg, long argc, t_atom* argv);
40 void InfoFree(InfoPtr self);
41 void InfoAssist(InfoPtr self, void* b, long msg, long arg, char* dst);
42 void InfoBang(InfoPtr self);
43 void InfoQfn(InfoPtr self);
44 TTErr InfoConnect(InfoPtr self, TTAudioGraphObjectBasePtr audioSourceObject, long sourceOutletNumber);
45 
46 
47 // Globals
48 static t_class* sInfoClass;
49 
50 
51 /************************************************************************************/
52 // Main() Function
53 
54 int C74_EXPORT main(void)
55 {
56  t_class* c;
57 
58  TTAudioGraphInit();
59  common_symbols_init();
60 
61  c = class_new("j.info=", (method)InfoNew, (method)InfoFree, sizeof(Info), (method)0L, A_GIMME, 0);
62 
63  class_addmethod(c, (method)InfoBang, "bang", 0);
64  class_addmethod(c, (method)MaxAudioGraphReset, "graph.reset", A_CANT, 0);
65  class_addmethod(c, (method)InfoConnect, "audio.connect", A_OBJ, A_LONG, 0);
66  class_addmethod(c, (method)MaxAudioGraphSetup, "audio.setup", A_CANT, 0);
67  class_addmethod(c, (method)MaxAudioGraphDrop, "audio.drop", A_CANT, 0);
68  class_addmethod(c, (method)MaxAudioGraphObject, "audio.object", A_CANT, 0);
69  class_addmethod(c, (method)InfoAssist, "assist", A_CANT, 0);
70  class_addmethod(c, (method)object_obex_dumpout, "dumpout", A_CANT, 0);
71 
72  class_register(_sym_box, c);
73  sInfoClass = c;
74  return 0;
75 }
76 
77 
78 /************************************************************************************/
79 // Object Creation Method
80 
81 InfoPtr InfoNew(t_symbol* msg, long argc, t_atom* argv)
82 {
83  InfoPtr self;
84  TTValue v;
85  TTErr err;
86 
87  self = InfoPtr(object_alloc(sInfoClass));
88  if (self) {
89  object_obex_store((TTPtr)self, _sym_dumpout, (t_object*)outlet_new(self, NULL));
90  self->outletNumChannels = outlet_new((t_pxobject*)self, 0);
91  self->outletVectorSize = outlet_new((t_pxobject*)self, 0);
92  self->outletSampleRate = outlet_new((t_pxobject*)self, 0);
93  self->outletSmartSignal = outlet_new((t_pxobject*)self, "audio.connect");
94 
95  self->qelem = qelem_new(self, (method)InfoQfn);
96 
97  v.resize(2);
98  v[0] = "thru";
99  v[1] = 1; // we set it up with 1 inlet, and later modify to 2 inlets if the connection is made
100  err = TTObjectBaseInstantiate(TT("audio.object"), (TTObjectBasePtr*)&self->audioGraphObject, v);
101  if (!self->audioGraphObject->getUnitGenerator().valid()) {
102  object_error(SELF, "cannot load Jamoma DSP object");
103  return NULL;
104  }
105 
106  attr_args_process(self, argc, argv);
107  }
108  return self;
109 }
110 
111 
112 void InfoFree(InfoPtr self)
113 {
114  TTObjectBaseRelease((TTObjectBasePtr*)&self->audioGraphObject);
115  qelem_free(self->qelem);
116 }
117 
118 
119 /************************************************************************************/
120 // Methods bound to input/inlets
121 
122 // Method for Assistance Messages
123 void InfoAssist(InfoPtr self, void* b, long msg, long arg, char* dst)
124 {
125  if (msg==1) // Inlets
126  strcpy(dst, "multichannel audio connection and control messages");
127  else if (msg==2) { // Outlets
128  if (arg == 0)
129  strcpy(dst, "multichannel audio connection, passing the input thru to the output");
130  else if (arg == 1)
131  strcpy(dst, "sample rate of the input signal");
132  else if (arg == 2)
133  strcpy(dst, "vector size of the input signal");
134  else if (arg == 3)
135  strcpy(dst, "number of channels in the input signal");
136  else if (arg == 4)
137  strcpy(dst, "dumpout");
138  }
139 }
140 
141 
142 void InfoBang(InfoPtr self)
143 {
144  qelem_set(self->qelem);
145 }
146 
147 
148 void InfoQfn(InfoPtr self)
149 {
150  outlet_int(self->outletNumChannels, self->audioGraphObject->getOutputNumChannels(self->audioSourceOutlet));
151  outlet_int(self->outletVectorSize, self->audioGraphObject->getOutputVectorSize(self->audioSourceOutlet));
152  outlet_int(self->outletSampleRate, self->audioGraphObject->getOutputSampleRate(self->audioSourceOutlet));
153 }
154 
155 
156 TTErr InfoConnect(InfoPtr self, TTAudioGraphObjectBasePtr newAudioSourceObject, long sourceOutletNumber)
157 {
158  TTErr err = MaxAudioGraphConnect((t_object*)self, newAudioSourceObject, sourceOutletNumber);
159 
160  self->audioSourceOutlet = sourceOutletNumber;
161  InfoBang(self);
162  return err;
163 }
164 
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
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.info.cpp:54
TTErr MaxAudioGraphSetup(t_object *x)
Set up fresh connections from this object to nodes that are connected downstream. ...
TTErr MaxAudioGraphReset(t_object *x, long vectorSize)
Clear the list of source objects from which this object will try to pull audio.
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
TTErr MaxAudioGraphConnect(t_object *x, TTAudioGraphObjectBasePtr audioSourceObject, TTUInt16 sourceOutletNumber)
Method called when an upstream node is connected to this node.
#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.
A thin wrapper of Jamoma AudioGraph for use in the Cycling '74 Max/MSP environment.
TTErr MaxAudioGraphObject(t_object *x, TTAudioGraphObjectBasePtr *returnedAudioGraphObject)
Returns a pointer to the Jamoma Audio Graph object that is wrapped by this Max object.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
The TTAudioGraphObjectBase wraps a TTDSP object such that it is possible to build a dynamic graph of ...
TTErr MaxAudioGraphDrop(t_object *x, long inletNumber, t_object *sourceMaxObject, long sourceOutletNumber)
Method called when a connection from an upstream node is dropped.
void resize(size_type n)
Change the number of elements.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34