Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 5 commits
  • 16 files changed
  • 0 comments
  • 1 contributor
Feb 12, 2012
Werner Almesberger stimuli, compiler: renamed "toggle" to "switch"
Switch is more general, a toggle button merely one possible implementation
of the concept.
9495de7
Werner Almesberger compiler/doc: renamed "toggle" to "switch" 7d5cc8b
Werner Almesberger compiler/doc: changed "MIDIC" to "MIDICC" to match MIDI terminology f45f7b5
Werner Almesberger compiler: fail if trying to use a "live" variable for control
A variable written to by set_pfv_from_frd can never be used as control
variable because set_pfv_from_frd would run after any updates from the
stimulus system, obliterating its changes.

The situation with transfer_pvv_regs is more difficult. At least in
theory, a variable like "sx" could act a control PFV but then
become a regular PVV. The compiler will bind the control PVV
regardlesss, but it will have no effect.

So we can only detect incorrect use of PFV and PVV that have a
corresponding PFV.
ab0d0e3
Werner Almesberger test/stimerr: test detection of duplicate control element and double …
…binding

The latter it is a new error check.
3c77035
8  experimental/T.fnp
@@ -47,11 +47,11 @@ midi "Faderfox LV3" {
47 47
 
48 48
 	enc1_push = button(28);
49 49
 
50  
-	fx1 = toggle(9, 4);
  50
+	fx1 = switch(9, 4);
51 51
 	joy1x = fader(9, 1);
52 52
 	joy1y = fader(9, 2);
53 53
 
54  
-	fx2 = toggle(10, 4);
  54
+	fx2 = switch(10, 4);
55 55
 	joy2x = fader(10, 1);
56 56
 	joy2y = fader(10, 2);
57 57
 }
@@ -72,10 +72,10 @@ green = range(fader6);
72 72
 blue = range(fader7);
73 73
 change = range(fader8);
74 74
 
75  
-offcenter = toggle(fx1);			// FX1
  75
+offcenter = switch(fx1);		// FX1
76 76
 xoff = range(joy1x);
77 77
 yoff = range(joy1y);
78  
-shift = toggle(fx2);			// FX2
  78
+shift = switch(fx2);			// FX2
79 79
 xshift = range(joy2x);
80 80
 yshift = range(joy2y);
81 81
 
16  src/compiler/doc/Makefile
@@ -5,7 +5,7 @@ PICEXT = pdf
5 5
 
6 6
 PICS = bind stim \
7 7
        button-up button-down \
8  
-       toggle-off toggle-on toggle-act toggle-deact \
  8
+       switch-off switch-on \
9 9
        fader-0 fader-40 fader-60 fader-100 \
10 10
        pot-0 pot-90 pot-180 pot-270 \
11 11
        enc-0 enc-90 enc-270 enc-450 enc-405 \
@@ -34,17 +34,11 @@ button-up.$(PICEXT):	button.fig
34 34
 button-down.$(PICEXT):	button.fig
35 35
 			$(call fig2pdf, button finger)
36 36
 
37  
-toggle-off.$(PICEXT):	button.fig
38  
-			$(call fig2pdf, toggle unlit)
  37
+switch-off.$(PICEXT):	switch.fig
  38
+			$(call fig2pdf, switch off)
39 39
 
40  
-toggle-on.$(PICEXT):	button.fig
41  
-			$(call fig2pdf, toggle lit)
42  
-
43  
-toggle-act.$(PICEXT):	button.fig
44  
-			$(call fig2pdf, toggle lit finger)
45  
-
46  
-toggle-deact.$(PICEXT):	button.fig
47  
-			$(call fig2pdf, toggle unlit finger)
  40
+switch-on.$(PICEXT):	switch.fig
  41
+			$(call fig2pdf, switch on)
48 42
 
49 43
 fader-0.$(PICEXT):	fader.fig
50 44
 			$(call fig2pdf, min)
20  src/compiler/doc/bind.fig
@@ -98,7 +98,7 @@ Single
98 98
 1 3 0 2 32 7 70 -1 20 0.000 1 0.0000 10485 3960 225 225 10485 3960 10710 3960
99 99
 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 4
100 100
 	1 1 2.00 60.00 60.00
101  
-	 5805 6390 5805 6660 8415 6660 8415 7605
  101
+	 5760 6390 5760 6660 8415 6660 8415 7605
102 102
 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 5
103 103
 	1 1 2.00 60.00 60.00
104 104
 	 4365 3780 4365 3150 11115 3150 11115 6030 10710 6030
@@ -112,7 +112,7 @@ Single
112 112
 	1 1 2.00 60.00 60.00
113 113
 	 5625 3780 5625 3375 8820 3375 8820 3780
