Mercurial > hg > opencollidoscope
annotate CollidoscopeApp/include/MIDI.h @ 0:02467299402e
First import
CollidoscopeApp for Raspberry Pi
JackDevice
Teensy code for Collidoscope
author | Fiore Martin <f.martin@qmul.ac.uk> |
---|---|
date | Thu, 30 Jun 2016 14:50:06 +0200 |
parents | |
children | 7fb593d53361 |
rev | line source |
---|---|
f@0 | 1 #pragma once |
f@0 | 2 |
f@0 | 3 #include "RtMidi.h" |
f@0 | 4 #include <memory> |
f@0 | 5 #include <mutex> |
f@0 | 6 #include <array> |
f@0 | 7 |
f@0 | 8 class Config; |
f@0 | 9 |
f@0 | 10 |
f@0 | 11 namespace collidoscope { |
f@0 | 12 |
f@0 | 13 |
f@0 | 14 class MIDIException : public std::exception |
f@0 | 15 { |
f@0 | 16 public: |
f@0 | 17 |
f@0 | 18 MIDIException( std::string message ) : mMessage( message ) {} |
f@0 | 19 |
f@0 | 20 virtual const std::string& getMessage( void ) const { return mMessage; } |
f@0 | 21 |
f@0 | 22 #ifdef _WINDOWS |
f@0 | 23 const char* what() const override { return mMessage.c_str(); } |
f@0 | 24 #else |
f@0 | 25 const char* what() const noexcept override { return mMessage.c_str(); } |
f@0 | 26 #endif |
f@0 | 27 |
f@0 | 28 protected: |
f@0 | 29 std::string mMessage; |
f@0 | 30 }; |
f@0 | 31 |
f@0 | 32 class MIDIMessage |
f@0 | 33 { |
f@0 | 34 friend class MIDI; |
f@0 | 35 public: |
f@0 | 36 |
f@0 | 37 enum class Voice { eNoteOn, eNoteOff, ePitchBend, eControlChange, eIgnore }; |
f@0 | 38 |
f@0 | 39 Voice getVoice() { return mVoice; } |
f@0 | 40 |
f@0 | 41 unsigned char getChannel() { return mChannel; } |
f@0 | 42 |
f@0 | 43 unsigned char getData_1() { return mData1; } |
f@0 | 44 |
f@0 | 45 unsigned char getData_2() { return mData2; } |
f@0 | 46 |
f@0 | 47 private: |
f@0 | 48 |
f@0 | 49 Voice mVoice = Voice::eIgnore; |
f@0 | 50 unsigned char mChannel; |
f@0 | 51 unsigned char mData1; |
f@0 | 52 unsigned char mData2; |
f@0 | 53 |
f@0 | 54 |
f@0 | 55 }; |
f@0 | 56 |
f@0 | 57 |
f@0 | 58 class MIDI |
f@0 | 59 { |
f@0 | 60 |
f@0 | 61 public: |
f@0 | 62 |
f@0 | 63 MIDI(); |
f@0 | 64 ~MIDI(); |
f@0 | 65 |
f@0 | 66 void setup( const Config& ); |
f@0 | 67 |
f@0 | 68 void checkMessages( std::vector< MIDIMessage >& ); |
f@0 | 69 |
f@0 | 70 private: |
f@0 | 71 |
f@0 | 72 static void RtMidiInCallback( double deltatime, std::vector<unsigned char> *message, void *userData ); |
f@0 | 73 |
f@0 | 74 MIDIMessage parseRtMidiMessage( std::vector<unsigned char> *message ); |
f@0 | 75 |
f@0 | 76 // messages to pass to checkMessages caller |
f@0 | 77 std::vector< MIDIMessage > mMIDIMessages; |
f@0 | 78 std::array< MIDIMessage, NUM_WAVES > mPitchBendMessages; |
f@0 | 79 std::array< MIDIMessage, NUM_WAVES > mFilterMessages; |
f@0 | 80 |
f@0 | 81 |
f@0 | 82 |
f@0 | 83 std::vector< std::unique_ptr <RtMidiIn> > mInputs; |
f@0 | 84 std::mutex mMutex; |
f@0 | 85 }; |
f@0 | 86 |
f@0 | 87 |
f@0 | 88 |
f@0 | 89 } // collidsocope } |