To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / CollidoscopeApp / include / MIDI.h @ 0:02467299402e

History | View | Annotate | Download (1.63 KB)

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