114 114
 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 0 0 4
115  
-	 5175 6345 5175 6390 6435 6390 6435 6345
  115
+	 5085 6345 5085 6390 6435 6390 6435 6345
116 116
 2 1 0 2 32 7 55 -1 -1 0.000 0 0 -1 0 0 2
117 117
 	 4500 6525 6975 6525
118 118
 2 1 0 2 32 7 55 -1 -1 0.000 0 0 -1 0 0 2
@@ -121,10 +121,6 @@ Single
121 121
 	 4500 5850 6975 5850 6975 6975 4500 6975 4500 5850
122 122
 2 2 0 2 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
123 123
 	 3825 5625 7200 5625 7200 8550 3825 8550 3825 5625
124  
-2 2 0 2 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
125  
-	 4500 6075 6975 6075 6975 6300 4500 6300 4500 6075
126  
-2 2 0 3 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
127  
-	 7515 7650 10125 7650 10125 8100 7515 8100 7515 7650
128 124
 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
129 125
 	 8685 7695 8685 8055
130 126
 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
@@ -133,7 +129,11 @@ Single
133 129
 	 9675 7695 9675 8055
134 130
 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
135 131
 	 8145 7695 8145 8055
136  
-4 1 0 50 -1 18 12 0.0000 4 150 555 5400 6255 MIDIC\001
  132
+2 2 0 2 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
  133
+	 4500 6075 6975 6075 6975 6300 4500 6300 4500 6075
  134
+2 2 0 3 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
  135
+	 7425 7650 10125 7650 10125 8100 7425 8100 7425 7650
  136
+4 1 0 50 -1 18 12 0.0000 4 150 690 5400 6255 MIDICC\001
137 137
 4 1 0 50 -1 18 12 0.0000 4 105 330 4815 6255 aux\001
138 138
 4 1 0 50 -1 18 12 0.0000 4 135 105 5850 6255 1\001
139 139
 4 1 0 50 -1 18 12 0.0000 4 135 210 6300 6255 16\001
@@ -152,8 +152,8 @@ Single
152 152
 4 1 0 50 -1 18 12 0.0000 4 150 435 9450 8370 Proc\001
153 153
 4 1 0 50 -1 18 12 0.0000 4 150 315 9900 8370 Var\001
154 154
 4 1 0 50 -1 18 12 0.0000 4 135 210 8955 7965 16\001
155  
-4 1 0 50 -1 18 12 0.0000 4 195 1365 8775 8775 Stimulus entry\001
156 155
 4 1 0 50 -1 18 12 0.0000 4 150 480 8415 8370 Chan\001
157 156
 4 1 0 50 -1 18 12 0.0000 4 135 105 8415 7965 1\001
158  
-4 1 0 50 -1 18 12 0.0000 4 150 555 7830 7965 MIDIC\001
159  
-4 1 0 50 -1 18 12 0.0000 4 195 450 7830 8370 Type\001
  157
+4 1 0 50 -1 18 12 0.0000 4 195 450 7785 8370 Type\001
  158
+4 1 0 50 -1 18 12 0.0000 4 150 690 7785 7965 MIDICC\001
  159
+4 1 0 50 -1 18 12 0.0000 4 195 1365 8730 8775 Stimulus entry\001
50  src/compiler/doc/midi.tex
@@ -114,7 +114,7 @@ \subsection{Device database}
114 114
 	aux = pot(1, 103);
115 115
 	but1 = button(1, 16);
116 116
 	but2 = button(1, 17);
117  
-	tog = toggle(1, 24);
  117
+	tog = switch(1, 24);
118 118
 }
119 119
 \end{listing}
120 120
 
@@ -157,8 +157,8 @@ \subsection{Binding}
157 157
     The control variable receives the value 1 when the button is
158 158
     pressed and returns to zero when it is released. When applied to
159 159
     elements that send values between 0 and 1, the value is rounded
160  
-    and the control acts like a {\tt toggle}.
161  
-  \item[\tt toggle]
  160
+    and the control acts like a {\tt switch}.
  161
+  \item[\tt switch]
162 162
     The value of the control variable changes between 0 and 1 each
163 163
     time the element -- typically a button -- is actuated. 
164 164
 \end{description}
@@ -272,13 +272,13 @@ \subsection{Faders}
272 272
   \midrule
273 273
   Translation
274 274
   & 0 & 0.4 & 0.6 & 1 & 0 & \tt range, $\ldots$ \\
275  
-  & 0 & 0   & 1   & 1 & 0 & \tt button, toggle \\
  275
+  & 0 & 0   & 1   & 1 & 0 & \tt button, switch \\
276 276
 \end{tabular}
277 277
 \end{expose}
278 278
 
