コード例 #1
0
ファイル: sdif-mem.c プロジェクト: BlakeJarvis/csound
void SDIFmem_FreeFrame(SDIFmem_Frame f)
{
    SDIFmem_Matrix m, next;

    if (f == 0) return;

    m = f->matrices;
    while (m != NULL) {
      next = m->next;
      SDIFmem_FreeMatrix(m);
      m = next;
    }

    (*my_free)(f, sizeof(*f));
}
コード例 #2
0
ファイル: SDIF-listpoke.c プロジェクト: CNMAT/CNMAT-Externs
static void SDIFlistpoke_listpoke(SDIFlistpoke *x, t_symbol *dummy, short argc, t_atom *argv) {
	int i;
	SDIFmem_Frame f;
	SDIFmem_Matrix m;
	float *mdata;
	char myFrameType[4];
	char myMatrixType[4];
	SDIFresult r;


	// post("* SDIFlistpoke_listpoke: x %p, argc %ld, argv %p", x, argc, argv);
	
 	
	/* Check that arguments are all numbers */
	for (i = 0; i < argc; ++i) {
		if (argv[i].a_type != A_FLOAT && argv[i].a_type != A_LONG) {
			object_post((t_object *)x, "¥ SDIF-listpoke: only numbers allowed in list.");
			return;
		}
	}
	
	/* Check that the number of arguments is a multiple of x->t_num_columns */
	if (argc % x->t_num_columns != 0) {
		post("¥ SDIF-listpoke: %d element list doesn't go into %ld columns.  Ignoring.",
			 argc, x->t_num_columns);
		return;
	}

	/* Get the frame */
	LookupMyBuffer(x);
	
	if (x->t_buffer == 0) {
		object_post((t_object *)x, "¥ SDIF-listpoke: no buffer!");
		return;
	}

  //  decide the frame type
  if(f = SDIFbuf_GetFirstFrame(x->t_buf))
    SDIF_Copy4Bytes(myFrameType, f->header.frameType);
  else
    //  we are about to create first frame in the buffer
    //  (give it the same type as the matrix we are adding)
    SDIF_Copy4Bytes(myFrameType, x->t_matrixType);
  
  //  decide the matrix type
	if (x->t_mainMatrix) {
		SDIF_Copy4Bytes(myMatrixType, myFrameType);
	} else {
		SDIF_Copy4Bytes(myMatrixType, x->t_matrixType);
	}

	/* post("** myMatrixType: %c%c%c%c", myMatrixType[0], myMatrixType[1],
		 myMatrixType[2], myMatrixType[3]); */
	
	f = (*(x->t_buffer->FrameLookup))(x->t_buffer, x->t_time, 0);
	
	if (f == 0) {
		/* There was no frame at the given time */
		// post("** There was no frame at that time");
		f = SDIFmem_CreateEmptyFrame();
		
		if (f == 0) {
			object_post((t_object *)x, "¥ SDIF-listpoke: out of memory for new frame in SDIF-buffer!");
			return;
		}
		
		SDIF_Copy4Bytes(f->header.frameType, myFrameType);
		f->header.time = x->t_time;
		f->header.streamID = x->t_buffer->streamID;
		
		i = (*(x->t_buffer->FrameInsert))(f, x->t_buffer);
		if (i) {
			object_post((t_object *)x, "¥ SDIF-listpoke: FrameInsert returned %d", i);
		}

				
	} else {
		/* There was already a frame at the given time */

		for (m = f->matrices; m != 0; m = m->next) {
			if (SDIF_Char4Eq(myMatrixType, m->header.matrixType)) {
				post("SDIF-listpoke: deleting old matrix %c%c%c%c at time %f",
					 m->header.matrixType[0], m->header.matrixType[1], 
					 m->header.matrixType[2], m->header.matrixType[3], x->t_time);
				r = SDIFmem_RemoveMatrix(f, m);
				if (r != ESDIF_SUCCESS) {
					object_post((t_object *)x, "¥ SDIF-listpoke: Problem removing matrix: %s", SDIF_GetErrorString(r));
				}
			}
		}
	}

	/* Now we know f is a frame in x->t_buffer, at the right time, with no matrix of 
	   the type we want to write into, and that we have to call SDIFmem_RepairFrameHeader(f) */

	m = SDIFmem_CreateEmptyMatrix();

	if (m == 0) {
		object_post((t_object *)x, "¥ SDIF-listpoke: out of memory for new matrix in SDIF-buffer!");
		SDIFmem_FreeFrame(f);
		return;
	}
	
	SDIF_Copy4Bytes(m->header.matrixType, myMatrixType);
	m->header.matrixDataType = SDIF_FLOAT32;
	
	m->header.columnCount = x->t_num_columns;
	m->header.rowCount = argc / x->t_num_columns;  // We checked above that it divides evenly

	// post("** about to getbytes() for the matrix data");

	m->data = getbytes(argc * sizeof(float));
	if (m->data == 0) {
		object_post((t_object *)x, "¥ SDIF-listpoke: out of memory for matrix data in SDIF-buffer!");
		SDIFmem_RemoveMatrix(f, m);
		SDIFmem_FreeMatrix(m);
		SDIFmem_RepairFrameHeader(f);	
		return;
	}

	mdata = m->data;
	for (i = 0; i < argc; ++i) {
		mdata[i] = asfloat(argv[i]);
	}	

	/*
	{
		SDIFmem_Matrix p;
		for (p = f->matrices; p != NULL; p = p->next) {
			post("Matrix: %p, type %c%c%c%c", p, 
				 p->header.matrixType[0], p->header.matrixType[1], p->header.matrixType[2],
				 p->header.matrixType[3]);
		}
	}
	*/
	
	
	// post("** about to SDIFmem_AddMatrix");
	SDIFmem_AddMatrix(f, m);

	// post("** about to SDIFmem_RepairFrameHeader");
	SDIFmem_RepairFrameHeader(f);	
}