Chuck Timber / Mbed 2 deprecated Gemphet8

Dependencies:   MIDI REnc button mbed

Revision:
6:16aa8fc30ef8
Parent:
1:2760654d0b44
Child:
7:2398a1835eae
--- a/main.cpp	Sun Aug 10 23:41:05 2014 +0000
+++ b/main.cpp	Mon Aug 11 07:51:26 2014 +0000
@@ -6,7 +6,7 @@
  *  @author     Chuck Timber
  *  @date       08/08/2014
  */
- 
+
 #include "mbed.h"
 //#include "button.h"
 //#include "REnc.h"
@@ -27,7 +27,7 @@
 /** @structure MIDI Note management structure
  *
  */
-struct _MidiNote {
+typedef struct _MidiNote {
     /// MIDI Note number
     uint8_t Note;
     /// MIDI Note velocity
@@ -36,11 +36,11 @@
     uint8_t Channel;
     /// pointer to the next _MidiNote object
     struct _MidiNote *next;
-};
+} MN_t, *MN_p;
 
-struct _MidiNote NoteEnd = { 255, 255, 15, 0 };
-struct _MidiNote NoteStart = { 0, 0, 0, &NoteEnd };
-struct _MidiNote MidiNotes[POLYPHONICE_NOTES];
+MN_t NoteEnd   = { 255, 255, 15,        0 };
+MN_t NoteStart = {   0,   0,  0, &NoteEnd };
+MN_t MidiNotes[POLYPHONICE_NOTES];
 static uint16_t MidiNotesTag;
 
 volatile static uint8_t NumOfNotes = POLYPHONICE_NOTES;
@@ -48,6 +48,7 @@
 /** @brief Prototypes related to MIDI
  *
  */
+void midi_init(void);
 struct _MidiNote *allocN(void);
 void freeN(struct _MidiNote *addr);
 void midi_allnoteoff(void);
@@ -59,7 +60,7 @@
 void midi_pc(byte channel, byte number);
 void midi_pbend(byte channel, int bend);
 
-uint8_t midi_params[]={
+uint8_t midi_params[]= {
     0,0,0,0,0,0,0,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,64,0,0,127,0,32,127,0,0,64,32,
@@ -69,22 +70,28 @@
 MIDI midi(dp16, dp15);
 
 
-int main() {
-    
+int main()
+{
+
+    midi_init();
+
+    while(1) {
+        myled = 1;
+        wait(0.2);
+        myled = 0;
+        wait(0.2);
+    }
+}
+
+
+void midi_init(void)
+{
     midi.setHandleNoteOff(&midi_noteoff);
     midi.setHandleNoteOn(&midi_noteon);
     midi.setHandleControlChange(&midi_cc);
     midi.setHandleProgramChange(&midi_pc);
     midi.setHandlePitchBend(&midi_pbend);
     midi.setHandleSystemReset(&midi_sysreset);
-    
-    
-    while(1) {
-        myled = 1;
-        wait(0.2);
-        myled = 0;
-        wait(0.2);
-    }
 }
 
 /// @brief  Reset all MIDI controller
@@ -96,7 +103,7 @@
     for (i = 0, msk = 0x01; i < NumOfNotes; i++, msk<<=1) {
         if (MidiNotesTag & msk) {
             midi.sendNoteOff(MidiNotes[i].Note, MidiNotes[i].Velocity, MidiNotes[i].Channel);
-            MidiNotesTag &= ~msk;           
+            MidiNotesTag &= ~msk;
         }
     }
 
@@ -118,8 +125,7 @@
 }
 
 /// @brief  MIDI note structure allocate function
-static struct _MidiNote *allocN(void)
-{
+static MN_p allocN(void) {
     int i;
     uint16_t msk;
 
@@ -134,13 +140,13 @@
 }
 
 /// @brief  MIDI note structure free function
-static void freeN(struct _MidiNote *addr)
+static void freeN(MN_p addr)
 {
     int i;
     uint16_t msk;
 
     for (i = 0, msk = 0x01; i < NumOfNotes; i++, msk<<=1) {
-        if (addr == &MidiNotes[i]) 
+        if (addr == &MidiNotes[i])
             MidiNotesTag &= ~msk;
     }
 }
@@ -172,7 +178,7 @@
 /// @brief  MIDI Note On callback funcion
 void midi_noteon(byte channel, byte note, byte velocity)
 {
-    struct _MidiNote *ptr, *newnote;
+    MN_p ptr, newnote;
 
     if ((newnote = allocN()) == NULL) { // if table full, release oldest note
         ptr = NoteStart.next;
@@ -197,7 +203,7 @@
 /// @brief  MIDI Note Off callback funcion
 void midi_noteoff(byte channel, byte note, byte velocity)
 {
-    struct _MidiNote *ptr, *lastptr;
+    MN_p ptr, lastptr;
 
     for (ptr = &NoteStart; ptr->next; ptr = ptr->next) {
         if (note == ptr->next->Note) {