/* PUTLAYER.C * The routine that implements the 'Put 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 #include "eps.h" /* PUT_LAYER * Set the parameters of the layer described in 'inst' to the * values given in 'params'. * Returns 0 on no error, or a negative error code. */ int put_layer(chan,inst,params) int chan; /* MIDI channel */ edit_spec *inst; /* Which layer? */ layer_par *params; /* Layer parameters */ { int i; int waiting; /* Are we waiting for the EPS to do things? */ /* Check parameters */ /* Name: the EPS (apparently) only accepts names in the * set ' ', *, -, +, 0-9, A-Z. Check to see that all the * characters in the name are in this range. */ for (i = 0; i < 12; i++) if (params->name[i] != ' ' && params->name[i] != '*' && params->name[i] != '-' && params->name[i] != '+' && (params->name[i] < '0' || params->name[i] > '9') && (params->name[i] < 'A' || params->name[i] > 'Z')) return(-5); /* Send instruction to await instrument parameters */ send_head(chan); /* Send SysEx head */ mpu_sbyte(PUT_LAYER); /* 'Put 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 */ /* This loop is a bit tricky. The basic idea is that the EPS can * send out one of three responses at this point: ACK, WAIT, or * something else. * If it sends an ACK, then all is well, and we can go on to * receive the data. If it sends a something else, then there's * clearly an error, and we can abort with a clean conscience. * If it sends a WAIT, however, then we have to wait for up to * 30 seconds, during which time any of the above can happen, * including a second, third, etc. WAIT message. * If the EPS has sent a WAIT, it will send an ACK before * sending the data (but this was implied by the above para- * graphs). */ waiting = 1; while (waiting) { /* See which response the EPS sends, and react * accordingly. */ switch(recv_response(NULL)) { case ACK: /* Acknowledgement */ waiting = 0; /* Stop waiting */ break; case WAIT: /* Wait for up to 30 seconds */ send_response(chan, ACK); /* Okay, I'll wait */ /* Wait for a timeout */ if (timeout(LONG_TIMEOUT)) return(-3); /* 30-sec timeout * has occurred */ break; default: /* Something's wrong */ wait(BREATHER); return(-4); } } /* Send layer parameters */ send_head(chan); for (i = 0; i < 12; i++) /* Send instrument name */ send16(params->name[i] << 8); send16(params->glidemode << 8); /* Send glide mode */ send16(params->glidetime << 8); /* Send glide time */ send16(params->legato_lay << 8);/* Send legato layer number */ send16(params->low_vel << 8); /* Send velocity low */ send16(params->high_vel << 8); /* Send velocity high */ send16(params->pitch_tab << 8); /* Send pitch table number */ send16(0x00); /* Unused */ for (i = 0; i < 88; i++) /* Send layer map */ send16(params->layermap[i] << 8); send_tail(); /* Send end of SysEx */ /* Receive response to see if everything went well */ i = recv_response(NULL); wait(BREATHER); if (i == ACK) return(0); /* All went well */ else return(-2); /* There was some error */ }