Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 5 files changed
  • 0 comments
  • 1 contributor
Jan 29, 2012
Werner Almesberger compiler: update pointers after realloc() in patch_add_cvar 6d81665
Jan 30, 2012
Werner Almesberger midi control: added processors for encoders sending acceleration
Processor selection is via a 3rd argument to midi():

- linear: normal linear control (default)
- accel_linear: control sends acceleration data; map to linear
- accel_cyclic: control sends acceleration data; cycle in interval [0, 1]
8553095
5  src/compiler/compiler.c
@@ -545,10 +545,13 @@ struct patch *patch_compile_filename(const char *filename,
545 545
 
546 546
 struct cvar *patch_add_cvar(struct patch *p)
547 547
 {
  548
+	struct cvar *old = p->cvars;
548 549
 	struct cvar *cv;
549 550
 
550 551
 	p->ncvars++;
551  
-	p->cvars = realloc(p->cvars, sizeof(struct cvar)*p->ncvars);
  552
+	p->cvars = realloc(old, sizeof(struct cvar)*p->ncvars);
  553
+	if(old)
  554
+		stim_redirect(p->stim, &old->val, &p->cvars->val);
552 555
 	cv = p->cvars+p->ncvars-1;
553 556
 	cv->val = 0;
554 557
 	cv->pfv_reg = cv->pvv_reg = -1;
25  src/compiler/parser.y
@@ -38,6 +38,7 @@ static void yy_parse_failed(struct yyParser *yypParser);
38 38
 
39 39
 typedef const char *(*assign_callback)(struct parser_comm *comm,
40 40
 	    struct sym *sym, struct ast_node *node);
  41
+typedef void (*midi_proc)(struct s_midi_ctrl *ct, int value);
41 42
 
42 43
 #define	FAIL(msg)				\
43 44
 	do {					\
@@ -215,6 +216,7 @@ static struct id *symbolify(struct id *id)
215 216
 %destructor primary_expr { free($$); }
216 217
 
217 218
 %type context {assign_callback}
  219
+%type midi_proc {midi_proc}
218 220
 
219 221
 %syntax_error {
220 222
 	FAIL("parse error");
@@ -296,7 +298,7 @@ assignment ::= ident(I) TOK_ASSIGN expr(N) opt_semi. {
296 298
 }
297 299
 
298 300
 assignment ::= ident(I) TOK_ASSIGN TOK_MIDI TOK_LPAREN expr(A) TOK_COMMA
299  
-    expr(B) TOK_RPAREN opt_semi. {
  301
+    expr(B) midi_proc(P) TOK_RPAREN opt_semi. {
300 302
 	/* @@@ clean up this mess later */
301 303
 	struct patch *p = *(struct patch **) state->comm->u.sc;
302 304
 	struct sym *sym = I->sym;
@@ -317,7 +319,7 @@ assignment ::= ident(I) TOK_ASSIGN TOK_MIDI TOK_LPAREN expr(A) TOK_COMMA
317 319
 		p->stim = stim_new();
318 320
 	/* @@@ check range ! */
319 321
 	if(!stim_add(p->stim, A->contents.constant, B->contents.constant,
320  
-	    &cvar->val, midi_proc_lin)) {
  322
+	    &cvar->val, P)) {
321 323
 		FAIL("stim_add failed\n");
322 324
 		return;
323 325
 	}
@@ -325,6 +327,22 @@ assignment ::= ident(I) TOK_ASSIGN TOK_MIDI TOK_LPAREN expr(A) TOK_COMMA
325 327
 	parse_free(B);
326 328
 }
327 329
 
  330
+midi_proc(P) ::= . {
  331
+	P = midi_proc_linear;
  332
+}
  333
+
  334
+midi_proc(P) ::= TOK_COMMA TOK_LINEAR. {
  335
+	P = midi_proc_linear;
  336
+}
  337
+
  338
+midi_proc(P) ::= TOK_COMMA TOK_ACCEL_LINEAR. {
  339
+	P = midi_proc_accel_linear;
  340
+}
  341
+
  342
+midi_proc(P) ::= TOK_COMMA TOK_ACCEL_CYCLIC. {
  343
+	P = midi_proc_accel_cyclic;
  344
+}
  345
+
328 346
 assignment ::= TOK_IMAGEFILE(I) TOK_ASSIGN TOK_FNAME(N). {
329 347
 	const char *msg;
330 348
 
@@ -612,6 +630,9 @@ ident(O) ::= binary(I).		{ O = symbolify(I); }
612 630
 ident(O) ::= binary_misc(I).	{ O = symbolify(I); }
613 631
 ident(O) ::= ternary(I).	{ O = symbolify(I); }
614 632
 ident(O) ::= TOK_MIDI(I).	{ O = symbolify(I); }
  633
+ident(O) ::= TOK_LINEAR(I).	{ O = symbolify(I); }
  634
+ident(O) ::= TOK_ACCEL_LINEAR(I).	{ O = symbolify(I); }
  635
+ident(O) ::= TOK_ACCEL_CYCLIC(I).	{ O = symbolify(I); }
615 636
 
616 637
 unary_misc(O) ::= TOK_ABS(I).	{ O = I; }
617 638
 unary_misc(O) ::= TOK_COS(I).	{ O = I; }
3  src/compiler/scanner.re
@@ -131,6 +131,9 @@ int scan(struct scanner *s)
131 131
 					{ return TOK_PER_PIXEL_UGLY; }
132 132
 
133 133
 		<N>"midi"		{ return TOK_MIDI; }
  134
+		<N>"linear"		{ return TOK_LINEAR; }
  135
+		<N>"accel_linear"	{ return TOK_ACCEL_LINEAR; }
  136
+		<N>"accel_cyclic"	{ return TOK_ACCEL_CYCLIC; }
134 137
 
135 138
 		<N>"imagefile"[1-9]	{ YYSETCONDITION(yycFNAME1);
136 139
 					  return TOK_IMAGEFILE; }
13  src/renderer/stimuli.c
@@ -14,13 +14,22 @@
14 14
 #include "stimuli.h"
15 15
 
16 16
 
17  
-void midi_proc_lin(struct s_midi_ctrl *ct, int value)
  17
+void midi_proc_linear(struct s_midi_ctrl *ct, int value)
18 18
 {
19 19
 	*ct->var = (float) value/127.0;
20 20
 }
21 21
 
22 22
 
23  
-void midi_proc_accel(struct s_midi_ctrl *ct, int value)
  23
+void midi_proc_accel_cyclic(struct s_midi_ctrl *ct, int value)
  24
+{
  25
+	if(value < 64)
  26
+		ct->last += value;
  27
+	else
  28
+		ct->last -= 128-value;
  29
+	*ct->var = (float) (ct->last & 0x7f)/127.0;
  30
+}
  31
+
  32
+void midi_proc_accel_linear(struct s_midi_ctrl *ct, int value)
24 33
 {
25 34
 	if(value < 64) {
26 35
 		ct->last += value;
5  src/renderer/stimuli.h
@@ -35,10 +35,11 @@ struct stimuli {
35 35
 
36 36
 
37 37
 /* Linear mapping [0, 127] -> [0, 1] */
38  
-void midi_proc_lin(struct s_midi_ctrl *ct, int value);
  38
+void midi_proc_linear(struct s_midi_ctrl *ct, int value);
39 39
 
40 40
 /* "Acceleration" (signed 7 bit delta value) with linear mapping */
41  
-void midi_proc_accel(struct s_midi_ctrl *ct, int value);
  41
+void midi_proc_accel_cyclic(struct s_midi_ctrl *ct, int value);
  42
+void midi_proc_accel_linear(struct s_midi_ctrl *ct, int value);
42 43
 
43 44
 void stim_midi_ctrl(struct stimuli *s, int chan, int ctrl, int value);
44 45
 int stim_add(struct stimuli *s, int chan, int ctrl, float *var,

No commit comments for this range

Something went wrong with that request. Please try again.