Exemplo n.º 1
0
/*------------------------------------ releaseObjectMemory ---*/
void
releaseObjectMemory(UdpObjectData * xx)
{
    if (xx)
    {
        if (xx->fErrorQueue)
        {
            qelem_unset(xx->fErrorQueue);
            qelem_free(xx->fErrorQueue);
            xx->fErrorQueue = NULL;
        }
        if (xx->fReceiveQueue)
        {
            qelem_unset(xx->fReceiveQueue);
            qelem_free(xx->fReceiveQueue);
            xx->fReceiveQueue = NULL;
        }
        xx->fReceiveBuffer = xx->fSendBuffer = NULL;
        if (xx->fBufferBase)
        {
            sysmem_lockhandle(reinterpret_cast<t_handle>(xx->fBufferBase), 0);
            sysmem_freehandle(reinterpret_cast<t_handle>(xx->fBufferBase));
            xx->fBufferBase = NULL;
        }
        xx->fReceiveHead = xx->fReceiveTail = xx->fPoolHead = xx->fPoolTail = NULL;
        if (xx->fLinkBase)
        {
            sysmem_lockhandle(reinterpret_cast<t_handle>(xx->fLinkBase), 0);
            sysmem_freehandle(reinterpret_cast<t_handle>(xx->fLinkBase));
            xx->fLinkBase = NULL;
        }
    }
} // releaseObjectMemory
Exemplo n.º 2
0
void filein_close(t_filein *x)
{
	if (x->f_open) {
		sysfile_close(x->f_fh);
		x->f_fh = 0;
		x->f_open = FALSE;
	}
	if (x->f_data) {
		sysmem_lockhandle((t_handle)x->f_data,0);
		sysmem_freehandle((t_handle)x->f_data);
		x->f_data = 0;
	}
}
Exemplo n.º 3
0
int lua_importfile(lua_State *L)
{
	const char *filename;
	long outtype;
	short file_volume, err;
	
	if(!lua_isstring(L, 1))
		luaL_error(L, "argument 1 for outlet must be a string");

	filename = lua_tostring(L, 1);
	err = locatefile_extended(filename, &file_volume, &outtype, 0, 0);
	
	if(err) {
		error("jit.gl.lua: can't find file %s", filename);
	}
	else {
		// read file from disk
		long count;
		char **texthandle;
		t_filehandle fh;
		
		err = path_opensysfile(filename, file_volume, &fh, READ_PERM);
		if (err) {
			error("jit.gl.lua: %s: error %d opening file", filename, err);
			return 0;
		}
		
		texthandle = sysmem_newhandle(0);
		sysfile_readtextfile(fh, texthandle, 0, TEXT_LB_NATIVE);
		sysfile_close(fh);
		count = sysmem_handlesize(texthandle);
		sysmem_resizehandle(texthandle, count + 1);
		(*texthandle)[count] = 0; //NULL terminate, '\0'?
		
		//run file in Lua
		err = luaL_loadstring(L, *texthandle);
		err = lua_pcall(L, 0, LUA_MULTRET, 0);
		
		if (err) {
			post("lua pcall error %s", lua_tostring(L, -1));
			lua_pop(L, 1);
		}
		
		sysmem_lockhandle(texthandle, false);
		sysmem_freehandle(texthandle);
	}

	return 0;
}
Exemplo n.º 4
0
void jsusfx_dblclick(t_jsusfx *x) {
    if (!x->m_editor) {
        t_filehandle fh_read;
        if ( path_opensysfile(x->scriptname, x->path, &fh_read, READ_PERM) ) {
            error("jsusfx~: unable to script file");
            return;
        }
        t_handle texthandle;
        texthandle = sysmem_newhandle(0);
        sysfile_readtextfile(fh_read, texthandle, 0, TEXT_NULL_TERMINATE);
		x->m_editor = reinterpret_cast<t_object *>(object_new(CLASS_NOBOX, gensym("jed"), (t_object *)x, 0));
        object_attr_setchar(x->m_editor, gensym("scratch"), 1);
        object_method(x->m_editor, gensym("settext"), *texthandle, gensym("utf-8"));
        object_method(x->m_editor, gensym("filename"), x->scriptname, x->path);
        sysmem_freehandle(texthandle);
		sysfile_close(fh_read);
    } else {
        object_attr_setchar(x->m_editor, gensym("visible"), 1);
    }
}
Exemplo n.º 5
0
void jit_gl_lua_free(t_jit_gl_lua *x)
{
	/* call closebang method on script if it exists*/
	jit_gl_lua_closebang(x);

	/* Remember to destroy the Lua State */
	lua_close(x->lua);
	
	//free handle on script data
	if (x->texthandle) {
		//HUnlock(x->texthandle);
		sysmem_lockhandle(x->texthandle, false);
		//DisposeHandle(x->texthandle);
		sysmem_freehandle(x->texthandle);
	}
	
	if (x->file_watcher) {
		freeobject((t_object *)x->file_watcher);
		x->file_watcher = NULL;
	}
	
	jit_ob3d_free(x);
}
Exemplo n.º 6
0
void *jsusfx_new(t_symbol *notused, long argc, t_atom *argv) {
	if ( argc < 1 || atom_gettype(argv) != A_SYM ) {
		error("jsusfx~: missing script name");
		return NULL;
	}
    
	t_jsusfx *x = reinterpret_cast<t_jsusfx *>(object_alloc(jsusfx_class));
	t_symbol *s = atom_getsym(argv);
    t_fourcc filetype = 'TEXT', outtype;
    short path;
    char filename[MAX_PATH_CHARS];
    
    strcpy(filename, s->s_name);
    
    if (locatefile_extended(filename, &path, &outtype, &filetype, 1)) {
        t_object *mypatcher;
        object_obex_lookup(x, gensym("#P"), &mypatcher);
        t_symbol *checkExists = object_attr_getsym(mypatcher, gensym("filepath"));
        
        if ( checkExists->s_name[0] == 0 ) {
            error("jsusfx~: patch needs to be saved in order to create new jsusfx script file");
            return NULL;
        }
        
        path = path_getdefault();
                
        t_fourcc type = 'TEXT';
        t_filehandle ref;

        if ( path_createsysfile(filename, path, type, &ref) ) {
            error("jsusfx~: unable to create file");
            return NULL;
        }

        char initText[] = "@sample\nspl0=1\nspl1=-1\n";
        t_handle h = sysmem_newhandle(0);
        sysmem_ptrandhand(initText,h,strlen(initText));
        
        if ( sysfile_writetextfile(ref, h, TEXT_LB_NATIVE) ) {
            error("jsusfx~: unable to write file");
            return NULL;
        }
        
        sysfile_close(ref);
        sysmem_freehandle(h);
    }
    
    strcpy(x->scriptname, filename);
    x->path = path;
    
    char fullpath[MAX_PATH_CHARS];
    path_toabsolutesystempath(path, filename, fullpath);
    std::ifstream is(fullpath);
	if ( ! is.is_open() ) {
		error("jsusfx~: error opening file %s", fullpath);
		return NULL;
	}
    
    x->bypass = false;
    dsp_setup((t_pxobject *)x, 2);
    x->outlet1 = outlet_new((t_object *)x, NULL);
	outlet_new((t_object *)x, "signal");
    outlet_new((t_object *)x, "signal");
    
	critical_new(&(x->critical));
	x->m_editor = NULL;
    JsusFxMax *fx = new JsusFxMax();
    fx->compile(is);
    x->fx = fx;

    /*if ( argc >= 2 && atom_gettype(argv+1) == A_LONG ) {
		x->fx->normalizeSliders = atom_getlong(argv+1);
	} else {
        x->fx->normalizeSliders = 1;
    }
    
    post("normalizer sl %x", x->fx->normalizeSliders);*/
    
	return (x);
}