1 
2 /*
3 #    Sfront, a SAOL to C translator
4 #    This file: Parses standard names
5 #
6 # Copyright (c) 1999-2006, Regents of the University of California
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions are
11 # met:
12 #
13 #  Redistributions of source code must retain the above copyright
14 #  notice, this list of conditions and the following disclaimer.
15 #
16 #  Redistributions in binary form must reproduce the above copyright
17 #  notice, this list of conditions and the following disclaimer in the
18 #  documentation and/or other materials provided with the distribution.
19 #
20 #  Neither the name of the University of California, Berkeley nor the
21 #  names of its contributors may be used to endorse or promote products
22 #  derived from this software without specific prior written permission.
23 #
24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #
36 #    Maintainer: John Lazzaro, lazzaro@cs.berkeley.edu
37 */
38 
39 
40 #include "tree.h"
41 
42 /***************************************************/
43 /* returns 1 if S_IDENT is a standard name, else 0 */
44 /***************************************************/
45 
standardname(tnode * ident)46 int standardname(tnode * ident)
47 
48 {
49   if (ident->ttype != S_IDENT)
50     return 0;
51   if (!(strcmp(ident->val,"k_rate")))
52     return 1;
53   if (!(strcmp(ident->val,"s_rate")))
54     return 1;
55   if (!(strcmp(ident->val,"inchan")))
56     return 1;
57   if (!(strcmp(ident->val,"outchan")))
58     return 1;
59   if (!(strcmp(ident->val,"time")))
60     return 1;
61   if (!(strcmp(ident->val,"dur")))
62     return 1;
63   if (!(strcmp(ident->val,"itime")))
64     return 1;
65   if (!(strcmp(ident->val,"preset")))
66     return 1;
67   if (!(strcmp(ident->val,"channel")))
68     return 1;
69   if (!(strcmp(ident->val,"MIDIctrl")))
70     return 1;
71   if (!(strcmp(ident->val,"MIDItouch")))
72     return 1;
73   if (!(strcmp(ident->val,"MIDIbend")))
74     return 1;
75   if (!(strcmp(ident->val,"input")))
76     return 1;
77   if (!(strcmp(ident->val,"inGroup")))
78     return 1;
79   if (!(strcmp(ident->val,"released")))
80     return 1;
81   if (!(strcmp(ident->val,"cpuload")))
82     return 1;
83   if (!(strcmp(ident->val,"position")))
84     return 1;
85   if (!(strcmp(ident->val,"direction")))
86     return 1;
87   if (!(strcmp(ident->val,"listenerPosition")))
88     return 1;
89   if (!(strcmp(ident->val,"listenerDirection")))
90     return 1;
91   if (!(strcmp(ident->val,"minFront")))
92     return 1;
93   if (!(strcmp(ident->val,"maxFront")))
94     return 1;
95   if (!(strcmp(ident->val,"minBack")))
96     return 1;
97   if (!(strcmp(ident->val,"maxBack")))
98     return 1;
99   if (!(strcmp(ident->val,"params")))
100     return 1;
101 
102   return 0;
103 }
104 
105 /***************************************************/
106 /*          updates has array                      */
107 /***************************************************/
108 
hasstandardname(tnode * ident)109 void hasstandardname(tnode * ident)
110 
111 {
112   if (ident->ttype != S_IDENT)
113     return;
114   if (!(strcmp(ident->val,"k_rate")))
115     {
116       has.s_k_rate++;
117       return;
118     }
119   if (!(strcmp(ident->val,"s_rate")))
120     {
121       has.s_s_rate++;
122       return;
123     }
124   if (!(strcmp(ident->val,"inchan")))
125     {
126       has.s_inchan++;
127       return;
128     }
129   if (!(strcmp(ident->val,"outchan")))
130     {
131       has.s_outchan++;
132       return;
133     }
134   if (!(strcmp(ident->val,"time")))
135     {
136       has.s_time++;
137       return;
138     }
139   if (!(strcmp(ident->val,"dur")))
140     {
141       has.s_dur++;
142       return;
143     }
144   if (!(strcmp(ident->val,"itime")))
145     {
146       has.s_itime++;
147       return;
148     }
149   if (!(strcmp(ident->val,"preset")))
150     {
151       has.s_preset++;
152       return;
153     }
154   if (!(strcmp(ident->val,"channel")))
155     {
156       has.s_channel++;
157       return;
158     }
159   if (!(strcmp(ident->val,"MIDIctrl")))
160     {
161       has.s_MIDIctrl++;
162       return;
163     }
164   if (!(strcmp(ident->val,"MIDItouch")))
165     {
166       has.s_MIDItouch++;
167       return;
168     }
169   if (!(strcmp(ident->val,"MIDIbend")))
170     {
171       has.s_MIDIbend++;
172       return;
173     }
174   if (!(strcmp(ident->val,"input")))
175     {
176       has.s_input++;
177       return;
178     }
179   if (!(strcmp(ident->val,"inGroup")))
180     {
181       has.s_inGroup++;
182       return;
183     }
184   if (!(strcmp(ident->val,"released")))
185     {
186       has.s_released++;
187       return;
188     }
189   if (!(strcmp(ident->val,"cpuload")))
190     {
191       has.s_cpuload++;
192       return;
193     }
194   if (!(strcmp(ident->val,"position")))
195     {
196       has.s_position++;
197       return;
198     }
199   if (!(strcmp(ident->val,"direction")))
200     {
201       has.s_direction++;
202       return;
203     }
204   if (!(strcmp(ident->val,"listenerPosition")))
205     {
206       has.s_listenerPosition++;
207       return;
208     }
209   if (!(strcmp(ident->val,"listenerDirection")))
210     {
211       has.s_listenerDirection++;
212       return;
213     }
214   if (!(strcmp(ident->val,"minFront")))
215     {
216       has.s_minFront++;
217       return;
218     }
219   if (!(strcmp(ident->val,"maxFront")))
220     {
221       has.s_maxFront++;
222       return;
223     }
224   if (!(strcmp(ident->val,"minBack")))
225     {
226       has.s_minBack++;
227       return;
228     }
229   if (!(strcmp(ident->val,"maxBack")))
230     {
231       has.s_maxBack++;
232       return;
233     }
234   if (!(strcmp(ident->val,"params")))
235     {
236       has.s_params++;
237       return;
238     }
239 }
240 
241 /***************************************************/
242 /*       returns rate of standard name             */
243 /***************************************************/
244 
standardrate(tnode * ident)245 int standardrate(tnode * ident)
246 
247 {
248   if (ident->ttype != S_IDENT)
249     return UNKNOWN;
250   if (!(strcmp(ident->val,"k_rate")))
251     return IRATETYPE;
252   if (!(strcmp(ident->val,"s_rate")))
253     return IRATETYPE;
254   if (!(strcmp(ident->val,"inchan")))
255     return IRATETYPE;
256   if (!(strcmp(ident->val,"outchan")))
257     return IRATETYPE;
258   if (!(strcmp(ident->val,"time")))
259     return IRATETYPE;
260   if (!(strcmp(ident->val,"dur")))
261     return IRATETYPE;
262   if (!(strcmp(ident->val,"itime")))
263     return KRATETYPE;
264   if (!(strcmp(ident->val,"preset")))
265     return IRATETYPE;
266   if (!(strcmp(ident->val,"channel")))
267     return IRATETYPE;
268   if (!(strcmp(ident->val,"MIDIctrl")))
269     return KRATETYPE;
270   if (!(strcmp(ident->val,"MIDItouch")))
271     return KRATETYPE;
272   if (!(strcmp(ident->val,"MIDIbend")))
273     return KRATETYPE;
274   if (!(strcmp(ident->val,"input")))
275     return ARATETYPE;
276   if (!(strcmp(ident->val,"inGroup")))
277     return IRATETYPE;
278   if (!(strcmp(ident->val,"released")))
279     return KRATETYPE;
280   if (!(strcmp(ident->val,"cpuload")))
281     return KRATETYPE;
282   if (!(strcmp(ident->val,"position")))
283     return KRATETYPE;
284   if (!(strcmp(ident->val,"direction")))
285     return KRATETYPE;
286   if (!(strcmp(ident->val,"listenerPosition")))
287     return KRATETYPE;
288   if (!(strcmp(ident->val,"listenerDirection")))
289     return KRATETYPE;
290   if (!(strcmp(ident->val,"minFront")))
291     return KRATETYPE;
292   if (!(strcmp(ident->val,"maxFront")))
293     return KRATETYPE;
294   if (!(strcmp(ident->val,"minBack")))
295     return KRATETYPE;
296   if (!(strcmp(ident->val,"maxBack")))
297     return KRATETYPE;
298   if (!(strcmp(ident->val,"params")))
299     return KRATETYPE;
300 
301   return UNKNOWN;
302 }
303 
304 /***************************************************/
305 /*       returns ASINT/ASFLOAT of standard name    */
306 /***************************************************/
307 
standardres(tnode * ident)308 int standardres(tnode * ident)
309 
310 {
311   if (ident->ttype != S_IDENT)
312     return ASFLOAT;
313   if (!(strcmp(ident->val,"k_rate")))
314     return ASINT;
315   if (!(strcmp(ident->val,"s_rate")))
316     return ASINT;
317   if (!(strcmp(ident->val,"inchan")))
318     return ASINT;
319   if (!(strcmp(ident->val,"outchan")))
320     return ASINT;
321   if (!(strcmp(ident->val,"time")))
322     return ASFLOAT;
323   if (!(strcmp(ident->val,"dur")))
324     return ASFLOAT;
325   if (!(strcmp(ident->val,"itime")))
326     return ASFLOAT;
327   if (!(strcmp(ident->val,"preset")))
328     return ASINT;
329   if (!(strcmp(ident->val,"channel")))
330     return ASINT;
331   if (!(strcmp(ident->val,"MIDIctrl")))
332     return ASFLOAT;
333   if (!(strcmp(ident->val,"MIDItouch")))
334     return ASFLOAT;
335   if (!(strcmp(ident->val,"MIDIbend")))
336     return ASFLOAT;
337   if (!(strcmp(ident->val,"input")))
338     return ASFLOAT;
339   if (!(strcmp(ident->val,"inGroup")))
340     return ASFLOAT;
341   if (!(strcmp(ident->val,"released")))
342     return ASINT;
343   if (!(strcmp(ident->val,"cpuload")))
344     return ASFLOAT;
345   if (!(strcmp(ident->val,"position")))
346     return ASFLOAT;
347   if (!(strcmp(ident->val,"direction")))
348     return ASFLOAT;
349   if (!(strcmp(ident->val,"listenerPosition")))
350     return ASFLOAT;
351   if (!(strcmp(ident->val,"listenerDirection")))
352     return ASFLOAT;
353   if (!(strcmp(ident->val,"minFront")))
354     return ASFLOAT;
355   if (!(strcmp(ident->val,"maxFront")))
356     return ASFLOAT;
357   if (!(strcmp(ident->val,"minBack")))
358     return ASFLOAT;
359   if (!(strcmp(ident->val,"maxBack")))
360     return ASFLOAT;
361   if (!(strcmp(ident->val,"params")))
362     return ASFLOAT;
363 
364   return ASFLOAT;
365 }
366 
367 /***************************************************/
368 /*   returns scalar/vector type of standardname    */
369 /***************************************************/
370 
standardvartype(tnode * ident)371 int standardvartype(tnode * ident)
372 
373 {
374   if (ident->ttype != S_IDENT)
375     return SCALARTYPE;
376   if (!(strcmp(ident->val,"k_rate")))
377     return SCALARTYPE;
378   if (!(strcmp(ident->val,"s_rate")))
379     return SCALARTYPE;
380   if (!(strcmp(ident->val,"inchan")))
381     return SCALARTYPE;
382   if (!(strcmp(ident->val,"outchan")))
383     return SCALARTYPE;
384   if (!(strcmp(ident->val,"time")))
385     return SCALARTYPE;
386   if (!(strcmp(ident->val,"dur")))
387     return SCALARTYPE;
388   if (!(strcmp(ident->val,"itime")))
389     return SCALARTYPE;
390   if (!(strcmp(ident->val,"preset")))
391     return SCALARTYPE;
392   if (!(strcmp(ident->val,"channel")))
393     return SCALARTYPE;
394   if (!(strcmp(ident->val,"MIDIctrl")))
395     return VECTORTYPE;
396   if (!(strcmp(ident->val,"MIDItouch")))
397     return SCALARTYPE;
398   if (!(strcmp(ident->val,"MIDIbend")))
399     return SCALARTYPE;
400   if (!(strcmp(ident->val,"input")))
401     return VECTORTYPE;
402   if (!(strcmp(ident->val,"inGroup")))
403     return VECTORTYPE;
404   if (!(strcmp(ident->val,"released")))
405     return SCALARTYPE;
406   if (!(strcmp(ident->val,"cpuload")))
407     return SCALARTYPE;
408   if (!(strcmp(ident->val,"position")))
409     return VECTORTYPE;
410   if (!(strcmp(ident->val,"direction")))
411     return VECTORTYPE;
412   if (!(strcmp(ident->val,"listenerPosition")))
413     return VECTORTYPE;
414   if (!(strcmp(ident->val,"listenerDirection")))
415     return VECTORTYPE;
416   if (!(strcmp(ident->val,"minFront")))
417     return SCALARTYPE;
418   if (!(strcmp(ident->val,"maxFront")))
419     return SCALARTYPE;
420   if (!(strcmp(ident->val,"minBack")))
421     return SCALARTYPE;
422   if (!(strcmp(ident->val,"maxBack")))
423     return SCALARTYPE;
424   if (!(strcmp(ident->val,"params")))
425     return VECTORTYPE;
426 
427   return SCALARTYPE;
428 }
429 
430 
431 /***************************************************/
432 /*       returns width of standard name            */
433 /***************************************************/
434 
standardwidth(tnode * ident)435 int standardwidth(tnode * ident)
436 
437 {
438   if (ident->ttype != S_IDENT)
439     return UNKNOWN;
440   if (!(strcmp(ident->val,"k_rate")))
441     return 1;
442   if (!(strcmp(ident->val,"s_rate")))
443     return 1;
444   if (!(strcmp(ident->val,"inchan")))
445     return 1;
446   if (!(strcmp(ident->val,"outchan")))
447     return 1;
448   if (!(strcmp(ident->val,"time")))
449     return 1;
450   if (!(strcmp(ident->val,"dur")))
451     return 1;
452   if (!(strcmp(ident->val,"itime")))
453     return 1;
454   if (!(strcmp(ident->val,"preset")))
455     return 1;
456   if (!(strcmp(ident->val,"channel")))
457     return 1;
458   if (!(strcmp(ident->val,"MIDIctrl")))
459     return 128;
460   if (!(strcmp(ident->val,"MIDItouch")))
461     return 1;
462   if (!(strcmp(ident->val,"MIDIbend")))
463     return 1;
464   if (!(strcmp(ident->val,"input")))
465     return currinputwidth;
466   if (!(strcmp(ident->val,"inGroup")))
467     return currinputwidth;
468   if (!(strcmp(ident->val,"released")))
469     return 1;
470   if (!(strcmp(ident->val,"cpuload")))
471     return 1;
472   if (!(strcmp(ident->val,"position")))
473     return 3;
474   if (!(strcmp(ident->val,"direction")))
475     return 3;
476   if (!(strcmp(ident->val,"listenerPosition")))
477     return 3;
478   if (!(strcmp(ident->val,"listenerDirection")))
479     return 3;
480   if (!(strcmp(ident->val,"minFront")))
481     return 1;
482   if (!(strcmp(ident->val,"maxFront")))
483     return 1;
484   if (!(strcmp(ident->val,"minBack")))
485     return 1;
486   if (!(strcmp(ident->val,"maxBack")))
487     return 1;
488   if (!(strcmp(ident->val,"params")))
489     return 128;
490 
491   return 0;
492 }
493 
494 /***************************************************/
495 /*       returns 1 if dur is a constant            */
496 /***************************************************/
497 
constdur(void)498 int constdur(void)
499 
500 {
501 
502   /* type of instruments where dur = -1 always */
503 
504   if ((currinstrument == NULL) ||      /* in global block */
505       (currinstance != NULL) ||        /* code for effects instance, or */
506       ((currinstrument->score == 0) && /* not in score and */
507       (currinstrument->ascore == 0) && /* not in score and */
508        (currinstrument->dyn == 0) &&   /* not dynamic and */
509        (csasl == 0)))                  /* not SASL control */
510     return 1;
511 
512   /* later add detection for other constant durs */
513 
514   return 0;
515 
516 }
517 
518 /***************************************************/
519 /*      collapses constant standard names          */
520 /***************************************************/
521 
standardcollapse(tnode * ident)522 int standardcollapse(tnode * ident)
523 
524 {
525   char name[128];
526 
527   if ((!(strcmp(ident->val,"k_rate"))) && (!reentrant))
528     {
529       ident->vol   = CONSTANT;
530       ident->ttype = S_INTGR;
531       ident->res = ASINT;
532       ident->rate = IRATETYPE;
533       sprintf(name,"%i",krate);
534       ident->val = dupval(name);
535       return CONSTANT;
536     }
537   if ((!(strcmp(ident->val,"s_rate"))) && (!reentrant))
538     {
539       ident->vol   = CONSTANT;
540       ident->ttype = S_INTGR;
541       ident->res = ASINT;
542       ident->rate = IRATETYPE;
543       sprintf(name,"%i",srate);
544       ident->val = dupval(name);
545       return CONSTANT;
546     }
547   if (!(strcmp(ident->val,"inchan")))
548     {
549       ident->vol   = CONSTANT;
550       ident->ttype = S_INTGR;
551       ident->res = ASINT;
552       ident->rate = IRATETYPE;
553       sprintf(name,"%i", currinputwidth);
554       ident->val = dupval(name);
555       return CONSTANT;
556     }
557   if (!(strcmp(ident->val,"outchan")))
558     {
559       ident->vol   = CONSTANT;
560       ident->ttype = S_INTGR;
561       ident->res = ASINT;
562       ident->rate = IRATETYPE;
563       sprintf(name,"%i", currinstrwidth);
564       ident->val = dupval(name);
565       return CONSTANT;
566     }
567   if (!(strcmp(ident->val,"dur")))
568     {
569       if (constdur())
570 	{
571 	  /* right now -1 is the only detected constant dur */
572 	  ident->vol   = CONSTANT;
573 	  ident->ttype = S_INTGR;
574 	  ident->res = ASINT;
575 	  ident->rate = IRATETYPE;
576 	  ident->val = dupval("-1");
577 	  return CONSTANT;
578 	}
579     }
580   return VARIABLE;
581 }
582 
583 
584 
585 /***************************************************/
586 /*       handles input/ingroup for non-effects     */
587 /***************************************************/
588 
nobus(tnode ** ident)589 void nobus(tnode ** ident)
590 
591 {
592   tnode * tptr = * ident;
593 
594   fprintf(outfile," 0 ");
595 
596   if ((tptr->next != NULL) &&     /* an array index */
597       (tptr->next->ttype == S_LB))
598     {
599       *ident = tptr->next->next->next;  /* skip to end  */
600     }
601 
602   return;
603 
604 }
605 
606 /***************************************************/
607 /*   handles input/ingroup in unindexed context    */
608 /***************************************************/
609 
arraybus(tnode ** ident,int group)610 void arraybus(tnode ** ident, int group)
611 
612 {
613   tnode * bptr = currinstance->ibus;
614   int i = 0;
615   int gcount = 1;
616 
617   if (currinstance->inwidth == 1)   /* array of size 1 */
618     {
619       if (bptr == NULL)
620 	fprintf(outfile," 0 ");
621       else
622 	{
623 	  if (group)
624 	    fprintf(outfile," 1 ");
625 	  else
626 	    fprintf(outfile," %s(BUS_%s) ", inputbusmacro(), bptr->val);
627 	}
628       return;
629     }
630 
631   while ((bptr != NULL)&& (i < currinstance->inwidth))
632     {
633       if (currarrayindex < i + bptr->width)
634 	{
635 	  if (group)
636 	    fprintf(outfile," %i ",gcount);
637 	  else
638 	    fprintf(outfile," %s(BUS_%s + %i) ", inputbusmacro(),
639 		    bptr->val, currarrayindex - i);
640 	  return;
641 	}
642       i += bptr->width;
643       bptr = bptr->next;
644       gcount++;
645     }
646   fprintf(outfile," 0 ");      /* out of range */
647   return;
648 
649 }
650 
651 /***************************************************/
652 /*   handles input/ingroup with constant index     */
653 /***************************************************/
654 
constbus(tnode ** ident,int group)655 void constbus(tnode ** ident, int group)
656 
657 {
658   tnode * tptr = * ident;
659   tnode * bptr = currinstance->ibus;
660   int i = 0;
661   int gcount = 1;
662   int idxval;
663 
664   if ((idxval = make_int(tptr->next->next->down)) < 0)
665     {
666       printf("Error: %s[] constant index < 0.\n\n", tptr->val);
667       showerrorplace(tptr->linenum, tptr->filename);
668     }
669 
670   while ((bptr != NULL)&& (i < currinstance->inwidth))
671     {
672       if (idxval < i + bptr->width)
673 	{
674 	  if (group)
675 	    fprintf(outfile," %i ",gcount);
676 	  else
677 	    fprintf(outfile," %s(BUS_%s + %i)", inputbusmacro(),
678 		    bptr->val, idxval - i);
679 	  *ident = tptr->next->next->next;
680 	  return;
681 	}
682       i += bptr->width;
683       bptr = bptr->next;
684       gcount++;
685     }
686 
687   fprintf(outfile," 0 ");      /* out of range */
688 
689   *ident = tptr->next->next->next;
690 
691   return;
692 
693 }
694 
695 /***************************************************/
696 /*       handles input/ingroup for one bus         */
697 /***************************************************/
698 
onebus(tnode ** ident,int group)699 void onebus(tnode ** ident, int group)
700 
701 {
702   tnode * tptr = * ident;
703   tnode * bptr = currinstance->ibus;
704   int currintstack;
705 
706   if (group)
707     {
708       fprintf(outfile," 1 ");
709       return;
710     }
711 
712   currintstack = currintprint;
713   fprintf(outfile," %s(BUS_%s + ", inputbusmacro(), bptr->val);
714 
715   if (tptr->next->next->res == ASINT)
716     {
717       currintprint = ASINT;
718       blocktree(tptr->next->next->down, PRINTTOKENS);
719       fprintf(outfile,")");
720     }
721   else
722     {
723       fprintf(outfile,"((int)(0.5F + (");
724       currintprint = ASFLOAT;
725       blocktree(tptr->next->next->down, PRINTTOKENS);
726       fprintf(outfile," )))) ");
727     }
728 
729   *ident = tptr->next->next->next;  /* skip to end  */
730   currintprint = currintstack;
731   return;
732 
733 }
734 
735 /***************************************************/
736 /*       handles MIDI names for non-midi programs  */
737 /***************************************************/
738 
hasmidisys(void)739 int hasmidisys(void)
740 
741 {
742   if (totmidichan)
743     return totmidichan;
744 
745   if (currintprint == ASFLOAT)
746     fprintf(outfile, " 0.0F ");
747   else
748     fprintf(outfile, " 0 ");
749 
750   return 0;
751 
752 }
753 
754 /***************************************************/
755 /*       handles audioBIFS names for !cin case     */
756 /***************************************************/
757 
hascdriver(void)758 int hascdriver(void)
759 
760 {
761   if (cin || session)
762     return 1;
763 
764   if (currintprint == ASFLOAT)
765     fprintf(outfile, " 0.0F ");
766   else
767     fprintf(outfile, " 0 ");
768 
769   return 0;
770 
771 }
772 
773 /***************************************************/
774 /*       handles array audioBIFS names             */
775 /***************************************************/
776 
printaudiobiffarray(tnode * tptr,tnode ** ident)777 void printaudiobiffarray(tnode * tptr, tnode ** ident)
778 
779 {
780   int currintstack;
781 
782   /* params will always be created if SAOL programs uses it */
783 
784   if (strcmp(tptr->val, "params") && (!hascdriver()))
785     {
786       if (tptr->next == NULL)
787 	return;
788       *ident = tptr->next->next->next;  /* skip to end  */
789       return;
790     }
791 
792   if (tptr->next == NULL)  /* unindexed array */
793     {
794       fprintf(outfile," EV(%s[%i]) ", tptr->val, currarrayindex);
795     }
796   else                    /* indexed array */
797     {
798       currintstack = currintprint;
799       fprintf(outfile," EV(%s[", tptr->val);
800       if (tptr->next->next->res == ASINT)
801 	{
802 	  currintprint = ASINT;
803 	  blocktree(tptr->next->next->down, PRINTTOKENS);
804 	  fprintf(outfile," ]) ");
805 	}
806       else
807 	{
808 	  currintprint = ASFLOAT;
809 	  fprintf(outfile, " (int)(0.5F + (");
810 	  blocktree(tptr->next->next->down, PRINTTOKENS);
811 	      fprintf(outfile," ))]) ");
812 	}
813       *ident = tptr->next->next->next;  /* skip to end  */
814       currintprint = currintstack;
815     }
816 }
817 
818 
819 /***************************************************/
820 /*       prints C code for each standard name      */
821 /***************************************************/
822 
printstandardname(tnode ** ident)823 void printstandardname(tnode ** ident)
824 
825 {
826 
827   tnode * bptr;
828   tnode * tptr = * ident;
829   int group;
830   int currintstack;
831 
832   if (tptr->ttype != S_IDENT)
833     return;
834   if (!(strcmp(tptr->val,"k_rate")))
835     {
836       if (reentrant)
837 	{
838 	  if (currintprint == ASFLOAT)
839 	    fprintf(outfile," EV(KRATE) ");
840 	  else
841 	    fprintf(outfile," ((int)(EV(KRATE))) ");
842 	}
843       else
844 	{
845 	  if (currintprint == ASFLOAT)
846 	    fprintf(outfile," %i.0F ", krate);
847 	  else
848 	    fprintf(outfile," %i ", krate);
849 	}
850       return;
851     }
852   if (!(strcmp(tptr->val,"s_rate")))
853     {
854       if (reentrant)
855 	{
856 	  if (currintprint == ASFLOAT)
857 	    fprintf(outfile," EV(ARATE) ");
858 	  else
859 	    fprintf(outfile," ((int)(EV(ARATE))) ");
860 	}
861       else
862 	{
863 	  if (currintprint == ASFLOAT)
864 	    fprintf(outfile," %i.0F ", srate);
865 	  else
866 	    fprintf(outfile," %i ", srate);
867 	}
868       return;
869     }
870   if (!(strcmp(tptr->val,"inchan")))
871     {
872       if (currintprint == ASFLOAT)
873 	fprintf(outfile," %i.0F ", currinputwidth);
874       else
875 	fprintf(outfile," %i ", currinputwidth);
876       return;
877     }
878   if (!(strcmp(tptr->val,"outchan")))
879     {
880       if (currintprint == ASFLOAT)
881 	fprintf(outfile," %i.0F ", currinstrwidth);
882       else
883 	fprintf(outfile," %i ", currinstrwidth);
884       return;
885     }
886   if (!(strcmp(tptr->val,"time")))
887     {
888       fprintf(outfile," NS(iline->time) ");
889       return;
890     }
891   if (!(strcmp(tptr->val,"dur")))
892     {
893       if (currinstance != NULL)
894 	fprintf(outfile, " NS(v[%s__dur].f) ", currinstance->val);
895       else
896 	{
897 	  if (currinstrument != NULL)
898 	    fprintf(outfile, "  NS(v[%s__dur].f) ", currinstrument->val);
899 	  else
900 	    fprintf(outfile," 0 ");
901 	}
902       return;
903     }
904   if (!(strcmp(tptr->val,"itime")))
905     {
906       fprintf(outfile, " NS(iline->itime) ");
907       return;
908     }
909   if (!(strcmp(tptr->val,"preset")))
910     {
911       if (hasmidisys())
912 	{
913 	  if (currintprint == ASFLOAT)
914 	    fprintf(outfile," ((float)NS(iline->preset)) ");
915 	  else
916 	    fprintf(outfile," NS(iline->preset) ");
917 	}
918       return;
919     }
920   if (!(strcmp(tptr->val,"channel")))
921     {
922       if (hasmidisys())
923 	fprintf(outfile," NG(%i*NS(iline->numchan)+%i)",
924 		MIDIFRAMELEN, MIDIEXTPOS);
925       return;
926     }
927   if (!(strcmp(tptr->val,"MIDIctrl")))
928     {
929 
930       /* MIDIctrl may be LHS, and so we can't use hasmidisys() */
931       /* to create 0.0F in the case of no MIDI inputs ...      */
932 
933       if (tptr->next == NULL)  /* unindexed array */
934 	{
935 	  if (totmidichan)
936 	    fprintf(outfile," NG(%i*NS(iline->numchan) + %i + %i) ",
937 		    MIDIFRAMELEN,MIDICTRLPOS,currarrayindex);
938 	  else
939 	    fprintf(outfile," EV(fakeMIDIctrl[%i]) ", currarrayindex);
940 	}
941       else                    /* indexed array */
942 	{
943 	  currintstack = currintprint;
944 
945 	  if (totmidichan)
946 	    fprintf(outfile," NG(%i*NS(iline->numchan) + %i + ",
947 		    MIDIFRAMELEN,MIDICTRLPOS);
948 	  else
949 	    fprintf(outfile," EV(fakeMIDIctrl[( ");
950 
951 	  if (tptr->next->next->res == ASINT)
952 	    {
953 	      currintprint = ASINT;
954 	      blocktree(tptr->next->next->down, PRINTTOKENS);
955 	      fprintf(outfile," ) ");
956 	    }
957 	  else
958 	    {
959 	      currintprint = ASFLOAT;
960 	      fprintf(outfile, " ((int)(0.5F + (");
961 	      blocktree(tptr->next->next->down, PRINTTOKENS);
962 	      fprintf(outfile," )))) ");
963 	    }
964 
965 	  if (!totmidichan)
966 	    fprintf(outfile, " ]) ");
967 
968 	  *ident = tptr->next->next->next;  /* skip to end  */
969 	  currintprint = currintstack;
970 	}
971       return;
972     }
973   if (!(strcmp(tptr->val,"MIDItouch")))
974     {
975       if (!hasmidisys())
976 	return;
977 
978       fprintf(outfile,
979       " ((NG(%i*NS(iline->numchan)+%i+(255&(NS(iline->notenum))))>0.0F) ? \n",
980 	      MIDIFRAMELEN, MIDITOUCHPOS);
981       fprintf(outfile,
982       " NG(%i*NS(iline->numchan)+%i+(255&(NS(iline->notenum)))) : \n",
983 	      MIDIFRAMELEN, MIDITOUCHPOS);
984       fprintf(outfile,
985       " NG(%i*NS(iline->numchan)+%i))\n",
986 	      MIDIFRAMELEN, MIDICHTOUCHPOS);
987       return;
988     }
989   if (!(strcmp(tptr->val,"MIDIbend")))
990     {
991       if (hasmidisys())
992 	fprintf(outfile," NG(%i*NS(iline->numchan)+%i)",
993 		MIDIFRAMELEN, MIDIBENDPOS);
994       return;
995     }
996   if ((!(strcmp(tptr->val,"input")))||(!(strcmp(tptr->val,"inGroup"))))
997     {
998       if (currinstance == NULL)  /* non-effects instruments */
999 	{
1000 	  nobus(ident);
1001 	  return;
1002 	}
1003 
1004       group = !strcmp(tptr->val,"inGroup");
1005 
1006       if (tptr->next == NULL)     /* unindexed array -- easy special case */
1007 	{
1008 	  arraybus(ident,group);
1009 	  return;
1010 	}
1011 
1012       bptr = currinstance->ibus;
1013 
1014       if (tptr->next->next->vol == CONSTANT) /* index is a constant */
1015 	{
1016 	  constbus(ident, group);
1017 	  return;
1018 	}
1019 
1020       if (bptr->next == NULL)     /* just one bus -- easy special case */
1021 	{
1022 	  onebus(ident, group);
1023 	  return;
1024 	}
1025 
1026       /* later, do krate index special case */
1027 
1028       /* slow worst case */
1029       /* later optimize for ASINT indexes and in other ways too */
1030 
1031       currintstack = currintprint;
1032       currintprint = tptr->next->next->res;
1033       if (group)
1034 	{
1035 	  currinstance->usesingroup = 1;
1036 	  printf ("finGroup%i((float)( \n",currinstance->arrayidx);
1037 	}
1038       else
1039 	{
1040 	  currinstance->usesinput = 1;
1041 	  fprintf(outfile,"finput%i((float)( ",currinstance->arrayidx);
1042 	}
1043       blocktree(tptr->next->next->down, PRINTTOKENS);
1044       fprintf(outfile,"))");
1045       *ident = tptr->next->next->next;  /* skip to end  */
1046       currintprint = currintstack;
1047       return;
1048     }
1049   if (!(strcmp(tptr->val,"released")))
1050     {
1051       if (currintprint == ASFLOAT)
1052 	fprintf(outfile," ((float)NS(iline->released)) ");
1053       else
1054 	fprintf(outfile, " NS(iline->released) ");
1055       return;
1056     }
1057   if (!(strcmp(tptr->val,"cpuload")))
1058     {
1059       fprintf(outfile," EV(cpuload) ");
1060       return;
1061     }
1062   if (!(strcmp(tptr->val,"position")))
1063     {
1064       printaudiobiffarray(tptr, ident);
1065       return;
1066     }
1067   if (!(strcmp(tptr->val,"direction")))
1068     {
1069       printaudiobiffarray(tptr, ident);
1070       return;
1071     }
1072   if (!(strcmp(tptr->val,"listenerPosition")))
1073     {
1074       printaudiobiffarray(tptr, ident);
1075       return;
1076     }
1077   if (!(strcmp(tptr->val,"listenerDirection")))
1078     {
1079       printaudiobiffarray(tptr, ident);
1080       return;
1081     }
1082   if (!(strcmp(tptr->val,"minFront")))
1083     {
1084       if (hascdriver())
1085 	fprintf(outfile," %s ", tptr->val);
1086       return;
1087     }
1088   if (!(strcmp(tptr->val,"maxFront")))
1089     {
1090       if (hascdriver())
1091 	fprintf(outfile," %s ", tptr->val);
1092       return;
1093     }
1094   if (!(strcmp(tptr->val,"minBack")))
1095     {
1096       if (hascdriver())
1097 	fprintf(outfile," %s ", tptr->val);
1098       return;
1099     }
1100   if (!(strcmp(tptr->val,"maxBack")))
1101     {
1102       if (hascdriver())
1103 	fprintf(outfile," %s ", tptr->val);
1104       return;
1105     }
1106   if (!(strcmp(tptr->val,"params")))
1107     {
1108       printaudiobiffarray(tptr, ident);
1109       return;
1110     }
1111 
1112 }
1113 
1114 
1115 /***************************************************/
1116 /*       prints C code to assign _dur              */
1117 /***************************************************/
1118 
printdurassign(void)1119 void printdurassign(void)
1120 
1121 {
1122   if ( (!constdur()) &&
1123        (((currblockrate == IRATETYPE) && (currinstrument->cref->idur)) ||
1124 	((currblockrate == KRATETYPE) && (currinstrument->cref->kadur))))
1125     {
1126 
1127       /* this can be simplified for special cases  */
1128 
1129       if (currinstance)
1130 	fprintf(outfile, "   NS(v[%s__dur].f) = \n", currinstance->val);
1131       else
1132 	{
1133 	  if (currinstrument)
1134 	    fprintf(outfile, "   NS(v[%s__dur].f) = \n", currinstrument->val);
1135 	}
1136 
1137       if (currinstrument)
1138 	{
1139 	  fprintf(outfile,"   ((NS(iline->sdur) < 0.0F) ? -1.0F :\n");
1140 	  fprintf(outfile,"   (NS(iline->abstime) + \n");
1141 	  fprintf(outfile,"   (EV(kcycleidx)-1)*EV(KTIME) - NS(iline->time) + \n");
1142 	  fprintf(outfile,"   POS((60/EV(tempo))*(NS(iline->endtime) - \n");
1143 	  fprintf(outfile,"   EV(scorebeats)))));\n\n");
1144 	}
1145     }
1146 }
1147