Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Full MIDI controller support

  • Loading branch information...
commit 893fe1a8f7f98d09cdd923a1e453b22c3eb9f1a4 1 parent a815873
Sébastien Bourdeauducq authored June 09, 2011
22  src/compiler.c
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * Flickernoise
3  
- * Copyright (C) 2010 Sebastien Bourdeauducq
  3
+ * Copyright (C) 2010, 2011 Sebastien Bourdeauducq
4 4
  *
5 5
  * This program is free software: you can redistribute it and/or modify
6 6
  * it under the terms of the GNU General Public License as published by
@@ -148,6 +148,15 @@ static const char pfv_names[COMP_PFV_COUNT][FPVM_MAXSYMLEN] = {
148 148
 	"osc2",
149 149
 	"osc3",
150 150
 	"osc4",
  151
+	
  152
+	"midi1",
  153
+	"midi2",
  154
+	"midi3",
  155
+	"midi4",
  156
+	"midi5",
  157
+	"midi6",
  158
+	"midi7",
  159
+	"midi8",
151 160
 
152 161
 	"video_a"
153 162
 };
@@ -342,7 +351,16 @@ static const char pvv_names[COMP_PVV_COUNT][FPVM_MAXSYMLEN] = {
342 351
 	"osc1",
343 352
 	"osc2",
344 353
 	"osc3",
345  
-	"osc4"
  354
+	"osc4",
  355
+	
  356
+	"midi1",
  357
+	"midi2",
  358
+	"midi3",
  359
+	"midi4",
  360
+	"midi5",
  361
+	"midi6",
  362
+	"midi7",
  363
+	"midi8",
346 364
 };
347 365
 
348 366
 static bool init_pvv(struct compiler_sc *sc)
18  src/compiler.h
@@ -114,6 +114,15 @@ enum {
114 114
 	pfv_osc2,
115 115
 	pfv_osc3,
116 116
 	pfv_osc4,
  117
+	
  118
+	pfv_midi1,
  119
+	pfv_midi2,
  120
+	pfv_midi3,
  121
+	pfv_midi4,
  122
+	pfv_midi5,
  123
+	pfv_midi6,
  124
+	pfv_midi7,
  125
+	pfv_midi8,
117 126
 
118 127
 	pfv_video_a,
119 128
 
@@ -170,6 +179,15 @@ enum {
170 179
 	pvv_osc2,
171 180
 	pvv_osc3,
172 181
 	pvv_osc4,
  182
+	
  183
+	pvv_midi1,
  184
+	pvv_midi2,
  185
+	pvv_midi3,
  186
+	pvv_midi4,
  187
+	pvv_midi5,
  188
+	pvv_midi6,
  189
+	pvv_midi7,
  190
+	pvv_midi8,
173 191
 
174 192
 	COMP_PVV_COUNT /* must be last */
175 193
 };
18  src/eval.c
@@ -104,6 +104,15 @@ static void transfer_pvv_regs(struct patch *p)
104 104
 	write_pvv(p, pvv_osc2, read_pfv(p, pfv_osc2));
105 105
 	write_pvv(p, pvv_osc3, read_pfv(p, pfv_osc3));
106 106
 	write_pvv(p, pvv_osc4, read_pfv(p, pfv_osc4));
  107
+	
  108
+	write_pvv(p, pvv_midi1, read_pfv(p, pfv_midi1));
  109
+	write_pvv(p, pvv_midi2, read_pfv(p, pfv_midi2));
  110
+	write_pvv(p, pvv_midi3, read_pfv(p, pfv_midi3));
  111
+	write_pvv(p, pvv_midi4, read_pfv(p, pfv_midi4));
  112
+	write_pvv(p, pvv_midi5, read_pfv(p, pfv_midi5));
  113
+	write_pvv(p, pvv_midi6, read_pfv(p, pfv_midi6));
  114
+	write_pvv(p, pvv_midi7, read_pfv(p, pfv_midi7));
  115
+	write_pvv(p, pvv_midi8, read_pfv(p, pfv_midi8));
107 116
 }
108 117
 
109 118
 static void reinit_pfv(struct patch *p, int pfv)
@@ -145,6 +154,15 @@ static void set_pfv_from_frd(struct patch *p, struct frame_descriptor *frd)
145 154
 	write_pfv(p, pfv_osc2, frd->osc[1]);
146 155
 	write_pfv(p, pfv_osc3, frd->osc[2]);
147 156
 	write_pfv(p, pfv_osc4, frd->osc[3]);
  157
+	
  158
+	write_pfv(p, pfv_midi1, frd->midi[0]);
  159
+	write_pfv(p, pfv_midi2, frd->midi[1]);
  160
+	write_pfv(p, pfv_midi3, frd->midi[2]);
  161
+	write_pfv(p, pfv_midi4, frd->midi[3]);
  162
+	write_pfv(p, pfv_midi5, frd->midi[4]);
  163
+	write_pfv(p, pfv_midi6, frd->midi[5]);
  164
