Example #1
0
static void ambi_decode_cube_encode_ls_2d(t_ambi_decode_cube *x, int argc, t_atom *argv, int ls0_ph1)
{
	double phi;
	double *dw = x->x_transp;
	int index;
	int n_ls=x->x_n_ls;
	int n_phls=x->x_n_phls;
	int order=x->x_n_order;

	if(argc < 2)
	{
		post("ambi_decode_cube ERROR: ls-input needs 1 index and 1 angle: ls_index + phi [degree]");
		return;
	}
	index = (int)atom_getint(argv++) - 1;
	phi = (double)atom_getfloat(argv);

	if(index < 0)
		index = 0;
	if(ls0_ph1)
	{
		if(n_phls)
		{
			if(index >= n_phls)
				index = n_phls - 1;
			index += n_ls;
		}
		else
			return;
	}
	else
	{
		if(index >= n_ls)
			index = n_ls - 1;
	}
	
	phi *= x->x_pi_over_180;

	dw += index * x->x_n_ambi;

	*dw++ = 1.0;
	*dw++ = cos(phi);
	*dw++ = sin(phi);

	if(order >= 2)
	{
		*dw++ = cos(2.0*phi);
		*dw++ = sin(2.0*phi);

		if(order >= 3)
		{
			*dw++ = cos(3.0*phi);
			*dw++ = sin(3.0*phi);

			if(order >= 4)
			{
				*dw++ = cos(4.0*phi);
				*dw++ = sin(4.0*phi);

				if(order >= 5)
				{
					*dw++ = cos(5.0*phi);
					*dw++ = sin(5.0*phi);

					if(order >= 6)
					{
						*dw++ = cos(6.0*phi);
						*dw++ = sin(6.0*phi);

						if(order >= 7)
						{
							*dw++ = cos(7.0*phi);
							*dw++ = sin(7.0*phi);

							if(order >= 8)
							{
								*dw++ = cos(8.0*phi);
								*dw++ = sin(8.0*phi);

								if(order >= 9)
								{
									*dw++ = cos(9.0*phi);
									*dw++ = sin(9.0*phi);

									if(order >= 10)
									{
										*dw++ = cos(10.0*phi);
										*dw++ = sin(10.0*phi);

										if(order >= 11)
										{
											*dw++ = cos(11.0*phi);
											*dw++ = sin(11.0*phi);

											if(order >= 12)
											{
												*dw++ = cos(12.0*phi);
												*dw++ = sin(12.0*phi);
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}
Example #2
0
static void blackboard_text(t_blackboard *x, t_symbol *s, int argc, t_atom *argv)
{
    int i;
    char buffer[MAXPDSTRING];
    size_t length;
    if(x->f_ninstructions >= _blackboard::maxcmd)
    {
        pd_error(x, "%s too many drawing commands.", eobj_getclassname(x)->s_name);
        return;
    }
    
    if(argc > 2 && argv)
    {
        if (atom_gettype(argv) == A_FLOAT && atom_gettype(argv+1) == A_FLOAT)
        {
            sprintf(x->f_instructions[x->f_ninstructions], "create text %d %d -anchor nw -text {", (int)atom_getfloat(argv), (int)atom_getfloat(argv+1));
            
            for(i = 2; i < argc; i++)
            {
                atom_string(argv+i, buffer, MAXPDSTRING);
                length = strlen(buffer);
                strncat(x->f_instructions[x->f_ninstructions], " ", 1);
                strncat(x->f_instructions[x->f_ninstructions], buffer, length);
            }
            
            sprintf(buffer, "} -font {%s %d %s} -fill %s", x->j_box.b_font.c_family->s_name, (int)x->j_box.b_font.c_size, x->j_box.b_font.c_weight->s_name, x->f_color->s_name);
            length = strlen(buffer);
            strncat(x->f_instructions[x->f_ninstructions], buffer, length);
            
            x->f_ninstructions++;
            ebox_redraw((t_ebox *)x);
        }
        
    }
}
void pix_opencv_patreco :: loadMess (t_symbol *s, int argc, t_atom* argv)
{
	t_symbol* filename;
	int id;
	
	if ( argc != 2 ) {
		error("wrong arguments : load <id> <filename>");
		return;
	} else if ( argv[0].a_type != A_FLOAT ||  argv[1].a_type != A_SYMBOL ) {
		error("wrong arguments : load <id> <filename>");
		return;
	} else {
		id = atom_getfloat(&argv[0]);
		filename = atom_getsymbol(&argv[1]);
	}
		
	
	if ( filename->s_name[0] == 0 ) {
		error("no filename passed to load message");
		return;
	}
	if ( filename == NULL ) { 
		error("%s is not a valid matrix", filename->s_name); 
		return;
	}
	
	Mat img = imread(filename->s_name,0);
	
	if ( img.data == NULL ){
		error("failed to load image '%s'", filename->s_name);
		puts("failed to laod images");
		return;
	}
	
	if(img.cols!=img.rows){
		error("%s is not a square pattern", filename->s_name);
		puts("not a square pattern");
		return;
	}

	cv::Mat src(m_pattern_size, m_pattern_size, CV_8UC1);
	Point2f center((m_pattern_size-1)/2.0f,(m_pattern_size-1)/2.0f);
	Mat rot_mat(2,3,CV_32F);
	
	//~ std::map<int PatternLib>::iterator it;
	//~ it = m_patternLibrary.find(id);
	//~ if ( m_patternLibrary.find(id) != m_patternLibrary.end() ){
		// TODO remove item from the map
	//~ }

	PatternLib pattern;
	pattern.id = id;
		
	cv::resize(img, src, Size(m_pattern_size,m_pattern_size));
	if ( m_detector->m_ART_pattern ) {
		Mat subImg = src(cv::Range(m_pattern_size/4,3*m_pattern_size/4), cv::Range(m_pattern_size/4,3*m_pattern_size/4));
		pattern.pattern[0]  = subImg;
		pattern.mean[0] = cvMean(&((CvMat)subImg));
		pattern.norm[0] = cv::norm(subImg, NORM_L1);
		//~ m_patternLibrary.push_back(subImg);
	}
	else {
		//~ m_patternLibrary.push_back(src);
		pattern.pattern[0]  = src;
		pattern.mean[0] = cvMean(&((CvMat)src));
		pattern.norm[0] = cv::norm(src, NORM_L1);
	}
	
	rot_mat = getRotationMatrix2D( center, 90, 1.0);

	for (int i=1; i<4; i++){
		Mat dst= Mat(m_pattern_size, m_pattern_size, CV_8UC1);
		rot_mat = getRotationMatrix2D( center, -i*90, 1.0);
		cv::warpAffine( src, dst , rot_mat, Size(m_pattern_size,m_pattern_size));
		if ( m_detector->m_ART_pattern ) {
			Mat subImg = dst(cv::Range(m_pattern_size/4,3*m_pattern_size/4), cv::Range(m_pattern_size/4,3*m_pattern_size/4)); // AV crop 25% on each side -> specific to AR tag ?
			pattern.pattern[i];
			pattern.mean[i] = cvMean(&((CvMat)subImg));
			pattern.norm[i] = cv::norm(subImg, NORM_L1);
			//~ m_patternLibrary.push_back(subImg);	
		} else {
			pattern.pattern[i] = dst;
			pattern.mean[i] = cvMean(&((CvMat)dst));
			pattern.norm[i] = cv::norm(dst, NORM_L1);			
			//~ m_patternLibrary.push_back(dst);
		}
	}

	t_atom data_out;
	SETFLOAT(&data_out, m_patternLibrary.size());
	outlet_anything( m_dataout, gensym("patternCount"), 1, &data_out);
}
Example #4
0
static typedArg packOSC_forceatom(t_atom *a, char ctype)
{ /* ctype is one of i,f,s,T,F,N,I*/
    typedArg    returnVal;
    t_float     f;
    t_int       i;
    t_symbol    s;
    static char buf[MAXPDSTRING];

#ifdef DEBUG
    atom_string(a, buf, MAXPDSTRING);
    post("packOSC: atom type %d (%s)", a->a_type, buf);
#endif
    /* the atom might be a float, or a symbol */
    switch (a->a_type)
    {
        case A_FLOAT:
            switch (ctype)
            {
                case 'i':
                    returnVal.type = INT_osc;
                    returnVal.datum.i = atom_getint(a);
#ifdef DEBUG
                    post("packOSC_forceatom: float to integer %d", returnVal.datum.i);
#endif
                    break;
                case 'f':
                    returnVal.type = FLOAT_osc;
                    returnVal.datum.f = atom_getfloat(a);
#ifdef DEBUG
                    post("packOSC_forceatom: float to float %f", returnVal.datum.f);
#endif
                    break;
                case 's':
                    f = atom_getfloat(a);
                    sprintf(buf, "%f", f);
                    returnVal.type = STRING_osc;
                    returnVal.datum.s = buf;
#ifdef DEBUG
                    post("packOSC_forceatom: float to string %s", returnVal.datum.s);
#endif
                    break;
                default:
                    post("packOSC: unknown OSC type %c", ctype);
                    returnVal.type = NOTYPE_osc;
                    returnVal.datum.s = NULL;
                    break;
            }
            break;
        case A_SYMBOL:
            s = *atom_getsymbol(a);
            switch (ctype)
            {
                case 'i':
                    i = atoi(s.s_name);
                    returnVal.type = INT_osc;
                    returnVal.datum.i = i;
#ifdef DEBUG
                    post("packOSC_forceatom: symbol to integer %d", returnVal.datum.i);
#endif
                    break;
                case 'f':
                    f = atof(s.s_name);
                    returnVal.type = FLOAT_osc;
                    returnVal.datum.f = f;
#ifdef DEBUG
                    post("packOSC_forceatom: symbol to float %f", returnVal.datum.f);
#endif
                    break;
                case 's':
                    returnVal.type = STRING_osc;
                    returnVal.datum.s = s.s_name;
#ifdef DEBUG
                    post("packOSC_forceatom: symbol to string %s", returnVal.datum.s);
#endif
                    break;
                default:
                    post("packOSC: unknown OSC type %c", ctype);
                    returnVal.type = NOTYPE_osc;
                    returnVal.datum.s = NULL;
                    break;
            }
            break;
        default:
            atom_string(a, buf, MAXPDSTRING);
            error("packOSC: atom type %d not implemented (%s)", a->a_type, buf);
            returnVal.type = NOTYPE_osc;
            returnVal.datum.s = NULL;
            break;
    }
    return returnVal;
}
Example #5
0
static void blackboard_arc(t_blackboard *x, t_symbol *s, int argc, t_atom *argv)
{
    if(x->f_ninstructions >= _blackboard::maxcmd)
    {
        pd_error(x, "%s too many drawing commands.", eobj_getclassname(x)->s_name);
        return;
    }
    
    if(argc > 5 && argv)
    {
        if (atom_gettype(argv) == A_FLOAT && atom_gettype(argv+1) == A_FLOAT && atom_gettype(argv+2) == A_FLOAT && atom_gettype(argv+3) == A_FLOAT && atom_gettype(argv+4) == A_FLOAT && atom_gettype(argv+5) == A_FLOAT)
        {
            if(x->f_fill)
                sprintf(x->f_instructions[x->f_ninstructions], "create arc %d %d %d %d -start %d -extent %d -style pieslice -fill %s -width 0", (int)atom_getfloat(argv), (int)atom_getfloat(argv+1), (int)atom_getfloat(argv+2), (int)atom_getfloat(argv+3), (int)atom_getfloat(argv+4), (int)atom_getfloat(argv+5), x->f_color->s_name);
            else
                sprintf(x->f_instructions[x->f_ninstructions], "create arc %d %d %d %d -start %d -extent %d -style arc -outline %s -width %d", (int)atom_getfloat(argv), (int)atom_getfloat(argv+1), (int)atom_getfloat(argv+2), (int)atom_getfloat(argv+3), (int)atom_getfloat(argv+4), (int)atom_getfloat(argv+5), x->f_color->s_name, (int)x->f_width);
        
            x->f_ninstructions++;
            ebox_redraw((t_ebox *)x);
        }
    }
}
void ircropfade_process_internal(t_ircropfade *x, t_symbol *sym, short argc, t_atom *argv)
{
    // Load arguments

    t_symbol *target = atom_getsym(argv++);
    t_symbol *source = atom_getsym(argv++);
    t_atom_long crop1 = atom_getlong(argv++);
    t_atom_long crop2 = atom_getlong(argv++);
    double fade_start = atom_getfloat(argv++);
    double in_length = atom_getfloat(argv++);
    double fade_end = atom_getfloat(argv++);
    double out_length = atom_getfloat(argv++);

    // Set fade variables

    double fade_in_lo = fade_start - 1;
    double fade_in_hi = in_length > 0 ? fade_start + in_length : fade_start;
    double fade_out_lo = fade_end;
    double fade_out_hi = out_length > 0 ? fade_end - out_length : fade_end - 1;
    double fade_in_recip = 1. / (fade_in_hi - fade_in_lo);
    double fade_out_recip = 1. / (fade_out_hi - fade_out_lo);

    float *temp1;
    double *temp2;

    t_buffer_write_error error;

    AH_SIntPtr full_length = buffer_length(source);
    AH_SIntPtr final_length;
    AH_SIntPtr i;

    t_atom_long read_chan = x->read_chan - 1;

    double sample_rate = 0;

    // Check source buffer

    if (buffer_check((t_object *) x, source, read_chan))
        return;
    sample_rate = buffer_sample_rate(source);

    crop1 = crop1 < 0 ? 0 : crop1;
    crop2 = crop2 < 0 ? 0 : crop2;
    crop1 = crop1 > full_length - 1 ? full_length - 1: crop1;
    crop2 = crop2 > full_length ? full_length : crop2;

    if (crop1 >= crop2)
        return;

    final_length = crop2 - crop1;

    // Allocate Memory

    temp1 = (float *) ALIGNED_MALLOC(full_length  * sizeof(float) + final_length * sizeof(double));
    temp2 = (double *) (temp1 + full_length);

    // Check momory allocation

    if (!temp1)
    {
        object_error((t_object *)x, "could not allocate temporary memory for processing");
        free(temp1);
        return;
    }

    // Read from buffer

    buffer_read(source, read_chan, (float *) temp1, full_length);

    // Copy with crops / fades to double precision version

    for (i = 0; i < final_length; i++)
    {
        double in_val = temp1[i + crop1];
        double fade_in = calculate_fade((double) (i + crop1), fade_in_lo, fade_in_recip);
        double fade_out = calculate_fade((double) (i + crop1), fade_out_lo, fade_out_recip);

        temp2[i] = in_val * fade_in * fade_out;
    }

    // Copy out to buffer

    error = buffer_write(target, temp2, final_length, x->write_chan - 1, x->resize, sample_rate, 1.);
    buffer_write_error((t_object *)x, target, error);

    // Free Resources

    ALIGNED_FREE(temp1);

    if (!error)
        outlet_bang(x->process_done);
}
Example #7
0
static void readFloatFromList (int n, t_atom *l, t_float *f)
{
  while (n--) {
    *f++ = atom_getfloat (l++);
  }
}
void irextract_sweep (t_irextract *x, t_symbol *sym, long argc, t_atom *argv)
{			
	double f1 = 20;
	double f2 = 22050;
	double length = 30000;
	double fade_in = 50;
	double fade_out = 10;
	double out_length = 0;
	double sample_rate;
	
	double amp_curve[33];
	
	t_atom_long num_channels = 1;
	
	t_symbol *rec_buffer = 0;
	
	// Load parameters

	if (argc > 0)
	{
		rec_buffer = atom_getsym(argv++);
		sample_rate = buffer_sample_rate(rec_buffer);
		f2 = sample_rate / 2.;
	}
	if (argc > 1)
		f1 = atom_getfloat(argv++);
	if (argc > 2)
		f2 = atom_getfloat(argv++);
	if (argc > 3)
		length = atom_getfloat(argv++);
	if (argc > 4)
		fade_in = atom_getfloat(argv++);
	if (argc > 5)
		fade_out = atom_getfloat(argv++);
	if (argc > 6)
		num_channels = atom_getlong(argv++);
	if (argc > 7)
		out_length = atom_getfloat(argv++);
	
	// Check parameters
		
	if (!rec_buffer)
	{
		object_error((t_object *)x, "no buffer given");
		return;
	}
	
	f1 = irextract_param_check(x, "low frequency", f1, 0.0001, sample_rate / 2);
	f2 = irextract_param_check(x, "high frequency", f2, f2, sample_rate / 2);
	length = irextract_param_check(x, "length", length, 0., HUGE_VAL);
	fade_in = irextract_param_check(x, "fade in time", fade_in, 0., length / 2);
	fade_out = irextract_param_check(x, "fade out time", fade_out, 0., length / 2);
	num_channels = (t_atom_long) irextract_param_check(x, "number of channels", (double) num_channels, 1, HIRT_MAX_MEASURE_CHANS);
	x->out_length = irextract_param_check(x, "output length", out_length, 0., HUGE_VAL) / 1000.;
	
	// Check length of sweep and memory allocation
	
	fill_amp_curve_specifier(amp_curve, x->amp_curve_specifier, x->amp_curve_num_specifiers);
	
	if (ess_params(&x->sweep_params, f1, f2, fade_in / 1000., fade_out / 1000., length / 1000., sample_rate, db_to_a(x->amp), amp_curve))
	{
		// Process
		
		x->measure_mode = SWEEP;
		irextract_process(x, rec_buffer, num_channels, sample_rate);
	}
	else 
		object_error((t_object *) x, "zero length sweep - requested length value is too small");		
}
void irextract_noise (t_irextract *x, t_symbol *sym, long argc, t_atom *argv)
{
	double length = 10000;
	double fade_in = 10;
	double fade_out = 10;
	double amp_comp = 1.;
	double out_length = 0;
	double max_pink, max_brown;
	double sample_rate;
	
	t_atom_long num_channels = 1;

	t_symbol *rec_buffer = 0;
	
	t_noise_mode noise_mode = NOISE_MODE_WHITE;
	
	if (sym == gensym("brown"))
		noise_mode = NOISE_MODE_BROWN;
	if (sym == gensym("pink"))
		noise_mode = NOISE_MODE_PINK;
		
	// Load parameters
	
	if (argc > 0)
	{
		rec_buffer = atom_getsym(argv++);
		sample_rate = buffer_sample_rate(rec_buffer);
	}
	if (argc > 1)
		length = atom_getfloat(argv++);
	if (argc > 2)
		fade_in = atom_getfloat(argv++);
	if (argc > 3)
		fade_out = atom_getfloat(argv++);
	if (argc > 4)
		num_channels = atom_getlong(argv++);
	if (argc > 5)
		out_length = atom_getfloat(argv++);
	
	// Check parameters
	
	if (!rec_buffer)
	{
		object_error((t_object *)x, "no buffer given");
		return;
	}
	
	length = irextract_param_check(x, "length", length, 0., HUGE_VAL);
	fade_in = irextract_param_check(x, "fade in time", fade_in, 0., length / 2);
	fade_out = irextract_param_check(x, "fade out time", fade_out, 0., length / 2);
	num_channels = (t_atom_long) irextract_param_check(x, "number of channels", (double) num_channels, 1, HIRT_MAX_MEASURE_CHANS);
	x->out_length = irextract_param_check(x, "output length", out_length, 0., HUGE_VAL) / 1000.;

	// Process

	x->measure_mode = NOISE;
	coloured_noise_params(&x->noise_params, noise_mode, fade_in / 1000., fade_out / 1000., length / 1000., sample_rate, db_to_a(x->amp) / amp_comp);
	
	if (noise_mode != NOISE_MODE_WHITE)
	{
		coloured_noise_measure(&x->noise_params, (int) (length * sample_rate * 1000.), &max_pink, &max_brown);
		coloured_noise_reset(&x->noise_params);
	}
	if (noise_mode == NOISE_MODE_BROWN)
		amp_comp = max_brown;
	if (noise_mode == NOISE_MODE_PINK)
		amp_comp = max_pink;

	irextract_process(x, rec_buffer, num_channels, sample_rate);
}
Example #10
0
static void *breakpoints_new(t_symbol *s,int argc,t_atom* argv)
{
	
	
	
     t_breakpoints *x = (t_breakpoints *)pd_new(breakpoints_class);
     
     x->borderwidth = 1;
     x->state = 0;
     x->x_f = 0;
     x->args = STATES;
     x->finalvalues = getbytes( x->args*sizeof(t_float));
     x->duration = getbytes( x->args*sizeof(t_float));
#ifdef DEBUG
     post("finalvalues %x",x->finalvalues);
#endif
     /* widget */
     
     x->w.grabbed = 0;
     x->resizing = 0;
     x->resizeable = 0;
     x->w.glist = (t_glist*) canvas_getcurrent();
     
     x->w.width = 200;
     if (argc) x->w.width = atom_getfloat(argv++),argc--;
     x->w.height = 140;
     if (argc) x->w.height = atom_getfloat(argv++),argc--;
     
     t_float initialDuration = 100;
     if (argc) initialDuration = atom_getfloat(argv++),argc--;

     x->r_sym = &s_;
     if (argc) {
       t_symbol* n;

       n = atom_getsymbol(argv++);
       bindsym(&x->x_obj.ob_pd,x->r_sym,n);
       x->r_sym = n;
       argc--;
     }
     #ifdef DEBUG
     post("recv %s",x->r_sym->s_name);
#endif
     x->s_sym = &s_;
     if (argc) x->s_sym = atom_getsymbol(argv++),argc--;
     #ifdef DEBUG
     post("send %s",x->s_sym->s_name);
     #endif
     x->d_sym = &s_;
     if (argc) x->d_sym = atom_getsymbol(argv++),argc--;
     #ifdef DEBUG
     post("send %s",x->d_sym->s_name);
     #endif 
      
      x->c_sym = &s_;
     if (argc) x->c_sym = atom_getsymbol(argv++),argc--;
     #ifdef DEBUG
     post("change %s",x->d_sym->s_name);
     #endif 
      
     if (argc>2)
	  breakpoints_init(x,argc,argv);
     else {
	  t_atom a[5];
	  SETFLOAT(a,0);
	  SETFLOAT(a+1,50);
	  SETFLOAT(a+2,1);
	  SETFLOAT(a+3,50);
	  SETFLOAT(a+4,0);
	  breakpoints_init(x,5,a);
     }	 
     
     x->x_val = 0.0;
     x->x_state = NONE;
     x->sustain_state = SUSTAIN;
     x->x_freeze = 0;
     
     
    breakpoints_totaldur(x,initialDuration);
     
     
     //outlet_new(&x->x_obj, gensym("signal"));
     outlet_new(&x->x_obj, &s_float);
     x->out2 = outlet_new(&x->x_obj, &s_float);
     x->out3 = outlet_new(&x->x_obj, &s_bang);
     
     x->x_clock = clock_new(x, (t_method) breakpoints_tick);
     return (x);
}
Example #11
0
static void breakpoints_init(t_breakpoints *x,int argc,t_atom* argv)
{
     t_float* dur;
     t_float* val;
     t_float tdur = 0;

     if (!argc) return;

     x->duration[0] = 0;

     x->last_state = argc>>1;
     breakpoints_resize(x,argc>>1);

     dur = x->duration;
     val = x->finalvalues;
     
     // get the first value
     if (argc) {
      *val = atom_getfloat(argv++);
      *dur = 0.0;
      x->max = *val;
      x->min = *val;
     }
     dur++;val++;argc--;
     // get the following
     for (;argc > 0;argc--) {
	  tdur += atom_getfloat(argv++);
#ifdef DEBUG
	  post("dur =%f",tdur);
#endif
	  *dur++ = tdur; 
	  argc--;
	  if (argc > 0) {
	       *val = atom_getfloat(argv++); 
	       if (*val > x->max ) x->max = *val;
	       if (*val < x->min ) x->min = *val;
	       *val++;
	   } else {
	       *val = 0; 
	       if (*val > x->max ) x->max = *val;
	       if (*val < x->min ) x->min = *val;
	       *val++;
	   }
#ifdef DEBUG
	  post("val =%f",*(val-1));
#endif

     }
     
     
     
     if ( x->max == x->min ) {
        if ( x->max == 0 ) {
          x->max = 1;
        } else {
          if (x->max > 0) {
            x->min = 0;
             if (x->max < 1) x->max =1;
          } else {
            x->max = 0;
          }
        }
     }

}
Example #12
0
/**
Called by _dict_recurse_dict() for each entry and _dict_recurse_array() for each index
*/
t_int32 _dict_recurse_value(t_dict_recurse *x, t_atom *value, t_int32 depth)
{
  TRACE("_dict_recurse_value");

  long type = atom_gettype(value);

  // ====  INT  ====
  if (type == A_LONG) {
    snprintf_zero(x->str_tmp, MAX_LEN_NUMBER, "%i", atom_getlong(value));
    _dict_recurse_value_find(x, value, x->str_tmp); }

  // ====  FLOAT  ====
  else if (type == A_FLOAT) {
    snprintf_zero(x->str_tmp, MAX_LEN_NUMBER, "%i", atom_getfloat(value));
    _dict_recurse_value_find(x, value, x->str_tmp); }
    
  // ====  SYMBOL / STRING  ====
  // NB: values in arrays are not A_SYM but A_OBJ 
  else if ((type == A_SYM) || atomisstring(value)) {

    t_symbol *value_sym = atom_getsym(value);

    switch (x->command) {
    
    // == FIND A SYMBOL VALUE
    case CMD_FIND_VALUE_SYM:

      if (regexpr_match(x->search_val_expr, value_sym)) {
        POST("  %s  \"%s\"", x->path, value_sym->s_name); x->count++; }
      break;

    // == FIND AN ENTRY
    case CMD_FIND_ENTRY:

      if (regexpr_match(x->search_key_expr, x->key_iter)
          && regexpr_match(x->search_val_expr, value_sym)
          && (x->type_iter == VALUE_TYPE_DICT)) {

        POST("  %s  \"%s\"", x->path, value_sym->s_name); x->count++; }
      break;

    // == REPLACE A SYMBOL VALUE
    case CMD_REPLACE_VALUE_SYM:
      
      if (regexpr_match(x->search_val_expr, value_sym)) {

        // If the value is from a dictionary entry
        if (x->type_iter == VALUE_TYPE_DICT) {
          dictionary_chuckentry(x->dict_iter, x->key_iter);
          dictionary_appendsym(x->dict_iter, x->key_iter, x->replace_val_sym); }

        // If the value is from an array
        else if (x->type_iter == VALUE_TYPE_ARRAY) { atom_setsym(value, x->replace_val_sym); }

        x->count++;
        if (x->a_verbose) {
          POST("  %s  \"%s\"  replaced by  \"%s\"",
            x->path, value_sym->s_name, x->replace_val_sym->s_name); } }
      break;

    // == REPLACE AN ENTRY
    case CMD_REPLACE_ENTRY:
      
      if (regexpr_match(x->search_key_expr, x->key_iter)
          && regexpr_match(x->search_val_expr, value_sym)
          && (x->type_iter == VALUE_TYPE_DICT)) {

        dictionary_chuckentry(x->dict_iter, x->key_iter);
        dictionary_appendsym(x->dict_iter, x->replace_key_sym, x->replace_val_sym);

        x->count++;
        if (x->a_verbose) {
          POST("  %s  \"%s\"  replaced by  (%s : %s)",
            x->path, value_sym->s_name, x->replace_key_sym->s_name, x->replace_val_sym->s_name); } }
      break;

    // == DELETE A SYMBOL VALUE
    case CMD_DELETE_VALUE_SYM:

      if (regexpr_match(x->search_val_expr, value_sym)) {

        // If the value is from a dictionary entry
        if (x->type_iter == VALUE_TYPE_DICT) {
          dictionary_deleteentry(x->dict_iter, x->key_iter); }

        // If the value is from an array
        else if (x->type_iter == VALUE_TYPE_ARRAY) {
          atomarray_chuckindex(x->array_iter, x->index_iter); }

        x->count++;
        if (x->a_verbose) {
          POST("  %s  \"%s\"  deleted",
            x->path, value_sym->s_name); }
        return VALUE_DEL; }
      break;

    // == DELETE A SYMBOL VALUE
    case CMD_DELETE_ENTRY:

      if (regexpr_match(x->search_key_expr, x->key_iter)
          && regexpr_match(x->search_val_expr, value_sym)
          && (x->type_iter == VALUE_TYPE_DICT)) {

        dictionary_deleteentry(x->dict_iter, x->key_iter);

        x->count++;
        if (x->a_verbose) {
          POST("  %s  \"%s\"  deleted",
            x->path, value_sym->s_name); }
        return VALUE_DEL; }
      break;

    // == DEFAULT: CMD_FIND_KEY or CMD_FIND_KEY_IN
    default:
      snprintf_zero(x->str_tmp, MAX_LEN_NUMBER, "\"%s\"", atom_getsym(value)->s_name);
      _dict_recurse_value_find(x, value, x->str_tmp);
      break; } }

  // ====  DICTIONARY  ====
  else if (atomisdictionary(value)) {

    t_dictionary *sub_dict = (t_dictionary *)atom_getobj(value);
    t_symbol *key_match = gensym("");
    t_symbol *value_match = gensym("");

    switch (x->command) {

    case CMD_FIND_DICT_CONT_ENTRY:
      
      if (_dict_recurse_match_dict(x, sub_dict, &key_match, &value_match)) {

        x->count++;
        POST("  %s:  dict containing  (%s : %s)",
          x->path, key_match->s_name, value_match->s_name); }
      break;

    case CMD_REPLACE_DICT_CONT_ENTRY:

      if (_dict_recurse_match_dict(x, sub_dict, &key_match, &value_match)) {

        t_dictionary *dict_cpy = dictionary_new();
        dictionary_clone_to_existing(x->replace_dict, dict_cpy);
        
        // If the value is from a dictionary entry
        if (x->type_iter == VALUE_TYPE_DICT) {
          dictionary_deleteentry(x->dict_iter, x->key_iter);
          dictionary_appenddictionary(x->dict_iter, x->key_iter, (t_object *)dict_cpy); }

        // If the value is from an array
        else if (x->type_iter == VALUE_TYPE_ARRAY) {
          long array_len;
          t_atom *atom_arr;
          atomarray_getatoms(x->array_iter, &array_len, &atom_arr);
          atom_setobj(atom_arr + x->index_iter, dict_cpy); } 

        x->count++;
        if (x->a_verbose) {
          POST("  %s:  dict containing  (%s : %s):  replaced by  \"%s\"",
            x->path, key_match->s_name, value_match->s_name, x->replace_dict_sym->s_name); } 
      
        return VALUE_NO_DEL; }
      break;

    case CMD_DELETE_DICT_CONT_ENTRY:

      if (_dict_recurse_match_dict(x, sub_dict, &key_match, &value_match)) {

        // If the value is from a dictionary entry
        if (x->type_iter == VALUE_TYPE_DICT) {
          dictionary_deleteentry(x->dict_iter, x->key_iter); }

        // If the value is from an array
        else if (x->type_iter == VALUE_TYPE_ARRAY) {
          atomarray_chuckindex(x->array_iter, x->index_iter);
          object_free(sub_dict); } 

        x->count++;
        if (x->a_verbose) {
          POST("  %s:  dict containing  (%s : %s):  deleted",
            x->path, key_match->s_name, value_match->s_name); }

        return VALUE_DEL; }
      break;

    case CMD_APPEND_IN_DICT_CONT_ENTRY:

      if (_dict_recurse_match_dict(x, sub_dict, &key_match, &value_match)) {

        dictionary_appendsym(sub_dict, x->replace_key_sym, x->replace_val_sym);

        x->count++;
        if (x->a_verbose) {
          POST("  %s:  dict containing  (%s : %s):  appended  (%s : %s)",
            x->path, key_match->s_name, value_match->s_name, x->replace_key_sym->s_name, x->replace_val_sym->s_name); } }
      break;

    case CMD_APPEND_IN_DICT_CONT_ENTRY_D:

      if (_dict_recurse_match_dict(x, sub_dict, &key_match, &value_match)
          && dictionary_hasentry(x->replace_dict, x->replace_key_sym)) {

        t_symbol *key[2]; key[0] = x->replace_key_sym; key[1] = NULL;
        dictionary_copyentries(x->replace_dict, sub_dict, key);    // NB: Strange it does not require the array size

        x->count++;
        if (x->a_verbose) {
          POST("  %s:  dict containing  (%s : %s):  appended entry  (%s : ...)  from \"%s\"",
            x->path, key_match->s_name, value_match->s_name, x->replace_key_sym->s_name, x->replace_dict_sym->s_name); } }
      break;

    case CMD_APPEND_IN_DICT_FROM_KEY:

      if (regexpr_match(x->search_key_expr, x->key_iter)
          && (x->type_iter == VALUE_TYPE_DICT)
          && dictionary_hasentry(x->replace_dict, x->replace_key_sym)) {

        t_symbol *key[2]; key[0] = x->replace_key_sym; key[1] = NULL;
        dictionary_copyentries(x->replace_dict, sub_dict, key);    // NB: Strange it does not require the array size
        
        x->count++;
        if (x->a_verbose) {
          POST("  %s:  dict value:  appended entry  (%s : ...)  from \"%s\"",
            x->path, x->replace_key_sym->s_name, x->replace_dict_sym->s_name); } }
      break;
    
    default:
      _dict_recurse_value_find(x, value, "_DICT_"); }    // End of command "switch ..."

    _dict_recurse_dict(x, sub_dict, depth); }    // End of dictionary "else if ..."

  // ====  ARRAY  ====
  else if (atomisatomarray(value)) {

    _dict_recurse_value_find(x, value, "_ARRAY_");

    t_atomarray *atomarray = (t_atomarray *)atom_getobj(value);
    _dict_recurse_array(x, atomarray, depth);  }

  return VALUE_NO_DEL;
}
Example #13
0
static void *matrix_bundle_line_tilde_new(t_symbol *s, int argc, t_atom *argv)
{
  t_matrix_bundle_line_tilde *x = (t_matrix_bundle_line_tilde *)pd_new(matrix_bundle_line_tilde_class);
  int i, n;
  
  switch (argc)
  {
  case 0:
    x->x_n_in = x->x_n_out = 1;
    x->x_time_ms = 50.0f;
    break;
  case 1:
    x->x_n_in = x->x_n_out = (int)atom_getint(argv);
    x->x_time_ms = 50.0f;
    break;
  case 2:
    x->x_n_in = (int)atom_getint(argv);
    x->x_n_out = (int)atom_getint(argv+1);
    x->x_time_ms = 50.0f;
    break;
  default:
    x->x_n_in = (int)atom_getint(argv);
    x->x_n_out = (int)atom_getint(argv+1);
    x->x_time_ms = atom_getfloat(argv+2);
    break;
  }
  
  if(x->x_n_in < 1)
    x->x_n_in = 1;
  if(x->x_n_out < 1)
    x->x_n_out = 1;
  if(x->x_time_ms < 0.0f)
    x->x_time_ms = 50.0f;
  i = x->x_n_in - 1;
  while(i--)
    inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
  i = x->x_n_out;
  while(i--)
    outlet_new(&x->x_obj, &s_signal);
  
  x->x_in2out_new = (int *)getbytes(x->x_n_in * sizeof(int));
  x->x_in2out_old = (int *)getbytes(x->x_n_in * sizeof(int));
  x->x_remaining_ticks = (int *)getbytes(x->x_n_in * sizeof(int));
  x->x_retarget = (int *)getbytes(x->x_n_in * sizeof(int));
  x->x_io = (t_float **)getbytes((x->x_n_in + x->x_n_out) * sizeof(t_float *));
  x->x_outsumbuf = (t_float *)0;
  x->x_outsumbufsize = 0;
  
  x->x_raise_cur = 1.0f;
  x->x_raise_end = 1.0f;
  x->x_fall_cur = 0.0f;
  x->x_fall_end = 0.0f;
  x->x_inc = 0.0f;
  x->x_biginc = 0.0f;
  x->x_msi = 0;
  x->x_ms2tick = 0.001f * 44100.0f / 64.0f;
  x->x_1overn = 1.0f / 64.0f;
  x->x_remaining_ticks_start = (int)(x->x_time_ms * x->x_ms2tick);
  if(!x->x_remaining_ticks_start)
    x->x_remaining_ticks_start = 1;
  
  n = x->x_n_in;
  for(i=0; i<n; i++)
  {
    x->x_in2out_new[i] = 0;
    x->x_in2out_old[i] = 0;
    x->x_remaining_ticks[i] = 0;
    x->x_retarget[i] = 0;
  }
  return(x);
}
Example #14
0
static void ambi_decode_cube_encode_ls_3d(t_ambi_decode_cube *x, int argc, t_atom *argv, int ls0_ph1)
{
	double delta, phi;
	double cd, sd, cd2, cd3, sd2, csd, cp, sp, cp2, sp2, cp3, sp3, cp4, sp4;
	double *dw = x->x_transp;
	int index;
	int n_ls=x->x_n_ls;
	int n_phls=x->x_n_phls;
	int order=x->x_n_order;

	if(argc < 3)
	{
		post("ambi_decode_cube ERROR: ls-input needs 1 index and 2 angles: ls index + delta [degree] + phi [degree]");
		return;
	}
	index = (int)atom_getint(argv++) - 1;
	delta = atom_getfloat(argv++);
	phi = atom_getfloat(argv);

	if(index < 0)
		index = 0;
	if(ls0_ph1)
	{
		if(n_phls)
		{
			if(index >= n_phls)
				index = n_phls - 1;
			index += n_ls;
		}
		else
			return;
	}
	else
	{
		if(index >= n_ls)
			index = n_ls - 1;
	}

	delta *= x->x_pi_over_180;
	phi *= x->x_pi_over_180;

	dw += index * x->x_n_ambi;	

	cd = cos(delta);
	sd = sin(delta);
	cp = cos(phi);
	sp = sin(phi);
	
	*dw++ = 1.0;
	*dw++ = cd * cp;
	*dw++ = cd * sp;
	*dw++ = sd;

	if(order >= 2)
	{
		cp2 = cos(2.0*phi);
		sp2 = sin(2.0*phi);
		cd2 = cd * cd;
		sd2 = sd * sd;
		csd = cd * sd;
		*dw++ = 0.5 * x->x_sqrt3 * cd2 * cp2;
		*dw++ = 0.5 * x->x_sqrt3 * cd2 * sp2;
		*dw++ = x->x_sqrt3 * csd * cp;
		*dw++ = x->x_sqrt3 * csd * sp;
		*dw++ = 0.5 * (3.0 * sd2 - 1.0);

		if(order >= 3)
		{
			cp3 = cos(3.0*phi);
			sp3 = sin(3.0*phi);
			cd3 = cd2 * cd;
			*dw++ = x->x_sqrt10_4 * cd3 * cp3;
			*dw++ = x->x_sqrt10_4 * cd3 * sp3;
			*dw++ = x->x_sqrt15_2 * cd * csd * cp2;
			*dw++ = x->x_sqrt15_2 * cd * csd * sp2;
			*dw++ = x->x_sqrt6_4 * cd * (5.0 * sd2 - 1.0) * cp;
			*dw++ = x->x_sqrt6_4 * cd * (5.0 * sd2 - 1.0) * sp;
			*dw++ = 0.5 * sd * (5.0 * sd2 - 3.0);

			if(order >= 4)
			{
				cp4 = cos(4.0*phi);
				sp4 = sin(4.0*phi);
				*dw++ = x->x_sqrt35_8 * cd2 * cd2 * cp4;
				*dw++ = x->x_sqrt35_8 * cd2 * cd2 * sp4;
				*dw++ = x->x_sqrt70_4 * cd2 * csd * cp3;
				*dw++ = x->x_sqrt70_4 * cd2 * csd * sp3;
				*dw++ = 0.5 * x->x_sqrt5_2 * cd2 * (7.0 * sd2 - 1.0) * cp2;
				*dw++ = 0.5 * x->x_sqrt5_2 * cd2 * (7.0 * sd2 - 1.0) * sp2;
				*dw++ = x->x_sqrt10_4 * csd * (7.0 * sd2 - 3.0) * cp;
				*dw++ = x->x_sqrt10_4 * csd * (7.0 * sd2 - 3.0) * sp;
				*dw++ = 0.125 * (sd2 * (35.0 * sd2 - 30.0) + 3.0);

				if(order >= 5)
				{
					*dw++ = x->x_sqrt126_16 * cd3 * cd2 * cos(5.0*phi);
					*dw++ = x->x_sqrt126_16 * cd3 * cd2 * sin(5.0*phi);
					*dw++ = x->x_sqrt315_8 * cd3 * csd * cp4;
					*dw++ = x->x_sqrt315_8 * cd3 * csd * sp4;
					*dw++ = 0.25 * x->x_sqrt70_4 * cd3 * (9.0 * sd2 - 1.0) * cp3;
					*dw++ = 0.25 * x->x_sqrt70_4 * cd3 * (9.0 * sd2 - 1.0) * sp3;
					*dw++ = x->x_sqrt105_4 * cd * csd * (3.0 * sd2 - 1.0) * cp2;
					*dw++ = x->x_sqrt105_4 * cd * csd * (3.0 * sd2 - 1.0) * sp2;
					*dw++ = 0.25 * x->x_sqrt15_2 * cd * (sd2 * (21.0 * sd2 - 14.0) + 1.0) * cp;
					*dw++ = 0.25 * x->x_sqrt15_2 * cd * (sd2 * (21.0 * sd2 - 14.0) + 1.0) * sp;
					*dw = 0.125 * sd * (sd2 * (63.0 * sd2 - 70.0) + 15.0);
				}
			}
		}
	}
}
Example #15
0
void GEMglFogfv :: paramsMess (int argc, t_atom*argv) {	// FUN
  int i = (argc<FOG_ARRAY_LENGTH)?argc:FOG_ARRAY_LENGTH;
  while(i--)params[i]=atom_getfloat(argv+i);
  setModified();
}
Example #16
0
static void readDoubleFromList (int n, t_atom *l, double *f) 
{
  while (n--) 
    *f++ = (double)atom_getfloat (l++);
}
Example #17
0
void *granufm_new(t_symbol *s, long argc, t_atom *argv)
{
    int n;
	t_grans *x = (t_grans *)pd_new(granufm_class);
    
	if (x) {
        
        x->numinlets = 8;
        for(n = 0; n < x->numinlets; n++)
            inlet_new(&x->ob, &x->ob.ob_pd, &s_signal, &s_signal);
        
        x->maxoscillators = DEFAULTMAXOSCILLATORS;
        
        
        x->x_arrayname = NULL;
        x->x_npoints = 0;
        x->x_vec = 0;
        
        if( argc > 0)
        {
            int i;
            t_atom *ap;
            for (i = 0, ap = argv; i < argc; i++, ap++) {
                if(ap->a_type == A_FLOAT)
                {
                    switch(i){
                        case 0:
                            n = atom_getfloat(ap);
                            x->maxoscillators = (int)n;
                            // object_post((t_object *)x, "%d oscillators initialized", n);
                            break;
                        case 1:
                            n = atom_getfloat(ap);
                            x->numoutlets = n;
                            // object_post((t_object *)x, "%d outlets?", n);
                            
                            while(n--){
                                outlet_new(&x->ob, &s_signal);
                            }
                        default:
                            break;
                    }
                }
                else if(ap->a_type == A_SYMBOL)
                {
                    //pseudo attributes here
                    //@envbuffer
                    //(@buffer for granubuf)
                
                }

            }
            
        }
        else
        {
            x->numoutlets = 1;
            outlet_new(&x->ob, &s_signal);
            
        }
		
    //    x->ob.z_misc |= Z_NO_INPLACE;
        
        x->w = (t_int **)malloc((x->numoutlets + x->numinlets + 2) * sizeof(t_int *)); //DSP vector array
        
		x->base = (t_osc *)calloc(x->maxoscillators, sizeof(t_osc));

        x->samplerate =  sys_getsr();
        if(x->samplerate<=0)
            x->samplerate = 44100;
        
        
        x->sampleinterval = 1.0 / x->samplerate;
        x->pkw = ( STABSZ * x->sampleinterval ) ;
        
        x->maxhz = (x->samplerate / 2) * x->pkw;
        x->nosc = x->next_nosc = 0;
        
        x->prev_in1 = 0.0;
        
       // x->sincripples = 5; //could make this an attribute, or maybe compute sinc in realtime...
       // I just made it a #define macro in the pd rev
        
        grans_clear(x);
        
        x->always_on = 0;
        
        
    } else {
        post("this is potentially bad!");
    }
    
	return (x);
}
Example #18
0
static void vvplus_lst(t_vvplus *x, t_symbol *s, int argc, t_atom *argv)
{
  t_float *fp;
  t_atom  *ap;
  int n;

  if (argc){
    if (x->n1 != argc) {
      freebytes(x->buf1, x->n1 * sizeof(t_float));
      x->n1 = argc;
      x->buf1=(t_float *)getbytes(sizeof(t_float)*x->n1);
    };
    fp = x->buf1;
    while(argc--)*fp++=atom_getfloat(argv++);
  }

  if (x->n1*x->n2==1){
    outlet_float(x->x_obj.ob_outlet, *x->buf1+*x->buf2);
    return;
  }
  if (x->n1==1){
    t_atom *a;
    int i = x->n2;
    t_float f = *x->buf1;
    fp = x->buf2;
    n = x->n2;
    ap = (t_atom *)getbytes(sizeof(t_atom)*n);
    a = ap;
    while(i--){
      SETFLOAT(a, *fp+++f);
      a++;
    }
  } else if (x->n2==1){
    t_float f = *x->buf2;
    t_atom *a;
    int i = x->n1;
    n = x->n1;
    ap = (t_atom *)getbytes(sizeof(t_atom)*n);
    a = ap;
    fp = x->buf1;
    while(i--){
      SETFLOAT(a, *fp+++f);
      a++;
    }
  } else {
    t_atom *a;
    int i;
    t_float *fp2=x->buf2;
    fp = x->buf1;
    n = x->n1;
    if (x->n1!=x->n2){
      post("scalar multiplication: truncating vectors to the same length");
      if (x->n2<x->n1)n=x->n2;
    }
    ap = (t_atom *)getbytes(sizeof(t_atom)*n);
    a = ap;
    i=n;
    while(i--){
      SETFLOAT(a, *fp+++*fp2++);
      a++;
    }
  }
  outlet_list(x->x_obj.ob_outlet, gensym("list"), n, ap);
  freebytes(ap, sizeof(t_atom)*n);
}
Example #19
0
static void radialBeamformSetWNG (RadialBeamform *x,  t_object *attr, int argc, t_atom *argv) {
    float max_wng,curr_lvl,next_lvl,curr_omega,next_omega,curr_slope,next_slope;
    float *shn_bpnum=sph_omega_bp[x->sh_degree];
    int n_bpnum=sph_bp_n[x->sh_degree];
    float *shn_bpden=sph_omega_bp[x->sh_degree];;
    int n_bpden=sph_bp_n[x->sh_degree];
    int knum=0;
    int kden=0;
    float one_over_dn=1.0f/x->delta_n;
    float one_over_dn0=1.0f/x->delta_n0;
    
    if ((argc<1)|(argv[0].a_type!=A_FLOAT && (argv[0].a_type!=A_LONG))) {
        post("radial_beamform~: no value given for wng");
        max_wng=20.0f;
    }
    else
        max_wng = atom_getfloat(&argv[0]);
    
    x->max_wng=max_wng;
    
    if (x->bf_mode==VELOCITY) {
        shn_bpden = sph_omega_bpd[x->sh_degree];
        n_bpden = sph_bpd_n[x->sh_degree];
    }
    
    next_slope=0.0f;
    next_omega=1000.0f;
    next_lvl=0.0f;
    
    do {
        curr_omega=next_omega;
        curr_lvl=next_lvl;
        curr_slope=next_slope;
        if ((knum<n_bpnum)&&(kden<n_bpden)) {
            if (shn_bpden[kden]*one_over_dn0>shn_bpnum[knum]*one_over_dn) {
                next_omega=shn_bpden[kden++]*one_over_dn0;
                next_slope+=6.0f;
            }
            else{
                next_omega=shn_bpnum[knum++]*one_over_dn;
                next_slope-=6.0f;
            }
        }
        else if (kden<n_bpden) {
            next_omega=shn_bpden[kden++]*one_over_dn0;
            next_slope+=6.0f;
        }
        else if (knum<n_bpnum) {
            next_omega=shn_bpnum[knum++]*one_over_dn;
            next_slope-=6.0f;
        } 
        else {
            break;
        }
        next_lvl = curr_lvl + curr_slope * (log2f(curr_omega)-log2f(next_omega));
    } while (next_lvl<max_wng);
    
    if (curr_slope>0.0f) {
        next_omega=curr_omega*pow(2.0f,(curr_lvl-max_wng)/curr_slope); 
    }
    else {
        next_omega=0;
    }
    x->omega_cutoff=next_omega;
    x->slope_cutoff=curr_slope;
    //   radialBeamformInfo(x);
}
Example #20
0
void bed_normalize(t_bed *x, t_symbol *msg, short argc, t_atom *argv)
{
    if (argc > 1) {
        error("bed • The message must have at most two members");
        return;
    }

    float newmax = 1.0;
    if (argc == 1) {
        newmax = atom_getfloat(argv);
    }

    if (!bed_attach_buffer(x)) {
        return;
    }

    t_buffer *b;
    b = x->buffer;

    ATOMIC_INCREMENT(&b->b_inuse);

    if (!b->b_valid) {
        ATOMIC_DECREMENT(&b->b_inuse);
        post("bed • Not a valid buffer!");
        return;
    }

    long chunksize = b->b_frames * b->b_nchans * sizeof(float);
    if (x->undo_samples == NULL) {
        x->undo_samples = (float *)sysmem_newptr(chunksize);
    } else {
        x->undo_samples = (float *)sysmem_resizeptr(x->undo_samples, chunksize);
    }

    if (x->undo_samples == NULL) {
        error("bed • Cannot allocate memory for undo");
        x->can_undo = 0;
        ATOMIC_DECREMENT(&b->b_inuse);
        return;
    } else {
        x->can_undo = 1;
        x->undo_start = 0;
        x->undo_frames = b->b_frames;
        x->undo_resize = 0;
        x->undo_cut = 0;
        sysmem_copyptr(b->b_samples, x->undo_samples, chunksize);
    }

    float maxamp = 0.0;
    for (int ii = 0; ii < b->b_frames * b->b_nchans; ii++) {
        if (maxamp < fabs(b->b_samples[ii])) {
            maxamp = fabs(b->b_samples[ii]);
        }
    }

    float rescale;
    if (maxamp > 1e-6) {
        rescale = newmax / maxamp;
    } else {
        post("bed • Amplitude is too low to rescale: %.2f", maxamp);
        ATOMIC_DECREMENT(&b->b_inuse);
        return;
    }

    for (int ii = 0; ii < b->b_frames * b->b_nchans; ii++) {
        b->b_samples[ii] *= rescale;
    }

    object_method(&b->b_obj, gensym("dirty"));
    ATOMIC_DECREMENT(&b->b_inuse);
}
Example #21
0
// ATTRIBUTE: gain
t_max_err attr_set_gain(t_gain *x, void *attr, long argc, t_atom *argv)
{
	x->attrGain = atom_getfloat(argv);
	x->gain->setAttributeValue(TT("midiGain"), x->attrGain);
	return MAX_ERR_NONE;
}
Example #22
0
static void oscformat_list(t_oscformat *x, t_symbol *s, int argc, t_atom *argv)
{
    int typeindex = 0, j, msgindex, msgsize, datastart, ndata;
    t_atom *msg;
    char *sp, *formatp = x->x_format->s_name, typecode;
        /* pass 1: go through args to find overall message size */
    for (j = ndata = 0, sp = formatp, msgindex = 0; j < argc;)
    {
        if (*sp)
            typecode = *sp++;
        else if (argv[j].a_type == A_SYMBOL)
            typecode = 's';
        else typecode = 'f';
        if (typecode == 's')
            msgindex += ROUNDUPTO4(strlen(argv[j].a_w.w_symbol->s_name) + 1);
        else if (typecode == 'b')
        {
            int blobsize = 0x7fffffff, blobindex;
                /* check if we have a nonnegative size field */
            if (argv[j].a_type == A_FLOAT &&
                (int)(argv[j].a_w.w_float) >= 0)
                    blobsize = (int)(argv[j].a_w.w_float);
            if (blobsize > argc - j - 1)
                blobsize = argc - j - 1;    /* if no or bad size, eat it all */
            msgindex += 4 + ROUNDUPTO4(blobsize);
            j += blobsize;
        }
        else msgindex += 4;
        j++;
        ndata++;
    }
    datastart = ROUNDUPTO4(strlen(x->x_pathbuf)+1) + ROUNDUPTO4(ndata + 2);
    msgsize = datastart + msgindex;
    msg = (t_atom *)alloca(msgsize * sizeof(t_atom));
    putstring(msg, &typeindex, x->x_pathbuf);
    SETFLOAT(&msg[typeindex], ',');
    typeindex++;
        /* pass 2: fill in types and data portion of packet */
    for (j = 0, sp = formatp, msgindex = datastart; j < argc;)
    {
        if (*sp)
            typecode = *sp++;
        else if (argv[j].a_type == A_SYMBOL)
            typecode = 's';
        else typecode = 'f';
        SETFLOAT(&msg[typeindex], typecode & 0xff);
        typeindex++;
        if (typecode == 'f')
        {
            union
            {
                float z_f;
                uint32_t z_i;
            } z;
            z.z_f = atom_getfloat(&argv[j]);
            WRITEINT(msg+msgindex, z.z_i);
            msgindex += 4;
        }
        else if (typecode == 'i')
        {
            int dat = atom_getfloat(&argv[j]);
            WRITEINT(msg+msgindex, dat);
            msgindex += 4;
        }
        else if (typecode == 's')
            putstring(msg, &msgindex, argv[j].a_w.w_symbol->s_name);
        else if (typecode == 'b')
        {
            int blobsize = 0x7fffffff, blobindex;
            if (argv[j].a_type == A_FLOAT &&
                (int)(argv[j].a_w.w_float) >= 0)
                    blobsize = (int)(argv[j].a_w.w_float);
            if (blobsize > argc - j - 1)
                blobsize = argc - j - 1;
            WRITEINT(msg+msgindex, blobsize);
            msgindex += 4;
            for (blobindex = 0; blobindex < blobsize; blobindex++)
                SETFLOAT(msg+msgindex+blobindex,
                    (argv[j+1+blobindex].a_type == A_FLOAT ?
                        argv[j+1+blobindex].a_w.w_float :
                        (argv[j+1+blobindex].a_type == A_SYMBOL ?
                            argv[j+1+blobindex].a_w.w_symbol->s_name[0] & 0xff :
                            0)));
            j += blobsize;
            while (blobsize & 3)
                SETFLOAT(msg+msgindex+blobsize, 0), blobsize++;
            msgindex += blobsize;
        }
        j++;
    }
    SETFLOAT(&msg[typeindex], 0);
    typeindex++;
    while (typeindex & 3)
        SETFLOAT(&msg[typeindex], 0), typeindex++;
    if (typeindex != datastart || msgindex != msgsize)
        bug("oscformat: typeindex %d, datastart %d, msgindex %d, msgsize %d",
            typeindex, datastart, msgindex, msgsize);
    /* else post("datastart %d, msgsize %d", datastart, msgsize); */
    outlet_list(x->x_obj.ob_outlet, 0, msgsize, msg);
}
Example #23
0
static void blackboard_line(t_blackboard *x, t_symbol *s, int argc, t_atom *argv)
{
    if(x->f_ninstructions >= _blackboard::maxcmd)
    {
        pd_error(x, "%s too many drawing commands.", eobj_getclassname(x)->s_name);
        return;
    }
    
    if(argc > 3 && argv)
    {
        if (atom_gettype(argv) == A_FLOAT && atom_gettype(argv+1) == A_FLOAT && atom_gettype(argv+2) == A_FLOAT && atom_gettype(argv+3) == A_FLOAT)
        {
            sprintf(x->f_instructions[x->f_ninstructions], "create line %d %d %d %d -fill %s -width %d", (int)atom_getfloat(argv), (int)atom_getfloat(argv+1), (int)atom_getfloat(argv+2), (int)atom_getfloat(argv+3), x->f_color->s_name, (int)x->f_width);
            x->f_ninstructions++;
        }
        ebox_redraw((t_ebox *)x);
    }
}
Example #24
0
File: atsread.c Project: bion/ats
void atsread_any(t_atsread *x, t_symbol *s, int argc, t_atom *argv){
	char * filename;
	int i, j, from, to;
	t_symbol * temp;

	if(strcmp(s->s_name, "open") == 0){
		//open data file
		if(argc < 1){
			post("ATSREAD: you need to specify a file name");
			return;
		}
		
		temp = atom_getsymbol(&argv[0]);
		
		if(temp == NULL){
			post("ATSREAD: not a valid filename");
			return;
		}
		readdatafile(x, temp->s_name);
		x->berrflg = 1;
		return;
	}
	if(strcmp(s->s_name, "noise") == 0){
		x->outnz = 1;
		post("ATSREAD: outputing noise, if there is any");
		return;
	}
	if(strcmp(s->s_name, "nonoise") == 0){
		x->outnz = 0;
		post("ATSREAD: not outputing noise");
		return;
	}
	if(strcmp(s->s_name, "sines") == 0){
		x->outsines = 1;
		post("ATSREAD: outputing sines");
		return;
	}
	if(strcmp(s->s_name, "nosines") == 0){
		x->outsines = 0;
		post("ATSREAD: not outputing sines");
		return;
	}
	
	/* BELOW HERE WE DEAL WITH PARTIAL and BAND ADDING/SETTING/REMOVING */
	
	if(x->atshead.magic != 123){
		post("ATSREAD: you must open a file before setting up the partials");
		return;
	}
	if(argc < 1){
		post("ATSREAD: you need to specify at least 1 partial/band to set/add/remove");
		return;
	}
	
	if(strcmp(s->s_name, "set") == 0 || strcmp(s->s_name, "add") == 0){
		//set or add partials to output
		if(strcmp(s->s_name, "set") == 0){
			//clear the data table
			for(i = 0; i < (int)x->atshead.npartials; i++)
				x->outpartials[i] = 0;
		}
		
		for(i = 0; i < argc; i++){
			temp = atom_getsymbol(&argv[i]);
			if(strcmp(temp->s_name, "float") == 0){
				j = (int)atom_getfloat(&argv[i]);
				if(j < 1)
					j = 1;
				else if(j >= (int)x->atshead.npartials)
					j = (int)x->atshead.npartials;
				x->outpartials[j - 1] = 1;
			}
			else{
				if(sscanf(temp->s_name, "%i..%i", &from, &to) == 2){
					if(from > to){
						j = from;
						from = to;
						to = j;
					}
					if(from < 1)
						from = 1;
					if(to > (int)x->atshead.npartials)
						to = (int)x->atshead.npartials;
					for(j = from; j <= to; j++)
						x->outpartials[j-1] = 1;
				}
				else
					post("ATSREAD: %s is not a valid range (ie 1..42) or partial number (ie 12)", temp->s_name);
			}
		}
		return;
	}
	if(strcmp(s->s_name, "remove") == 0){
		//remove partials
		for(i = 0; i < argc; i++){
			temp = atom_getsymbol(&argv[i]);
			if(strcmp(temp->s_name, "float") == 0){
				j = (int)atom_getfloat(&argv[i]);
				if(j < 1)
					j = 1;
				else if(j >= (int)x->atshead.npartials)
					j = (int)x->atshead.npartials;
				x->outpartials[j - 1] = 0;
			}
			else{
				if(sscanf(temp->s_name, "%i..%i", &from, &to) == 2){
					if(from > to){
						j = from;
						from = to;
						to = j;
					}
					if(from < 1)
						from = 1;
					if(to > (int)x->atshead.npartials)
						to = (int)x->atshead.npartials;
					for(j = from; j <= to; j++)
						x->outpartials[j-1] = 0;
				}
				else
					post("ATSREAD: %s is not a valid range (ie 1..42) or partial number (ie 12)", temp->s_name);
			}
		}
		return;
	}
	if(strcmp(s->s_name, "setnz") == 0 || strcmp(s->s_name, "addnz") == 0){
		//set or add bands to output
		if(strcmp(s->s_name, "setnz") == 0){
			//clear the data table
			for(i = 0; i < 25; i++)
				x->outnzbands[i] = 0;
		}
		
		for(i = 0; i < argc; i++){
			temp = atom_getsymbol(&argv[i]);
			if(strcmp(temp->s_name, "float") == 0){
				j = (int)atom_getfloat(&argv[i]);
				if(j < 1)
					j = 1;
				else if(j >= 25)
					j = 25;
				x->outnzbands[j - 1] = 1;
			}
			else{
				if(sscanf(temp->s_name, "%i..%i", &from, &to) == 2){
					if(from > to){
						j = from;
						from = to;
						to = j;
					}
					if(from < 1)
						from = 1;
					if(to > 25)
						to = 25;
					for(j = from; j <= to; j++)
						x->outnzbands[j-1] = 1;
				}
				else
					post("ATSREAD: %s is not a valid range (ie 1..25) or band number (ie 2)", temp->s_name);
			}
		}
		return;
	}
	if(strcmp(s->s_name, "removenz") == 0){
		//remove bands
		for(i = 0; i < argc; i++){
			temp = atom_getsymbol(&argv[i]);
			if(strcmp(temp->s_name, "float") == 0){
				j = (int)atom_getfloat(&argv[i]);
				if(j < 1)
					j = 1;
				else if(j >= 25)
					j = 25;
				x->outnzbands[j - 1] = 0;
			}
			else{
				if(sscanf(temp->s_name, "%i..%i", &from, &to) == 2){
					if(from > to){
						j = from;
						from = to;
						to = j;
					}
					if(from < 1)
						from = 1;
					if(to > 25)
						to = 25;
					for(j = from; j <= to; j++)
						x->outnzbands[j-1] = 0;
				}
				else
					post("ATSREAD: %s is not a valid range (ie 1..25) or band number (ie 12)", temp->s_name);
			}
		}
		return;
	}
}
Example #25
0
static void blackboard_image(t_blackboard *x, t_symbol *s, int argc, t_atom *argv)
{
	int fd;
    char path[MAXPDSTRING];
	char name[MAXPDSTRING];
	char *nameptr;
    
    if(x->f_ninstructions >= _blackboard::maxcmd)
    {
        pd_error(x, "%s too many drawing commands.", eobj_getclassname(x)->s_name);
        return;
    }

    if(argc > 2 && argv)
    {
        if(atom_gettype(argv) == A_FLOAT && atom_gettype(argv+1) == A_FLOAT && atom_gettype(argv+2) == A_SYMBOL)
        {
            sprintf(path, "%s",atom_getsymbol(argv+2)->s_name);
            if(access(path, O_RDONLY) != -1)
            {
                sprintf(x->f_instructions[x->f_ninstructions], "create image %d %d -anchor nw -image [image create photo -file %s]", (int)atom_getfloat(argv), (int)atom_getfloat(argv+1), path);
                
                x->f_ninstructions++;
                ebox_redraw((t_ebox *)x);
                return;
            }
            sprintf(path, "%s/%s", canvas_getdir(x->j_box.b_obj.o_canvas)->s_name, atom_getsymbol(argv+2)->s_name);
            if(access(path, O_RDONLY) != -1)
            {
                sprintf(x->f_instructions[x->f_ninstructions], "create image %d %d -anchor nw -image [image create photo -file %s]", (int)atom_getfloat(argv), (int)atom_getfloat(argv+1), path);
                
                x->f_ninstructions++;
                ebox_redraw((t_ebox *)x);
                return;
            }
			sprintf(name, "%s", atom_getsymbol(argv+2)->s_name);
			if(!strncmp(name+strlen(name)-4, ".gif", 4))
			{
				strncpy(name+strlen(name)-4, "\0", 4);
			}

			fd = open_via_path(canvas_getdir(x->j_box.b_obj.o_canvas)->s_name, name,  ".gif", path, &nameptr, MAXPDSTRING, 0);
            if(fd >= 0)
			{
                sprintf(x->f_instructions[x->f_ninstructions], "create image %d %d -anchor nw -image [image create photo -file %s/%s.gif]", (int)atom_getfloat(argv), (int)atom_getfloat(argv+1), path, name);
                
                x->f_ninstructions++;
                ebox_redraw((t_ebox *)x);
				return;
			}
        }
    }
    
}
Example #26
0
// ATTRIBUTE: position
t_max_err attr_set_position(t_fade *x, void *attr, long argc, t_atom *argv)
{
	fade_float(x, atom_getfloat(argv));
	return MAX_ERR_NONE;
}
static void *iem_append_kernel_new(void)
{
  t_iem_append_kernel *x = (t_iem_append_kernel *)pd_new(iem_append_kernel_class);
  t_glist *glist = (t_glist *)canvas_getcurrent();
  t_canvas *canvas=glist_getcanvas(glist);
  int ac=0;
  t_atom *av;
  
  canvas_setcurrent(canvas);
  canvas_getargs(&ac, &av);
  canvas_unsetcurrent(canvas);
  
  x->x_type1 = A_NULL;
  x->x_sym1 = &s_list;
  x->x_size2 = 10;
  if(ac > 5)
    x->x_size2 = 2*ac;
  x->x_at2 = (t_atom *)getbytes(x->x_size2 * sizeof(t_atom));
  x->x_size12 = x->x_size2 + 10;
  x->x_at12 = (t_atom *)getbytes(x->x_size12 * sizeof(t_atom));
  x->x_ac1 = 0;
  x->x_inlet_select = 1;
  if(ac <= 0)
  {
    x->x_type2 = A_NULL;
    x->x_ac2 = 0;
    x->x_sym2 = &s_list;
  }
  else
  {
    if(IS_A_FLOAT(av, 0))
    {
      if(ac == 1)
        iem_append_kernel_float(x, atom_getfloat(av));
      else
        iem_append_kernel_list(x, &s_list, ac, av);
    }
    else if(IS_A_SYMBOL(av, 0))
    {
      t_symbol *xsym=atom_getsymbol(av);
      
      if(xsym == gensym("symbol"))
      {
        if(ac > 1)
          iem_append_kernel_symbol(x, atom_getsymbol(av+1));
        else
          iem_append_kernel_symbol(x, gensym(""));
      }
      else if(xsym == gensym("float"))
      {
        if(ac > 1)
        {
          if(IS_A_FLOAT(av, 1))
            iem_append_kernel_float(x, atom_getfloat(av+1));
          else
            iem_append_kernel_float(x, 0.0f);
        }
        else
          iem_append_kernel_float(x, 0.0f);
      }
      else if(xsym == gensym("list"))
      {
        iem_append_kernel_list(x, &s_list, ac-1, av+1);
      }
      else
      {
        iem_append_kernel_anything(x, xsym, ac-1, av+1);
      }
    }
  }
  outlet_new(&x->x_obj, &s_list);
  return (x);
}
int pd_extern_sched(char *flags)
{
    int naudioindev, audioindev[MAXAUDIOINDEV], chindev[MAXAUDIOINDEV];
    int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV];
    int i, j, rate, advance, callback, chin, chout, fill = 0, c;
    t_binbuf *b = binbuf_new();

    sys_get_audio_params(&naudioindev, audioindev, chindev,
        &naudiooutdev, audiooutdev, choutdev, &rate, &advance, &callback);

    chin = (naudioindev < 1 ? 0 : chindev[0]);
    chout = (naudiooutdev < 1 ? 0 : choutdev[0]);

    fprintf(stderr, "Pd plug-in scheduler called, chans %d %d, sr %d\n",
        chin, chout, (int)rate);
    sys_setchsr(chin, chout, rate);
    sys_audioapi = API_NONE;
    while ((c = getchar()) != EOF)
    {
        if (c == ';')
        {
            int n;
            t_atom *ap;
            binbuf_text(b, inbuf, fill);
            n = binbuf_getnatom(b);
            ap = binbuf_getvec(b);
            fill = 0;
            if (n > 0 && ap[0].a_type == A_FLOAT)
            {
                /* a list -- take it as incoming signals. */
                int chan, nchan = n/DEFDACBLKSIZE;
                t_sample *fp;
                for (i = chan = 0, fp = sys_soundin; chan < nchan; chan++)
                    for (j = 0; j < DEFDACBLKSIZE; j++)
                        *fp++ = atom_getfloat(ap++);
                for (; chan < chin; chan++)
                    for (j = 0; j < DEFDACBLKSIZE; j++)
                        *fp++ = 0;
                sched_tick(sys_time+sys_time_per_dsp_tick);
                sys_pollgui();
                printf(";\n");
                for (i = chout*DEFDACBLKSIZE, fp = sys_soundout; i--; fp++)
                {
                    printf("%g\n", *fp);
                    *fp = 0;
                }
                printf(";\n");
                fflush(stdout);
            }
            else if (n > 1 && ap[0].a_type == A_SYMBOL)
            {
                t_pd *whom = ap[0].a_w.w_symbol->s_thing;
                if (!whom)
                    error("%s: no such object", ap[0].a_w.w_symbol->s_name);
                else if (ap[1].a_type == A_SYMBOL)
                    typedmess(whom, ap[1].a_w.w_symbol, n-2, ap+2);
                else pd_list(whom, 0, n-1, ap+1);
            }
        }
        else if (fill < BUFSIZE)
            inbuf[fill++] = c;
        else if (fill == BUFSIZE)
            fprintf(stderr, "pd-extern: input buffer overflow\n");
    }
    return (0);
}
Example #29
0
static void route_list(t_route *x, t_symbol *sel, int argc, t_atom *argv)
{
    t_routeelement *e;
    int nelement;
    if (x->x_type == A_FLOAT || x->x_mixed)
    {
        t_float f;
        if (!argc) return;
        if (argv->a_type != A_FLOAT)
            goto try_symbol;
        f = atom_getfloat(argv);
        for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
            if (e->e_w.w_float == f)
        {
            if (argc > 1 && argv[1].a_type == A_SYMBOL)
                outlet_anything(e->e_outlet, argv[1].a_w.w_symbol,
                    argc-2, argv+2);
            else outlet_list(e->e_outlet, 0, argc-1, argv+1);
            return;
        }
    }
 try_symbol:
    if (x->x_type == A_SYMBOL || x->x_mixed)    /* symbol arguments */
    {
        if (argc > 1)       /* 2 or more args: treat as "list" */
        {
            for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
            {
                if (e->e_w.w_symbol == &s_list)
                {
                    if (argc > 0 && argv[0].a_type == A_SYMBOL)
                        outlet_anything(e->e_outlet, argv[0].a_w.w_symbol,
                            argc-1, argv+1);
                    else outlet_list(e->e_outlet, 0, argc, argv);
                    return;
                }
            }
        }
        else if (argc == 0)         /* no args: treat as "bang" */
        {
            for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
            {
                if (e->e_w.w_symbol == &s_bang)
                {
                    outlet_bang(e->e_outlet);
                    return;
                }
            }
        }
        else if (argv[0].a_type == A_FLOAT)     /* one float arg */
        {
            for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
            {
                if (e->e_w.w_symbol == &s_float)
                {
                    outlet_float(e->e_outlet, argv[0].a_w.w_float);
                    return;
                }
            }
        }
        else if (argv[0].a_type == A_SYMBOL)   /* one symbol arg */
        {
            for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
            {
                if (e->e_w.w_symbol == &s_symbol)
                {
                    outlet_symbol(e->e_outlet, argv[0].a_w.w_symbol);
                    return;
                }
            }
        }
    }
 rejected:
    outlet_list(x->x_rejectout, 0, argc, argv);
}
Example #30
0
File: fwriteln.c Project: Tzero2/pd
static void fwriteln_write (t_fwriteln *x, t_symbol *s, int argc, t_atom *argv)
{
   int length=0;
   char *text=x->x_textbuf;
   if (x->x_file) {
      if ((s!=gensym("list"))||(argv->a_type==A_SYMBOL)) {
         snprintf(text,MAXPDSTRING,"%s ", s->s_name);
         text[MAXPDSTRING-1]=0;
         length=strlen(text);
         if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) {
            pd_error(x, "failed to write %128s",x->x_filename);
            freebytes (text, MAXPDSTRING * sizeof(char));
            fwriteln_close(x);
            return;
         }
      }
      while (argc--)
      {
         switch (argv->a_type) {
            case A_FLOAT:
              snprintf(text,MAXPDSTRING,x->format_string_afloats,
                       atom_getfloat(argv));
              text[MAXPDSTRING-1]=0;
              length=strlen(text);
              if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) {
                pd_error(x, "failed to write %128s",x->x_filename);
                freebytes (text, MAXPDSTRING * sizeof(char));
                fwriteln_close(x);
                return;
              }
              break;
         case A_SYMBOL:
           snprintf(text,MAXPDSTRING,"%s ", atom_getsymbol(argv)->s_name);
           text[MAXPDSTRING-1]=0;
           length=strlen(text);
           if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) {
             pd_error(x, "failed to write %128s",x->x_filename);
             freebytes (text, MAXPDSTRING * sizeof(char));
             fwriteln_close(x);
             return;
           }
           break;
         case A_COMMA:
           snprintf(text,MAXPDSTRING,", ");
           length=strlen(text);
           if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) {
             pd_error(x, "failed to write %128s",x->x_filename);
             freebytes (text, MAXPDSTRING * sizeof(char));
             fwriteln_close(x);
             return;
           }
           break;
         case A_SEMI:
           snprintf(text,MAXPDSTRING,"; ");
           length=strlen(text);
           if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) {
             pd_error(x, "failed to write %128s",x->x_filename);
             freebytes (text, MAXPDSTRING * sizeof(char));
             fwriteln_close(x);
             return;
           }
           break;
         default:
           break;
         }
         argv++;
      }

      snprintf(text,MAXPDSTRING,"%s", x->linebreak_chr);
      length=strlen(text);
      if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) {
         pd_error(x, "failed to write %128s",x->x_filename);
         freebytes (text, MAXPDSTRING * sizeof(char));
         fwriteln_close(x);
         return;
      }
   }
   else {
      pd_error(x, "no file opened for writing");
   }
}