12-polyphonic "chiptune" MIDI synthesizer for LPC1768 (Standalone version)

Dependencies:   ClockControl PowerControl mbed

Committer:
kayekss
Date:
Tue Dec 23 21:50:53 2014 +0000
Revision:
6:cda45a5e723e
Parent:
0:727737138ac5
Supports "Panic on offline" feature when using MIDI-port input

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kayekss 0:727737138ac5 1 #include <stdarg.h>
kayekss 0:727737138ac5 2 #include "mbed.h"
kayekss 0:727737138ac5 3 #include "defs.h"
kayekss 0:727737138ac5 4 #include "RingBuffer.h"
kayekss 0:727737138ac5 5 #include "debug.h"
kayekss 0:727737138ac5 6 #include "note.h"
kayekss 0:727737138ac5 7
kayekss 0:727737138ac5 8 extern Serial console;
kayekss 0:727737138ac5 9 extern note_t noteSent[NUM_INSTRUMENT];
kayekss 0:727737138ac5 10 extern RingBuffer<char> buffer;
kayekss 0:727737138ac5 11 extern dumpmode_t dumpMode;
kayekss 0:727737138ac5 12
kayekss 0:727737138ac5 13 void checkBuffer() {
kayekss 0:727737138ac5 14 size_t bufferCount = buffer.getItemCount();
kayekss 0:727737138ac5 15 size_t bufferCountToDisplay;
kayekss 0:727737138ac5 16 char* bufferPtr = NULL;
kayekss 0:727737138ac5 17
kayekss 0:727737138ac5 18 if (bufferCount) {
kayekss 0:727737138ac5 19 bufferPtr = buffer.peek();
kayekss 0:727737138ac5 20 bufferCountToDisplay = bufferCount > 16 ? 16 : bufferCount;
kayekss 0:727737138ac5 21
kayekss 0:727737138ac5 22 console.printf("* %u byte%c in buffer", bufferCount,
kayekss 0:727737138ac5 23 bufferCount == 1 ? '\0' : 's');
kayekss 0:727737138ac5 24 if (bufferCount > 16) {
kayekss 0:727737138ac5 25 console.printf(". The first 16 bytes:\r\n ");
kayekss 0:727737138ac5 26 } else {
kayekss 0:727737138ac5 27 console.printf(":\r\n ");
kayekss 0:727737138ac5 28 }
kayekss 0:727737138ac5 29 for (uint8_t i = 0; i < bufferCountToDisplay; i++) {
kayekss 0:727737138ac5 30 console.printf(" %02X", *bufferPtr++);
kayekss 0:727737138ac5 31 }
kayekss 0:727737138ac5 32 console.printf("h\r\n");
kayekss 0:727737138ac5 33 } else {
kayekss 0:727737138ac5 34 console.printf("* Buffer is empty.\r\n");
kayekss 0:727737138ac5 35 }
kayekss 0:727737138ac5 36 }
kayekss 0:727737138ac5 37
kayekss 0:727737138ac5 38 void dumpInstrumentList() {
kayekss 0:727737138ac5 39 char const channelLetter[] = {
kayekss 0:727737138ac5 40 '-', '1', '2', '3', '4', '5', '6', '7', '8',
kayekss 0:727737138ac5 41 '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G'
kayekss 0:727737138ac5 42 };
kayekss 0:727737138ac5 43
kayekss 0:727737138ac5 44 if (dumpMode == DUMP_INST_DETAIL) {
kayekss 0:727737138ac5 45 console.printf("\r\n");
kayekss 0:727737138ac5 46 for (uint16_t i = 0; i < NUM_INSTRUMENT; i++) {
kayekss 0:727737138ac5 47 if (noteSent[i].channel) {
kayekss 0:727737138ac5 48 console.printf("#%2d ch=%2d n=%02Xh v=%02Xh ms=%lu\r\n",
kayekss 0:727737138ac5 49 i, noteSent[i].channel, noteSent[i].noteNumber,
kayekss 0:727737138ac5 50 noteSent[i].velocity, noteSent[i].noteOnMs);
kayekss 0:727737138ac5 51 } else {
kayekss 0:727737138ac5 52 console.printf("#%2d not in use\r\n", i);
kayekss 0:727737138ac5 53 }
kayekss 0:727737138ac5 54 }
kayekss 0:727737138ac5 55 } else if (dumpMode == DUMP_INST) {
kayekss 0:727737138ac5 56 for (uint16_t i = 0; i < NUM_INSTRUMENT; i++) {
kayekss 0:727737138ac5 57 console.printf(" %c", channelLetter[noteSent[i].channel]);
kayekss 0:727737138ac5 58 }
kayekss 0:727737138ac5 59 console.printf("\r\n");
kayekss 0:727737138ac5 60 }
kayekss 0:727737138ac5 61 }