+	write_pfv(p, pfv_midi7, frd->midi[6]);
  165
+	write_pfv(p, pfv_midi8, frd->midi[7]);
148 166
 }
149 167
 
150 168
 static void set_frd_from_pfv(struct patch *p, struct frame_descriptor *frd)
2  src/eval.h
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * Flickernoise
3  
- * Copyright (C) 2010 Sebastien Bourdeauducq
  3
+ * Copyright (C) 2010, 2011 Sebastien Bourdeauducq
4 4
  *
5 5
  * This program is free software: you can redistribute it and/or modify
6 6
  * it under the terms of the GNU General Public License as published by
1  src/framedescriptor.h
@@ -47,6 +47,7 @@ struct frame_descriptor {
47 47
 	float bass_att, mid_att, treb_att;
48 48
 	float idmx[IDMX_COUNT];
49 49
 	float osc[OSC_COUNT];
  50
+	float midi[MIDI_COUNT];
50 51
 
51 52
 	float decay;
52 53
 	float wave_mode;
17  src/midi.c
@@ -168,6 +168,7 @@ static void load_config()
168 168
 	char config_key[8];
169 169
 	int i;
170 170
 	const char *val;
  171
+	int value;
171 172
 
172 173
 	mtk_cmdf(appid, "e_channel.set(-text \"%d\")", config_read_int("midi_channel", 0));
173 174
 	for(i=0;i<128;i++) {
@@ -178,13 +179,27 @@ static void load_config()
178 179
 		else
179 180
 			midi_bindings[i][0] = 0;
180 181
 	}
  182
+	for(i=0;i<MIDI_COUNT;i++) {
  183
+		sprintf(config_key, "midi%d", i+1);
  184
+		value = config_read_int(config_key, i);
  185
+		mtk_cmdf(appid, "e_midi%d.set(-text \"%d\")", i, value);
  186
+	}
181 187
 }
182 188
 
183 189
 static void set_config()
184 190
 {
185  
-	char config_key[8];
  191
+	char config_key[16];
186 192
 	int i;
  193
+	int value;
187 194
 
  195
+	for(i=0;i<MIDI_COUNT;i++) {
  196
+		sprintf(config_key, "e_midi%d.text", i);
  197
+		value = mtk_req_i(appid, config_key);
  198
+		if((value < 0) || (value > 128))
  199
+			value = i;
  200
+		sprintf(config_key, "midi%d", i+1);
  201
+		config_write_int(config_key, value);
  202
+	}
188 203
 	for(i=0;i<128;i++) {
189 204
 		sprintf(config_key, "midi_%02x", i);
190 205
 		if(midi_bindings[i][0] != 0)
12  src/monitor.c
@@ -36,6 +36,7 @@ static float bass, mid, treb;
36 36
 static float bass_att, mid_att, treb_att;
37 37
 static float idmx[IDMX_COUNT];
38 38
 static float osc[OSC_COUNT];
  39
+static float midi[MIDI_COUNT];
39 40
 
40 41
 static void sampler_callback(struct frame_descriptor *frd)
41 42
 {
@@ -55,6 +56,8 @@ static void sampler_callback(struct frame_descriptor *frd)
55 56
 		idmx[i] = frd->idmx[i];
56 57
 	for(i=0;i<OSC_COUNT;i++)
57 58
 		osc[i] = frd->osc[i];
  59
+	for(i=0;i<MIDI_COUNT;i++)
  60
+		midi[i] = frd->midi[i];
58 61
 	sampler_return(frd);
59 62
 }
60 63
 
@@ -83,6 +86,15 @@ static float *get_variable(const char *name)
83 86
 	else if(strcmp(name, "osc2") == 0) return &osc[1];
84 87
 	else if(strcmp(name, "osc3") == 0) return &osc[2];
85 88
 	else if(strcmp(name, "osc4") == 0) return &osc[3];
  89
+	
  90
+	else if(strcmp(name, "midi1") == 0) return &midi[0];
  91
+	else if(strcmp(name, "midi2") == 0) return &midi[1];
  92
+	else if(strcmp(name, "midi3") == 0) return &midi[2];
  93
+	else if(strcmp(name, "midi4") == 0) return &midi[3];
  94
+	else if(strcmp(name, "midi5") == 0) return &midi[4];
  95
+	else if(strcmp(name, "midi6") == 0) return &midi[5];
  96
+	else if(strcmp(name, "midi7") == 0) return &midi[6];
  97
+	else if(strcmp(name, "midi8") == 0) return &midi[7];
86 98
 
87 99
 	else return NULL;
88 100
 }
43  src/sampler.c
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * Flickernoise
3  
- * Copyright (C) 2010 Sebastien Bourdeauducq
  3
+ * Copyright (C) 2010, 2011 Sebastien Bourdeauducq
4 4
  *
5 5
  * This program is free software: you can redistribute it and/or modify
6 6
  * it under the terms of the GNU General Public License as published by
@@ -22,6 +22,7 @@
22 22
 #include <fcntl.h>
23 23
 #include <unistd.h>
24 24
 #include <assert.h>
  25
+#include <mtklib.h>
25 26
 #include <rtems.h>
26 27
 #include <bsp/milkymist_ac97.h>
27 28
 
@@ -29,6 +30,7 @@
29 30
 #include "analyzer.h"
30 31
 #include "osc.h"
31 32
 #include "config.h"
  33
+#include "input.h"
32 34
 #include "sampler.h"
33 35
 
34 36
 struct snd_history {
@@ -78,6 +80,18 @@ static void get_dmx_variables(int fd, float *out)
78 80
 	}
79 81
 }
