Exemplo n.º 1
0
void ui_preset_interface(t_ui *x)
{
	char			filename[MAX_FILENAME_CHARS];
	short			path;
	t_fourcc		type;
	t_fourcc		filetype = 'JSON';
	t_dictionary*	d;
	t_object*		p;
	t_atom			a;
	
	strncpy_zero(filename, "j.preset_interface.maxpat", MAX_FILENAME_CHARS);
	locatefile_extended(filename, &path, &type, &filetype, 1);
	dictionary_read(filename, path, &d);
	
	atom_setobj(&a, d);
	p = (t_object*)object_new_typed(_sym_nobox, _sym_jpatcher, 1, &a);
	object_attr_setlong(p, _sym_locked, 1);										// start out locked
	object_attr_setchar(p, _sym_enablehscroll, 0);								// turn off scroll bars
	object_attr_setchar(p, _sym_enablevscroll, 0);
	object_attr_setchar(p, _sym_openinpresentation, 1);	
	object_attr_setchar(p, _sym_toolbarvisible, 0);	
	object_attr_setsym(p, _sym_title, gensym("preset_interface"));		
	object_method_parse(p, _sym_window, "constrain 5 320 179 595", NULL);
	object_attach_byptr_register(x, p, _sym_nobox);
	
	object_method(p, _sym_vis);													// "vis" happens immediately, "front" is defer_lowed
	object_attr_setobj(jpatcher_get_firstview(p), _sym_owner, (t_object*)x);	// become the owner
	
	OBJ_ATTR_SYM(p, "arguments", 0, gensym((char*)x->modelAddress.c_str()));	// the patch needs a [j.interfaceArguments.js]
	
	object_method(p, _sym_loadbang);
}
Exemplo n.º 2
0
t_plugtastic* plugtastic_new()
{
	t_plugtastic*	self = (t_plugtastic*)(object_alloc(sPlugtasticClass));
	t_atom			a;
	t_class*		c;
	t_object*		p;

	c = class_findbyname(_sym_box, _sym_forward);
	if (!c) {
		p = (t_object*)newinstance(_sym_forward, 0, NULL);
		if (p) {
			c = class_findbyname(_sym_box, _sym_forward);
			freeobject(p);
			p = NULL;
		}
	}
	atom_setsym(&a, GENSYM("plugtastic_extra_toggle"));
	self->forward = (t_object*)object_new_typed(CLASS_BOX, _sym_forward, 1, &a);
	
	self->openSplash = &sPlugtasticSplash;
	a.a_type = 0;
	preferences_getatomforkey(GENSYM("plugtastic_splash"), &a);
	if (a.a_type)
		*self->openSplash = atom_getlong(&a);
		
	return self;
}
Exemplo n.º 3
0
void scripto_dblclick(t_scripto *x)
{
	if (x->s_patcher)
		object_method(x->s_patcher, gensym("vis"));
	else {
		t_dictionary *d = dictionary_new();
		char parsebuf[256];
		t_atom a;
		long ac = 0;
		t_atom *av = NULL;

		// create a patcher without scroll bars and a toolbar
		sprintf(parsebuf,"@defrect 0 0 300 400 @title scripto @enablehscroll 0 @enablevscroll 0 @presentation 0 @toolbarid \"\"");
		atom_setparse(&ac,&av,parsebuf);
		attr_args_dictionary(d,ac,av);
		atom_setobj(&a,d);
		sysmem_freeptr(av);
		x->s_patcher = (t_object *)object_new_typed(CLASS_NOBOX,gensym("jpatcher"),1, &a);
		freeobject((t_object *)d);	// we created this dictionary and we don't need it anymore

		object_method(x->s_patcher,gensym("vis"));
		x->s_ui = newobject_sprintf(x->s_patcher, "@maxclass scripto_ui @patching_rect 0 0 300 400 @oncolor %.2f %.2f %.2f %.2f @offcolor %.2f %.2f %.2f %.2f",
									x->s_oncolor.red, x->s_oncolor.green, x->s_oncolor.blue, x->s_oncolor.alpha, x->s_offcolor.red, x->s_offcolor.green, x->s_offcolor.blue, x->s_offcolor.alpha);
		object_attach_byptr_register(x, x->s_ui, CLASS_BOX);			// attach our UI object to us
		object_attach_byptr_register(x, x->s_patcher, CLASS_NOBOX);		// attach our UI object to us
	}
}
Exemplo n.º 4
0
t_max_err db_open(t_symbol *dbname, const char *filename, t_database **db)
{
	long	ac=0;
	t_atom	av[6];
	
	if (*db)
		object_free(*db);
	
	if (filename) {
		atom_setsym(av+ac, gensym("@rambased"));
		ac++;
		atom_setlong(av+ac, 0);
		ac++;
		atom_setsym(av+ac, gensym("@filename"));
		ac++;
		atom_setsym(av+ac, gensym((char*)filename));
		ac++;
	}
	atom_setsym(av+ac, gensym("@db"));
	ac++;
	atom_setsym(av+ac, dbname);
	ac++;
	
	*db = (t_database*)object_new_typed(_sym_nobox, _sym_sqlite, ac, av);
	if (!*db)
		return MAX_ERR_GENERIC;
	
	return MAX_ERR_NONE;
}
Exemplo n.º 5
0
// Load an external for internal use
t_max_err loadextern(t_symbol *objectname, long argc, t_atom *argv, t_object **object)
{
	t_class 	*c = NULL;
	t_object	*p = NULL;
	
	c = class_findbyname(_sym_box, objectname);
	if (!c) {
		p = (t_object*)newinstance(objectname, 0, NULL);
		if(p){
			c = class_findbyname(_sym_box, objectname);
			freeobject(p);
			p = NULL;
		}
		else{
			error("could not load extern (%s) within the oscar extension", objectname->s_name);
			return MAX_ERR_GENERIC;
		}
	}
	
	if (*object != NULL) {			// if there was an object set previously, free it first...
		object_free(*object);
		*object = NULL;
	}
	
	*object = (t_object*)object_new_typed(_sym_box, objectname, argc, argv);
	return MAX_ERR_NONE;
}
Exemplo n.º 6
0
// Load an external for internal use
// returns true if successful
bool jamoma_loadextern(t_symbol *objectname, long argc, t_atom *argv, t_object **object)
{
	t_class 	*c = NULL;
	t_object	*p = NULL;
    
	c = class_findbyname(jps_box, objectname);
	if (!c) {
		p = (t_object *)newinstance(objectname, 0, NULL);
		if (p) {
			c = class_findbyname(jps_box, objectname);
			freeobject(p);
			p = NULL;
		}
		else {
			error("jamoma: could not load extern (%s) within the core", objectname->s_name);
			return false;
		}
	}
    
	if (*object != NULL) {			// if there was an object set previously, free it first...
		object_free(*object);
		*object = NULL;
	}
    
	*object = (t_object *)object_new_typed(CLASS_BOX, objectname, argc, argv);
	return true;
}
Exemplo n.º 7
0
// Create
void *receive_new(t_symbol *s, long argc, t_atom *argv)
{
	long		attrstart = attr_args_offset(argc, argv);		// support normal arguments
	t_receive	*x = (t_receive *)object_alloc(s_receive_class);

	if (x) {
		object_obex_store((void *)x, _sym_dumpout, (object *)outlet_new(x, NULL));
		x->outlet = outlet_new(x, NULL);

		if (!g_receivemaster_object)
			g_receivemaster_object = (t_object *)object_new_typed(CLASS_NOBOX, SymbolGen("jcom.receivemaster"), 0, NULL);

		x->callback = NULL;
		x->attr_name = NULL;
		// attr_args_process(x, argc, argv);					// handle attribute args				

		// If no name was specified as an attribute
		if (x->attr_name == NULL) {
			if (attrstart > 0)
				x->attr_name = atom_getsym(argv);
			else
				x->attr_name = SymbolGen("jcom.receive no arg specified");
			receive_bind(x);
		}
	}
	return x;
}
Exemplo n.º 8
0
// Entry
void ext_main(void *r)
{
	common_symbols_init();
	
	testmaster_classinit();
	testrunner_classinit();
	testunit_classinit();
	testdb_classinit();
	testport_classinit();
	testassert_classinit();
	testequals_classinit();
	testlog_classinit();
	testterminate_classinit();
	testsample_classinit();
	
	ps_testmaster = gensym("test.master");
	ps_testport = gensym("test.port");

	ps_testmaster->s_thing = (t_object*)object_new_typed(_sym_nobox, ps_testmaster, 0, NULL);
	
	defer_low(ps_testmaster->s_thing, (method)deferred_startup, NULL, 0, NULL);
	quittask_install((method)testmaster_quittask, NULL);

	object_method(gensym("max")->s_thing, gensym("setmirrortoconsole"), 1);
}
Exemplo n.º 9
0
void *hoa_dac_new(t_symbol *s, int argc, t_atom *argv)
{
	int i, j, count = 0;
	t_hoa_dac *x;
	t_atom channels[512];
	int min, max;
    int symPrepend = 0;

    x = (t_hoa_dac *)object_alloc(hoa_dac_class);
    
    if (argc && atom_gettype(argv) == A_SYM)
    {
        char *dac_bus_name = atom_getsym(argv)->s_name;
        if (isalpha(dac_bus_name[0])) // only works if the first letter isn't a number
        {
            symPrepend = 1;
            atom_setsym(channels, atom_getsym(argv));
        }
    }
    
	for(i = 0; i < (argc-symPrepend); i++)
	{
		if(atom_gettype(argv+i+symPrepend) == A_SYM)
		{
			min = atoi(atom_getsym(argv+i+symPrepend)->s_name);
			if (min < 10)
				max = atoi(atom_getsym(argv+i+symPrepend)->s_name+2);
			else if (min < 100)
				max = atoi(atom_getsym(argv+i+symPrepend)->s_name+3);
			else if (min < 1000)
				max = atoi(atom_getsym(argv+i+symPrepend)->s_name+4);
			else
				max = atoi(atom_getsym(argv+i+symPrepend)->s_name+5);
			if (max > min) 
			{
				for(j = min; j <= max; j++)
				{
					atom_setlong(channels + symPrepend + count++, j);
				}
			}
			else 
			{
				for(j = min; j >= max; j--)
				{
					atom_setlong(channels + symPrepend + count++, j);
				}
			}
		}	
		else if(atom_gettype(argv + symPrepend + i) == A_LONG)
		{
            atom_setlong(channels + symPrepend + count++, atom_getlong(argv + symPrepend + i));
		}
	}
	x->f_number_of_channels = count;
    dsp_setup((t_pxobject *)x, x->f_number_of_channels);
	x->f_dac = (t_object *)object_new_typed(CLASS_BOX, gensym("dac~"), count + symPrepend, channels);
	
	return x;
}
Exemplo n.º 10
0
void *record_new(t_symbol *s, int argc, t_atom *argv)
{
    // @arg 0 @ambisonic-order @optional 0 @type int @digest The ambisonic order
    // @description The ambisonic order, must be at least equal to 1
    
	t_object *x;
	t_atom arguments[2];
	int order = 1;
	if(atom_gettype(argv) == A_LONG)
		order = atom_getlong(argv);
	else if(atom_gettype(argv) == A_FLOAT)
		order = atom_getfloat(argv);

	if(order < 1)
		order = 1;
    
    int is2D = 1;
    
    if (s == gensym("hoa.3d.record~"))
        is2D = 0;
    
    int number_of_channels = is2D ? (order * 2 + 1) : ( (order+1)*(order+1) );
	
	atom_setlong(arguments, number_of_channels);
    
	switch (number_of_channels)
	{
		case 9:
			atom_setlong(arguments+1, 181440);
			break;
		case 10:
			atom_setlong(arguments+1, 20160);
			break;
		case 11:
			atom_setlong(arguments+1, 221760);
			break;
		case 12:
			atom_setlong(arguments+1, 60480);
			break;
		case 13:
			atom_setlong(arguments+1, 262080);
			break;
		case 14:
			atom_setlong(arguments+1, 20160);
			break;
		case 15:
			atom_setlong(arguments+1, 60480);
			break;
		case 16:
			atom_setlong(arguments+1, 40320);
			break;
		default:
			atom_setlong(arguments+1, 20160);
			break;
	}
	x = (t_object *)object_new_typed(CLASS_BOX, gensym("sfrecord~"), 2, arguments);
	
	return x;
}	
Exemplo n.º 11
0
void hoa_print_credit()
{
    if(gensym("hoa_print_credits")->s_thing == NULL)
    {
		t_object* print;
		t_atom* sym = (t_atom*) malloc( sizeof(t_atom));
		atom_setsym(sym, gensym("HoaLibrary"));
		print = (t_object*)object_new_typed(CLASS_BOX, gensym("print"), 1, sym);
		atom_setsym(sym, _sym_credit_line1);
		object_method_typed(print, gensym("list"), 1, sym, NULL);
		atom_setsym(sym, _sym_hoa_version);
		print = (t_object*)object_new_typed(CLASS_BOX, gensym("print"), 1, sym);
		atom_setsym(sym, _sym_credit_line2);
		object_method_typed(print, gensym("list"), 1, sym, NULL);
		gensym("hoa_print_credits")->s_thing = print;
		freeobject(print);
		free(sym);
    }
}
Exemplo n.º 12
0
void *folder_new(t_symbol *msg, short argc, t_atom *argv)
{
	t_folder *x = (t_folder *)object_alloc(s_folder_class);;
	if(x){
		object_obex_store((void *)x, _sym_dumpout, (object *)outlet_new(x,NULL));
#ifdef MAC_VERSION
		x->applescript = (t_object*)object_new_typed(_sym_box, gensym("tap.applescript"), 0, NULL);
#endif
    	attr_args_process(x,argc,argv);
    }
 	return (x);
}
Exemplo n.º 13
0
void deferred_startup(void)
{
	t_atom a[2];
	
	atom_setlong(a+0, g_port_send);
	atom_setlong(a+1, g_port_listen);
	
	// cannot load classes from disk at the time that the extensions folder is processed
	ps_testport->s_thing = (t_object*)object_new_typed(_sym_nobox, ps_testport, 2, a);
	
	// notify anyone who is listening (e.g. a ruby script that launched max) that we are ready
	object_method(ps_testport->s_thing, _sym_send, gensym("/testport/ready"), 0, NULL);
}
Exemplo n.º 14
0
t_max_err db_open(t_symbol *dbname, const char *fullpath, t_database **db)
{
	long	ac=0;
	t_atom	av[6];
	
	if (*db)
		object_free(*db);
	
	if (fullpath) {
		char	coercedpath[MAX_PATH_CHARS];
		short	err;
		char	dbpath[MAX_PATH_CHARS];
#ifdef MAC_VERSION
		char	*temppath;
#endif

		err = path_nameconform((char*)fullpath, coercedpath, PATH_STYLE_NATIVE_PLAT, PATH_TYPE_ABSOLUTE);
		if (err)
			strncpy_zero(coercedpath, fullpath, MAX_PATH_CHARS);
		
#ifdef MAC_VERSION
		temppath = strchr(coercedpath, ':');
		*temppath = '\0';
		temppath += 1;
		
		// at this point temppath points to the path after the volume, and coercedpath has the volume
		snprintf(dbpath, MAX_PATH_CHARS, "/Volumes/%s%s", coercedpath, temppath);
#else // WIN_VERSION
		strncpy_zero(dbpath, coercedpath, MAX_PATH_CHARS);
#endif
		
		atom_setsym(av+ac, gensym("@rambased"));
		ac++;
		atom_setlong(av+ac, 0);
		ac++;
		atom_setsym(av+ac, gensym("@filename"));
		ac++;
		atom_setsym(av+ac, gensym(dbpath));
		ac++;
	}
	atom_setsym(av+ac, gensym("@db"));
	ac++;
	atom_setsym(av+ac, dbname);
	ac++;
	
	*db = (t_database*)object_new_typed(_sym_nobox, _sym_sqlite, ac, av);
	if (!*db)
		return MAX_ERR_GENERIC;
	
	return MAX_ERR_NONE;
}
Exemplo n.º 15
0
void ep_print_credit()
{
    if(gensym("ep_print_credits")->s_thing == NULL)
    {
		t_object* print;
		t_atom* sym = (t_atom*) malloc( sizeof(t_atom));
		atom_setsym(sym, gensym("EpLib Beta 0.1"));
		print = (t_object*)object_new_typed(CLASS_BOX, gensym("print"), 1, sym);
		atom_setsym(sym, gensym("Copyright \u00a9 2014, Eliott Paris"));
		object_method_typed(print, gensym("list"), 1, sym, NULL);
		gensym("hoa_print_credits")->s_thing = print;
		freeobject(print);
		free(sym);
    }
}
Exemplo n.º 16
0
void return_makesend(t_return *x)
{
	t_atom		a;
	char		osc[512];
	t_symbol*	module_name = object_attr_getsym(x->common.hub, _sym_name);

	if (module_name && module_name != _sym_nothing) {
		strcpy(osc, module_name->s_name);
		strcat(osc, "/");
		strcat(osc, x->common.attr_name->s_name);
		atom_setsym(&a, gensym(osc));
		x->send = (t_object*)object_new_typed(_sym_box, jps_jcom_send, 1, &a);
	}
	else
		defer_low(x, (method)return_makesend, 0, 0, 0);
}
Exemplo n.º 17
0
void *play_new(t_symbol *s, int argc, t_atom *argv)
{
    // @arg 0 @ambisonic-order @optional 0 @type int @digest The ambisonic order
    // @description The ambisonic order, must be at least equal to 1

	t_atom arguments[1];
	ulong order = 1;
	ulong channels = 1;
    
	if(atom_isNumber(argv))
		order = max<ulong>(atom_getlong(argv), 1);
	
	if (s == gensym("hoa.play~") || s == gensym("hoa.2d.play~"))
		channels = order * 2 + 1;
	else if (s == gensym("hoa.3d.play~"))
		channels = (order+1) * (order+1);
    
	return object_new_typed(CLASS_BOX, gensym("sfplay~"), 1, arguments);
}
Exemplo n.º 18
0
	void *NewObj(t_symbol *s, long argc, t_atom *argv){
		
		OBJECT *x = NULL;
		x = (OBJECT *)object_alloc(g_class);
		
		if (x != NULL){
			dsp_setup ((t_pxobject *)x, 0);

			outlet_new((t_pxobject *)x, "signal");

			x -> glitched = true;
			coreobject = (t_object *)object_new_typed(CLASS_NOBOX,
					gensym("__ray.sniff~_core__"), argc, argv);
  		}
		else
			post("Can't Allocate Object");
		
		return x;
	}	
