/* -------------------------------------------------------- rtcmix_advise --- */ void rtcmix_advise(const char *inst_name, const char *format, ...) { if (get_print_option() >= MMP_ADVISE) { char buf[BUFSIZE]; va_list args; va_start(args, format); vsnprintf(buf, BUFSIZE, format, args); va_end(args); #ifndef MAXMSP if (inst_name) printf("%s: %s\n", inst_name, buf); else printf("%s\n", buf); #else // MAXMSP if (inst_name) { int nchars = sprintf(get_mm_print_ptr(), "ADVISE [%s]: %s\n", inst_name, buf); set_mm_print_ptr(nchars+1); } else { int nchars = sprintf(get_mm_print_ptr(), "ADVISE: %s\n", buf); set_mm_print_ptr(nchars+1); } #endif // MAXMSP } }
/* -------------------------------------------------------- rtcmix_warn --- */ void rtcmix_warn(const char *inst_name, const char *format, ...) { if (get_print_option() >= MMP_WARN) { char buf[BUFSIZE]; va_list args; va_start(args, format); vsnprintf(buf, BUFSIZE, format, args); va_end(args); #ifndef MAXMSP if (inst_name) fprintf(stderr, "\n" PREFIX "WARNING [%s]: %s\n\n", inst_name, buf); else fprintf(stderr, "\n" PREFIX "WARNING: %s\n\n", buf); #else // MAXMSP if (inst_name) { int nchars = sprintf(get_mm_print_ptr(), "WARNING [%s]: %s\n", inst_name, buf); set_mm_print_ptr(nchars+1); } else { int nchars = sprintf(get_mm_print_ptr(), "WARNING: %s\n", buf); set_mm_print_ptr(nchars+1); } #endif // MAXMSP } }
/* -------------------------------------------------------------- rterror --- */ void rterror(const char *inst_name, const char *format, ...) { char buf[BUFSIZE]; va_list args; if (get_print_option() < MMP_RTERRORS) return; va_start(args, format); vsnprintf(buf, BUFSIZE, format, args); va_end(args); #ifndef MAXMSP if (inst_name) fprintf(stderr, PREFIX "ERROR [%s]: %s\n", inst_name, buf); else fprintf(stderr, PREFIX "ERROR: %s\n", buf); #else // MAXMSP if (inst_name) { int nchars = sprintf(get_mm_print_ptr(), "ERROR [%s]: %s\n", inst_name, buf); set_mm_print_ptr(nchars+1); } else { int nchars = sprintf(get_mm_print_ptr(), "ERROR: %s\n", buf); set_mm_print_ptr(nchars+1); } #endif // MAXMSP }
/* ----------------------------------------------------------------- print -- */ MincFloat _minc_print(const MincValue args[], const int nargs) { if (get_print_option() < MMP_PRINTS) return 0.0; _do_print(args, nargs); RTPrintf("\n"); return 0.0; }
double m_input(float *p,short n_args,double *pp) { p[1] = (n_args > 1) ? p[1] : 0.; p[2] = 0; n_args = 3; if (get_print_option()) fprintf(stderr,"Opening input file as unit %d\n",(int)p[1]); return m_open(p,n_args,pp); }
double m_output(float *p,short n_args,double *pp) { int i; p[1] = (n_args > 1) ? p[1] : 1.; p[2] = 2; n_args = 3; i = p[0]; if (get_print_option()) fprintf(stderr,"Opening output file as unit %d\n",(int)p[1]); return m_open(p,n_args,pp); }
/* Parse file <fname> instead of stdin. */ void use_script_file(char *fname) { #ifndef EMBEDDED // BGG mm -- we don't use this in Max/MSP, and there is no yy_in var yyin = fopen(fname, "r+"); if (yyin == NULL) { RTFPrintf(stderr, "Can't open %s\n", fname); exit(1); } #endif if (get_print_option() > MMP_ADVISE) RTPrintf("Using file %s\n", fname); }
/* --------------------------------------------------------------- warn --- */ void warn(const char *inst_name, const char *format, ...) { if (get_print_option()) { char buf[BUFSIZE]; va_list args; va_start(args, format); vsnprintf(buf, BUFSIZE, format, args); va_end(args); // JWM: use Pd's post() command to print to console if (inst_name) post("%s %s %s", PREFIX, inst_name, buf); else post("%s %s", PREFIX, buf); //fprintf(stdout,"Warn: %s",buf); } }
// BGG mm -- changed "advise" to "rtcmix_advise"; rtcmix~ conflict in OSX 10.5 void rtcmix_advise(const char *inst_name, const char *format, ...) { if (get_print_option()) { char buf[BUFSIZE]; va_list args; va_start(args, format); vsnprintf(buf, BUFSIZE, format, args); va_end(args); // use Pd's built-in post() to print to console if (inst_name) post("%s: %s", inst_name, buf); else post("%s", buf); //fprintf(stdout,"Advise: %s",buf); } }
MincFloat _minc_printf(const MincValue args[], const int nargs) { int n; const char *p; if (get_print_option() < MMP_PRINTS) return 0.0; if (args[0].dataType() != MincStringType) { minc_warn("printf: first argument must be format string"); goto err; } n = 1; p = (MincString) args[0]; while (*p) { switch (*p) { case '%': p++; if (n >= nargs) { minc_warn("printf: not enough arguments for format string"); goto err; } switch (*p) { case 'd': /* print float object as integer */ if (args[n].dataType() != MincFloatType) { minc_warn("printf: wrong argument type for format"); goto err; } RTPrintfCat("%d", (int) (MincFloat)args[n]); break; case 'f': /* print float object */ if (args[n].dataType() != MincFloatType) { minc_warn("printf: wrong argument type for format"); goto err; } RTPrintfCat("%.12g", (MincFloat)args[n]); break; case 'l': /* print list object */ if (args[n].dataType() != MincListType) { minc_warn("printf: wrong argument type for format"); goto err; } RTPrintfCat("["); _do_print(((MincList *)args[n])->data, ((MincList *)args[n])->len); RTPrintfCat("]"); break; case 's': /* print string object */ if (args[n].dataType() != MincStringType) { minc_warn("printf: wrong argument type for format"); goto err; } RTPrintfCat("%s", (MincString)args[n]); break; case 't': /* print type of object */ { char *tstr = (char *) _make_type_string(args[n].dataType() ); RTPrintfCat("%s", tstr); free(tstr); } break; case 'z': /* print as appropriate for type */ _do_print(&args[n], 1); break; case '\0': minc_warn("printf: premature end of format string"); goto err; break; default: minc_warn("printf: invalid format specifier"); goto err; break; } n++; p++; break; case '\\': p++; switch (*p) { case 'n': RTPrintfCat("\n"); break; case 't': RTPrintfCat("\t"); break; //FIXME: currently, minc.l can't handle escaped quotes in strings case '\'': RTPrintfCat("'"); break; case '"': RTPrintfCat("\""); break; case '\0': minc_warn("printf: premature end of format string"); goto err; break; default: minc_warn("printf: invalid escape character"); goto err; break; } p++; break; default: RTPrintfCat("%c", *p); p++; break; } } return 0.0; err: RTPrintf("\n"); // fflush(stdout); return -1.0; }
double m_load(float *p, int n_args, double *pp) { char dsoPath[1024]; int profileLoaded; DynamicLib theDSO; ProfileFun profileFun = NULL; // BGG mm -- dynamic loading not working in max/msp yet return 1.0; if (get_dso_path(pp[0], dsoPath) != 0) return 0; if (theDSO.load(dsoPath) != 0) { #ifdef linux warn("load", theDSO.error()); #else warn("load", "Unable to dynamically load '%s': %s", dsoPath, theDSO.error()); #endif return 0; } /* load & call the shared library's profile function to load its symbols */ profileLoaded = 0; if (theDSO.loadFunction(&profileFun, "profile") == 0) { profileLoaded++; (*profileFun)(); #ifdef DBUG printf("Loaded standard profile\n"); #endif } /* if present, load & call the shared library's rtprofile function to * load its symbols. Note that we access the function via its * unmangled symbol name due to its extern "C" decl in rt.h. */ if (theDSO.loadFunction(&profileFun, "rtprofile") == 0) { profileLoaded += 2; (*profileFun)(); #ifdef DBUG printf("Loaded RT profile\n"); #endif } if (!profileLoaded) { warn("load", "Unable to find a profile routine in DSO '%s'", dsoPath); theDSO.unload(); return 0; } if (get_print_option()) { printf("Loaded %s functions from shared library:\n\t'%s'.\n", (profileLoaded == 3) ? "standard and RT" : (profileLoaded == 2) ? "RT" : "standard", dsoPath); } return 1; }
double m_open(float *p, short n_args, double *pp) { char *name,*cp,*getsfcode(); int fno,i,inew; float *opk; name = DOUBLE_TO_STRING(pp[0]); fno = p[1]; // JGG: will name ptr be valid for entire program run? Is its memory held by // parser? If not, we should malloc sfname[fno] below (with other mallocs) sfname[fno] = name; status[fno] = (n_args == 3) ? (int)p[2] : 2; if((fno >= NFILES) || (fno < 0)) { fprintf(stderr," Only %d files allowed\n", NFILES); closesf(); } inew = 0; if(isopen[fno]) { close(sfd[fno]); } else inew = 1; istape[fno] = (n_args == 4) ? 1 : 0; /* in the case of a tape, there will be a 4th argument listing the file number */ rwopensf(name,sfd[fno],sfdesc[fno],sfst[fno],"CMIX",i,status[fno]); if (i < 0) closesf(); if (status[fno] == O_RDWR && !WRITEABLE_HEADER_TYPE(sfheadertype(&sfdesc[fno]))) { fprintf(stderr, "m_open: can't write this type of header.\n"); closesf(); } isopen[fno] = 1; swap_bytes[fno] = swap; /* swap and isNext set in rwopensf */ is_Next[fno] = isNext; headersize[fno] = getheadersize(&sfdesc[fno]); if (get_print_option()) { printf("name: %s sr: %.3f nchans: %d class: %d\n",name, sfsrate(&sfdesc[fno]),sfchans(&sfdesc[fno]), sfclass(&sfdesc[fno])); printf("Soundfile type: %s\n", mus_header_type_name(sfheadertype(&sfdesc[fno]))); printf(" data format: %s\n", mus_data_format_name(sfdataformat(&sfdesc[fno]))); printf("Duration of file is %f seconds.\n", (float)(sfst[fno].st_size - headersize[fno])/(float)sfclass(&sfdesc[fno])/(float)sfchans(&sfdesc[fno])/sfsrate(&sfdesc[fno])); } originalsize[fno] = istape[fno] ? 999999999 : sfst[fno].st_size; /* sfstats(sfd[fno]); */ if(inew) { if((sndbuf[fno] = (char *)malloc((unsigned)nbytes)) == NULL) { fprintf(stderr," CMIX: malloc sound buffer error\n"); closesf(); } if((peakloc[fno] = (char *)malloc((unsigned)(sfchans(&sfdesc[fno]) * LONG))) == NULL) { fprintf(stderr,"CMIX: malloc ovpeak buffer error\n"); closesf(); } if((peak[fno] = (char *)malloc((unsigned)(sfchans(&sfdesc[fno])* FLOAT))) == NULL) { fprintf(stderr,"CMIX: malloc peak buffer error!\n"); closesf(); } peakoff[fno] = 0; /* default to peakcheckon when opening file*/ punch[fno] = 0; /* default to no punch when opening file*/ } if(sfclass(&sfdesc[fno]) == SHORT) { addoutpointer[fno] = _iaddout; layoutpointer[fno] = _ilayout; wipeoutpointer[fno] = _iwipeout; getinpointer[fno] = _igetin; } else { addoutpointer[fno] = _faddout; layoutpointer[fno] = _flayout; wipeoutpointer[fno] = _fwipeout; getinpointer[fno] = _fgetin; } if(!SR()) set_SR(sfsrate(&sfdesc[fno])); if(sfsrate(&sfdesc[fno])!= SR()) fprintf(stderr,"Note--> SR reset to %f\n",SR()); /* read in former peak amplitudes, make sure zero'ed out to start.*/ /* In the sndlib version, we store peak stats differently. See comments in sndlibsupport.c for an explanation. The sndlib version of rwopensf reads peak stats, so here we just have to copy these into the sfm[fno] array. (No swapping necessary.) */ memcpy(&sfm[fno], &(sfmaxampstruct(&sfdesc[fno])), sizeof(SFMAXAMP)); for(opk = (float *)peak[fno], i = 0; i<sfchans(&sfdesc[fno]); i++) *(opk+i) = sfmaxamp(&sfm[fno],i); bufsize[fno] = nbytes / sfclass(&sfdesc[fno]);/* set size in words */ return 0.0; }