-
Notifications
You must be signed in to change notification settings - Fork 0
/
midi.hpp
107 lines (85 loc) · 2.52 KB
/
midi.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#ifndef INC_MIDI_H
#define INC_MIDI_H
#include <string>
#include <vector>
#include <map>
//#include <memory>
#include <RtMidi.h>
#include "Scheduled.hpp"
#include "Waiter.hpp"
typedef std::vector<unsigned char> RawMidi;
void midi_init();
void midiPanic (RtMidiOut * midiout);
void midiCallback (double timeStamp, RawMidi *message, void *userData);
std::string char_vector_to_hex (RawMidi v);
// MIDI message types filtered by status byte, sorted by categories (events, channel mode, system common, realtime)
// source : https://www.midi.org/specifications/item/table-1-summary-of-midi-message
enum MidiMessageType { MMT_NOTE_OFF, MMT_NOTE_ON, MMT_AFTERTOUCH, MMT_CONTROL_CHANGE, MMT_PROGRAM_CHANGE, MMT_CHANNEL_AFTERTOUCH, MMT_PITCH_BEND,
MMT_ALL_SOUND_OFF, MMT_RESET_ALL_CTRLS, MMT_LOCAL_CONTROL, MMT_ALL_NOTES_OFF,
MMT_SYSEX, MMT_TIMECODE, MMT_SONG_POSITION_POINTER, MMT_SONG_SELECT, MMT_TUNE_REQUEST, MMT_SYSEX_END,
MMT_CLOCK, MMT_START, MMT_CONTINUE, MMT_STOP, MMT_ACTIVE_SENSING, MMT_RESET };
class MidiMessage
{
public:
MidiMessage( RawMidi data );
~MidiMessage();
inline RawMidi * getData() { return &data_; }
std::string hexData();
inline bool equals( RawMidi * const & v ) const { return data_ == *v; }
protected:
int type;
RawMidi data_;
};
inline bool operator==( MidiMessage const & m, RawMidi * const & v )
{
return m.equals(v);
}
class ScheduledMidiMessage : public Scheduled, public MidiMessage
{
public:
ScheduledMidiMessage (long unsigned int time, RawMidi data);
~ScheduledMidiMessage ();
protected:
int bar_, beat_, tick_;
};
RawMidi note_on_trigger( int, int );
RawMidi note_off_trigger( int, int );
class MidiWaiter
{
public:
void addCommand( RawMidi, BaseCommand * );
void deleteCommand( RawMidi, Clip * );
bool inCommands ( RawMidi m );
void execute ( RawMidi m );
inline void preempt() { preemption_ = true; }
inline void release() { preemption_ = false; }
inline bool getPreemption() { return preemption_; }
inline unsigned int assignmentSize() { return assignment_.size(); }
RawMidi getAssignment();
void setAssignment( RawMidi m );
// Singleton
static MidiWaiter *getInstance ()
{
if ( NULL == singleton_ )
singleton_ = new MidiWaiter;
return singleton_;
}
static void kill ()
{
if ( NULL != singleton_ )
{
delete singleton_;
singleton_ = NULL;
}
}
private:
// Constructor
MidiWaiter ();
// Destructor
~MidiWaiter ();
std::map<RawMidi, std::vector<BaseCommand *>> filters_;
static MidiWaiter * singleton_;
bool preemption_;
RawMidi assignment_;
};
#endif