source: buchla-68k/orig/GEMDOS/MCAPTURE.C@ 0170798

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

Imported original source code.

  • Property mode set to 100755
File size: 4.9 KB
Line 
1/*
2 =============================================================================
3 mcapture.c -- capture MIDI data to a file
4 See VERMSG below for version and date.
5 =============================================================================
6*/
7
8#define VERMSG "mcapture -- Version 1.1 -- 1989-07-28 -- D.N. Lynx Crowe"
9
10#include "stdio.h"
11#include "osbind.h"
12#include "stddefs.h"
13
14#define void int
15
16#define DFLTFILE "mcapture.out"
17
18#define MIDI 2 /* device number */
19
20#define MAXNOL 2
21
22#define FORMAT1 "\n%5u %02.2xH %-16.16s"
23#define FORMAT2 " %02.2xH %3u %-10.10s"
24#define FORMAT3 "\n%5u "
25
26extern char *malloc();
27
28void cleanbf();
29
30int SetMBuf(), midi_in(), m_stat();
31
32struct iorec { /* structure for MIDI buffer description */
33
34 char *ibuf;
35 short ibufsz;
36 short ibufhd;
37 short ibuftl;
38 short ibuflo;
39 short ibufhi;
40};
41
42unsigned int index; /* MIDI input byte number */
43
44int nol; /* number of MIDI data bytes on the line */
45
46FILE *ofp; /* output file pointer */
47
48char *newbuf;
49char *oldbuf; /* old MIDI buffer pointer */
50short oldbsz;
51short oldbhi;
52short oldblo;
53
54struct iorec *m_buff; /* MIDI iorec pointer */
55
56/*
57
58*/
59
60/* FUNCTIONS */
61
62/* set up MIDI buffer */
63
64int
65SetMBuf()
66{
67 unsigned short size;
68
69 size = 16384; /* 16K MIDI buffer */
70
71 m_buff = (struct iorec *)Iorec(MIDI); /* pointer to buffer descriptor */
72
73 oldbuf = m_buff->ibuf;
74 oldbsz = m_buff->ibufsz;
75 oldbhi = m_buff->ibufhi;
76 oldblo = m_buff->ibuflo;
77
78 if ((char *)NULL EQ (newbuf = (char *)malloc(size))) {
79
80 printf ("ERROR -- unable to allocate MIDI buffer.\n");
81 return(FAILURE);
82 }
83
84 /* clear out the buffer */
85
86 m_buff->ibufhd = 0; /* reset the head index */
87 m_buff->ibuftl = 0; /* reset the tail index */
88
89 /* we do this twice because we aren't disabling interrupts ... */
90
91 m_buff->ibufhd = 0; /* reset the head index */
92 m_buff->ibuftl = 0; /* reset the tail index */
93
94 m_buff->ibuf = newbuf; /* change address of buffer */
95 m_buff->ibufsz = size; /* change size of buffer */
96
97 index = 0; /* reset the byte index */
98
99 return(SUCCESS);
100}
101
102/* get MIDI byte */
103
104int
105midi_in()
106{
107 return((int)Bconin(3) & 0x00ff);
108}
109
110/* check midi status */
111
112int
113m_stat()
114{
115 return((int)Bconstat(3) ? TRUE : FALSE);
116}
117
118/* clean out MIDI buffer */
119
120void
121cleanbf()
122{
123 int mstat;
124
125 printf("Clearing MIDI input buffer ...\n");
126
127 /* clear out the buffer by resetting the head and tail indices */
128
129 m_buff->ibufhd = 0; /* reset the head index */
130 m_buff->ibuftl = 0; /* reset the tail index */
131
132 /* we do this twice because we aren't disabling interrupts ... */
133
134 m_buff->ibufhd = 0; /* reset the head index */
135 m_buff->ibuftl = 0; /* reset the tail index */
136
137 /* make sure it's really drained */
138
139 mstat = m_stat();
140
141 while (mstat) {
142
143 midi_in();
144 mstat = m_stat();
145 }
146
147 index = 0;
148}
149
150/*
151
152*/
153
154/* MAIN PROGRAM LOOP */
155
156main(argc, argv)
157int argc;
158char *argv[];
159{
160 int ch, runtag;
161
162 ofp = (FILE *)NULL;
163
164 printf("\033E%s\n\n", VERMSG);
165 printf("Hit / to clear buffer, ESC to finish.\n\n");
166
167 if (SetMBuf()) /* move MIDI buffer & increase size */
168 exit(2);
169
170 cleanbf(); /* clear out MIDI buffer */
171
172 if (argc EQ 2) {
173
174 if ((FILE *)NULL EQ (ofp = fopen(argv[1], "w"))) {
175
176 printf("ERROR -- Unable to open \"%s\" for output.\n",
177 argv[1]);
178
179 exit(2);
180
181 } else {
182
183 printf("Program will output to file \"%s\".\n", argv[1]);
184 }
185
186 } else {
187
188 if ((FILE *)NULL EQ (ofp = fopen(DFLTFILE, "w"))) {
189
190 printf("ERROR -- Unable to open \"%s\" for output.\n",
191 DFLTFILE);
192
193 exit(2);
194
195 } else {
196
197 printf("Program will output to file \"%s\".\n", DFLTFILE);
198 }
199 }
200
201 printf("Ready for MIDI data.\n");
202
203 runtag = TRUE;
204
205 while (runtag) {
206
207 if (Bconstat(2)) {
208
209 ch = 0x00FF & Bconin(2);
210
211 switch (ch) {
212
213 case '\033': /* escape */
214
215 runtag = FALSE;
216 break;
217
218 case '/': /* / = clear buffer and screen */
219
220 cleanbf();
221 printf("\033E");
222 printf("Ready for MIDI data.\n");
223 break;
224 }
225 }
226
227 if (m_stat())
228 ProcMIDI(midi_in());
229 }
230
231 fflush(ofp);
232 fclose(ofp);
233
234 /* clear out the buffer */
235
236 m_buff->ibufhd = 0; /* reset the head index */
237 m_buff->ibuftl = 0; /* reset the tail index */
238
239 /* we do this twice because we aren't disabling interrupts ... */
240
241 m_buff->ibufhd = 0; /* reset the head index */
242 m_buff->ibuftl = 0; /* reset the tail index */
243
244 m_buff->ibufsz = oldbsz; /* restore the old buffer size */
245 m_buff->ibuf = oldbuf; /* restore the old buffer address */
246
247 free(newbuf); /* give back the big MIDI buffer */
248
249 printf("\n");
250 fflush(stdout);
251 exit(0);
252}
Note: See TracBrowser for help on using the repository browser.