-
Notifications
You must be signed in to change notification settings - Fork 13
/
awful_midi.h
138 lines (105 loc) · 5.04 KB
/
awful_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
132
133
134
135
136
137
138
#ifndef _AWFUL_MIDI_
#define _AWFUL_MIDI_
/*==================================================================================================
Module Name: awful_midi.h
General Description: Helper MIDI host declaration. Midi host class is responsible for
interaction with system MIDI devices.
====================================================================================================
Revision History:
Author Date Major Changes description
--------------------- ------------- ------------------------------------------------------------
Anonymous 02/18/2009 Initial creation
====================================================================================================
INCLUDE FILES
==================================================================================================*/
//#include "windows.h"
#include "Awful_instruments.h"
#include "Awful_JuceComponents.h"
#include "Awful_midi_def.h"
/*==================================================================================================
CONSTANTS AND DEFINITIONS SECTION
==================================================================================================*/
/* Controls how many Midi input sources chaotic can work with */
#define MAX_NUM_MIDI_IN_SRC 10
/* Defines how many instruments can be controlled by each Midi input source */
#define MAX_NUM_INSTR_PER_MIDI_IN_SRC 10
/*==================================================================================================
TYPEDEFS AND ENUM DEFINITIONS SECTION
==================================================================================================*/
typedef struct MIDEVICE_DESCR_T
{
unsigned char index;
char* name;
}MIDEVICE_DESCR_T;
typedef struct MidiInputRecord
{
MidiInput* source;
int index;
}MidiInputRecord;
/*==================================================================================================
FUNCTIONS AND CLASS MEMBER DECLARATION SECTION
==================================================================================================*/
class AwfulMidiWrapper;
class AwfulMidiInputCallback : public MidiInputCallback
{
public:
AwfulMidiInputCallback(AwfulMidiWrapper* Owner) : owner(Owner) {};
~AwfulMidiInputCallback(){};
void handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message);
void handlePartialSysexMessage (MidiInput* source,
const uint8* messageData,
const int numBytesSoFar,
const double timestamp);
private:
AwfulMidiWrapper* owner;
};
class AwfulMidiWrapper
{
friend class AwfulMidiInputCallback;
public:
AwfulMidiWrapper();
~AwfulMidiWrapper();
void Initialize();
/* This method is to add instrument to listening loop and map it to particular midi IN device */
unsigned char Attach(Instrument* instr, unsigned char juce_index);
/* Remove an instrument from instr array and stop route MIDI events to this instr */
void Detach(Instrument* instr);
/* How many Midi input sources exist in a system (num of records in m_DevList) */
unsigned char GetDeviceCount() const;
/* returns index and description of chosen midi source */
const MIDEVICE_DESCR_T* GetDeviceDescr(unsigned char index) const;
/* Opens MidiSource - it starts message routing loop */
bool OpenMidiSource(unsigned char juce_index);
/* Close MidiSource - stops the thread and so on... */
void CloseMidiSource(unsigned char index);
/* Check whether MidiSource is open */
bool isOpen(unsigned char index) const;
private:
AwfulMidiInputCallback* m_MidiInputCallback;
/* An array of MidiIn devices. Each device can produce MIDI messages and pass it to callback */
MidiInputRecord m_MidiInputs[MAX_NUM_MIDI_IN_SRC];
/* Set of instrument arrays. Each instr array is dedicated to particular MidiIn device.
So, in theory we can manipulate several instruments by one MIDI source. It means, you can
preview or record several instruments simultaneusly. Let's say you press a key on Midi keybd
and it causes few instruments to produce the same note. */
Instrument* m_InstrSlots[MAX_NUM_MIDI_IN_SRC][MAX_NUM_INSTR_PER_MIDI_IN_SRC];
unsigned char m_InstrCount[MAX_NUM_MIDI_IN_SRC];
/* Holds the list of strings representing all available Midi In devices. This array is filled
in upon object initialization */
MIDEVICE_DESCR_T m_DevList[MAX_NUM_MIDI_IN_SRC];
unsigned char m_DeviceCount;
/* return index of MidiInput in the source array */
unsigned char GetSrcIndex(MidiInput* source)
{
unsigned char index;
for (index = 0; index < MAX_NUM_MIDI_IN_SRC; ++index)
{
if (m_MidiInputs[index].source == source)
{
return index;
}
}
return -1;
}
};
#endif /* _AWFUL_MIDI_ */