279 279
 The mapping is quite straightforward: {\tt range}, {\tt unbounded},
280 280
 and {\tt cycle} produce a value from 0 to 1 corresponding to the
281  
-position of the knob. {\tt button} and {\tt toggle} produce 0 if
  281
+position of the knob. {\tt button} and {\tt switch} produce 0 if
282 282
 the knob is the lower half of the range, 1 if it is in the upper half.
283 283
 
284 284
 
@@ -320,7 +320,7 @@ \subsection{Rotary potentiometers}
320 320
   \midrule
321 321
   Translation
322 322
   & 0 & 0.33 & 0.67 & 1 &  \tt range, $\ldots$ \\
323  
-  & 0 & 0    & 1   & 1 &  \tt button, toggle \\
  323
+  & 0 & 0    & 1   & 1 &  \tt button, switch \\
324 324
 \end{tabular}
325 325
 \end{expose}
326 326
 
@@ -359,7 +359,7 @@ \subsection{Rotary encoders acting as potentiometers}
359 359
   \midrule
360 360
   Translation
361 361
   & 0 & 0.25 & 0.75 & 1 & 0.875 & \tt range, $\ldots$ \\
362  
-  & 0 & 0    & 1    & 1 & 1     & \tt button, toggle \\
  362
+  & 0 & 0    & 1    & 1 & 1     & \tt button, switch \\
363 363
 \end{tabular}
364 364
 \end{expose}
365 365
 
@@ -377,7 +377,7 @@ \subsection{Push buttons}
377 377
 fully off, without intermediate values.
378 378
 
379 379
 Push buttons are declared with {\tt button()} and bound with
380  
-{\tt button()} or {\tt toggle()}:
  380
+{\tt button()} or {\tt switch()}:
381 381
 
382 382
 \begin{listing}{1}
