home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Audio 4.94 - Over 11,000 Files
/
audio-11000.iso
/
amiga
/
midi
/
obrst103.lha
/
OberSuite-1.03
/
SourceCode
/
tomidi.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-01-23
|
3KB
|
120 lines
/**************************************************************************
* tomidi.c: Functions for sending patch data to MIDI.
* A part of OberSuite for the Commodore Amiga.
*
* Author: Daniel Barrett, barrett@cs.umass.edu.
* Version: 1.0.
* Copyright: None! This program is in the Public Domain.
* Please share it with others.
***************************************************************************/
#include "decl.h"
/*
* Send the patch data from the PATCHINFO structure to MIDI.
* Return TRUE on success (else FALSE).
*/
BOOL PutPatchToMidi(PATCHINFO *pi)
{
if (!FigureThingsOutFromHeader(pi))
return(FALSE);
else if (!VerifyAllPatches(pi))
return(FALSE);
AdjustPatchNumber(pi);
return(RepeatedlySend(pi));
}
/*
* Keep trying to send the data from the PATCHINFO structure to MIDI.
* Try a maximum of NUM_RETRIES times.
* Return TRUE if successful (else FALSE).
*/
BOOL RepeatedlySend(PATCHINFO *pi)
{
int numTries = 0; /* How many retries so far? */
int patchesSent = 0; /* How many patches sent successfully? */
long offset = 0L; /* Where does the data start? */
ResetSerialPort();
while ((patchesSent < pi->numPatches) && (numTries < NUM_RETRIES))
{
/* Attempt to send the patch data. */
PutToMidi(pi, offset);
/* If the user pressed ^C, goodbye! */
if (pi->actualSize == CTRL_C_NO_BYTES)
{
ErrorMsg(ERROR_CTRLC);
return(FALSE);
}
/*
* If the correct amount of data was sent, get ready to send the next
* patch.
*/
else if (pi->actualSize == pi->rightSize)
{
patchesSent++;
if (OUTPUT_ALLOWED)
PrintPatchInfo(pi, offset);
numTries = 0;
offset += pi->rightSize;
}
/*
* The data was not sent successfully. If we haven't already retried
* too many times, try again.
*/
else if (++numTries < NUM_RETRIES)
{
if (ERR_OUTPUT_ALLOWED)
fprintf(stderr, " <%d> Retry #%d...\n",
patchesSent, numTries);
ResetSerialPort();
}
}
/* Did we send the data in fewer than NUM_RETRIES attempts? */
return((BOOL)(numTries < NUM_RETRIES));
}
/*
* Send the patch data found at address pi->data + offset.
* Save the number of bytes sent in pi->actualSize.
*/
void PutToMidi(PATCHINFO *pi, long offset)
{
PrepareToWriteMidi(pi->data + offset, pi->rightSize);
pi->actualSize = DoTheIO();
}
/*
* If the user supplied a patch number, use it.
* Otherwise, use the patch number found at pi->data[BYTE_PATCHNUMBER].
*/
void AdjustPatchNumber(PATCHINFO *pi)
{
if (pi->numPatches == 1)
{
if (pi->patchNum != DEFAULT_PATCH_NUM)
pi->data[BYTE_PATCHNUMBER] = pi->patchNum;
else
pi->patchNum = pi->data[BYTE_PATCHNUMBER];
}
}