
a MIDI-to-Morse code application.
Dependencies: MIDI REnc button mbed morse
Revision 8:96f4614a46ba, committed 2014-07-19
- Comitter:
- ChuckTimber
- Date:
- Sat Jul 19 09:43:12 2014 +0000
- Parent:
- 7:82910f3806b3
- Child:
- 9:09fc839da416
- Commit message:
- Morse with MIDI, initial version.; tick factor table.
Changed in this revision
MIDI.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MIDI.lib Sat Jul 19 09:43:12 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/okini3939/code/MIDI/#0eeca7deec08
--- a/main.cpp Sun Jul 13 10:00:28 2014 +0000 +++ b/main.cpp Sat Jul 19 09:43:12 2014 +0000 @@ -1,6 +1,7 @@ #include "mbed.h" #include "button.h" #include "morse.h" +#include "MIDI.h" char* codes[] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", @@ -29,12 +30,23 @@ "........" // 'HH' }; +float rate[] = { 0.50000000, 0.50544464, 0.51094857, 0.51651244, 0.52213689, 0.52782259, 0.53357020, 0.53938040, + 0.54525387, 0.55119129, 0.55719337, 0.56326081, 0.56939432, 0.57559461, 0.58186243, 0.58819850, + 0.59460356, 0.60107837, 0.60762368, 0.61424027, 0.62092891, 0.62769038, 0.63452548, 0.64143501, + 0.64841978, 0.65548061, 0.66261832, 0.66983376, 0.67712777, 0.68450121, 0.69195494, 0.69948984, + 0.70710678, 0.71480667, 0.72259040, 0.73045890, 0.73841307, 0.74645386, 0.75458221, 0.76279908, + 0.77110541, 0.77950220, 0.78799042, 0.79657108, 0.80524517, 0.81401371, 0.82287774, 0.83183829, + 0.84089642, 0.85005318, 0.85930965, 0.86866692, 0.87812608, 0.88768825, 0.89735454, 0.90712609, + 0.91700404, 0.92698956, 0.93708382, 0.94728799, 0.95760328, 0.96803090, 0.97857206, 0.98922801 }; + + +void proc_NoteOn(byte channel, byte note, byte velocity); +void proc_ControlChange(byte channel, byte number, byte value); BTN btn(dp13); Morse morse; -//Morse morse(dp24, LED1); -//Morse morse(dp24, LED1, 0.08, 1000); +MIDI midi(dp16, dp15); int main() { @@ -42,21 +54,52 @@ int mode = 0; int value; - srand( 0 ); + //Morse morse(dp24, LED1); + //Morse morse(dp24, LED1, 0.08, 1000); + + midi.setHandleNoteOn(&proc_NoteOn); + midi.setHandleControlChange(&proc_ControlChange); + + midi.begin(); + wait(1.0); btn.CMD = 0; + while(1) { + midi.read(); if(btn.CMD) { mode++; btn.CMD = 0; + srand( time(NULL) ); } if (mode % 2) { - for (i = 0; i < 27; i++) morse.code(codes[i]); - } else { for (i = 0; i < 5; i++) { value = rand(); morse.code(codes[value % 26]); } morse.code(codes[26]); + //} else { + // for (i = 0; i < 27; i++) morse.code(codes[i]); } } } + +void proc_NoteOn(byte channel, byte note, byte velocity) +{ + if ((36 <= note) && (note <= 36+26)) { + morse.code(codes[note - 36]); + } +} + +void proc_ControlChange(byte channel, byte number, byte value) +{ + float ftmp; + + ftmp = 0.08; // default CW tick + if (number == 16) { // General Purpose Controller 1 + if (value >= 64) { + morse.settick(ftmp * 2. * rate[value-64]); + } else { + morse.settick(ftmp * rate[value]); + } + } +} \ No newline at end of file