~ubuntu-branches/ubuntu/precise/csound/precise

« back to all changes in this revision

Viewing changes to Engine/rdscor.c

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler
  • Date: 2012-04-19 09:26:46 UTC
  • mfrom: (3.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20120419092646-96xbj1n6atuqosk2
Tags: 1:5.17.6~dfsg-1
* New upstream release
 - Do not build the wiimote opcodes (we need wiiuse).
* Add new API function to symbols file
* Disable lua opcodes, they were broken. Requires OpenMP to be enabled.
* Backport fixes from upstream:
  - Link dssi4cs with dl. Backport
  - Fix building of CsoundAC

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
    rdscor.c:
3
3
 
4
 
    Copyright (C) 1991, 1997 Barry Vercoe, John ffitch
 
4
    Copyright (C) 2011 John ffitch (after Barry Vercoe)
5
5
 
6
6
    This file is part of Csound.
7
7
 
21
21
    02111-1307 USA
22
22
*/
23
23
 
24
 
#include "csoundCore.h"         /*                              RDSCOR.C */
 
24
#include "csoundCore.h"         /*                  RDSCORSTR.C */
 
25
#include "corfile.h"
25
26
 
26
27
static void dumpline(CSOUND *);
27
28
 
28
29
static void flushline(CSOUND *csound)   /* flush scorefile to next newline */
29
30
{
30
31
    int     c;
31
 
    FILE    *xx = csound->scfp;
32
 
    while ((c = getc(xx)) != EOF && c != '\n')
 
32
    while ((c = corfile_getc(csound->scstr)) != '\0' && c != '\n')
33
33
        ;
34
34
}
35
35
 
36
36
static int scanflt(CSOUND *csound, MYFLT *pfld)
37
37
{   /* read a MYFLT from scorefile; return 1 if OK, else 0 */
38
38
    int     c;
39
 
    FILE    *xx = csound->scfp;
40
 
    while ((c = getc(xx)) == ' ' || c == '\t')  /* skip leading white space */
 
39
 
 
40
    while ((c = corfile_getc(csound->scstr)) == ' ' ||
 
41
           c == '\t')  /* skip leading white space */
41
42
        ;
42
43
    if (c == ';') {             /* Comments terminate line */
43
44
      flushline(csound);
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);
53
54
          *sstrp++ = c;
54
55
        }
55
56
        *sstrp++ = '\0';
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);
66
67
          *sstrp++ = c;
67
68
        }
68
69
        *sstrp++ = '\0';
74
75
      return(1);
75
76
    }
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: "),
80
81
                      c, c);
81
82
      dumpline(csound);
82
83
      return(0);
83
84
    }
84
 
    ungetc(c, csound->scfp);
85
 
#ifdef USE_DOUBLE
86
 
    fscanf(csound->scfp, "%lf", pfld);
87
 
#else
88
 
    fscanf(csound->scfp, "%f", pfld);
89
 
#endif
 
85
    corfile_ungetc(csound->scstr);
 
86
    {
 
87
      MYFLT ans = corfile_get_flt(csound->scstr);
 
88
      *pfld = ans;
 
89
      //printf("%s(%d):%lf %lf\n", __FILE__, __LINE__, ans, *pfld);
 
90
    }
90
91
    return(1);
91
92
}
92
93
 
93
94
static void dumpline(CSOUND *csound)    /* print the line while flushing it */
94
95
{
95
96
    int     c;
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);
99
99
    }
100
100
    csound->Message(csound, Str("\n\tremainder of line flushed\n"));
101
101
}
102
102
 
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;
107
107
    int     c;
108
 
    FILE    *xx = csound->scfp;
109
108
 
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  */
 
111
#ifdef BETA
 
112
      csound->Message(csound, "THIS SHOULD NOT HAPPEN -- CONTACT jpff");
 
113
#endif
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);
 
116
      e->p[2] = FL(INF);
 
117
      e->p2orig = FL(INF);
115
118
      e->pcnt = 2;
116
119
      return(1);
117
120
    }
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;
120
123
      switch (c) {
121
124
      case ' ':
135
138
        pp = &e->p[0];
136
139
        plim = &e->p[PMAX];             /*    caution, irregular format */
137
140
        while (1) {
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);
146
150
            break;
154
158
        e->opcod = c;
155
159
        e->pcnt = 0;
156
160
        return(1);
 
161
      case EOF:                          /* necessary for cscoreGetEvent */
 
162
        return(0);
157
163
      default:                                /* WARPED scorefile:       */
158
164
        if (!csound->warped) goto unwarped;
159
165
        e->opcod = c;                                       /* opcod */
161
167
        e->c.extra = NULL;
162
168
        pp = &e->p[0];
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))
170
182
                    /* p4....  */
171
183
                    if (pp >= plim) {
172
184
                      MYFLT *q;
173
185
                      int c=1;
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;
179
191
                      q = e->c.extra;
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) );
185
198
                          q = e->c.extra =
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;
189
202
                        }
190
203
                      }
191
204
                      e->c.extra[0] = c;
192
205
                      /* flushline(csound); */
193
 
                      goto setp;
 
206
                       goto setp;
194
207
                    }
195
208
      setp:
196
209
        if (!csound->csoundIsScorePending_ && e->opcod == 'i') {
209
222
        return 1;
210
223
      }
211
224
    }
 
225
    corfile_rm(&(csound->scstr));
212
226
    return 0;
213
227
}
214
228