Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 6 files changed
  • 0 comments
  • 1 contributor
Jan 30, 2012
Werner Almesberger stimuli: added processor for acceleration with an unbounded range
accel_unbounded is (re)settable, as shown in T.fnp
2f337e1
Werner Almesberger stimuli: remember and update base pointer for stim_redirect
Running a patch twice broke direct MIDI because pointers were updated
relative to the previous copy instead of the original patch. The commit
fixed the problem. The overall ugliness of the process remains, though.
c037acc
5  experimental/T.fnp
@@ -39,7 +39,8 @@ growth = midi(1, 7);			// fader 2
39 39
 radius = midi(2, 7);			// fader 3
40 40
 sensitivity = midi(3, 7);		// fader 4
41 41
 
42  
-twist = midi(0, 24, accel_linear);	// encoder 1
  42
+twist = midi(0, 24, accel_unbounded);	// encoder 1
  43
+reset_twist = midi(0, 28);		// encoder 1 push
43 44
 theta = midi(0, 25, accel_cyclic);	// encoder 2
44 45
 
45 46
 red = midi(4, 7);			// fader 5
@@ -72,6 +73,8 @@ per_frame:
72 73
 	dx = shift ? (xshift-0.5)*0.2 : 0;
73 74
 	dy = shift ? (yshift-0.5)*0.2 : 0;
74 75
 	zoom = 0.9+growth/5;
  76
+	twist = last_reset_twist == reset_twist+1 ? twist : 0;
  77
+	last_reset_twist = reset_twist+1; // avoid 0, so first push is change
75 78
 
76 79
 per_vertex:
77 80
 	rot = rot + (rad-0.4)*1.7*max(0,min((bass_att-1.1)*1.5,5));
4  src/compiler/compiler.c
@@ -544,7 +544,7 @@ struct patch *patch_compile_filename(const char *filename,
544 544
 struct stimuli *compiler_get_stimulus(struct compiler_sc *sc)
545 545
 {
546 546
 	if(!sc->p->stim)
547  
-                sc->p->stim = stim_new();
  547
+                sc->p->stim = stim_new(sc->p);
548 548
 	return sc->p->stim;
549 549
 }
550 550
 
@@ -568,7 +568,7 @@ struct patch *patch_copy(struct patch *p)
568 568
 		pixbuf_inc_ref(img->pixbuf);
569 569
 	}
570 570
 	new_patch->stim = stim_get(p->stim);
571  
-	stim_redirect(p->stim, p, new_patch);
  571
+	stim_redirect(p->stim, new_patch);
572 572
 	return new_patch;
573 573
 }
574 574
 
4  src/compiler/parser.y
@@ -335,6 +335,10 @@ midi_proc(P) ::= TOK_COMMA TOK_ACCEL_LINEAR. {
335 335
 	P = midi_proc_accel_linear;
336 336
 }
337 337
 
  338
+midi_proc(P) ::= TOK_COMMA TOK_ACCEL_UNBOUNDED. {
  339
+	P = midi_proc_accel_unbounded;
  340
+}
  341
+
338 342
 midi_proc(P) ::= TOK_COMMA TOK_ACCEL_CYCLIC. {
339 343
 	P = midi_proc_accel_cyclic;
340 344
 }
1  src/compiler/scanner.re
@@ -133,6 +133,7 @@ int scan(struct scanner *s)
133 133
 		<N>"midi"		{ return TOK_MIDI; }
134 134
 		<N>"linear"		{ return TOK_LINEAR; }
135 135
 		<N>"accel_linear"	{ return TOK_ACCEL_LINEAR; }
  136
+		<N>"accel_unbounded"	{ return TOK_ACCEL_UNBOUNDED; }
136 137
 		<N>"accel_cyclic"	{ return TOK_ACCEL_CYCLIC; }
137 138
 
