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