Exemplo n.º 19
0
void *hoa_dac_new(t_symbol *s, int argc, t_atom *argv)
{
    // @arg 0 @name outputs @optional 1 @type int/symbol @digest Output routing or/and bus name
    // @description You can create a <o>hoa.dac~</o> object that uses one or more audio output channel numbers between 1 and 512. These numbers refer to logical channels and can be dynamically reassigned to physical device channels of a particular driver using either the Audio Status window, its I/O Mappings subwindow, or an adstatus object with an output keyword argument. Arguments, If the computer's built-in audio hardware is being used, there will be two input channels available. Other audio drivers and/or devices may have more than two channels. If no argument is typed in, dac~ will have two inlets, for input channels 1 and 2.
    // If a symbol is provided as the first argument to a dac~ object, then it will get an independent control section in the Max mixer. If two dac~ instances in a patcher hierarchy have the same name they will be on the same "bus" and share controls.
    
	int i, j, count = 0;
	t_hoa_dac *x;
	t_atom channels[512];
	int min, max;
    int symPrepend = 0;
    
    x = (t_hoa_dac *)object_alloc(hoa_dac_class);
    
    if (x)
    {
        if (argc && atom_gettype(argv) == A_SYM)
        {
            char *dac_bus_name = atom_getsym(argv)->s_name;
            if (isalpha(dac_bus_name[0])) // only works if the first letter isn't a number
            {
                symPrepend = 1;
                atom_setsym(channels, atom_getsym(argv));
            }
        }
        
        for(i = 0; i < (argc-symPrepend); i++)
        {
            if(atom_gettype(argv+i+symPrepend) == A_SYM)
            {
                min = atoi(atom_getsym(argv+i+symPrepend)->s_name);
                if (min < 10)
                    max = atoi(atom_getsym(argv+i+symPrepend)->s_name+2);
                else if (min < 100)
                    max = atoi(atom_getsym(argv+i+symPrepend)->s_name+3);
                else if (min < 1000)
                    max = atoi(atom_getsym(argv+i+symPrepend)->s_name+4);
                else
                    max = atoi(atom_getsym(argv+i+symPrepend)->s_name+5);
                if (max > min)
                {
                    for(j = min; j <= max; j++)
                    {
                        atom_setlong(channels + symPrepend + count++, j);
                    }
                }
                else
                {
                    for(j = min; j >= max; j--)
                    {
                        atom_setlong(channels + symPrepend + count++, j);
                    }
                }
            }
            else if(atom_gettype(argv + symPrepend + i) == A_LONG)
            {
                atom_setlong(channels + symPrepend + count++, atom_getlong(argv + symPrepend + i));
            }
        }
        
        x->f_number_of_channels = count;
        dsp_setup((t_pxobject *)x, x->f_number_of_channels);
        x->f_dac = (t_object *)object_new_typed(CLASS_BOX, gensym("dac~"), count + symPrepend, channels);
    }
	
    return x->f_dac;
	//return x;
}
Exemplo n.º 20
0
void *hub_new(t_symbol *s, long argc, t_atom *argv)
{
	short			i;
	long			attrstart = attr_args_offset(argc, argv);
	t_hub			*x = (t_hub *)object_alloc(s_hub_class);
	t_symbol		*name = _sym_nothing;
	t_atom			a[2];
	
	if(attrstart && argv)
		atom_arg_getsym(&name, 0, attrstart, argv);
	else{
		t_object*	patcher = jamoma_object_getpatcher((t_object*)x);
		t_symbol*	filepath = object_attr_getsym(patcher, _sym_filepath);
		char		pathstr[MAX_PATH_CHARS];
		char*		filename = 0;
		
		strncpy_zero(pathstr, filepath->s_name, MAX_PATH_CHARS);
		filename = strrchr(pathstr, '.');
		if(filename) {
			*filename = 0;	// strip the suffix by setting '.' to terminating NULL char
			filename = strrchr(pathstr, '/');
			if (filename) {
				// Our module name is the patchers name since the patcher is typically located
				// at /some/where/nameToUseForModule.maxpat
				filename++; // get rid of slash
				name = gensym(filename);
			}
			else
				name = gensym(pathstr);
		} else {
			// We are an unnamed jcom.hub inserted into an unsaved max patcher which has
			// no '.' in it's filename.  Just leave as untitled, at least until it is saved.
			name = gensym("Untitled");
		}
	}
		
	if(x){
		for(i=k_num_outlets; i > 0; i--)
			x->outlets[i-1] = outlet_new(x, 0);
		object_obex_store((void *)x, _sym_dumpout, (t_object *)x->outlets[k_outlet_dumpout]);
		x->init_qelem = qelem_new(x, (method)hub_qfn_init);

		// set default attributes
		x->attr_name = name;
		x->osc_name = _sym_nothing;
		x->attr_type = jps_control;
		x->attr_description = _sym_nothing;
		x->attr_algorithm_type = jps_default;		// poly for audio, jitter for video, control for control
		x->attr_size = jps_1U_half;
		x->attr_inspector = 0;
		x->using_wildcard = false;
		x->in_object = NULL;						// module MUST have a jcom.in object
		x->out_object = NULL;						// the jcom.out object is optional
		x->gui_object = NULL;						// jcom.remote in the gui
		x->num_parameters = 0;
		for(i=0; i<MAX_NUM_CHANNELS; i++)
			x->meter_object[i] = NULL;
		
		x->preset = new presetList;					// begin with no presets
		x->subscriber = new subscriberList;			// ... and no subscribers
		
		attr_args_process(x, argc, argv);			// handle attribute args
		
		x->jcom_send = NULL;
		x->jcom_receive = NULL;
		atom_setsym(a, jps_jcom_remote_fromModule);
		x->jcom_send = (t_object*)object_new_typed(_sym_box, jps_jcom_send, 1, a);
		
		atom_setsym(a, jps_jcom_remote_toModule);
		x->jcom_receive = (t_object*)object_new_typed(_sym_box, jps_jcom_receive, 1, a);
		object_method(x->jcom_receive, jps_setcallback, &hub_receive_callback, x);
					
		if(!g_jcom_send_notifications){
			atom_setsym(a, gensym("notifications"));
			g_jcom_send_notifications = (t_object*)object_new_typed(_sym_box, jps_jcom_send, 1, a);
		}
		
		x->container = jamoma_object_getpatcher((t_object*)x);
		
		// The following must be deferred because we have to interrogate our box,
		// and our box is not yet valid until we have finished instantiating the object.
		// Trying to use a loadbang method instead is also not fully successful (as of Max 5.0.6)
		defer_low(x, (method)hub_examine_context, 0, 0, 0);
	}
	return x;
}
Exemplo n.º 21
0
void filecontainer_doopen(t_filecontainer *x, t_symbol *arg)
{
    t_atom			a[4];
    int				err = 0;
    char			filename[256];
    short			path;
    t_fourcc		outtype = 0;
    t_fourcc		type = 'cO0p';
#ifdef MAC_VERSION
    char			*temppath;
    FSRef			ref;
    Boolean			isDir;
    FSCatalogInfo	catalogInfo;
#else // WIN_VERSION
    char			temppath[512];
#endif
    char			fullpath[512];
    t_object		*result = NULL;
    t_object		*result2 = NULL;
    char			**record = NULL;		// sqlite records
    char			**record2 = NULL;		// sqlite records
    t_filehandle	file_handle;
    t_ptr_size		len = 0;
    char			*blob;
    char			sql[512];

    if(!arg || !arg->s_name[0]) {
        if(open_dialog(filename, &path, &outtype, NULL, -1))			// Returns 0 if successful
            return;
    }
    else {
        t_fourcc typelist[1];
        typelist[0] = 'cO0p';
        strcpy(filename, arg->s_name);
        path = 0;
        locatefile_extended(filename, &path, &type, typelist, 0);
    }
    path_topotentialname(path, filename, fullpath, 0);
#ifdef MAC_VERSION
    temppath = strchr(fullpath, ':');
    temppath += 1;
#else // WIN_VERSION
    path_nameconform(fullpath, temppath, PATH_STYLE_NATIVE_WIN, PATH_TYPE_ABSOLUTE);
#endif
    x->name = gensym(temppath);

    // Create our temp folder for extracted files
    filecontainer_gettemppath(x);

    // Create the SQLite instance
    atom_setsym(&a[0], gensym("@rambased"));
    atom_setlong(&a[1], 0);
    atom_setsym(&a[2], gensym("@db"));
    atom_setsym(&a[3], x->name);
    x->sqlite = object_new_typed(CLASS_NOBOX, _sym_sqlite, 4, a);

    // Operate on the open DB
    if(x->sqlite) {
        object_method(x->sqlite, ps_starttransaction);
        object_method(x->sqlite, _sym_execstring, TABLEDEF_FILES, NULL);
        object_method(x->sqlite, _sym_execstring, TABLEDEF_ATTRS, NULL);

        object_method(x->sqlite, _sym_execstring, "UPDATE files SET valid = 1", NULL);
        object_method(x->sqlite, _sym_execstring, "SELECT file_id, filename, moddate FROM files", &result);
        while(record = (char **)object_method(result, _sym_nextrecord)) {
            // Here we check for the optional 'platform' attr for this file.
            // If a flag exists for the other platform, but not for the current platform, then we ignore this file.
#ifdef MAC_VERSION
            sprintf(sql, "SELECT file_id_ext FROM attrs \
							WHERE attr_name = 'platform' AND attr_value = 'windows' AND file_id_ext = %s ", record[0]);
            object_method(x->sqlite, _sym_execstring, sql, &result2);
            record2 = (char **)object_method(result2, _sym_nextrecord);
            if(record2) {
                sprintf(sql, "SELECT file_id_ext FROM attrs \
								WHERE attr_name = 'platform' AND attr_value = 'mac' AND file_id_ext = %s ", record[0]);
                object_method(x->sqlite, _sym_execstring, sql, &result2);
                record2 = (char **)object_method(result2, _sym_nextrecord);
                if(!record2) {
                    sprintf(sql, "UPDATE files SET valid = 0 WHERE file_id = %s ", record[0]);
                    object_method(x->sqlite, _sym_execstring, sql, NULL);
                    continue;
                }
            }
#else // WIN_VERSION
            snprintf(sql, 512, "SELECT file_id_ext FROM attrs \
							WHERE attr_name = 'platform' AND attr_value = 'mac' AND file_id_ext = %s ", record[0]);
            object_method(x->sqlite, _sym_execstring, sql, &result2);
            record2 = (char **)object_method(result2, _sym_nextrecord);
            if(record2) {
                snprintf(sql, 512, "SELECT file_id_ext FROM attrs \
								WHERE attr_name = 'platform' AND attr_value = 'windows' AND file_id_ext = %s ", record[0]);
                object_method(x->sqlite, _sym_execstring, sql, &result2);
                record2 = (char **)object_method(result2, _sym_nextrecord);
                if(!record2) {
                    snprintf(sql, 512, "UPDATE files SET valid = 0 WHERE file_id = %s ", record[0]);
                    object_method(x->sqlite, _sym_execstring, sql, NULL);
                    continue;
                }
            }
#endif
            // At this point we have a file (record[0]), and we have determined that it is indeed a file we want to cache
            // So cache it to a new file in our temp path
            err = path_createsysfile(record[1], x->temp_path, type, &file_handle);
            if(err) {																// Handle any errors that occur
                object_error((t_object *)x, "%s - error %d creating file", filename, err);
            }
            else {
                snprintf(sql, 512, "SELECT content FROM files WHERE file_id = %s", record[0]);
                object_method(x->sqlite, ps_getblob, sql, &blob, &len);
                err = sysfile_write(file_handle, &len, blob);
                if(err) {
                    object_error((t_object *)x, "sysfile_write error (%d)", err);
                }
            }
            err = sysfile_seteof(file_handle, len);
            if(err) {
                object_error((t_object *)x, "%s - error %d setting EOF", filename, err);
            }
            sysfile_close(file_handle);		// close file reference
            sysmem_freeptr(blob);
            blob = NULL;

            // Set the moddate
#ifdef MAC_VERSION
//			FSCatalogInfo		catalogInfo;
//			Boolean             status;
            CFGregorianDate     gdate;
            CFAbsoluteTime      abstime;
            CFTimeZoneRef		tz;
            UTCDateTime			utc;

            sscanf(record[2], "%4ld-%02hd-%02hd %02hd:%02hd:%02lf", &gdate.year, (signed short*)&gdate.month, (signed short*)&gdate.day,
                   (signed short*)&gdate.hour, (signed short*)&gdate.minute, &gdate.second);
            tz = CFTimeZoneCopySystem();
            abstime = CFGregorianDateGetAbsoluteTime(gdate, tz);
            UCConvertCFAbsoluteTimeToUTCDateTime(abstime, &utc);
            catalogInfo.contentModDate = utc;

            strcpy(s_tempstr, x->temp_fullpath->s_name);
            temppath = strchr(s_tempstr, ':');
            temppath++;
            strcat(temppath, "/");
            strcat(temppath, record[1]);
            FSPathMakeRef((UInt8*)temppath, &ref, &isDir);
            err = FSSetCatalogInfo(&ref, kFSCatInfoContentMod, &catalogInfo);

#else // WIN_VERSION
            char				winpath[512];
            HANDLE				hFile;
            FILETIME			fileTime;
            SYSTEMTIME			systemTime;

            sscanf(record[2], "%4lu-%02lu-%02lu %02lu:%02lu:%02lu", &systemTime.wYear, &systemTime.wMonth, &systemTime.wDay,
                   &systemTime.wHour, &systemTime.wMinute, &systemTime.wSecond);
            err = SystemTimeToFileTime(&systemTime, &fileTime);

            strcpy(s_tempstr, x->temp_fullpath->s_name);
            path_nameconform(s_tempstr, winpath, PATH_STYLE_NATIVE_WIN, PATH_TYPE_ABSOLUTE);
            strcat(winpath, "\\");
            strcat(winpath, record[1]);
            hFile = CreateFile((LPCSTR)winpath , GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
            if(hFile == INVALID_HANDLE_VALUE) {
                object_error((t_object *)x, "invalid handle value");
                goto out;
            }
            err = SetFileTime(hFile, &fileTime, &fileTime, &fileTime);
            if(err == 0) {
                err = GetLastError();
                object_error((t_object *)x, "Error setting date: %i", err);
            }
            CloseHandle(hFile);
out:
            ;
#endif
        }
        object_method(x->sqlite, ps_endtransaction);
    }
Exemplo n.º 22
0
int main(void)
{
	common_symbols_init();
	PlugtasticInit();

	plugtastic_classinit();
	sPlugtasticObject = (t_object*)plugtastic_new();
	ps_plugtastic = GENSYM("plugtastic");
	ps_plugtastic->s_thing = sPlugtasticObject;

	sMaxObject = _sym_max->s_thing;
	ps_objectfile				= GENSYM("objectfile");
	ps_db_object_addinternal	= GENSYM("db.object_addinternal");
	ps_oblist					= GENSYM("oblist");
	ps_db_addmetadata			= GENSYM("db.addmetadata");
	
	//defer_low(sMaxObject, (method)plug_setup_db, NULL, 0, NULL);
	plug_setup_db();
	
	post("Plugtastic                                            Version %s | 74Objects.com", PLUGTASTIC_VERSION);
	

	// This tells Max 5.0.6 and higher that we want the patcher files to be saved such that they are sorted.
	// Having the saved this way makes our SVN diffs much more meaningful.
	object_method_long(sMaxObject, GENSYM("sortpatcherdictonsave"), 1, NULL);
	
	// This tells Max 4.5.7 and higher to take any posts to the Max window and also make the
	// post to the system console, which greatly aids in debugging problems and crashes
	object_method_long(sMaxObject, GENSYM("setmirrortoconsole"), 1, NULL);
	
	
	// OPEN THE SPLASH
	
	if (sPlugtasticSplash) {
		char			name[MAX_FILENAME_CHARS];
		short			path = 0;
		long			type = 0;
		long			typelist[2] = {'JSON', 'TEXT'};
		short			err;
		t_dictionary*	d;
		t_object*		p;
		t_atom			a[2];
		
		strncpy_zero(name, "Plugtastic.maxpat", MAX_FILENAME_CHARS);
		err = locatefile_extended(name, &path, &type, typelist, 2);
		dictionary_read(name, path, &d);
		
		atom_setobj(a, d);
		p = (t_object*)object_new_typed(_sym_nobox, _sym_jpatcher, 1, a);
		object_attr_setlong(p, _sym_locked, 1);			// start out locked
		object_attr_setchar(p, _sym_enablehscroll, 0);		// turn off scroll bars
		object_attr_setchar(p, _sym_enablevscroll, 0);
		object_attr_setchar(p, _sym_toolbarvisible, 0);	
		object_attr_setsym(p, _sym_title, gensym("Welcome to Plugtastic"));		
		object_attr_setparse(p, _sym_rect, "271 170 799 489");
		object_attr_setparse(p, _sym_defrect, "271 170 799 489");

		object_method(p, _sym_vis);	// "vis" happens immediately, "front" is defer_lowed
		object_method(p, _sym_loadbang);

//		object_method_parse(p, _sym_window, "constrain 799 489 799 489", NULL);
		object_method_parse(p, _sym_window, "flags nozoom", NULL);
		object_method_parse(p, _sym_window, "flags nogrow", NULL);
		object_method_parse(p, _sym_window, "exec", NULL);
	}	
	
	
	return 0;
}