source: buchla-68k/orig/BUCHLA/INSDFLT.C

Last change on this file was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 3.3 KB
Line 
1/*
2 =============================================================================
3 insdflt.c -- read the default isntrument and create a C data file
4 Version 3 -- 1988-04-19 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#define M7CAT 1 /* so libdsp.h gets it right */
9
10#include "stdio.h"
11#include "stddefs.h"
12#include "graphdef.h"
13#include "vsdd.h"
14
15#include "midas.h"
16#include "instdsp.h"
17#include "libdsp.h"
18
19#define LIBNAME "m7dflt.orc" /* library name */
20#define THEINST 0 /* library offset: 0 = 1 */
21
22#define DFLTNAME "dfltins.h"
23#define MAXPERL 8
24
25extern int errno;
26
27struct instdef idefs[NINORC];
28struct mlibhdr ldhead;
29
30/*
31
32*/
33
34/*
35 =============================================================================
36 readit() -- read a file, with error checking
37 =============================================================================
38*/
39
40short
41readit(fp, to, len)
42register FILE *fp;
43register char *to;
44register long len;
45{
46 register long count;
47 register int c;
48
49 for (count = 0; count < len; count++) {
50
51 if (EOF EQ (c = getc(fp))) {
52
53 printf("ERROR: Unexpected EOF -- errno = %d\n", errno);
54 fclose(fp);
55 return(FAILURE);
56
57 } else {
58
59 *to++ = c;
60 }
61 }
62
63 return(SUCCESS);
64}
65
66/*
67 =============================================================================
68 die() -- close a file and terminate the program
69 =============================================================================
70*/
71
72die(fp)
73FILE *fp;
74{
75 fclose(fp);
76 printf("Program terminated\n");
77 exit(1);
78}
79
80/*
81
82*/
83
84/*
85 =============================================================================
86 convert an instrument definition to a data block in a header file
87 =============================================================================
88*/
89
90main()
91{
92 register FILE *fp;
93 register unsigned *wp;
94 register struct instdef *ip;
95 register short i, npl, count;
96
97 if ((FILE *)NULL EQ (fp = fopenb(LIBNAME, "r"))) {
98
99 printf("Unable to open [%s]\n", LIBNAME);
100 exit(1);
101 }
102
103 printf("Reading orchestra from [%s]\n", LIBNAME);
104
105 printf(" header\n");
106
107 if (readit(fp, &ldhead, (long)LH_LEN))
108 die(fp);
109
110 for (i = 0; i < NINORC; i++) {
111
112 ip = &idefs[i];
113
114 printf(" instrument %d\n", i + 1);
115
116 if (readit(fp, ip, (long)OR_LEN1))
117 die(fp);
118
119 if (readit(fp, ip->idhwvao, (long)OR_LEN2))
120 die(fp);
121
122 if (readit(fp, ip->idhwvbo, (long)OR_LEN2))
123 die(fp);
124
125 /* unpack offsets (and eventually harmonics) into finals */
126
127 memcpyw(ip->idhwvaf, ip->idhwvao, NUMWPNT);
128 memcpyw(ip->idhwvbf, ip->idhwvbo, NUMWPNT);
129 }
130
131 fclose(fp);
132/*
133
134*/
135 if ((FILE *)NULL EQ (fp = fopena(DFLTNAME, "w"))) {
136
137 printf("Unable to open [%s] for output\n", DFLTNAME);
138 exit(1);
139 }
140
141 printf("Writing default instrument (%d) to [%s]\n",
142 (THEINST + 1), DFLTNAME);
143
144 count = sizeof (struct instdef) / 2;
145 wp = (unsigned *)&idefs[THEINST];
146 npl = 0;
147
148 fprintf(fp, "short\tdfltins[] = {\t\t/* default instrument */\n\n\t");
149
150 while (count--) {
151
152 fprintf(fp, "0x%04.4x", *wp++);
153
154 if (++npl EQ MAXPERL) {
155
156 if (count)
157 fprintf(fp, ",\n\t");
158
159 npl = 0;
160
161 } else {
162
163 if (count)
164 fprintf(fp, ", ");
165 }
166 }
167
168 fprintf(fp, "\n};\n");
169 fclose(fp);
170 printf("Default instrument file written.\n");
171 exit(0);
172}
Note: See TracBrowser for help on using the repository browser.