80 82
 
  83
+static int midi_channel;
  84
+static int midi_map[MIDI_COUNT];
  85
+static int midi_controllers[129];
  86
+
  87
+static void get_midi_variables(float *out)
  88
+{
  89
+	int i;
  90
+	
  91
+	for(i=0;i<MIDI_COUNT;i++)
  92
+		out[i] = ((float)midi_controllers[midi_map[i]])/127.0;
  93
+}
  94
+
81 95
 static rtems_id returned_q;
82 96
 static rtems_id sampler_terminated;
83 97
 
@@ -176,9 +190,10 @@ static rtems_task sampler_task(rtems_task_argument argument)
176 190
 		analyze_snd(recorded_descriptor, &history);
177 191
 		recorded_descriptor->time = time;
178 192
 		time += 1.0/FPS;
179  
-		/* Get DMX/OSC */
  193
+		/* Get DMX/OSC/MIDI inputs */
180 194
 		get_dmx_variables(dmx_fd, recorded_descriptor->idmx);
181 195
 		get_osc_variables(recorded_descriptor->osc);
  196
+		get_midi_variables(recorded_descriptor->midi);
182 197
 		/* Update status and send downstream */
183 198
 		recorded_descriptor->status = FRD_STATUS_SAMPLED;
184 199
 		callback(recorded_descriptor);
@@ -243,6 +258,21 @@ static rtems_task sampler_task(rtems_task_argument argument)
243 258
 	rtems_task_delete(RTEMS_SELF);
244 259
 }
245 260
 
  261
+static void event_callback(mtk_event *e, int count)
  262
+{
  263
+	int i;
  264
+
  265
+	for(i=0;i<count;i++) {
  266
+		if(e[i].type == EVENT_TYPE_MIDI_CONTROLLER) {
  267
+			if(((e[i].press.code & 0x0f0000) >> 16) == midi_channel)
  268
+				midi_controllers[(e[i].press.code & 0x7f00) >> 8] = e[i].press.code & 0x7f;
  269
+		} else if(e[i].type == EVENT_TYPE_MIDI_PITCH) {
  270
+			if(((e[i].press.code & 0x0f0000) >> 16) == midi_channel)
  271
+				midi_controllers[128] = e[i].press.code & 0x7f;
  272
+		}
  273
+	}
  274
+}
  275
+
246 276
 static rtems_id sampler_task_id;
247 277
 
248 278
 void sampler_start(frd_callback callback)
@@ -255,6 +285,13 @@ void sampler_start(frd_callback callback)
255 285
 		sprintf(confname, "idmx%d", i+1);
256 286
 		idmx_map[i] = config_read_int(confname, i+1)-1;
257 287
 	}
  288
+	midi_channel = config_read_int("midi_channel", 0);
  289
+	for(i=0;i<MIDI_COUNT;i++) {
  290
+		sprintf(confname, "midi%d", i+1);
  291
+		midi_map[i] = config_read_int(confname, i);
  292
+		if((midi_map[i] < 0) || (midi_map[i] > 128))
  293
+			midi_map[i] = i;
  294
+	}
258 295
 
259 296
 	sc = rtems_message_queue_create(
260 297
 		rtems_build_name('S', 'M', 'P', 'L'),
@@ -278,6 +315,7 @@ void sampler_start(frd_callback callback)
278 315
 	assert(sc == RTEMS_SUCCESSFUL);
279 316
 	sc = rtems_task_start(sampler_task_id, sampler_task, (rtems_task_argument)callback);
280 317
 	assert(sc == RTEMS_SUCCESSFUL);
  318
+	input_add_callback(event_callback);
281 319
 }
282 320
 
283 321
 void sampler_return(struct frame_descriptor *frd)
@@ -287,6 +325,7 @@ void sampler_return(struct frame_descriptor *frd)
287 325
 
288 326
 void sampler_stop()
289 327
 {
  328
+	input_delete_callback(event_callback);
290 329
 	rtems_event_send(sampler_task_id, RTEMS_EVENT_0);
291 330
 
292 331
 	rtems_semaphore_obtain(sampler_terminated, RTEMS_WAIT, RTEMS_NO_TIMEOUT);

0 notes on commit 893fe1a

Please sign in to comment.
Something went wrong with that request. Please try again.