Index: midi.c
===================================================================
RCS file: /cvsroot/x0xb0x/firmware/midi.c,v
retrieving revision 1.6
diff -u -r1.6 midi.c
--- midi.c	6 Jun 2005 00:39:04 -0000	1.6
+++ midi.c	4 Dec 2005 08:51:54 -0000
@@ -63,6 +63,8 @@
 
 #define ACCENT_THRESH 100
 
+#define PREV_NOTE_OFF 255
+
 #define MIDI_Q_SIZE 32
 volatile uint8_t midi_q[MIDI_Q_SIZE];      // cyclic queue for midi msgs
 volatile static uint8_t head_idx = 0;
@@ -129,7 +131,7 @@
 
   last_bank = bank;
 
-  prev_note = 255;        // no notes played yet
+  prev_note = PREV_NOTE_OFF;        // no notes played yet
 
   while (1) {
     read_switches();
@@ -244,25 +246,28 @@
 void midi_note_off(uint8_t note, uint8_t velocity) {
   if (note == prev_note) {
     note_off(0);
-    prev_note = 255;
+    clear_note_leds();
+    prev_note = PREV_NOTE_OFF;
   }
 }
 
 void midi_note_on(uint8_t note, uint8_t velocity) {
-  uint8_t slide = 0;
+  uint8_t slide  = 0;
+  uint8_t accent = 0;
 
   if (velocity == 0) {
     // strange midi thing: velocity 0 -> note off!
     midi_note_off(note, velocity);
   } else {
-    if (prev_note != 255)
-      slide = 1;
+    if (prev_note != PREV_NOTE_OFF) slide = 1;
+    if (velocity > ACCENT_THRESH)   accent = 1;
 
-    if (velocity > ACCENT_THRESH) {
-      note_on(note - 0x1A, slide, 1); // with accent
-    } else {
-      note_on(note - 0x1A, slide, 0); // no accent
-    }
+    note_on( from_midi_note(note), slide, accent);
+
+    // light relevant LEDs
+    set_note_led( from_midi_note(note) );
+    if (accent == 1) set_led(LED_ACCENT);
+    if (slide == 1)  set_led(LED_SLIDE);
 
     prev_note = note;
   }
@@ -274,7 +279,7 @@
   if ( (note & 0x3F) == 0)
     midi_putchar(0);                                 // rest
   else 
-    midi_putchar((note & 0x3F) + 0x19);              // note
+    midi_putchar( to_midi_note(note & 0x3F) );       // note
 
   if ((note >> 6) & 0x1)              // if theres an accent, give high velocity 
     midi_putchar(midion_accent_velocity);
@@ -288,7 +293,7 @@
   if ((note & 0x3F) == 0)
     midi_putchar(0);                                 // rest
   else 
-    midi_putchar((note & 0x3F) + 0x19);              // note
+    midi_putchar( to_midi_note(note & 0x3F) );       // note
 
 
   midi_putchar(midioff_velocity);                   // velocity
Index: midi.h
===================================================================
RCS file: /cvsroot/x0xb0x/firmware/midi.h,v
retrieving revision 1.6
diff -u -r1.6 midi.h
--- midi.h	11 May 2005 01:44:10 -0000	1.6
+++ midi.h	4 Dec 2005 08:51:54 -0000
@@ -51,6 +51,10 @@
 
 #define MIDISYNC_PPQ 24
 
+// map between MIDI note number and x0xb0x note number
+#define to_midi_note(note)   ((note) + 0x19)
+#define from_midi_note(note) ((note) - 0x19)
+
 int midi_putchar(char c);
 int midi_getch(void);
 int midi_getchar(void);

