/* CRELAYER.C
 * The routine that implements the 'Create Layer' message.
 *
 * Copyright (C) 1991 by Andrew Arensburger. Permission is granted to
 * use, copy and/or distribute this file freely for non-commercial purposes,
 * as long as this notice remains intact. Any commercial use is prohibited
 * without express permission from the author.
 *
 * If you make any changes, fix bugs, etc., please send them to me that I
 * might coordinate fixes and improvements.
 */

#include <stdio.h>
#include "eps.h"

/* CRE_LAYER
 * Create a new layer, with one wavesample.
 * Returns 0 on no error, or a negative error code.
 */
int cre_layer(chan,inst)
int chan;			/* MIDI channel */
edit_spec *inst;		/* Which layer? */
{
	int i;

	/* Send instruction to create new layer */
	send_head(chan);	/* Send SysEx head */
	mpu_sbyte(CRE_LAYER);	/* 'Create Layer' message */
	send12(inst->inst_num);	/* Instrument number */
	send12(inst->layer_num);/* Layer number */
	send12(inst->ws_num);	/* Wavesample number */
	send_tail();		/* Send SysEx tail */

	if (timeout(SHORT_TIMEOUT))
		return(-1);	/* Short timeout occurred */

	/* Receive response to see if everything went well */
	i = recv_response(NULL);

	wait(BREATHER);
	if (i == ACK)
		return(0);		/* All went well */
	else
		return(-1);		/* There was some error */
}
