void jsusfx_compile(t_jsusfx *x, t_symbol *notused, long argc, t_atom *argv) { // new file if ( argc >= 1 && atom_gettype(argv) == A_SYM ) { t_fourcc filetype = 'TEXT', outtype; short path; char filename[MAX_PATH_CHARS]; strcpy(filename, atom_getsym(argv)->s_name); if (locatefile_extended(filename, &path, &outtype, &filetype, 1)) { error("jsusfx~: script %s not found", filename); return; } if ( x->m_editor ) { object_method(x->m_editor, gensym("w_close")); x->m_editor = NULL; } strncpy(x->scriptname, filename, MAX_PATH_CHARS); x->path = path; } char fullpath[1024]; path_toabsolutesystempath(x->path, x->scriptname, fullpath); std::ifstream is(fullpath); if ( ! is.is_open() ) { error("jsusfx~: error opening file %s", fullpath); return; } critical_enter(x->critical); if ( x->fx->compile(is) == true ) { x->fx->prepare(sys_getsr(), sys_getmaxblksize()); } critical_exit(x->critical); }
void breakgen_writefile(t_breakgen *x, t_symbol *s, long argc, t_atom *argv) { t_atom *ap; long num_frames; // t_max_err buferror; float frame; int i; FILE *break_out; float amp = 1.0; short path; char ps[MAX_FILENAME_CHARS] = ""; char finalpath[MAX_PATH_CHARS]; ap = argv; // if (atom_gettype(ap) == A_SYM) { // if (atom_getsym(ap) != gensym("")) { // *ps = atom_getsym(ap); // } // } // strcpy(ps, ""); if (saveas_dialog(ps,&path,NULL)) { return; } path_toabsolutesystempath(path, ps, finalpath); post(finalpath); if (atom_gettype(ap) == A_LONG) { if ((break_out = fopen(finalpath, "w"))) { post("file opened"); num_frames = atom_getlong(ap); post("%i", argc); if (argc > 1) { ap++; if ( (atom_gettype(ap) == A_FLOAT) && (atom_getfloat(ap) < 1.0) ) { amp = atom_getfloat(ap); } } for (i = 0; i < num_frames; i++) { frame = ((output_val(x) - 1) * amp) + 1; fprintf(break_out, "%f", frame); if (i + 1 != num_frames) { fprintf(break_out, "\n"); } } fclose(break_out); post("file closed"); } else { post("couldn't create file"); } } else { post("wrong atom type"); } }
void testdb_setup(t_testdb *d) { if (!d->d_db) { short path = packages_getpackagepath("testpackage"); char fullpath[MAX_PATH_CHARS]; short apppath = path_getapppath(); char appfullpath[MAX_PATH_CHARS]; unsigned long appfullpathlen; int i; char dbfilename[MAX_PATH_CHARS]; t_db_result *dbresult = NULL; path_topathname(apppath, "", appfullpath); appfullpathlen = strlen(appfullpath); for (i=0; i<appfullpathlen; i++) { if (appfullpath[i] == ':' || appfullpath[i] == '/') appfullpath[i] ='-'; } strncpy_zero(dbfilename, appfullpath, MAX_PATH_CHARS); strncat_zero(dbfilename, "--maxtestresults.db3", MAX_PATH_CHARS); path_topathname(path, "", fullpath); strncat_zero(fullpath, "/", MAX_PATH_CHARS); strncat_zero(fullpath, dbfilename, MAX_PATH_CHARS); db_open(gensym("unittestdb"), fullpath, &d->d_db); // cache the fullpath so it can be requested from the outside world { short apath; char afilename[MAX_FILENAME_CHARS]; path_frompathname(fullpath, &apath, afilename); path_toabsolutesystempath(apath, afilename, g_dbpath); } db_query(d->d_db, &dbresult, "SELECT name FROM sqlite_master WHERE type='table' AND name='tests'"); if (!db_result_numrecords(dbresult)) { db_query_table_new(d->d_db, "tests"); db_query_table_addcolumn(d->d_db, "tests", "test_name", "VARCHAR(512)", 0); db_query_table_addcolumn(d->d_db, "tests", "test_start", "DATETIME", 0); db_query_table_addcolumn(d->d_db, "tests", "test_finish", "DATETIME", 0); db_query_table_new(d->d_db, "assertions"); db_query_table_addcolumn(d->d_db, "assertions", "test_id_ext", "INTEGER", 0); db_query_table_addcolumn(d->d_db, "assertions", "assertion_name", "VARCHAR(512)", 0); db_query_table_addcolumn(d->d_db, "assertions", "assertion_value", "VARCHAR(512)", 0); db_query_table_addcolumn(d->d_db, "assertions", "assertion_data", "VARCHAR(512)", 0); db_query_table_addcolumn(d->d_db, "assertions", "assertion_start", "DATETIME", 0); db_query_table_addcolumn(d->d_db, "assertions", "assertion_finish", "DATETIME", 0); db_query_table_addcolumn(d->d_db, "assertions", "assertion_tags", "VARCHAR(512)", 0); db_query_table_new(d->d_db, "logs"); db_query_table_addcolumn(d->d_db, "logs", "test_id_ext", "INTEGER", 0); db_query_table_addcolumn(d->d_db, "logs", "text", "VARCHAR(512)", 0); db_query_table_addcolumn(d->d_db, "logs", "timestamp", "DATETIME", 0); } object_free(dbresult); } }
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); }