save.c 1.28 KB


#include <libaudio.h>
#include <audiotools.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "midiApp.h"
#include "midiDmon.h"
#include "midiGlobals.h"

#ifdef SYSEX_IMPL
#include <sysex.h>
#include <synthcommon.h>



void WriteBuffer(char *fileName, char *extn, char *buffer,int buffLen);

void SaveBanks(char *fileName)
{
    WriteBuffer(fileName,".ctl",gMirror,gMirrorCur);
    WriteBuffer(fileName,".tbl",gSamples,gSamplesCur);
    WriteSymFile(fileName,".sym");
}

void WriteBuffer(char *fileName, char *extn, char *buffer,int buffLen)
{
    int     fnameLen,rv;
    char    *fullName;
    FILE    *outFile;

    
    fnameLen = strlen(fileName);
    fnameLen += strlen(extn);
    fullName = malloc(fnameLen);
    if(!fullName)
    {
        fprintf(stderr,"%s: Unable to allocate memory for filename\n",gAppName);
        return;
    }
    strcpy(fullName,fileName);
    strcat(fullName,extn);

    outFile = fopen(fullName,"w");
    if(!outFile)
    {
        fprintf(stderr,"%s: Unable to create file %s for writing\n",gAppName,fullName);
        return;
    }

    rv = fwrite(buffer,buffLen,1,outFile);
    if(rv!=1)
        fprintf(stderr,"%s: Error while trying to write buffer to file\n",gAppName);

    free(fullName);
    fclose(outFile);
}

    
#endif /* SYSEX_IMPL */