save.c
1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#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 */