-
Notifications
You must be signed in to change notification settings - Fork 2
/
ld_midi.h
131 lines (104 loc) · 2.79 KB
/
ld_midi.h
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef _LD_MIDI_H_
#define _LD_MIDI_H_
#include "rtmidi/RtMidi.h"
// The PCR-30 has 8 sets of controls
// Other controllers may have more or fewer,
// but let's think about that some other time.
#define CONTROLS 8
enum MidiType
{
MidiInput,
MidiOutput,
MidiUnknown
};
// There are 2 control types:
// A slider which gives the volume level
// and an "effect" which modifies the currently
// select effect parameter.
enum CtrlType
{
CT_LEVEL,
CT_EFFECT1,
CT_EFFECT2,
CT_EFFECT3,
CT_EFFECT4,
CT_BUTTON,
CT_SELECT,
N_CT
};
// MIDI CC messages can be sent by the controller
// in response to assignable button pushes.
// Since most MIDI controllers have fewer buttons
// than the LoopDub display, it is instead possible
// to assign certain CCs to Select which button is
// to be pushed, and other CCs to individual loops.
enum Buttons
{
BT_CUE=0,
BT_SPLIT=1,
BT_HOLD=2,
BT_KEYS=3,
BT_NORM=4,
BT_SWITCH=5,
N_BT
};
class MidiControl
{
public:
MidiControl();
~MidiControl();
// Open MIDI ports, etc
bool Initialize();
bool IsInitialized() { return m_bInitialized; }
// Check for MIDI messages
// Return immediately if none
void CheckMsg();
// Return number of MIDI devices
int GetMidiNum();
// Return name of MIDI device n
const char *GetMidiName(int n);
// Return type of MIDI device
MidiType GetMidiType(int n);
// Select a MIDI device
void SelectDevice(int n);
// Poll for a MIDI message from the hardware
bool PollMidi(int *code, int *val, int *status, int *channel);
// Mode
void SetLearningMode(bool bLearnMode);
void SetButtonMode(int mode);
// Send a midi clock tick (24 per beat)
// in ms milliseconds from now.
void SendClockTick(long ms, bool startnow);
void UpdateClockTicks();
void LoadConfiguration();
// Send a CC message setting the given control to the given value
// (between 0 and 127).
void SendControlMsg(int ctrlStrip, int ctrlType, int value);
protected:
// MIDI control codes, one for each control type
char m_ctrlcode[CONTROLS][N_CT];
// True if we are in learning mode, otherwise
// we are in play mode.
bool m_bLearning;
int m_nLearnCh;
int m_nLearnType;
int m_nLastCode;
bool m_bMidiCodesHaveChanged;
bool m_bMidiClockActive;
bool m_bMidiClockWaiting;
// Select which button is affected by MIDI buttons
int m_nButtonMode;
// Midi streams
RtMidiIn *m_pMidiIn;
RtMidiOut *m_pMidiOut;
bool m_bInitialized;
#define LDMIDI_BUFFER_SIZE 4096
unsigned char m_MidiBuffer[LDMIDI_BUFFER_SIZE*3];
unsigned int m_nMidiBufferR;
unsigned int m_nMidiBufferW;
// RtMidi callback
static void callbackRtMidi( double timeStamp,
std::vector<unsigned char> *message,
void *userData );
};
#endif // _LD_MIDI_H_