Jamoma API  0.6.0.a19
j_equal.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup implementationMaxExternalsAudioGraph
4  *
5  * @brief j= : Creates an AudioGraph external that is able to wrap any Jamoma class
6  *
7  * @details
8  *
9  * @authors Tim Place, Trond Lossius
10  *
11  * @copyright © 2012 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 #include "maxAudioGraph.h"
17 
18 // Prototypes for methods
19 t_object* jamoma_new(t_symbol *s, long argc, t_atom* argv);
20 t_object* MaxAudioGraphWrappedClass_new(t_symbol *name, long argc, t_atom* argv);
21 
22 // Globals
23 static t_class* s_jamoma_class;
24 static t_hashtab* s_jamoma_class_hash = NULL;
25 
26 /************************************************************************************/
27 // Define a Max class that does essentially nothing but let users type the name into an object box.
28 // The class we actually use will be defined in the new method.
29 
30 int C74_EXPORT main(void)
31 {
32  s_jamoma_class = class_new("j=", (method)jamoma_new, (method)NULL, 0 /*sizeof(t_object)*/, (method)0L, A_GIMME, 0);
33  class_register(CLASS_BOX, s_jamoma_class);
34 
35  common_symbols_init();
36  TTAudioGraphInit();
37  return 0;
38 }
39 
40 /************************************************************************************/
41 // When a new instance of jamoma~ is created, we look at the first argument to get a Jamoma class name.
42 // Then we wrap that class as a Max class.
43 // Finally, we proceed to then instantiate the new Max class instead of the jamoma~ Max class.
44 
45 t_object* jamoma_new(t_symbol *s, long argc, t_atom* argv)
46 {
47  int attrstart = attr_args_offset(argc, argv);
48  int i = 0;
49  int channelCount = 2;
50  t_symbol *className = gensym("gain");
51  MaxAudioGraphWrappedClassPtr classWrapper = NULL;
52  char maxClassName[256];
53 
54  if (!attrstart) {
55  error("must specify a jamoma class as the first argument");
56  return NULL;
57  }
58  while (attrstart--) {
59  if (atom_gettype(argv+i) == A_LONG)
60  channelCount = atom_getlong(argv+i);
61  else if (atom_gettype(argv+i) == A_SYM)
62  className = atom_getsym(argv+i);
63  i++;
64  }
65 
66  snprintf(maxClassName, 256, "j.%s=", className->s_name);
67 
68  if (!s_jamoma_class_hash)
69  s_jamoma_class_hash = hashtab_new(0);
70  hashtab_lookup(s_jamoma_class_hash, className, (t_object**)&classWrapper);
71 
72  if (!classWrapper) {
73  wrapAsMaxAudioGraph(className->s_name, maxClassName, &classWrapper);
74  hashtab_store(s_jamoma_class_hash, className, (t_object*)(classWrapper));
75  }
76 
77  return MaxAudioGraphWrappedClass_new(gensym(maxClassName), argc-1, argv+1);
78 }
TTErr wrapAsMaxAudioGraph(TTSymbol ttClassName, char *maxClassName, MaxAudioGraphWrappedClassPtr *c)
Wrap an AudioGraph class as a Max class.
Type definition for an AudioGraph class wrapped as a Max external.
Definition: MaxAudioGraph.h:44
A thin wrapper of Jamoma AudioGraph for use in the Cycling '74 Max/MSP environment.
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_equal.cpp:30