Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Full MIDI controller support

  • Loading branch information...
commit 893fe1a8f7f98d09cdd923a1e453b22c3eb9f1a4 1 parent a815873
Sébastien Bourdeauducq sbourdeauducq authored
22 src/compiler.c
View
@@ -1,6 +1,6 @@
/*
* Flickernoise
- * Copyright (C) 2010 Sebastien Bourdeauducq
+ * Copyright (C) 2010, 2011 Sebastien Bourdeauducq
*
* This program is free software: you can redistribute it and/or modify
* 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] = {
"osc2",
"osc3",
"osc4",
+
+ "midi1",
+ "midi2",
+ "midi3",
+ "midi4",
+ "midi5",
+ "midi6",
+ "midi7",
+ "midi8",
"video_a"
};
@@ -342,7 +351,16 @@ static const char pvv_names[COMP_PVV_COUNT][FPVM_MAXSYMLEN] = {
"osc1",
"osc2",
"osc3",
- "osc4"
+ "osc4",
+
+ "midi1",
+ "midi2",
+ "midi3",
+ "midi4",
+ "midi5",
+ "midi6",
+ "midi7",
+ "midi8",
};
static bool init_pvv(struct compiler_sc *sc)
18 src/compiler.h
View
@@ -114,6 +114,15 @@ enum {
pfv_osc2,
pfv_osc3,
pfv_osc4,
+
+ pfv_midi1,
+ pfv_midi2,
+ pfv_midi3,
+ pfv_midi4,
+ pfv_midi5,
+ pfv_midi6,
+ pfv_midi7,
+ pfv_midi8,
pfv_video_a,
@@ -170,6 +179,15 @@ enum {
pvv_osc2,
pvv_osc3,
pvv_osc4,
+
+ pvv_midi1,
+ pvv_midi2,
+ pvv_midi3,
+ pvv_midi4,
+ pvv_midi5,
+ pvv_midi6,
+ pvv_midi7,
+ pvv_midi8,
COMP_PVV_COUNT /* must be last */
};
18 src/eval.c
View
@@ -104,6 +104,15 @@ static void transfer_pvv_regs(struct patch *p)
write_pvv(p, pvv_osc2, read_pfv(p, pfv_osc2));
write_pvv(p, pvv_osc3, read_pfv(p, pfv_osc3));
write_pvv(p, pvv_osc4, read_pfv(p, pfv_osc4));
+
+ write_pvv(p, pvv_midi1, read_pfv(p, pfv_midi1));
+ write_pvv(p, pvv_midi2, read_pfv(p, pfv_midi2));
+ write_pvv(p, pvv_midi3, read_pfv(p, pfv_midi3));
+ write_pvv(p, pvv_midi4, read_pfv(p, pfv_midi4));
+ write_pvv(p, pvv_midi5, read_pfv(p, pfv_midi5));
+ write_pvv(p, pvv_midi6, read_pfv(p, pfv_midi6));
+ write_pvv(p, pvv_midi7, read_pfv(p, pfv_midi7));
+ write_pvv(p, pvv_midi8, read_pfv(p, pfv_midi8));
}
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)
write_pfv(p, pfv_osc2, frd->osc[1]);
write_pfv(p, pfv_osc3, frd->osc[2]);
write_pfv(p, pfv_osc4, frd->osc[3]);
+
+ write_pfv(p, pfv_midi1, frd->midi[0]);
+ write_pfv(p, pfv_midi2, frd->midi[1]);
+ write_pfv(p, pfv_midi3, frd->midi[2]);
+ write_pfv(p, pfv_midi4, frd->midi[3]);
+ write_pfv(p, pfv_midi5, frd->midi[4]);
+ write_pfv(p, pfv_midi6, frd->midi[5]);
+ write_pfv(p, pfv_midi7, frd->midi[6]);
+ write_pfv(p, pfv_midi8, frd->midi[7]);
}
static void set_frd_from_pfv(struct patch *p, struct frame_descriptor *frd)
2  src/eval.h
View
@@ -1,6 +1,6 @@
/*
* Flickernoise
- * Copyright (C) 2010 Sebastien Bourdeauducq
+ * Copyright (C) 2010, 2011 Sebastien Bourdeauducq
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
1  src/framedescriptor.h
View
@@ -47,6 +47,7 @@ struct frame_descriptor {
float bass_att, mid_att, treb_att;
float idmx[IDMX_COUNT];
float osc[OSC_COUNT];
+ float midi[MIDI_COUNT];
float decay;
float wave_mode;
17 src/midi.c
View
@@ -168,6 +168,7 @@ static void load_config()
char config_key[8];
int i;
const char *val;
+ int value;
mtk_cmdf(appid, "e_channel.set(-text \"%d\")", config_read_int("midi_channel", 0));
for(i=0;i<128;i++) {
@@ -178,13 +179,27 @@ static void load_config()
else
midi_bindings[i][0] = 0;
}
+ for(i=0;i<MIDI_COUNT;i++) {
+ sprintf(config_key, "midi%d", i+1);
+ value = config_read_int(config_key, i);
+ mtk_cmdf(appid, "e_midi%d.set(-text \"%d\")", i, value);
+ }
}
static void set_config()
{
- char config_key[8];
+ char config_key[16];
int i;
+ int value;
+ for(i=0;i<MIDI_COUNT;i++) {
+ sprintf(config_key, "e_midi%d.text", i);
+ value = mtk_req_i(appid, config_key);
+ if((value < 0) || (value > 128))
+ value = i;
+ sprintf(config_key, "midi%d", i+1);
+ config_write_int(config_key, value);
+ }
for(i=0;i<128;i++) {
sprintf(config_key, "midi_%02x", i);
if(midi_bindings[i][0] != 0)
12 src/monitor.c
View
@@ -36,6 +36,7 @@ static float bass, mid, treb;
static float bass_att, mid_att, treb_att;
static float idmx[IDMX_COUNT];
static float osc[OSC_COUNT];
+static float midi[MIDI_COUNT];
static void sampler_callback(struct frame_descriptor *frd)
{
@@ -55,6 +56,8 @@ static void sampler_callback(struct frame_descriptor *frd)
idmx[i] = frd->idmx[i];
for(i=0;i<OSC_COUNT;i++)
osc[i] = frd->osc[i];
+ for(i=0;i<MIDI_COUNT;i++)
+ midi[i] = frd->midi[i];
sampler_return(frd);
}
@@ -83,6 +86,15 @@ static float *get_variable(const char *name)
else if(strcmp(name, "osc2") == 0) return &osc[1];
else if(strcmp(name, "osc3") == 0) return &osc[2];
else if(strcmp(name, "osc4") == 0) return &osc[3];
+
+ else if(strcmp(name, "midi1") == 0) return &midi[0];
+ else if(strcmp(name, "midi2") == 0) return &midi[1];
+ else if(strcmp(name, "midi3") == 0) return &midi[2];
+ else if(strcmp(name, "midi4") == 0) return &midi[3];
+ else if(strcmp(name, "midi5") == 0) return &midi[4];
+ else if(strcmp(name, "midi6") == 0) return &midi[5];
+ else if(strcmp(name, "midi7") == 0) return &midi[6];
+ else if(strcmp(name, "midi8") == 0) return &midi[7];
else return NULL;
}
43 src/sampler.c
View
@@ -1,6 +1,6 @@
/*
* Flickernoise
- * Copyright (C) 2010 Sebastien Bourdeauducq
+ * Copyright (C) 2010, 2011 Sebastien Bourdeauducq
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,6 +22,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
+#include <mtklib.h>
#include <rtems.h>
#include <bsp/milkymist_ac97.h>
@@ -29,6 +30,7 @@
#include "analyzer.h"
#include "osc.h"
#include "config.h"
+#include "input.h"
#include "sampler.h"
struct snd_history {
@@ -78,6 +80,18 @@ static void get_dmx_variables(int fd, float *out)
}
}
+static int midi_channel;
+static int midi_map[MIDI_COUNT];
+static int midi_controllers[129];
+
+static void get_midi_variables(float *out)
+{
+ int i;
+
+ for(i=0;i<MIDI_COUNT;i++)
+ out[i] = ((float)midi_controllers[midi_map[i]])/127.0;
+}
+
static rtems_id returned_q;
static rtems_id sampler_terminated;
@@ -176,9 +190,10 @@ static rtems_task sampler_task(rtems_task_argument argument)
analyze_snd(recorded_descriptor, &history);
recorded_descriptor->time = time;
time += 1.0/FPS;
- /* Get DMX/OSC */
+ /* Get DMX/OSC/MIDI inputs */
get_dmx_variables(dmx_fd, recorded_descriptor->idmx);
get_osc_variables(recorded_descriptor->osc);
+ get_midi_variables(recorded_descriptor->midi);
/* Update status and send downstream */
recorded_descriptor->status = FRD_STATUS_SAMPLED;
callback(recorded_descriptor);
@@ -243,6 +258,21 @@ static rtems_task sampler_task(rtems_task_argument argument)
rtems_task_delete(RTEMS_SELF);
}
+static void event_callback(mtk_event *e, int count)
+{
+ int i;
+
+ for(i=0;i<count;i++) {
+ if(e[i].type == EVENT_TYPE_MIDI_CONTROLLER) {
+ if(((e[i].press.code & 0x0f0000) >> 16) == midi_channel)
+ midi_controllers[(e[i].press.code & 0x7f00) >> 8] = e[i].press.code & 0x7f;
+ } else if(e[i].type == EVENT_TYPE_MIDI_PITCH) {
+ if(((e[i].press.code & 0x0f0000) >> 16) == midi_channel)
+ midi_controllers[128] = e[i].press.code & 0x7f;
+ }
+ }
+}
+
static rtems_id sampler_task_id;
void sampler_start(frd_callback callback)
@@ -255,6 +285,13 @@ void sampler_start(frd_callback callback)
sprintf(confname, "idmx%d", i+1);
idmx_map[i] = config_read_int(confname, i+1)-1;
}
+ midi_channel = config_read_int("midi_channel", 0);
+ for(i=0;i<MIDI_COUNT;i++) {
+ sprintf(confname, "midi%d", i+1);
+ midi_map[i] = config_read_int(confname, i);
+ if((midi_map[i] < 0) || (midi_map[i] > 128))
+ midi_map[i] = i;
+ }
sc = rtems_message_queue_create(
rtems_build_name('S', 'M', 'P', 'L'),
@@ -278,6 +315,7 @@ void sampler_start(frd_callback callback)
assert(sc == RTEMS_SUCCESSFUL);
sc = rtems_task_start(sampler_task_id, sampler_task, (rtems_task_argument)callback);
assert(sc == RTEMS_SUCCESSFUL);
+ input_add_callback(event_callback);
}
void sampler_return(struct frame_descriptor *frd)
@@ -287,6 +325,7 @@ void sampler_return(struct frame_descriptor *frd)
void sampler_stop()
{
+ input_delete_callback(event_callback);
rtems_event_send(sampler_task_id, RTEMS_EVENT_0);
rtems_semaphore_obtain(sampler_terminated, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
Please sign in to comment.
Something went wrong with that request. Please try again.