138 139
 		<N>"imagefile"[1-9]	{ YYSETCONDITION(yycFNAME1);
31  src/renderer/stimuli.c
@@ -10,10 +10,22 @@
10 10
 
11 11
 #include <stdlib.h>
12 12
 #include <string.h>
  13
+#include <sys/types.h>
13 14
 
14 15
 #include "stimuli.h"
15 16
 
16 17
 
  18
+static void midi_add(struct s_midi_ctrl *ct, int value)
  19
+{
  20
+	float f;
  21
+
  22
+	f = (float) value/127.0;
  23
+	if(ct->regs.pfv)
  24
+		*ct->regs.pfv += f;
  25
+	if(ct->regs.pvv)
  26
+		*ct->regs.pvv += f;
  27
+}
  28
+
17 29
 void midi_proc_linear(struct s_midi_ctrl *ct, int value)
18 30
 {
19 31
 	float f;
@@ -34,6 +46,11 @@ void midi_proc_accel_cyclic(struct s_midi_ctrl *ct, int value)
34 46
 	midi_proc_linear(ct, ct->last & 0x7f);
35 47
 }
36 48
 
  49
+void midi_proc_accel_unbounded(struct s_midi_ctrl *ct, int value)
  50
+{
  51
+	midi_add(ct, value < 64 ? value : value-128);
  52
+}
  53
+
37 54
 void midi_proc_accel_linear(struct s_midi_ctrl *ct, int value)
38 55
 {
39 56
 	if(value < 64) {
@@ -88,13 +105,15 @@ struct stim_regs *stim_add_midi_ctrl(struct stimuli *s, int chan, int ctrl,
88 105
 	return &ct->regs;
89 106
 }
90 107
 
91  
-struct stimuli *stim_new(void)
  108
+struct stimuli *stim_new(const void *target)
92 109
 {
93 110
 	struct stimuli *s;
94 111
 
95 112
 	s = calloc(1, sizeof(struct stimuli));
96  
-	if(s)
  113
+	if(s) {
97 114
 		s->ref = 1;
  115
+		s->target = target;
  116
+	}
98 117
 	return s;
99 118
 }
100 119
 
@@ -122,10 +141,11 @@ void stim_put(struct stimuli *s)
122 141
 	free(s);
123 142
 }
124 143
 
125  
-void stim_redirect(struct stimuli *s, const void *old, void *new)
  144
+void stim_redirect(struct stimuli *s, void *new)
126 145
 {
127 146
 	int i, j;
128 147
 	struct s_midi_ctrl *ct;
  148
+	ptrdiff_t d = new-s->target;
129 149
 
130 150
 	if(!s)
131 151
 		return;
@@ -137,9 +157,10 @@ void stim_redirect(struct stimuli *s, const void *old, void *new)
137 157
 			if (!ct)
138 158
 				continue;
139 159
 			if(ct->regs.pfv)
140  
-				ct->regs.pfv = new+((void *) ct->regs.pfv-old);
  160
+				ct->regs.pfv = (void *) ct->regs.pfv+d;
141 161
 			if(ct->regs.pvv)
142  
-				ct->regs.pvv = new+((void *) ct->regs.pvv-old);
  162
+				ct->regs.pvv = (void *) ct->regs.pvv+d;
143 163
 		}
144 164
 	}
  165
+	s->target = new;
145 166
 }
6  src/renderer/stimuli.h
@@ -34,6 +34,7 @@ struct s_midi_chan {
34 34
 struct stimuli {
35 35
 	struct s_midi_chan *midi[MIDI_CHANS];
36 36
 	int ref;
  37
+	const void *target;	/* reference address for pointer relocation */
37 38
 };
38 39
 
39 40
 
@@ -42,14 +43,15 @@ void midi_proc_linear(struct s_midi_ctrl *ct, int value);
42 43
 
43 44
 /* "Acceleration" (signed 7 bit delta value) with linear mapping */
44 45
 void midi_proc_accel_cyclic(struct s_midi_ctrl *ct, int value);
  46
+void midi_proc_accel_unbounded(struct s_midi_ctrl *ct, int value);
45 47
 void midi_proc_accel_linear(struct s_midi_ctrl *ct, int value);
46 48
 
47 49
 void stim_midi_ctrl(struct stimuli *s, int chan, int ctrl, int value);
48 50
 struct stim_regs *stim_add_midi_ctrl(struct stimuli *s, int chan, int ctrl,
49 51
     void (*proc)(struct s_midi_ctrl *ct, int value));
50  
-struct stimuli *stim_new(void);
  52
+struct stimuli *stim_new(const void *target);
51 53
 struct stimuli *stim_get(struct stimuli *s);
52 54
 void stim_put(struct stimuli *s);
53  
-void stim_redirect(struct stimuli *s, const void *old, void *new);
  55
+void stim_redirect(struct stimuli *s, void *new);
54 56
 
55 57
 #endif /* STIMULI_H */

No commit comments for this range

Something went wrong with that request. Please try again.