? changelog.meow
Index: keyboard.c
===================================================================
RCS file: /cvsroot/x0xb0x/firmware/keyboard.c,v
retrieving revision 1.4
diff -u -r1.4 keyboard.c
--- keyboard.c	2 Aug 2005 15:28:27 -0000	1.4
+++ keyboard.c	23 Dec 2005 07:36:01 -0000
@@ -64,8 +64,9 @@
 
 void do_keyboard_mode(void) {
   signed int shift = 0;
-  uint8_t accent=0, slide=0;
+  uint8_t accent=FALSE, slide=FALSE;
   uint8_t i, last_bank;
+  uint8_t note;
   
   // turn tempo off!
   turn_on_tempo();
@@ -104,18 +105,24 @@
 
     // show the octave
     display_octave_shift(shift);
+    if (accent) set_led(LED_ACCENT);
+    if (slide)  set_led(LED_SLIDE);
 
     for (i=0; i<13; i++) {
       // check if any notes were just pressed
       if (just_pressed(notekey_tab[i])) {
-	note_on((C2+i) + shift*OCTAVE, slide, accent);
-	midi_send_note_on( ((C2+i) + shift*OCTAVE) | (accent << 6));
+	note = (C2+i) + shift*OCTAVE;
+	note_on(note, slide, accent);
+	midi_send_note_on(note | (accent << 6));
+	set_note_led(note);
 	slide = TRUE;
       }
       
       // check if any notes were released
       if (just_released(notekey_tab[i])) {
-	midi_send_note_off( ((C2+i) + shift*OCTAVE) | (accent << 6));
+	note = (C2+i) + shift*OCTAVE;
+	midi_send_note_off(note | (accent << 6));
+	clear_note_leds();
       }
     }
 
@@ -140,6 +147,7 @@
     // turn off the note.
     if ((NOTE_PIN & 0x3F) && no_keys_pressed()) {
       note_off(0);
+      clear_note_leds();  // ?
       slide = FALSE;
     }
   }
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	23 Dec 2005 07:36:01 -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  = FALSE;
+  uint8_t accent = FALSE;
 
   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 = TRUE;
+    if (velocity > ACCENT_THRESH)   accent = TRUE;
 
-    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 == TRUE) set_led(LED_ACCENT);
+    if (slide == TRUE)  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	23 Dec 2005 07:36:01 -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);
Index: pattern.h
===================================================================
RCS file: /cvsroot/x0xb0x/firmware/pattern.h,v
retrieving revision 1.2
diff -u -r1.2 pattern.h
--- pattern.h	24 Apr 2005 18:55:42 -0000	1.2
+++ pattern.h	23 Dec 2005 07:36:01 -0000
@@ -55,3 +55,26 @@
 
 #define END_OF_PATTERN 0xFF
 #define END_OF_CHAIN 0xFF
+
+#define DONE_NOTE 0x3F  // strip(END_OF_PATTERN)
+#define REST_NOTE 0x00
+
+// strip slide and accent from a note byte
+#ifndef strip
+#define strip(note)  ((note) & 0x3f)
+#endif
+
+// do note_on for full note byte (including accent and slide)
+#ifndef note_on_full
+#define note_on_full(note)  note_on((curr_note) & 0x3f,                  \
+                                    (curr_note) >> 7,       /* slide */  \
+                                    ((curr_note)>>6) & 0x1) /* accent */
+#endif
+
+#ifndef set_accent
+#define set_accent(note)  ((note) ^= 1 << 6)
+#endif
+
+#ifndef set_slide
+#define set_slide(note)   ((note) ^= 1 << 7)
+#endif
Index: pattern_edit.c
===================================================================
RCS file: /cvsroot/x0xb0x/firmware/pattern_edit.c,v
retrieving revision 1.7
diff -u -r1.7 pattern_edit.c
--- pattern_edit.c	25 Apr 2005 07:04:29 -0000	1.7
+++ pattern_edit.c	23 Dec 2005 07:36:01 -0000
@@ -64,9 +64,9 @@
 
   // initialize
   patt_location = 0;
-  in_stepwrite_mode = 0;
-  in_runwrite_mode = 0;
-  play_loaded_pattern = 0;
+  in_stepwrite_mode = FALSE;
+  in_runwrite_mode = FALSE;
+  play_loaded_pattern = FALSE;
   curr_pattern_index = 0;
   curr_note = 0;
   sync = INTERNAL_SYNC;
@@ -159,20 +159,20 @@
 
       index = curr_pattern_index;
 
-      curr_note = pattern_buff[index] & 0x3F;
+      curr_note = strip( pattern_buff[index] );
       
       // dont accent or slide 'done' notes, duh!