383 383
 midi ... {
@@ -387,7 +387,7 @@ \subsection{Push buttons}
387 387
 var = button(name);
388 388
 \end{listing}
389 389
 
390  
-The alternative {\tt toggle()} turns the control on when the button
  390
+The alternative {\tt switch()} turns the control on when the button
391 391
 is pressed the first time and then off again when pressed the second
392 392
 time.
393 393
 
@@ -407,7 +407,7 @@ \subsection{Push buttons}
407 407
   \midrule
408 408
   Translation
409 409
   & 0 & 1 & 0 & 1 & 0 & \tt range, $\ldots$, button \\
410  
-  & 0 & 1 & 1 & 0 & 0 & \tt toggle \\
  410
+  & 0 & 1 & 1 & 0 & 0 & \tt switch \\
411 411
 \end{tabular}
412 412
 \end{expose}
413 413
 
@@ -415,37 +415,35 @@ \subsection{Push buttons}
415 415
 % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
416 416
 
417 417
 
418  
-\subsection{Toggles}
  418
+\subsection{Switches}
419 419
 
420  
-A toggle button or switch flips from on to off each time it is
421  
-actuated. Toggles are declared with {\tt toggle()} and typically
422  
-bound with {\tt toggle()} as well:
  420
+A switch is set to either on or off and retains its state until
  421
+actuated again. Switches are declared with {\tt switch()} and typically
  422
+bound with {\tt switch()} as well:
423 423
 
424 424
 \begin{listing}{1}
425 425
 midi ... {
426  
-	name = toggle(...);
  426
+	name = switch(...);
427 427
 }
428 428
 
429  
-var = toggle(name);
  429
+var = switch(name);
430 430
 \end{listing}
431 431
 
432 432
 In the example below, we indicate whether the control is activated
433 433
 by a lamp next to the button:
434 434
 
435 435
 \begin{expose}
436  
-\begin{tabular}{lcccccl}
  436
+\begin{tabular}{lcccl}
437 437
   \raisebox{6mm}{User input} &
438  
-  \includegraphics{toggle-off.pdf} &
439  
-  \includegraphics{toggle-act.pdf} &
440  
-  \includegraphics{toggle-on.pdf} &
441  
-  \includegraphics{toggle-deact.pdf} &
442  
-  \includegraphics{toggle-off.pdf} \\
443  
-  \cmidrule(r){1-6}
  438
+  \includegraphics{switch-off.pdf} &
  439
+  \includegraphics{switch-on.pdf} &
  440
+  \includegraphics{switch-off.pdf} \\
  441
+  \cmidrule(r){1-4}
444 442
   MIDI value &
445  
-  & 127 & 0 & 127 & 0\\
  443
+  & 127 & 0 \\
446 444
   \midrule
447 445
   Translation
448  
-  & 0 & 1 & 1 & 0 & 0 & all \\
  446
+  & 0 & 1 & 0 & all \\
449 447
 \end{tabular}
450 448
 \end{expose}
451 449
 
@@ -519,7 +517,7 @@ \subsection{Differential encoders}
519 517
   & 0 & 0.25 & 0.5 & 1 & 1 & 0.75 & \tt range \\
520 518
   & 0 & 0.25 & 0.5 & 1 & 1.125 & 0.875 & \tt unbounded \\
521 519
   & 0 & 0.25 & 0.5 & 0 & 0.125 & 0.875 & \tt cyclic \\
522  
-%  & 0 & 1 & 1 & 0 & \tt button, toggle \\
  520
+%  & 0 & 1 & 1 & 0 & \tt button, switch \\
523 521
 \end{tabular}
524 522
 \end{expose}
525 523
 
6  src/compiler/doc/stim.fig
@@ -90,7 +90,7 @@ Single
90 90
 2 1 0 2 0 7 45 -1 -1 0.000 0 0 -1 1 0 2
91 91
 	1 1 2.00 60.00 60.00
92 92
 	 6210 2250 7155 2250
93  
-4 1 0 50 -1 18 12 0.0000 4 150 135 2025 1890 C\001
  93
+4 1 0 50 -1 18 12 0.0000 4 150 270 2025 1890 CC\001
94 94
 4 1 0 50 -1 18 12 0.0000 4 195 450 1980 1440 Type\001
95 95
 4 1 0 50 -1 18 12 0.0000 4 150 480 2520 1440 Chan\001
96 96
 4 1 0 50 -1 18 12 0.0000 4 135 105 2520 1890 1\001
@@ -99,8 +99,6 @@ Single
99 99
 4 1 0 50 -1 18 12 0.0000 4 135 210 3555 1890 28\001
100 100
 4 1 0 50 -1 18 12 0.0000 4 150 525 3555 1440 Value\001
101 101
 4 1 0 50 -1 18 12 0.0000 4 150 420 1125 1755 MIDI\001
102  
-4 1 0 50 -1 18 12 0.0000 4 150 555 3690 3555 MIDIC\001
103  
-4 1 0 50 -1 18 12 0.0000 4 135 105 4185 3555 1\001
104 102
 4 1 0 50 -1 18 12 0.0000 4 195 450 3645 3780 Type\001
105 103
 4 1 0 50 -1 18 12 0.0000 4 150 480 4185 3780 Chan\001
106 104
 4 1 0 50 -1 18 12 0.0000 4 150 330 4680 3780 Ctrl\001
@@ -111,3 +109,5 @@ Single
111 109
 4 1 0 45 -1 18 12 0.0000 4 150 1350 4545 4770 Stimulus table\001
112 110
 4 1 0 45 -1 18 12 0.0000 4 150 870 7785 3780 Variables\001
113 111
 4 1 0 50 -1 18 12 0.0000 4 150 945 5850 1800 Translator\001
  112
+4 1 0 50 -1 18 12 0.0000 4 150 690 3735 3555 MIDICC\001
  113
+4 1 0 50 -1 18 12 0.0000 4 135 105 4275 3555 1\001
23  src/compiler/doc/switch.fig
... ...
@@ -0,0 +1,23 @@
  1
+#FIG 3.2  Produced by xfig version 3.2.5b
  2
+Landscape
  3
+Center
  4
+Metric
  5
+A4      
  6
+100.00
  7
+Single
  8
+-2
  9
+1200 2
  10
+5 1 0 4 0 7 50 -1 -1 0.000 0 0 0 0 4590.000 4500.000 4275 4500 4590 4185 4905 4500
  11
+5 1 0 4 0 7 50 -1 -1 0.000 0 1 0 0 4590.000 5400.000 4275 5400 4590 5715 4905 5400
  12
+# on
  13
+1 3 0 4 0 7 45 -1 49 0.000 1 0.0000 4590 4500 315 315 4590 4500 4905 4500
  14
+# off
  15
+1 3 0 4 0 7 45 -1 49 0.000 1 0.0000 4590 5400 315 315 4590 5400 4905 5400
  16
+2 1 0 4 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
  17
+	 4275 4500 4275 5400
  18
+2 1 0 4 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
  19
+	 4905 4500 4905 5400
  20
+2 2 0 1 7 7 50 -1 -1 0.000 0 0 -1 0 0 5
  21
+	 4050 3915 6210 3915 6210 5985 4050 5985 4050 3915
  22
+4 0 0 50 -1 18 28 0.0000 4 345 930 5175 5670 OFF\001
  23
+4 0 0 50 -1 18 28 0.0000 4 345 690 5175 4545 ON\001
60  src/compiler/fnp.ids
@@ -59,14 +59,14 @@ mv_a		pfv_mv_a	-1
59 59
 
60 60
 bTexWrap	pfv_tex_wrap	-1
61 61
 
62  
-time		pfv_time	pvv_time
63  
-frame		pfv_frame	pvv_frame
64  
-bass		pfv_bass	pvv_bass
65  
-mid		pfv_mid		pvv_mid
66  
-treb		pfv_treb	pvv_treb
67  
-bass_att	pfv_bass_att	pvv_bass_att
68  
-mid_att		pfv_mid_att	pvv_mid_att
69  
-treb_att	pfv_treb_att	pvv_treb_att
  62
+time		pfv_time	pvv_time	SF_LIVE
  63
+frame		pfv_frame	pvv_frame	SF_LIVE
  64
+bass		pfv_bass	pvv_bass	SF_LIVE
  65
+mid		pfv_mid		pvv_mid		SF_LIVE
  66
+treb		pfv_treb	pvv_treb	SF_LIVE
  67
+bass_att	pfv_bass_att	pvv_bass_att	SF_LIVE
  68
+mid_att		pfv_mid_att	pvv_mid_att	SF_LIVE
  69
+treb_att	pfv_treb_att	pvv_treb_att	SF_LIVE
70 70
 
71 71
 warp		pfv_warp	pvv_warp
72 72
 fWarpAnimSpeed	pfv_warp_anim_speed pvv_warp_anim_speed
@@ -94,28 +94,28 @@ dmx6		pfv_dmx6	-1
94 94
 dmx7		pfv_dmx7	-1
95 95
 dmx8		pfv_dmx8	-1
96 96
 
97  
-idmx1		pfv_idmx1	pvv_idmx1
98  
-idmx2		pfv_idmx2	pvv_idmx2
99  
-idmx3		pfv_idmx3	pvv_idmx3
100  
-idmx4		pfv_idmx4	pvv_idmx4
101  
-idmx5		pfv_idmx5	pvv_idmx5
102  
-idmx6		pfv_idmx6	pvv_idmx6
103  
-idmx7		pfv_idmx7	pvv_idmx7
104  
-idmx8		pfv_idmx8	pvv_idmx8
105  
-
106  
-osc1		pfv_osc1	pvv_osc1
107  
-osc2		pfv_osc2	pvv_osc2
108  
-osc3		pfv_osc3	pvv_osc3
109  
-osc4		pfv_osc4	pvv_osc4
110  
-
111  
-midi1		pfv_midi1	pvv_midi1
112  
-midi2		pfv_midi2	pvv_midi2
113  
-midi3		pfv_midi3	pvv_midi3
114  
-midi4		pfv_midi4	pvv_midi4
115  
-midi5		pfv_midi5	pvv_midi5
116  
-midi6		pfv_midi6	pvv_midi6
117  
-midi7		pfv_midi7	pvv_midi7
118  
-midi8		pfv_midi8	pvv_midi8
  97
+idmx1		pfv_idmx1	pvv_idmx1	SF_LIVE
  98
+idmx2		pfv_idmx2	pvv_idmx2	SF_LIVE
  99
+idmx3		pfv_idmx3	pvv_idmx3	SF_LIVE
  100
+idmx4		pfv_idmx4	pvv_idmx4	SF_LIVE
  101
+idmx5		pfv_idmx5	pvv_idmx5	SF_LIVE
  102
+idmx6		pfv_idmx6	pvv_idmx6	SF_LIVE
  103
+idmx7		pfv_idmx7	pvv_idmx7	SF_LIVE
  104
+idmx8		pfv_idmx8	pvv_idmx8	SF_LIVE
  105
+
  106
+osc1		pfv_osc1	pvv_osc1	SF_LIVE
  107
+osc2		pfv_osc2	pvv_osc2	SF_LIVE
  108
+osc3		pfv_osc3	pvv_osc3	SF_LIVE
  109
+osc4		pfv_osc4	pvv_osc4	SF_LIVE
  110
+
  111
+midi1		pfv_midi1	pvv_midi1	SF_LIVE
  112
+midi2		pfv_midi2	pvv_midi2	SF_LIVE
  113
+midi3		pfv_midi3	pvv_midi3	SF_LIVE
  114
+midi4		pfv_midi4	pvv_midi4	SF_LIVE
  115
+midi5		pfv_midi5	pvv_midi5	SF_LIVE
  116
+midi6		pfv_midi6	pvv_midi6	SF_LIVE
  117
+midi7		pfv_midi7	pvv_midi7	SF_LIVE
  118
+midi8		pfv_midi8	pvv_midi8	SF_LIVE
119 119
 
120 120
 video_a		pfv_video_a	-1
121 121
 
7  src/compiler/idgen
@@ -44,13 +44,18 @@ sed 's/#.*//;/^ *$/d' $1 | LANG=C sort | {
44 44
 	i=0
45 45
 	while read n; do
46 46
 		set - $n
  47
+		if [ "$4" ]; then
  48
+			flags="SF_SYSTEM | $4"
  49
+		else
  50
+			flags=SF_SYSTEM
  51
+		fi
47 52
 		echo "#define ID_$1 (well_known[$i])" >>$f.h
48 53
 		cat <<EOF >>$f.inc
49 54
 {
50 55
 	.fpvm_sym = { .name = "$1" },
51 56
 	.pfv_idx = $2,
52 57
 	.pvv_idx = $3,
53  
-	.flags = SF_SYSTEM,
  58
+	.flags = $flags,
54 59
 	.stim_regs = NULL,
55 60
 },
56 61
 EOF
19  src/compiler/parser.y
@@ -308,6 +308,7 @@ assignment ::= ident(I) TOK_ASSIGN expr(N) opt_semi. {
308 308
 	parse_free(N);
309 309
 }
310 310
 
  311
+
311 312
 /* ----- MIDI device database ---------------------------------------------- */
312 313
 
313 314
 
@@ -339,7 +340,7 @@ midi_dev_type(T) ::= TOK_FADER.		{ T = dt_range; }
339 340
 midi_dev_type(T) ::= TOK_POT.		{ T = dt_range; }
340 341
 midi_dev_type(T) ::= TOK_DIFF.		{ T = dt_diff; }
341 342
 midi_dev_type(T) ::= TOK_BUTTON.	{ T = dt_button; }
342  
-midi_dev_type(T) ::= TOK_TOGGLE.	{ T = dt_toggle; }
  343
+midi_dev_type(T) ::= TOK_SWITCH.	{ T = dt_switch; }
343 344
 
344 345
 midi_addr(M) ::= expr(A) opt_arg(B). {
345 346
 	if(B) {
@@ -380,6 +381,18 @@ assignment ::= ident(I) TOK_ASSIGN midi_fn_type(T) TOK_LPAREN ident(D)
380 381
 	struct stimuli *stim = compiler_get_stimulus(state->comm->u.sc);
381 382
 
382 383
 	free(I);
  384
+	if(sym->flags & SF_LIVE) {
  385
+		FAIL("\"%s\" cannot be used as control variable",
  386
+		    sym->fpvm_sym.name);
  387
+		free(D);
  388
+		return;
  389
+	}
  390
+	if(sym->stim_regs) {
  391
+		FAIL("\"%s\" is already used as control variable",
  392
+		    sym->fpvm_sym.name);
  393
+		free(D);
  394
+		return;
  395
+	}
383 396
 	sym->stim_regs = stim_bind(stim, D->sym, T);
384 397
 	free(D);
385 398
 	if(!sym->stim_regs) {
@@ -393,7 +406,7 @@ midi_fn_type(T) ::= TOK_RANGE.		{ T = ft_range; }
393 406
 midi_fn_type(T) ::= TOK_UNBOUNDED.	{ T = ft_unbounded; }
394 407
 midi_fn_type(T) ::= TOK_CYCLIC.		{ T = ft_cyclic; }
395 408
 midi_fn_type(T) ::= TOK_BUTTON.		{ T = ft_button; }
396  
-midi_fn_type(T) ::= TOK_TOGGLE.		{ T = ft_toggle; }
  409
+midi_fn_type(T) ::= TOK_SWITCH.		{ T = ft_switch; }
397 410
 
398 411
 opt_arg(E) ::= . {
399 412
 	E = NULL;
@@ -706,7 +719,7 @@ ident(O) ::= TOK_FADER(I).	{ O = symbolify(I); }
706 719
 ident(O) ::= TOK_POT(I).	{ O = symbolify(I); }
707 720
 ident(O) ::= TOK_DIFF(I).	{ O = symbolify(I); }
708 721
 ident(O) ::= TOK_BUTTON(I).	{ O = symbolify(I); }
709  
-ident(O) ::= TOK_TOGGLE(I).	{ O = symbolify(I); }
  722
+ident(O) ::= TOK_SWITCH(I).	{ O = symbolify(I); }
710 723
 ident(O) ::= TOK_RANGE(I).	{ O = symbolify(I); }
711 724
 ident(O) ::= TOK_CYCLIC(I).	{ O = symbolify(I); }
712 725
 ident(O) ::= TOK_UNBOUNDED(I).	{ O = symbolify(I); }
2  src/compiler/scanner.re
@@ -135,7 +135,7 @@ int scan(struct scanner *s)
135 135
 		<N>"pot"		{ return TOK_POT; }
136 136
 		<N>"differential"	{ return TOK_DIFF; }
137 137
 		<N>"button"		{ return TOK_BUTTON; }
138  
-		<N>"toggle"		{ return TOK_TOGGLE; }
  138
+		<N>"switch"		{ return TOK_SWITCH; }
139 139
 		<N>"range"		{ return TOK_RANGE; }
140 140
 		<N>"cyclic"		{ return TOK_CYCLIC; }
141 141
 		<N>"unbounded"		{ return TOK_UNBOUNDED; }
7  src/compiler/symtab.h
@@ -15,9 +15,10 @@
15 15
 #include "../renderer/stimuli.h"
16 16
 
17 17
 
18  
-#define	SF_SYSTEM	(1 << 0)
19  
-#define	SF_ASSIGNED	(1 << 1)
20  
-#define	SF_FIXED	SF_SYSTEM
  18
+#define	SF_SYSTEM	(1 << 0)	/* variable is predefined */
  19
+#define	SF_ASSIGNED	(1 << 1)	/* variable has been assigned to */
  20
+#define	SF_LIVE		(1 << 2)	/* variable is written to by FN */
  21
+#define	SF_FIXED	(SF_SYSTEM | SF_LIVE)
21 22
 
22 23
 struct sym {
23 24
 	struct fpvm_sym fpvm_sym;
4  src/compiler/test/stimdb
@@ -97,9 +97,9 @@ EOF
97 97
 
98 98
 #------------------------------------------------------------------------------
99 99
 
100  
-ptest "stimuli, DB, MIDI: toggle(1, 0)" -c -q << EOF
  100
+ptest "stimuli, DB, MIDI: switch(1, 0)" -c -q << EOF
101 101
 midi "foo" {
102  
-	bar = toggle(1, 0);
  102
+	bar = switch(1, 0);
103 103
 }
104 104
 EOF
105 105
 expect <<EOF
44  src/compiler/test/stimerr
... ...
@@ -0,0 +1,44 @@
  1
+#!/bin/sh
  2
+. ./Common
  3
+
  4
+###############################################################################
  5
+
  6
+ptest_fail "stimuli, errors: \"time\" as control variable" -c -q << EOF
  7
+midi "foo" {
  8
+	bar = pot(0);
  9
+}
  10
+
  11
+time = range(bar);
  12
+EOF
  13
+expect <<EOF
  14
+line 6: "time" cannot be used as control variable near 'EOF'
  15
+EOF
  16
+
  17
+#------------------------------------------------------------------------------
  18
+
  19
+ptest_fail "stimuli, errors: duplicate control element" -c -q << EOF
  20
+midi "foo" {
  21
+	bar = pot(0);
  22
+	bar = pot(1);
  23
+}
  24
+EOF
  25
+expect <<EOF
  26
+line 4: cannot add MIDI input "bar" near '}'
  27
+EOF
  28
+
  29
+
  30
+#------------------------------------------------------------------------------
  31
+
  32
+ptest_fail "stimuli, errors: bind control variable twice" -c -q << EOF
  33
+midi "foo" {
  34
+	bar = pot(0);
  35
+}
  36
+
  37
+foo = range(bar);
  38
+foo = range(bar);
  39
+EOF
  40
+expect <<EOF
  41
+line 7: "foo" is already used as control variable near 'EOF'
  42
+EOF
  43
+
  44
+###############################################################################
16  src/compiler/test/stimin
@@ -56,10 +56,10 @@ EOF
56 56
 
57 57
 #------------------------------------------------------------------------------
58 58
 
59  
-ptest "stimuli, input, MIDI: fader -> toggle" -c -q \
  59
+ptest "stimuli, input, MIDI: fader -> switch" -c -q \
60 60
     -v sx -m 0=63 -m 0=64 -m 0=127 -m 0=0 <<EOF
61 61
 midi "foo" { bar = fader(1, 0); }
62  
-sx = toggle(bar);
  62
+sx = switch(bar);
63 63
 EOF
64 64
 expect <<EOF
65 65
 0
@@ -156,10 +156,10 @@ EOF
156 156
 
157 157
 #------------------------------------------------------------------------------
158 158
 
159  
-ptest "stimuli, input, MIDI: button -> toggle" -c -q \
  159
+ptest "stimuli, input, MIDI: button -> switch" -c -q \
160 160
     -v sx -m 0=127 -m 0=0 -m 0=127 -m 0=0 -m 0=127 <<EOF
161 161
 midi "foo" { bar = button(1, 0); }
162  
-sx = toggle(bar);
  162
+sx = switch(bar);
163 163
 EOF
164 164
 expect <<EOF
165 165
 1
@@ -171,9 +171,9 @@ EOF
171 171
 
172 172
 #------------------------------------------------------------------------------
173 173
 
174  
-ptest "stimuli, input, MIDI: toggle -> range" -c -q \
  174
+ptest "stimuli, input, MIDI: switch -> range" -c -q \
175 175
     -v sx -m 0=127 -m 0=0 -m 0=127 -m 0=0 <<EOF
176  
-midi "foo" { bar = toggle(1, 0); }
  176
+midi "foo" { bar = switch(1, 0); }
177 177
 sx = range(bar);
178 178
 EOF
179 179
 expect <<EOF
@@ -185,9 +185,9 @@ EOF
185 185
 
186 186
 #------------------------------------------------------------------------------
187 187
 
188  
-ptest "stimuli, input, MIDI: toggle -> button" -c -q \
  188
+ptest "stimuli, input, MIDI: switch -> button" -c -q \
189 189
     -v sx -m 0=127 -m 0=0 -m 0=127 -m 0=0 <<EOF
190  
-midi "foo" { bar = toggle(1, 0); }
  190
+midi "foo" { bar = switch(1, 0); }
191 191
 sx = button(bar);
192 192
 EOF
193 193
 expect <<EOF
12  src/renderer/stimuli.c
@@ -83,7 +83,7 @@ static void midi_proc_diff_button(struct s_midi_ctrl *ct, int value)
83 83
 		regs_set(&ct->regs, 1);
84 84
 }
85 85
 
86  
-static void midi_proc_button_toggle(struct s_midi_ctrl *ct, int value)
  86
+static void midi_proc_button_switch(struct s_midi_ctrl *ct, int value)
87 87
 {
88 88
 	if(!value)
89 89
 		return;
@@ -283,28 +283,28 @@ static void (*map[dt_last][ft_last])(struct s_midi_ctrl *sct, int value) = {
283 283
 		[ft_unbounded] =	midi_proc_linear,
284 284
 		[ft_cyclic] =		midi_proc_linear,
285 285
 		[ft_button] =		midi_proc_range_button,
286  
-		[ft_toggle] =		midi_proc_range_button,
  286
+		[ft_switch] =		midi_proc_range_button,
287 287
 	},
288 288
 	[dt_diff] = {
289 289
 		[ft_range] =		midi_proc_diff_linear,
290 290
 		[ft_unbounded] =	midi_proc_diff_unbounded,
291 291
 		[ft_cyclic] =		midi_proc_diff_cyclic,
292 292
 		[ft_button] =		midi_proc_diff_button,
293  
-		[ft_toggle] =		midi_proc_diff_button,
  293
+		[ft_switch] =		midi_proc_diff_button,
294 294
 	},
295 295
 	[dt_button] = {
296 296
 		[ft_range] =		midi_proc_linear,
297 297
 		[ft_unbounded] =	midi_proc_linear,
298 298
 		[ft_cyclic] =		midi_proc_linear,
299 299
 		[ft_button] =		midi_proc_linear,
300  
-		[ft_toggle] =		midi_proc_button_toggle,
  300
+		[ft_switch] =		midi_proc_button_switch,
301 301
 	},
302  
-	[dt_toggle] = {
  302
+	[dt_switch] = {
303 303
 		[ft_range] =		midi_proc_linear,
304 304
 		[ft_unbounded] =	midi_proc_linear,
305 305
 		[ft_cyclic] =		midi_proc_linear,
306 306
 		[ft_button] =		midi_proc_linear,
307  
-		[ft_toggle] =		midi_proc_linear,
  307
+		[ft_switch] =		midi_proc_linear,
308 308
 	},
309 309
 };
310 310
 
4  src/renderer/stimuli.h
@@ -21,7 +21,7 @@ enum stim_midi_dev_type {
21 21
 	dt_range,	/* 0-127, holds value */
22 22
 	dt_diff,	/* differential, 0 = 0, 1 = +1, 127 = -1, ... */
23 23
 	dt_button,	/* button, 0 = up, 127 = down */
24  
-	dt_toggle,	/* toggle, 0 = off, 127 = on */
  24
+	dt_switch,	/* switch, 0 = off, 127 = on */
25 25
 	dt_last
26 26
 };
27 27
 
@@ -30,7 +30,7 @@ enum stim_midi_fn_type {
30 30
 	ft_unbounded,	/* additive, use with caution */
31 31
 	ft_cyclic,	/* wraps around 0 <-> 1 */
32 32
 	ft_button,	/* 0 = up, 1 = down */
33  
-	ft_toggle,	/* 0 = off, 1 = on */
  33
+	ft_switch,	/* 0 = off, 1 = on */
34 34
 	ft_last
35 35
 	
36 36
 };

No commit comments for this range

Something went wrong with that request. Please try again.