-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
AUMIDIBase.h
169 lines (142 loc) · 5.38 KB
/
AUMIDIBase.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*!
@file AudioUnitSDK/AUMIDIBase.h
@copyright © 2000-2021 Apple Inc. All rights reserved.
*/
#ifndef AudioUnitSDK_AUMIDIBase_h
#define AudioUnitSDK_AUMIDIBase_h
#include <AudioUnitSDK/AUBase.h>
#ifndef AUSDK_HAVE_XML_NAMES
#define AUSDK_HAVE_XML_NAMES TARGET_OS_OSX // NOLINT(cppcoreguidelines-macro-usage)
#endif
#ifndef AUSDK_HAVE_MIDI_MAPPING
#define AUSDK_HAVE_MIDI_MAPPING TARGET_OS_OSX // NOLINT(cppcoreguidelines-macro-usage)
#endif
namespace ausdk {
#if AUSDK_HAVE_MIDI_MAPPING
/// Abstract interface for parameter MIDI mapping
class AUMIDIMapper {
public:
AUMIDIMapper() = default;
virtual ~AUMIDIMapper() = default;
AUMIDIMapper(const AUMIDIMapper&) = delete;
AUMIDIMapper(AUMIDIMapper&&) = delete;
AUMIDIMapper& operator=(const AUMIDIMapper&) = delete;
AUMIDIMapper& operator=(AUMIDIMapper&&) = delete;
[[nodiscard]] virtual UInt32 GetNumberMaps() const = 0;
virtual void GetMaps(AUParameterMIDIMapping* outMapping) = 0;
virtual void GetHotParameterMap(AUParameterMIDIMapping& outMapping) = 0;
virtual void AddParameterMapping(
const AUParameterMIDIMapping* maps, UInt32 count, AUBase& auBase) = 0;
virtual void RemoveParameterMapping(
const AUParameterMIDIMapping* maps, UInt32 count, bool& outDidChange) = 0;
virtual void SetHotMapping(const AUParameterMIDIMapping& mapping) = 0;
virtual void ReplaceAllMaps(
const AUParameterMIDIMapping* maps, UInt32 count, AUBase& auBase) = 0;
virtual bool HandleHotMapping(UInt8 status, UInt8 channel, UInt8 data1, AUBase& auBase) = 0;
virtual bool FindParameterMapEventMatch(UInt8 status, UInt8 channel, UInt8 data1, UInt8 data2,
UInt32 inStartFrame, AUBase& auBase) = 0;
};
#endif
// ________________________________________________________________________
// AUMIDIBase
//
/*!
@class AUMIDIBase
@brief Auxiliary class supporting MIDI events.
*/
class AUMIDIBase {
public:
explicit AUMIDIBase(AUBase& inBase) : mAUBaseInstance(inBase) {}
virtual ~AUMIDIBase() = default;
AUMIDIBase(const AUMIDIBase&) = delete;
AUMIDIBase(AUMIDIBase&&) = delete;
AUMIDIBase& operator=(const AUMIDIBase&) = delete;
AUMIDIBase& operator=(AUMIDIBase&&) = delete;
virtual OSStatus MIDIEvent(
UInt32 inStatus, UInt32 inData1, UInt32 inData2, UInt32 inOffsetSampleFrame)
{
const UInt32 strippedStatus = inStatus & 0xf0U; // NOLINT
const UInt32 channel = inStatus & 0x0fU; // NOLINT
return HandleMIDIEvent(strippedStatus, channel, inData1, inData2, inOffsetSampleFrame);
}
#if AUSDK_MIDI2_AVAILABLE
virtual OSStatus MIDIEventList(
UInt32 /*inOffsetSampleFrame*/, const MIDIEventList* /*eventList*/)
{
return kAudio_UnimplementedError;
}
#endif
virtual OSStatus SysEx(const UInt8* inData, UInt32 inLength);
virtual OSStatus DelegateGetPropertyInfo(AudioUnitPropertyID inID, AudioUnitScope inScope,
AudioUnitElement inElement, UInt32& outDataSize, bool& outWritable);
virtual OSStatus DelegateGetProperty(AudioUnitPropertyID inID, AudioUnitScope inScope,
AudioUnitElement inElement, void* outData);
virtual OSStatus DelegateSetProperty(AudioUnitPropertyID inID, AudioUnitScope inScope,
AudioUnitElement inElement, const void* inData, UInt32 inDataSize);
protected:
// MIDI dispatch
virtual OSStatus HandleMIDIEvent(
UInt8 inStatus, UInt8 inChannel, UInt8 inData1, UInt8 inData2, UInt32 inStartFrame);
virtual OSStatus HandleNonNoteEvent(
UInt8 status, UInt8 channel, UInt8 data1, UInt8 data2, UInt32 inStartFrame);
// Old name
AUSDK_DEPRECATED("HandleMIDIEvent")
OSStatus HandleMidiEvent(
UInt8 inStatus, UInt8 inChannel, UInt8 inData1, UInt8 inData2, UInt32 inStartFrame)
{
return HandleMIDIEvent(inStatus, inChannel, inData1, inData2, inStartFrame);
}
#if AUSDK_HAVE_XML_NAMES
virtual OSStatus GetXMLNames(CFURLRef* /*outNameDocument*/)
{
return kAudioUnitErr_InvalidProperty;
} // if not overridden, it's unsupported
#endif
// channel messages
virtual OSStatus HandleNoteOn(
UInt8 /*inChannel*/, UInt8 /*inNoteNumber*/, UInt8 /*inVelocity*/, UInt32 /*inStartFrame*/)
{
return noErr;
}
virtual OSStatus HandleNoteOff(
UInt8 /*inChannel*/, UInt8 /*inNoteNumber*/, UInt8 /*inVelocity*/, UInt32 /*inStartFrame*/)
{
return noErr;
}
virtual OSStatus HandleControlChange(
UInt8 /*inChannel*/, UInt8 /*inController*/, UInt8 /*inValue*/, UInt32 /*inStartFrame*/)
{
return noErr;
}
virtual OSStatus HandlePitchWheel(
UInt8 /*inChannel*/, UInt8 /*inPitch1*/, UInt8 /*inPitch2*/, UInt32 /*inStartFrame*/)
{
return noErr;
}
virtual OSStatus HandleChannelPressure(
UInt8 /*inChannel*/, UInt8 /*inValue*/, UInt32 /*inStartFrame*/)
{
return noErr;
}
virtual OSStatus HandleProgramChange(UInt8 /*inChannel*/, UInt8 /*inValue*/) { return noErr; }
virtual OSStatus HandlePolyPressure(
UInt8 /*inChannel*/, UInt8 /*inKey*/, UInt8 /*inValue*/, UInt32 /*inStartFrame*/)
{
return noErr;
}
virtual OSStatus HandleResetAllControllers(UInt8 /*inChannel*/) { return noErr; }
virtual OSStatus HandleAllNotesOff(UInt8 /*inChannel*/) { return noErr; }
virtual OSStatus HandleAllSoundOff(UInt8 /*inChannel*/) { return noErr; }
// System messages
virtual OSStatus HandleSysEx(const UInt8* /*inData*/, UInt32 /*inLength*/) { return noErr; }
#if AUSDK_HAVE_MIDI_MAPPING
void SetMIDIMapper(const std::shared_ptr<AUMIDIMapper>& mapper) { mMIDIMapper = mapper; }
#endif
private:
AUBase& mAUBaseInstance;
#if AUSDK_HAVE_MIDI_MAPPING
std::shared_ptr<AUMIDIMapper> mMIDIMapper;
#endif
};
} // namespace ausdk
#endif // AudioUnitSDK_AUMIDIBase_h