utilrout.c 2.9 KB
#include <libaudio.h> 
#include <stdio.h>
#include <stdlib.h>
#include <dmedia/midi.h>
#include <u64gio.h>
#include <ultratypes.h>
#include "midiApp.h"
#include "midiDmon.h"
#include "midiGlobals.h"

#ifdef SYSEX_IMPL
/********************************************************************
 * Check to see if request string is in list. maxStr is the         *
 * maximum number of strings in the list.  If you find a match      *
 * return that list item number, counting from 1, else return       *
 * zero                                                             * 
 ********************************************************************/
int CheckString(char **requestStr, array32 *list, int maxStr)
{
    int     i;
    char    *r,*l;

    for(i=0;i<maxStr;i++)
    {
        r = *requestStr;
        if(*r==0)
            return 0;
        l = (char*)&list[i];

        while(*r==*l)
        {
            r++;
            l++;
            if(*l == 0)
            {
                if(*r == ':') /* skip any semicolons */
                    r++;
                *requestStr = r;
                return(i+1);
            }
        }
    }
    return 0;
}

char *parsename(char *name,char *nameStr)
{
    char       c;
    
    while(*name!=' ' && *name!=0 && *name!=',') /* name seperated by ' ' */
    {
        *nameStr = *name;
        name++;
        nameStr++;
    }
    if(*name == ' ' || *name == ',')
        name++;
    
    *nameStr = 0; /* terminate string */

    return name;
}

int GetNumber(char **hdl)
{
    int     value = 0;
    char    *ptr = *hdl;

    while(*ptr >= '0' && *ptr<='9')
    {
        value *= 10;
        value += *ptr - '0';
        ptr++;
    }

    if(*ptr == ',' || *ptr == ':') /* skip comma */
        ptr++;
    
    *hdl = ptr;
    return value;    
}

char *listcat(char *lptr,char *nptr)
{
    if(*nptr == 0) /* if null string */
        return(lptr);
    
    while(*nptr!=0)
    {
        *lptr = *nptr;
        nptr++;
        lptr++;
    }

    *lptr = ' '; /* add a space to end of name */
    lptr++;
    return (lptr);
}

void FakeProgChnge(int inst)
{
    int             i;
    midiBlock       midiBlk;
    u64_write_arg_t writeHdr;

    for(i=0;i<MAX_SEQ_CHANNELS;i++)
    {
        if(gCurChanInst[i]==inst)
        {
            midiBlk.pcktType = STATUS_TYPE;
            midiBlk.numEvts = 1;
            midiBlk.mess[0].midiByte[0] = 0xC0 + i;
            midiBlk.mess[0].midiByte[1] = (unsigned char)inst;
            midiBlk.mess[0].midiByte[2] = 0;
            writeHdr.buffer = &midiBlk;
            writeHdr.ramrom_addr = RAMROM_APP_READ_ADDR;
            writeHdr.nbytes =  sizeof(midiBlock);
            writeHdr.value = HOST_APP_CMD_READY;

            if(hardware)
            {
                ioctl(gGIOfd, U64_SAFE_WRITE, &writeHdr); 
                if(verbose)
                    fprintf(stderr,"%s: Back from IOCTL\n",gAppName); 
            }


        }
    }
}

#endif /* SYSEX_IMPL */