/* PUTPARAM.C * The routine that implements the 'Put Parameter' 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_PARAM * Set the parameter 'param' to the value 'value'. If 'param' is a * system parameter, then the instrument, layer and wavesample numbers * are irrelevant. * Returns 0 on no error, or a negative error code. */ int put_param(chan,inst,param,value) int chan; /* MIDI channel */ edit_spec *inst; /* Which instrument? */ int param; /* Parameter number */ ulong value; /* Parameter value */ { int i; int waiting; /* Are we waiting for the EPS to do things? */ /* Send instruction to await instrument parameters */ /* Send parameter number and value */ send_head(chan); /* Send SysEx head */ mpu_sbyte(PUT_PARAM); /* 'Put Parameter' message */ send12(inst->inst_num); /* Instrument number */ send12(inst->layer_num);/* Layer number */ send12(inst->ws_num); /* Wavesample number */ send12((ushort) param); /* Parameter number */ send12((ushort) (value >> 8)); /* High byte of value */ send12((ushort) (value & 0xff));/* Low byte of value */ send_tail(); /* Send SysEx tail */ /* Normally, this command does not require a response. * If a timeout occurs, then all went well. Otherwise, * either the parameter number or value was bogus. */ if (timeout(SHORT_TIMEOUT) != 0) return(0); /* 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); } } return(-1); /* Something must have gone wrong */ }