static void *mtr_new(t_floatarg f) { t_mtr *x = 0; int ntracks = (int)f; t_mtrack **tracks; if (ntracks < 1) ntracks = 1; if (tracks = getbytes(ntracks * sizeof(*tracks))) { int i; t_mtrack **tpp; for (i = 0, tpp = tracks; i < ntracks; i++, tpp++) { if (!(*tpp = (t_mtrack *)pd_new(mtrack_class)) || !((*tpp)->tr_binbuf = binbuf_new()) || !((*tpp)->tr_clock = clock_new(*tpp, (t_method)mtrack_tick))) { if (*tpp) pd_free((t_pd *)*tpp); if ((*tpp)->tr_binbuf) binbuf_free((*tpp)->tr_binbuf); while (i--) { tpp--; binbuf_free((*tpp)->tr_binbuf); clock_free((*tpp)->tr_clock); pd_free((t_pd *)*tpp); } return (0); } } if (x = (t_mtr *)pd_new(mtr_class)) { int id; t_outlet *mainout = outlet_new((t_object *)x, &s_list); x->x_glist = canvas_getcurrent(); x->x_filehandle = hammerfile_new((t_pd *)x, 0, mtr_readhook, mtr_writehook, 0); if (ntracks > MTR_C74MAXTRACKS) fittermax_rangewarning(mtr_class, MTR_C74MAXTRACKS, "tracks"); x->x_ntracks = ntracks; x->x_tracks = tracks; for (id = 1; id <= ntracks; id++, tracks++) /* CHECKED 1-based */ { t_mtrack *tp = *tracks; inlet_new((t_object *)x, (t_pd *)tp, 0, 0); tp->tr_trackout = outlet_new((t_object *)x, &s_); tp->tr_mainout = mainout; tp->tr_owner = x; tp->tr_id = id; tp->tr_listed = 0; tp->tr_filehandle = /* LATER rethink */ hammerfile_new((t_pd *)tp, 0, mtrack_readhook, mtrack_writehook, 0); tp->tr_mode = MTR_STEPMODE; tp->tr_muted = 0; tp->tr_restarted = 0; tp->tr_atdelta = 0; tp->tr_ixnext = 0; tp->tr_tempo = 1.; tp->tr_clockdelay = 0.; tp->tr_prevtime = 0.; } } } return (x); }
static void qlist_free(t_qlist *x) { binbuf_free(x->x_binbuf); if (x->x_clock) clock_free(x->x_clock); }
static void mtr_doread(t_mtr *x, t_mtrack *target, t_symbol *fname) { char path[MAXPDSTRING]; FILE *fp; /* FIXME use open_via_path() */ if (x->x_glist) canvas_makefilename(x->x_glist, fname->s_name, path, MAXPDSTRING); else { strncpy(path, fname->s_name, MAXPDSTRING); path[MAXPDSTRING-1] = 0; } /* CHECKED no global message */ if (fp = sys_fopen(path, "r")) { t_mtrack *tp = 0; char linebuf[MTR_FILEBUFSIZE]; t_binbuf *bb = binbuf_new(); while (fgets(linebuf, MTR_FILEBUFSIZE, fp)) { char *line = linebuf; int linelen; while (*line && (*line == ' ' || *line == '\t')) line++; if (linelen = strlen(line)) { if (tp) { if (!strncmp(line, "end;", 4)) { post("ok"); tp = 0; } else { int ac; binbuf_text(bb, line, linelen); if (ac = binbuf_getnatom(bb)) { t_atom *ap = binbuf_getvec(bb); if (!binbuf_getnatom(tp->tr_binbuf)) { if (ap->a_type != A_FLOAT) { t_atom at; SETFLOAT(&at, 0.); binbuf_add(tp->tr_binbuf, 1, &at); } else if (ap->a_w.w_float < 0.) ap->a_w.w_float = 0.; } binbuf_add(tp->tr_binbuf, ac, ap); } } } else if (!strncmp(line, "track ", 6)) { int id = strtol(line + 6, 0, 10); startpost("Track %d... ", id); if (id < 1 || id > x->x_ntracks) post("no such track"); /* LATER rethink */ else if (target) { if (id == target->tr_id) tp = target; post("skipped"); /* LATER rethink */ } else tp = x->x_tracks[id - 1]; if (tp) { binbuf_clear(tp->tr_binbuf); } } } } fclose(fp); binbuf_free(bb); } else { /* CHECKED no complaint, open dialog not presented... */ /* LATER rethink */ hammerpanel_open(target ? target->tr_filehandle : x->x_filehandle, 0); } }