24
#include "csoundCore.h" /* RDSCOR.C */
24
#include "csoundCore.h" /* RDSCORSTR.C */
26
27
static void dumpline(CSOUND *);
28
29
static void flushline(CSOUND *csound) /* flush scorefile to next newline */
31
FILE *xx = csound->scfp;
32
while ((c = getc(xx)) != EOF && c != '\n')
32
while ((c = corfile_getc(csound->scstr)) != '\0' && c != '\n')
36
36
static int scanflt(CSOUND *csound, MYFLT *pfld)
37
37
{ /* read a MYFLT from scorefile; return 1 if OK, else 0 */
39
FILE *xx = csound->scfp;
40
while ((c = getc(xx)) == ' ' || c == '\t') /* skip leading white space */
40
while ((c = corfile_getc(csound->scstr)) == ' ' ||
41
c == '\t') /* skip leading white space */
42
43
if (c == ';') { /* Comments terminate line */
48
49
if (csound->scnt0==0) {
49
50
if ((sstrp = csound->sstrbuf) == NULL)
50
51
sstrp = csound->sstrbuf = mmalloc(csound, SSTRSIZ);
51
while ((c = getc(xx)) != '"') {
52
if (c=='\\') c = getc(xx);
52
while ((c = corfile_getc(csound->scstr)) != '"') {
53
if (c=='\\') c = corfile_getc(csound->scstr);
61
62
printf("***Entering dubious code; n=%d\n", n);
62
63
if ((sstrp = csound->sstrbuf0[n]) == NULL)
63
64
sstrp = csound->sstrbuf0[n] = mmalloc(csound, SSTRSIZ);
64
while ((c = getc(xx)) != '"') {
65
if (c=='\\') c = getc(xx);
65
while ((c = corfile_getc(csound->scstr)) != '"') {
66
if (c=='\\') c = corfile_getc(csound->scstr);
76
77
if (UNLIKELY(!((c>='0' && c<='9') || c=='+' || c=='-' || c=='.'))) {
77
ungetc(c, csound->scfp);
78
corfile_ungetc(csound->scstr);
78
79
csound->Message(csound,
79
80
Str("ERROR: illegal character %c(%.2x) in scoreline: "),
84
ungetc(c, csound->scfp);
86
fscanf(csound->scfp, "%lf", pfld);
88
fscanf(csound->scfp, "%f", pfld);
85
corfile_ungetc(csound->scstr);
87
MYFLT ans = corfile_get_flt(csound->scstr);
89
//printf("%s(%d):%lf %lf\n", __FILE__, __LINE__, ans, *pfld);
93
94
static void dumpline(CSOUND *csound) /* print the line while flushing it */
96
FILE *xx = csound->scfp;
97
while ((c = getc(xx)) != EOF && c != '\n') {
97
while ((c = corfile_getc(csound->scstr)) != '\0' && c != '\n') {
98
98
csound->Message(csound, "%c", c);
100
100
csound->Message(csound, Str("\n\tremainder of line flushed\n"));
103
103
int rdscor(CSOUND *csound, EVTBLK *e) /* read next score-line from scorefile */
104
/* & maintain section warped status */
105
{ /* presumes good format if warped */
104
/* & maintain section warped status */
105
{ /* presumes good format if warped */
106
106
MYFLT *pp, *plim;
108
FILE *xx = csound->scfp;
110
if (xx == NULL || feof(xx)) { /* if no concurrent scorefile */
109
if (csound->scstr == NULL ||
110
csound->scstr->body[0] == '\0') { /* if no concurrent scorefile */
112
csound->Message(csound, "THIS SHOULD NOT HAPPEN -- CONTACT jpff");
111
114
e->opcod = 'f'; /* return an 'f 0 3600' */
112
115
e->p[1] = FL(0.0);
113
e->p[2] = FL(3600.0);
114
e->p2orig = FL(3600.0);
118
while ((c = getc(xx)) != EOF) { /* else read the real score */
121
while ((c = corfile_getc(csound->scstr)) != '\0') { /* else read the real score */
119
122
csound->scnt0 = 0;
136
139
plim = &e->p[PMAX]; /* caution, irregular format */
138
while ((c = getc(xx))==' ' || c=='\t'); /* eat whitespace */
141
while ((c = corfile_getc(csound->scstr))==' ' ||
142
c=='\t'); /* eat whitespace */
139
143
if (c == ';') { flushline(csound); break; } /* comments? skip */
140
if (c == '\n' || c == EOF) break; /* newline? done */
141
ungetc(c, csound->scfp); /* pfld: back up */
144
if (c == '\n' || c == '\0') break; /* newline? done */
145
corfile_ungetc(csound->scstr); /* pfld: back up */
142
146
if (!scanflt(csound, ++pp)) break; /* & read value */
143
if (UNLIKELY(pp >= plim)) {
147
if (UNLIKELY(pp >= plim)) {
144
148
csound->Message(csound, Str("ERROR: too many pfields: "));
145
149
dumpline(csound);
161
167
e->c.extra = NULL;
163
169
plim = &e->p[PMAX];
164
if (getc(xx) != '\n' && scanflt(csound, ++pp)) /* p1 */
165
if (getc(xx) != '\n' && scanflt(csound, &e->p2orig)) /* p2 orig */
166
if (getc(xx) != '\n' && scanflt(csound, ++pp)) /* p2 warp */
167
if (getc(xx) != '\n' && scanflt(csound, &e->p3orig)) /* p3 */
168
if (getc(xx) != '\n' && scanflt(csound, ++pp)) /* p3 warp */
169
while (getc(xx) != '\n' && scanflt(csound, ++pp))
170
if (corfile_getc(csound->scstr) != '\n' &&
171
scanflt(csound, ++pp)) /* p1 */
172
if (corfile_getc(csound->scstr) != '\n' &&
173
scanflt(csound, &e->p2orig)) /* p2 orig */
174
if (corfile_getc(csound->scstr) != '\n' &&
175
scanflt(csound, ++pp)) /* p2 warp */
176
if (corfile_getc(csound->scstr) != '\n' &&
177
scanflt(csound, &e->p3orig)) /* p3 */
178
if (corfile_getc(csound->scstr) != '\n' &&
179
scanflt(csound, ++pp)) /* p3 warp */
180
while (corfile_getc(csound->scstr) != '\n' &&
181
scanflt(csound, ++pp))
171
183
if (pp >= plim) {
174
fprintf(stderr, "Extra p-fields (%d %d %d %d)\n",
186
csound->DebugMsg(csound, "Extra p-fields (%d %d %d %d)\n",
175
187
(int)e->p[1],(int)e->p[2],
176
188
(int)e->p[3],(int)e->p[4]);
177
189
e->c.extra = (MYFLT*)realloc(e->c.extra,sizeof(MYFLT)*PMAX);
178
190
e->c.extra[0] = PMAX-2;
180
while ((getc(xx) != '\n') && (scanflt(csound, &q[c++]))) {
192
while ((corfile_getc(csound->scstr) != '\n') &&
193
(scanflt(csound, &q[c++]))) {
181
194
if (c > (int) e->c.extra[0]) {
182
fprintf(stderr, "and more extra p-fields [%d](%d)%d\n",
195
csound->DebugMsg(csound, "and more extra p-fields [%d](%d)%d\n",
183
196
c, (int) e->c.extra[0],
184
197
sizeof(MYFLT)*((int)e->c.extra[0]+PMAX) );
186
199
(MYFLT *)realloc(e->c.extra,
187
sizeof(MYFLT)*((int) e->c.extra[0]+PMAX));
200
sizeof(MYFLT)*((int) e->c.extra[0]+PMAX));
188
201
e->c.extra[0] = e->c.extra[0]+PMAX-1;
191
204
e->c.extra[0] = c;
192
205
/* flushline(csound); */
196
209
if (!csound->csoundIsScorePending_ && e->opcod == 'i') {