/*------------------------------------ map1dLoadRangeList ---*/ bool map1dLoadRangeList(Map1dData * xx, t_symbol * fileName) { bool result = false; t_filehandle fileRef; if (path_opensysfile(fileName->s_name, path_getdefault(), &fileRef, PATH_READ_PERM)) { LOG_ERROR_2(xx, OUTPUT_PREFIX "problem opening file '%s'", fileName->s_name) } else { t_handle fileContents = sysmem_newhandle(0); if (sysfile_readtextfile(fileRef, fileContents, 0, TEXT_LB_NATIVE)) { LOG_ERROR_2(xx, OUTPUT_PREFIX "problem reading file '%s'", fileName->s_name) } else if (binbuf_text(xx->fBuffer, fileContents, sysmem_handlesize(fileContents))) { post("problem processing"); LOG_ERROR_2(xx, OUTPUT_PREFIX "problem converting file '%s'", fileName->s_name) } else {
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; }
void filein_open(t_filein *x, char *name) { long size; if (x->f_spool) x->f_open = TRUE; else { sysfile_geteof(x->f_fh,&size); if (!(x->f_data = (Byte **)sysmem_newhandle(size))) object_error((t_object *)x, "%s too big to read",name); else { sysmem_lockhandle((t_handle)x->f_data,1); sysfile_read(x->f_fh,&size,*x->f_data); x->f_size = size; } sysfile_close(x->f_fh); } x->f_spool = FALSE; }
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); } }
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); }
/*------------------------------------ initObject ---*/ bool initObject(UdpObjectData * xx, const long port, const long numBuffers) { bool okSoFar = true; if (xx) { long buffSize = static_cast<long>(BUFF_MEMORY_TO_ALLOC * (numBuffers + 2)); xx->fSelfPort = static_cast<unsigned short>(port ? port : DEFAULT_PORT); memset(&xx->fPartnerAddress, 0, sizeof(xx->fPartnerAddress)); xx->fPartnerPort = 0; xx->fPartnerKnown = false; xx->fErrorBangOut = static_cast<t_outlet *>(bangout(xx)); xx->fResultOut = static_cast<t_outlet *>(outlet_new(xx, NULL)); setObjectState(xx, kUdpStateUnbound); xx->fSocket = NULL; xx->fErrorQueue = MAKE_QELEM(xx, processErrorQueue); xx->fReceiveQueue = MAKE_QELEM(xx, processReceiveQueue); xx->fBufferBase = reinterpret_cast<DataBuffer **>(sysmem_newhandle(buffSize)); if (xx->fBufferBase) { sysmem_lockhandle(reinterpret_cast<t_handle>(xx->fBufferBase), 1); xx->fSendBuffer = *xx->fBufferBase; xx->fReceiveBuffer = reinterpret_cast<DataBuffer *>(ADD_TO_ADDRESS(xx->fSendBuffer, BUFF_MEMORY_TO_ALLOC)); } xx->fLinkBase = MAKE_TYPED_HANDLE(UdpBufferLink, numBuffers); if (xx->fLinkBase) { DataBuffer * this_buffer = reinterpret_cast<DataBuffer *>(ADD_TO_ADDRESS(xx->fReceiveBuffer, BUFF_MEMORY_TO_ALLOC)); UdpBufferLink * prev_link = NULL; UdpBufferLink * this_link = NULL; sysmem_lockhandle(reinterpret_cast<t_handle>(xx->fLinkBase), 1); xx->fPoolHead = *xx->fLinkBase; this_link = xx->fPoolHead; for (long link_count = 0; link_count < numBuffers; ++link_count) { this_link->fPrevious = prev_link; this_link->fData = this_buffer; this_buffer = reinterpret_cast<DataBuffer *>(ADD_TO_ADDRESS(this_buffer, BUFF_MEMORY_TO_ALLOC)); this_link->fNext = NULL; if (prev_link) { prev_link->fNext = this_link; } prev_link = this_link; this_link = reinterpret_cast<UdpBufferLink *>(ADD_TO_ADDRESS(this_link, sizeof(UdpBufferLink))); } xx->fPoolTail = prev_link; } xx->fClosing = xx->fRawMode = false; if (! (xx->fResultOut && xx->fErrorBangOut && xx->fErrorQueue && xx->fBufferBase && xx->fReceiveQueue && xx->fLinkBase)) { LOG_ERROR_1(xx, OUTPUT_PREFIX "unable to create port or buffer for object") okSoFar = false; } } return okSoFar; } // initObject