Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MIDI: decode controller and pitch events

  • Loading branch information...
commit 26c25be4edbc92166b7f0c5eda382f7d177dcfb8 1 parent 31c3619
@sbourdeauducq sbourdeauducq authored
Showing with 51 additions and 27 deletions.
  1. +21 −15 src/input.c
  2. +6 −4 src/input.h
  3. +22 −6 src/midi.c
  4. +2 −2 src/performance.c
View
36 src/input.c
@@ -235,13 +235,24 @@ static int handle_ir_event(mtk_event *e, unsigned char *msg)
return 0;
}
-static void handle_note_on(mtk_event *e, unsigned char *msg)
+static int handle_midi_msg(mtk_event *e, unsigned char *msg)
{
- if((msg[0] & 0xf0) == 0x90) {
- /* Note On */
- e->type = EVENT_TYPE_MIDI;
- e->press.code = (((unsigned int)(msg[0]) & 0x0f) << 8)
- |(unsigned int)msg[1];
+ e->press.code = ((unsigned int)(msg[0]) & 0x0f) << 16; /* set channel */
+ switch(msg[0] & 0xf0) {
+ case 0x90: /* Note On */
+ e->type = EVENT_TYPE_MIDI_NOTEON;
+ e->press.code |= (unsigned int)msg[1];
+ return 1;
+ case 0xb0: /* Controller */
+ e->type = EVENT_TYPE_MIDI_CONTROLLER;
+ e->press.code |= ((unsigned int)msg[1] << 8) | (unsigned int)msg[2];
+ return 1;
+ case 0xe0: /* Pitch */
+ e->type = EVENT_TYPE_MIDI_PITCH;
+ e->press.code |= (unsigned int)msg[2];
+ return 1;
+ default:
+ return 0;
}
}
@@ -254,6 +265,7 @@ static unsigned char midi_msg[3];
static int handle_midi_event(mtk_event *e, unsigned char *msg)
{
rtems_interval t;
+ int r;
t = rtems_clock_get_ticks_since_boot();
if(t > (midi_last + MIDI_TIMEOUT))
@@ -265,20 +277,14 @@ static int handle_midi_event(mtk_event *e, unsigned char *msg)
if(midi_p == 3) {
/* received a complete MIDI message */
- handle_note_on(e, midi_msg);
+ r = handle_midi_msg(e, midi_msg);
midi_p = 0;
- return 1;
+ return r;
}
return 0;
}
-static int handle_injected_midi_event(mtk_event *e, unsigned char *msg)
-{
- handle_note_on(e, msg);
- return 1;
-}
-
static int handle_btn_event(mtk_event *e, unsigned char *msg)
{
switch(msg[0]) {
@@ -428,7 +434,7 @@ void input_eventloop()
} else if(m.fd == btn_fd) {
n = handle_btn_event(&e[total], m.data);
} else if(m.fd == -1) {
- n = handle_injected_midi_event(&e[total], m.data);
+ n = handle_midi_event(&e[total], m.data);
} else if(m.fd == -2) {
/* injected OSC */
e[total].type = EVENT_TYPE_OSC;
View
10 src/input.h
@@ -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
@@ -20,9 +20,11 @@
#include <mtklib.h>
-#define EVENT_TYPE_IR (EVENT_TYPE_USER_BASE)
-#define EVENT_TYPE_MIDI (EVENT_TYPE_USER_BASE+1)
-#define EVENT_TYPE_OSC (EVENT_TYPE_USER_BASE+2)
+#define EVENT_TYPE_IR (EVENT_TYPE_USER_BASE)
+#define EVENT_TYPE_MIDI_NOTEON (EVENT_TYPE_USER_BASE+1)
+#define EVENT_TYPE_MIDI_CONTROLLER (EVENT_TYPE_USER_BASE+2)
+#define EVENT_TYPE_MIDI_PITCH (EVENT_TYPE_USER_BASE+3)
+#define EVENT_TYPE_OSC (EVENT_TYPE_USER_BASE+4)
typedef void (*input_callback)(mtk_event *e, int count);
View
28 src/midi.c
@@ -242,17 +242,33 @@ static void selchange_callback(mtk_event *e, void *arg)
}
}
+static void note_event(int code)
+{
+ char note[16];
+
+ strmidi(note, code);
+ mtk_cmdf(appid, "e_note.set(-text \"%s\")", note);
+}
+
+static void controller_event(int controller, int value)
+{
+ printf("MIDI controller %d: %d\n", controller, value);
+}
+
static void midi_event(mtk_event *e, int count)
{
int i;
- char note[16];
for(i=0;i<count;i++) {
- if(e[i].type == EVENT_TYPE_MIDI) {
- if(((e[i].press.code & 0x0f00) >> 8) == mtk_req_i(appid, "e_channel.text")) {
- strmidi(note, e[i].press.code & 0x7f);
- mtk_cmdf(appid, "e_note.set(-text \"%s\")", note);
- break;
+ if((e[i].type == EVENT_TYPE_MIDI_NOTEON) || (e[i].type == EVENT_TYPE_MIDI_CONTROLLER) || (e[i].type == EVENT_TYPE_MIDI_PITCH)) {
+ if(((e[i].press.code & 0x0f0000) >> 16) == mtk_req_i(appid, "e_channel.text")) {
+ if(e[i].type == EVENT_TYPE_MIDI_NOTEON)
+ note_event(e[i].press.code & 0x7f);
+ else if(e[i].type == EVENT_TYPE_MIDI_CONTROLLER)
+ controller_event((e[i].press.code & 0x7f00) >> 8, e[i].press.code & 0x7f);
+ else
+ /* EVENT_TYPE_MIDI_PITCH */
+ controller_event(128, e[i].press.code & 0x7f);
}
}
}
View
4 src/performance.c
@@ -392,8 +392,8 @@ static void event_callback(mtk_event *e, int count)
} else if(e[i].type == EVENT_TYPE_IR) {
index = e[i].press.code;
index = ir_patches[index];
- } else if(e[i].type == EVENT_TYPE_MIDI) {
- if(((e[i].press.code & 0x0f00) >> 8) == midi_channel) {
+ } else if(e[i].type == EVENT_TYPE_MIDI_NOTEON) {
+ if(((e[i].press.code & 0x0f0000) >> 16) == midi_channel) {
index = e[i].press.code & 0x7f;
index = midi_patches[index];
}
Please sign in to comment.
Something went wrong with that request. Please try again.