-      if (just_pressed(KEY_ACCENT) && (curr_note != 0x3F)) {
+      if (just_pressed(KEY_ACCENT) && (curr_note != DONE_NOTE)) {
 	//putstring("accent ");
-	pattern_buff[index] ^= 1 << 6;
+	set_accent( pattern_buff[index] );
       }
-      if (just_pressed(KEY_SLIDE) && (curr_note != 0x3F)) {
+      if (just_pressed(KEY_SLIDE) && (curr_note != DONE_NOTE)) {
 	//putstring("slide ");
-      	pattern_buff[index] ^= 1 << 7;
+      	set_slide( pattern_buff[index] );
       }
 
       // rests/dones are middle octave (if you hit a note key next)
-      if ((curr_note == 0x3F) || (curr_note == 0)) 
+      if ((curr_note == DONE_NOTE) || (curr_note == REST_NOTE)) 
 	shift = 0;
       else if (curr_note < C2)
 	shift = -1;
@@ -186,18 +186,18 @@
 	shift = 3;
 
       if (just_pressed(KEY_REST)) {
-	curr_note = 0;
+	curr_note = REST_NOTE;
       }
       
       // cant change octaves on rest/done
       if (just_pressed(KEY_UP) &&       
-	  (curr_note != 0x3F) && (curr_note != 0))
+	  (curr_note != DONE_NOTE) && (curr_note != REST_NOTE))
 	if (shift < 1)
 	  curr_note += OCTAVE;
 
       // cant change octaves on rest/done, but default to mid octave
       if (just_pressed(KEY_DOWN) &&
-	  (curr_note != 0x3F) && (curr_note != 0))
+	  (curr_note != DONE_NOTE) && (curr_note != REST_NOTE))
 	if (shift > -1)
 	  curr_note -= OCTAVE;
 
@@ -234,7 +234,7 @@
       }
 
       // when changing to a note from end of pattern (0xff), toss top 2 bits
-      if ((pattern_buff[index] != 0xFF) || (curr_note == 0x3F))
+      if ((pattern_buff[index] != END_OF_PATTERN) || (curr_note == DONE_NOTE))
 	curr_note |= (pattern_buff[index] & 0xC0);   
 
       if (curr_note != pattern_buff[index]) {
@@ -246,9 +246,7 @@
 	pattern_buff[index] = curr_note;
 
 	if (in_stepwrite_mode) 	 // restrike note
-	  note_on(curr_note & 0x3F,
-		  curr_note >> 7,              // slide
-		  (curr_note>>6) & 0x1);       // accent
+	  note_on_full(curr_note);
 	
       }
       if (curr_note != 0xFF) {
@@ -301,10 +299,8 @@
 	  set_led(LED_DONE);
 	} else {
 	  clear_led(LED_DONE);
-	  note_on(curr_note & 0x3F,
-		  curr_note >> 7,              // slide
-		  (curr_note>>6) & 0x1);       // accent
-	  
+	  note_on_full(curr_note);
+
 	  set_note_led(curr_note);
 	}
       } else if (just_pressed(KEY_NEXT) && !in_runwrite_mode) {
@@ -314,9 +310,7 @@
 
 	curr_note = pattern_buff[curr_pattern_index];
 	if (curr_note != 0xFF) {
-	  note_on(curr_note & 0x3F,
-		  curr_note >> 7,              // slide
-		  (curr_note>>6) & 0x1);       // accent
+	  note_on_full(curr_note);
 	  
 	  set_note_led(curr_note);
 	}
@@ -332,7 +326,7 @@
 	  pattern_buff[i] = 0xFF;
 	*/
 	if (curr_pattern_index+1 < PATT_SIZE)
-	  pattern_buff[curr_pattern_index+1] = 0xff;
+	  pattern_buff[curr_pattern_index+1] = END_OF_PATTERN;
 
 	stop_stepwrite_mode();
       }
@@ -410,22 +404,22 @@
 void start_runwrite_mode() {
   //putstring("start runwrite\n\r");
   curr_pattern_index = 0;
-  in_runwrite_mode = 1;
+  in_runwrite_mode = TRUE;
   set_led(LED_RS); 
   note_off(0);
   turn_on_tempo();
   while (note_counter & 0x1);  // wait for the tempo interrupt to be ready for a note-on
-  play_loaded_pattern = 1;
+  play_loaded_pattern = TRUE;
 }
 
 void stop_runwrite_mode() {
   //putstring("stop runwrite\n\r");
   turn_off_tempo();
-  play_loaded_pattern = 0;
+  play_loaded_pattern = FALSE;
   clear_key_leds();
   clear_bank_leds();
   set_bank_led(bank);
-  in_runwrite_mode = 0;
+  in_runwrite_mode = FALSE;
   clear_led(LED_RS);
   note_off(0);
 }
@@ -435,7 +429,7 @@
 
 void start_stepwrite_mode() {
   //putstring("start stepwrite\n\r");
-  in_stepwrite_mode = 1;
+  in_stepwrite_mode = TRUE;
   set_led(LED_NEXT); 
   clear_bank_leds();
   set_bank_led(0);
@@ -445,7 +439,7 @@
 
 void stop_stepwrite_mode() {
   //putstring("stop stepwrite\n\r");
-  in_stepwrite_mode = 0;
+  in_stepwrite_mode = FALSE;
   clear_led(LED_NEXT); 
   clear_key_leds();
   clear_bank_leds();

