|
| 1 | +#include "analyzer_MIDI.h" |
| 2 | +#include <iostream> |
| 3 | + |
| 4 | +BEGIN_ANALYZER_NAMESPACE |
| 5 | + |
| 6 | +void handleNoteOn(byte inChannel, byte inPitch, byte inVelocity) |
| 7 | +{ |
| 8 | + std::cout << "NoteOn Ch " << int(inChannel) << " Pitch " << int(inPitch) << " Vel " << int(inVelocity); |
| 9 | + if (inPitch > 127) { |
| 10 | + std::cout << "--------------- Pitch greater than 127 detected "; |
| 11 | + } |
| 12 | + if (inVelocity > 127) { |
| 13 | + std::cout << "--------------- Velocity greater than 127 detected "; |
| 14 | + } |
| 15 | + std::cout << std::endl; |
| 16 | +} |
| 17 | +void handleNoteOff(byte inChannel, byte inPitch, byte inVelocity) |
| 18 | +{ |
| 19 | + std::cout << "NoteOff Ch " << int(inChannel) << " Pitch " << int(inPitch) << " Vel " << int(inVelocity); |
| 20 | + if (inPitch > 127) { |
| 21 | + std::cout << "--------------- Pitch greater than 127 detected "; |
| 22 | + } |
| 23 | + if (inVelocity > 127) { |
| 24 | + std::cout << "--------------- Velocity greater than 127 detected "; |
| 25 | + } |
| 26 | + std::cout << std::endl; |
| 27 | +} |
| 28 | +void handleControlChange(byte inChannel, byte inControl, byte inValue) |
| 29 | +{ |
| 30 | + std::cout << "ControlChange Ch " << int(inChannel) << " Cntrl " << int(inControl) << " Val " << int(inValue); |
| 31 | + if (inControl > 127) { |
| 32 | + std::cout << "--------------- Control greater than 127 detected "; |
| 33 | + } |
| 34 | + if (inValue > 127) { |
| 35 | + std::cout << "--------------- Value greater than 127 detected "; |
| 36 | + } |
| 37 | + std::cout << std::endl; |
| 38 | +} |
| 39 | +void handleProgramChange(byte inChannel, byte inProgram) |
| 40 | +{ |
| 41 | + std::cout << "ProgramChange Ch " << int(inChannel) << " Progm " << int(inProgram); |
| 42 | + if (inProgram > 127) { |
| 43 | + std::cout << "--------------- Program greater than 127 detected "; |
| 44 | + } |
| 45 | + std::cout << std::endl; |
| 46 | +} |
| 47 | +void handleChannelPressure(byte inChannel, byte inPressure) |
| 48 | +{ |
| 49 | + std::cout << "AftertouchChannel Ch " << int(inChannel) << " Press " << int(inPressure); |
| 50 | + if (inPressure > 127) { |
| 51 | + std::cout << "--------------- Pressure greater than 127 detected "; |
| 52 | + } |
| 53 | + std::cout << std::endl; |
| 54 | +} |
| 55 | + |
| 56 | +MIDIAnalyzer::MIDIAnalyzer() |
| 57 | + : mSerialBuffer() |
| 58 | + , mTransport(mSerialBuffer) |
| 59 | + , mMIDI((Transport&)mTransport) |
| 60 | +{ |
| 61 | +} |
| 62 | + |
| 63 | +void MIDIAnalyzer::setup() |
| 64 | +{ |
| 65 | + mMIDI.begin(MIDI_CHANNEL_OMNI); |
| 66 | + mMIDI.turnThruOff(); |
| 67 | + mMIDI.setHandleNoteOn(handleNoteOn); |
| 68 | + mMIDI.setHandleNoteOff(handleNoteOff); |
| 69 | + mMIDI.setHandleControlChange(handleControlChange); |
| 70 | + mMIDI.setHandleProgramChange(handleProgramChange); |
| 71 | + mMIDI.setHandleAfterTouchChannel(handleChannelPressure); |
| 72 | +} |
| 73 | + |
| 74 | +void MIDIAnalyzer::process(uint8_t inByte) |
| 75 | +{ |
| 76 | + std::cout << "Processing byte " << std::hex <<int(inByte) << std::dec << std::endl; |
| 77 | + mSerialBuffer.mRxBuffer.write(inByte); |
| 78 | + mMIDI.read(); |
| 79 | +} |
| 80 | + |
| 81 | +END_ANALYZER_NAMESPACE |
0 commit comments