Standard MIDI file player for the eVY1 shield and analog joy stick

Dependencies:   DirectoryList SDFileSystem mbed

Fork of eVY1_SMF_player by Toyomasa Watarai

MicroSDカードからSMF(スタンダードMIDIファイル)を読み込み、データをシリアルでeVY1シールドに転送して再生します。 MIDIファイル形式は、Format 0のみ対応しています。アナログジョイスティックを使用してテンポとピッチの変更が出来るようにしました。

動作確認は、mbed FRDM-K64Fで行っています。

eVY1シールドをそのまま刺して使用できます(オンボードのMicroSDスロットを使います)。

eVY1を使用した場合、MIDIデータのCH.1は強制的にeVocalodによる歌声として使用されてしまうため(プログラムチェンジも不可)、強制的にCH.16に割り当てています。そのため、CH.16を使用しているMIDIファイルはデータ通りに再生する事が出来ません。

アナログジョイスティックの X Y データは、それぞれアナログ入力の A0, A1 に接続しています。

Revision:
4:4dcc1464c89e
Parent:
3:2a58b7f4b0cb
--- a/main.cpp	Fri Jan 06 10:58:07 2017 +0000
+++ b/main.cpp	Sat Jan 07 06:40:26 2017 +0000
@@ -25,6 +25,10 @@
 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS
 RawSerial midi(D1, NC);
 InterruptIn btn(PTA4);
+AnalogIn ax(A0);
+AnalogIn ay(A1);
+Ticker click;
+float x, y;
 
 #elif defined(TARGET_LPC1114)
 SDFileSystem sd(dp2, dp1, dp6, dp4, "sd"); // MOSI, MISO, SCK, CS
@@ -54,13 +58,22 @@
 
 FILE *fp;
 Timer timer;
-uint32_t tempo;
+uint32_t tempo, org_tempo;
 uint32_t delta_time;
 uint32_t TIMER;
 uint32_t STATE;
+uint32_t pitch_update = 0;
 
 #define midi_read() (fgetc(fp))
 
+void get_val(void)
+{
+    x = ax.read();
+    y = ay.read();
+    tempo = org_tempo + ((ax - 0.5f) * 400);
+    pitch_update = 1;
+}
+
 void disable_timer(void)
 {
     timer.stop();
@@ -88,6 +101,16 @@
     uint32_t cnt;
     uint32_t cmd;
 
+    if (pitch_update) {
+        uint32_t pitch;
+        pitch = 0x4000 + ((y - 0.5f) * 2000);
+        for(uint32_t i=0; i<16; i++) {
+            midi.putc(0xE0 | i);
+            midi.putc(pitch & 0x7F);
+            midi.putc((pitch >> 8) & 0x7F);
+        }
+        pitch_update = 0;
+    }
     buf[0] = midi_read();
     buf[1] = midi_read();
 
@@ -137,6 +160,8 @@
                         tempo = (tempo << 8 ) | midi_read();
                         tempo = (tempo << 8 ) | midi_read();
                         tempo = tempo / 1000;
+                        org_tempo = tempo;
+                        //tempo += (ax * 10);
                         DEBUG_PRINT("Set tempo = %d\n", tempo);
                         break;
                     case 0x2f: // End of Track
@@ -146,6 +171,9 @@
                         break;
                     case 0x01:
                     case 0x02:
+                    case 0x03:
+                    case 0x04:
+                    case 0x05:
                         cnt = midi_read(); // len
                         for(uint32_t i=0; i<cnt; i++)
                             DEBUG_PRINT("%c", midi_read());
@@ -237,6 +265,8 @@
     btn.fall(&skip);
     midi.baud(31250);
 
+    click.attach(&get_val, 0.2);
+
     wait(3.5);    // Wait few seconds for booting eVY1-Shleld.
 
 #if !defined(_NO_eVocaloid_)