/* AUDWS.C * The routine that implements the 'Audtion Wavesamples' 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" /* AUDIT_WS * Audition the wavesamples in 'inst' and 'new'. After the audition, * the EPS will delete the instrument that was not chosen. * Returns 0 on no error, or a negative error code. 'which' is set to * 0 if 'inst' was deleted, 1 if 'new' was deleted, and -1 if neither * was deleted. */ int audit_ws(chan,inst,new,which) int chan; /* MIDI channel */ edit_spec *inst; /* Old wavesample */ edit_spec *new; /* New wavesample */ int *which; /* Which one was deleted? */ { int i; int waiting; /* Are we waiting for the EPS to do things? */ /* Send instruction to audition the two wavesamples */ send_head(chan); /* Send SysEx head */ mpu_sbyte(AUDITION); /* 'Audition Wavesamples' message */ send12(inst->inst_num); /* Old instrument number */ send12(inst->layer_num);/* Old layer number */ send12(inst->ws_num); /* Old wavesample number */ send12(new->inst_num); /* New instrument number */ send12(new->layer_num); /* New layer number */ send12(new->ws_num); /* New wavesample number */ send_tail(); /* Send SysEx tail */ *which = -1; /* For the moment, assume that something * went wrong, and that neither wavesample * was deleted. */ 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); } } /* Receive 'Delete Wavesample' message */ *which = 0; /* Assume 'inst' was deleted */ recv_head(NULL); /* Receive head of SysEx message */ mpu_rbyte(); /* Should return 0x1a */ if (recv12() != inst->inst_num) /* If any of the parameters */ *which = 1; /* the deleted wavesample are not */ if (recv12() != inst->layer_num)/* those of 'inst', then the */ *which = 1; /* deleted wavesample must have */ if (recv12() != inst->ws_num) /* been 'new'. */ *which = 1; recv_tail(); /* Send ACK to say that we received the 'Delete Wavesample' * message. */ send_response(chan,ACK); /* 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 */ }