Jamoma API  0.6.0.a19
Max/source/j.loader/j.loader.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup implementationMaxExternals
4  *
5  * @brief j.loader - Simply used to load the framework when Max is launched
6  *
7  * @details
8  *
9  * @authors Tim Place, Trond Lossius
10  *
11  * @copyright Copyright © 2007 by Tim 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 "JamomaForMax.h"
17 
18 
19 // Data Structure for this object
20 typedef struct _loader{
21  t_object ob;
22 } t_loader;
23 
24 
25 // Prototypes for methods
26 void* loader_new(t_symbol *name, long argc, t_atom *argv);
27 
28 
29 // Globals
30 static t_class *loader_class;
31 
32 
33 /************************************************************************************/
34 // A class that we can send messages to in the same way that messages are sent to ;max or ;dsp
35 
36 #ifdef STUFF_INHERITED_FROM_PLUGTASTIC
37 
38 static t_class* sPlugtasticClass;
39 static (t_object*) sPlugtasticObject;
40 static t_symbol* ps_plugtastic;
41 static long sPlugtasticSplash = 1;
42 
43 
44 typedef struct _plugtastic {
45  Object obj;
46  long* openSplash;
47  t_object* forward;
48 } t_plugtastic;
49 
50 
51 t_plugtastic* plugtastic_new()
52 {
53  t_plugtastic* self = (t_plugtastic*)(object_alloc(sPlugtasticClass));
54  //t_atom a;
55  t_class* c;
56  t_object* p;
57 
58  c = class_findbyname(_sym_box, _sym_forward);
59  if (!c) {
60  p = (t_object*)newinstance(_sym_forward, 0, NULL);
61  if (p) {
62  c = class_findbyname(_sym_box, _sym_forward);
63  freeobject(p);
64  p = NULL;
65  }
66  }/*
67  atom_setsym(&a, GENSYM("plugtastic_extra_toggle"));
68  self->forward = (t_object*)object_new_typed(CLASS_BOX, _sym_forward, 1, &a);
69 
70  self->openSplash = &sPlugtasticSplash;
71  a.a_type = 0;
72  preferences_getatomforkey(GENSYM("plugtastic_splash"), &a);
73  if (a.a_type)
74  *self->openSplash = atom_getlong(&a);
75  */
76  return self;
77 }
78 
79 
80 // prefs
81 
82  t_max_err plugtastic_getpref(void *dummy, void *attr, long *argc, t_atom **argv)
83  {
84  char alloc;
85 
86  atom_alloc_array(1, argc, argv, &alloc);
87  atom_setlong(*argv, sPlugtasticSplash);
88  return MAX_ERR_NONE;
89  }
90 
91  t_max_err plugtastic_setpref(void *dummy, void *attr, long argc, t_atom *argv)
92  {
93  sPlugtasticSplash = atom_getlong(argv);
94  return MAX_ERR_NONE;
95  }
96 
97 
98 // methods
99 
100  void plugtastic_get_splash(t_plugtastic* self)
101  {
102  t_atom a;
103 
104  // receive name: plugtastic_extra_toggle
105  if (self->forward != NULL) {
106  atom_setlong(&a, *self->openSplash);
107  object_method_typed(self->forward, _sym_int, 1, &a, NULL);
108  }
109  }
110 
111 
112  void plugtastic_set_splash(t_plugtastic* self, long state)
113  {
114  *self->openSplash = state;
115  }
116 
117 void plugtastic_classinit()
118 {
119  sPlugtasticClass = class_new((char*)"plugtastic", (method)plugtastic_new, (method)NULL, sizeof(t_plugtastic), (method)NULL, 0);
120 
121  /*class_addmethod(sPlugtasticClass, (method)plugtastic_get_splash, "get_show_extra_on_launch", 0);
122  class_addmethod(sPlugtasticClass, (method)plugtastic_set_splash, "set_show_extra_on_launch", A_LONG, 0);*/
123 
124  class_register(_sym_nobox, sPlugtasticClass);
125 
126  //preferences_define("plugtastic_splash", "long", "Show Plugtastic Intro Screen At Launch", "onoff", "Plugtastic", 0,
127  // (method)plugtastic_getpref, (method)plugtastic_setpref, 0/*PREFERENCES_FLAGS_INVISIBLE*/);
128 
129 }
130 
131 #endif // STUFF_INHERITED_FROM_PLUGTASTIC
132 
133 
134 
135 /************************************************************************************/
136 // Main() Function
137 
138 int JAMOMA_EXPORT_MAXOBJ main(void)
139 {
140  t_class *c;
141 
142  jamoma_init();
143  common_symbols_init();
144 
145  // Define our class
146  c = class_new("j.loader",(method)loader_new, (method)NULL, sizeof(t_loader), (method)NULL, A_GIMME, 0);
147 
148 
149 #ifdef STUFF_INHERITED_FROM_PLUGTASTIC
150  plugtastic_classinit();
151  sPlugtasticObject = (t_object*)plugtastic_new();
152  ps_plugtastic = GENSYM("plugtastic");
153  ps_plugtastic->s_thing = sPlugtasticObject;
154 
155  post("Plugtastic Version %s | jamoma.org", PLUGTASTIC_VERSION);
156 
157  // This tells Max 5.0.6 and higher that we want the patcher files to be saved such that they are sorted.
158  // Having the saved this way makes our GIT diffs much more meaningful.
159  // But it is already the default on Max 6
160  // object_method_long(sMaxObject, GENSYM("sortpatcherdictonsave"), 1, NULL);
161 
162  // This tells Max 4.5.7 and higher to take any posts to the Max window and also make the
163  // post to the system console, which greatly aids in debugging problems and crashes
164  // object_method_long(sMaxObject, GENSYM("setmirrortoconsole"), 1, NULL);
165 
166 
167  // OPEN THE SPLASH
168 
169  if (sPlugtasticSplash) {
170  char name[MAX_FILENAME_CHARS];
171  short path = 0;
172  long type = 0;
173  long typelist[2] = {'JSON', 'TEXT'};
174  short err;
175  t_dictionary* d;
176  t_object* p;
177  t_atom a[2];
178 
179  strncpy_zero(name, "Plugtastic.maxpat", MAX_FILENAME_CHARS);
180  err = locatefile_extended(name, &path, &type, typelist, 2);
181  dictionary_read(name, path, &d);
182 
183  atom_setobj(a, d);
184  p = (t_object*)object_new_typed(_sym_nobox, _sym_jpatcher, 1, a);
185  object_attr_setlong(p, _sym_locked, 1); // start out locked
186  object_attr_setchar(p, _sym_enablehscroll, 0); // turn off scroll bars
187  object_attr_setchar(p, _sym_enablevscroll, 0);
188  object_attr_setchar(p, _sym_toolbarvisible, 0);
189  object_attr_setsym(p, _sym_title, gensym("Welcome to Plugtastic"));
190  object_attr_setparse(p, _sym_rect, "271 170 799 489");
191  object_attr_setparse(p, _sym_defrect, "271 170 799 489");
192 
193  object_method(p, _sym_vis); // "vis" happens immediately, "front" is defer_lowed
194  object_method(p, _sym_loadbang);
195 
196  // object_method_parse(p, _sym_window, "constrain 799 489 799 489", NULL);
197  object_method_parse(p, _sym_window, "flags nozoom", NULL);
198  object_method_parse(p, _sym_window, "flags nogrow", NULL);
199  object_method_parse(p, _sym_window, "exec", NULL);
200  }
201 #endif // STUFF_INHERITED_FROM_PLUGTASTIC
202 
203 
204  // Finalize our class
205  class_register(CLASS_BOX, c);
206  loader_class = c;
207  return 0;
208 }
209 
210 
211 /************************************************************************************/
212 // Object Life
213 
214 void *loader_new(t_symbol *name, long argc, t_atom *argv)
215 {
216  t_loader *obj;
217 
218  obj = (t_loader*)object_alloc(loader_class);
219  return obj;
220 }
221 
Various utilities for interfacing with Max that are not specific to JamomaModular as such...
int JAMOMA_EXPORT_MAXOBJ main(void)
Set up this class as a Max external the first time an object of this kind is instantiated.