Ejemplo n.º 1
0
/*
	This routine checks and sets instrument parameters.
	npv is number of valid AUpvlist pairs.
*/
void _af_instparam_set (AFfilehandle file, int instid, AUpvlist pvlist, int npv)
{
	int i, instno, j;

	if (!_af_filehandle_ok(file))
		return;

	if (!_af_filehandle_can_write(file))
		return;

	if ((instno = _af_handle_instrument_index_from_id(file, instid)) == -1)
		return;

	if (AUpvgetmaxitems(pvlist) < npv)
	npv = AUpvgetmaxitems(pvlist);

	for (i=0; i < npv; i++)
	{
		int	param;
		int	type;

		AUpvgetparam(pvlist, i, &param);

		if  ((j = _af_instparam_index_from_id(file->fileFormat, param)) == -1)
			/* no parameter with that id; ignore */
			continue;

		if (_af_units[file->fileFormat].write.instparamvalid &&
			!_af_units[file->fileFormat].write.instparamvalid(file, pvlist, i))
			/* bad parameter value; ignore */
			continue;

		type = _af_units[file->fileFormat].instrumentParameters[j].type;

		switch (type)
		{
			case AU_PVTYPE_LONG:
				AUpvgetval(pvlist, i, &file->instruments[instno].values[j].l);
				break;
			case AU_PVTYPE_DOUBLE:
				AUpvgetval(pvlist, i, &file->instruments[instno].values[j].d);
				break;
			case AU_PVTYPE_PTR:
				AUpvgetval(pvlist, i, &file->instruments[instno].values[j].v);
				break;
			default:
				return;
		}
	}
}
Ejemplo n.º 2
0
static _Loop *getLoop (AFfilehandle handle, int instid, int loopid,
	bool mustWrite)
{
	int	loopno, instno;

	if (!_af_filehandle_ok(handle))
		return NULL;

	if (mustWrite && !_af_filehandle_can_write(handle))
		return NULL;

	if ((instno = _af_handle_instrument_index_from_id(handle, instid)) == -1)
		return NULL;

	if ((loopno = _af_handle_loop_index_from_id(handle, instno, loopid)) == -1)
		return NULL;

	return &handle->instruments[instno].loops[loopno];
}
Ejemplo n.º 3
0
void afSetAESChannelData (AFfilehandle file, int trackid, unsigned char buf[24])
{
	_Track	*track;

	if ((track = _af_filehandle_get_track(file, trackid)) == NULL)
		return;

	if (!_af_filehandle_can_write(file))
		return;

	if (track->hasAESData)
	{
		memcpy(track->aesData, buf, 24);
	}
	else
	{
		_af_error(AF_BAD_NOAESDATA,
			"unable to store AES channel status data for track %d",
			trackid);
	}
}
Ejemplo n.º 4
0
int afWriteFrames (AFfilehandle file, int trackid, const void *samples,
	int nvframes2write)
{
	_AFmoduleinst	*firstmod;
	_AFchunk	*userc;
	_Track		*track;
	int		bytes_per_vframe;
	AFframecount	vframe;

	if (!_af_filehandle_ok(file))
		return -1;

	if (!_af_filehandle_can_write(file))
		return -1;

	if ((track = _af_filehandle_get_track(file, trackid)) == NULL)
		return -1;

	if (track->ms.modulesdirty)
	{
		if (_AFsetupmodules(file, track) != AF_SUCCEED)
			return -1;
	}

	/*if (file->seekok) {*/

	if (af_fseek(file->fh, track->fpos_next_frame, SEEK_SET) < 0)
	{
		_af_error(AF_BAD_LSEEK, "unable to position write pointer at next frame");
		return -1;
	}

	/* } */

	bytes_per_vframe = _af_format_frame_size(&track->v, AF_TRUE);

	firstmod = &track->ms.module[0];
	userc = &track->ms.chunk[0];

	track->filemodhappy = AF_TRUE;

	vframe = 0;
#ifdef UNLIMITED_CHUNK_NVFRAMES
	/*
		OPTIMIZATION: see the comment at the very end of
		arrangemodules() in modules.c for an explanation of this:
	*/
	if (!trk->ms.mustuseatomicnvframes)
	{
		userc->buf = (char *)buf;
		userc->nframes = nvframes2write;

		(*firstmod->mod->run_push)(firstmod);

		/* Count this chunk if there was no i/o error. */
		if (trk->filemodhappy)
			vframe += userc->nframes;
	}
	else
#else
	/* Optimization must be off. */
	assert(track->ms.mustuseatomicnvframes);
#endif
	{
		while (vframe < nvframes2write)
		{
			userc->buf = (char *) samples + bytes_per_vframe * vframe;
			if (vframe <= nvframes2write - _AF_ATOMIC_NVFRAMES)
				userc->nframes = _AF_ATOMIC_NVFRAMES;
			else
				userc->nframes = nvframes2write - vframe;

			(*firstmod->mod->run_push)(firstmod);

			if (track->filemodhappy == AF_FALSE)
				break;

			vframe += userc->nframes;
		}
	}

	track->nextvframe += vframe;
	track->totalvframes += vframe;

	return vframe;
}