41 #include "CAAUMIDIMapManager.h"
42 #include <AudioToolbox/AudioUnitUtilities.h>
44 CAAUMIDIMapManager::CAAUMIDIMapManager()
49 static void FillInMap (CAAUMIDIMap &map, AUBase &That)
51 AudioUnitParameterInfo info;
52 That.GetParameterInfo (map.mScope, map.mParameterID, info);
54 if (map.IsSubRange()) {
55 map.mMinValue = map.mSubRangeMin;
56 map.mMaxValue = map.mSubRangeMax;
58 map.mMinValue = info.minValue;
59 map.mMaxValue = info.maxValue;
62 map.mTransType = CAAUMIDIMap::GetTransformer(info.flags);
65 OSStatus CAAUMIDIMapManager::SortedInsertToParamaterMaps (AUParameterMIDIMapping *maps, UInt32 inNumMaps, AUBase &That)
67 for (
unsigned int i = 0; i < inNumMaps; ++i)
69 CAAUMIDIMap map(maps[i]);
71 FillInMap (map, That);
73 int idx = FindParameterIndex (maps[i]);
75 mParameterMaps.erase(mParameterMaps.begin() + idx);
78 mParameterMaps.push_back(map);
81 std::sort(mParameterMaps.begin(), mParameterMaps.end(), CompareMIDIMap());
86 void CAAUMIDIMapManager::GetHotParameterMap(AUParameterMIDIMapping &outMap )
91 void CAAUMIDIMapManager::SortedRemoveFromParameterMaps(AUParameterMIDIMapping *maps, UInt32 inNumMaps,
bool &outMapDidChange)
97 outMapDidChange =
false;
98 for (
unsigned int i = 0; i < inNumMaps; ++i) {
99 int idx = FindParameterIndex (maps[i]);
102 mParameterMaps.erase(mParameterMaps.begin() + idx);
103 outMapDidChange =
true;
108 void CAAUMIDIMapManager::ReplaceAllMaps (AUParameterMIDIMapping* inMappings, UInt32 inNumMaps, AUBase &That)
110 mParameterMaps.clear();
112 for (
unsigned int i = 0; i < inNumMaps; ++i) {
113 CAAUMIDIMap mapping(inMappings[i]);
115 FillInMap (mapping, That);
116 mParameterMaps.push_back (mapping);
119 std::sort(mParameterMaps.begin(),mParameterMaps.end(), CompareMIDIMap());
122 bool CAAUMIDIMapManager::HandleHotMapping(UInt8 inStatus,
128 if (inStatus == 0xf0)
return false;
130 if (!hotMapping)
return false;
133 mHotMap.mStatus = inStatus | inChannel;
134 mHotMap.mData1 = inData1;
136 SortedInsertToParamaterMaps (&mHotMap, 1, That);
142 void CAAUMIDIMapManager::Print()
144 for ( ParameterMaps::iterator i = mParameterMaps.begin(); i < mParameterMaps.end(); ++i) {
145 CAAUMIDIMap* listmap = &(*i);
152 void CAAUMIDIMapManager::GetMaps(AUParameterMIDIMapping* maps)
155 for ( ParameterMaps::iterator iter = mParameterMaps.begin(); iter < mParameterMaps.end(); ++iter, ++i) {
156 AUParameterMIDIMapping &listmap = (*iter);
161 int CAAUMIDIMapManager::FindParameterIndex (AUParameterMIDIMapping &inMap)
166 for ( ParameterMaps::iterator i = mParameterMaps.begin(); i < mParameterMaps.end(); ++i) {
167 CAAUMIDIMap & listmap = (*i);
168 if ( (listmap.mParameterID == inMap.mParameterID) &&
169 (listmap.mScope == inMap.mScope) &&
170 (listmap.mElement == inMap.mElement) )
179 bool CAAUMIDIMapManager::FindParameterMapEventMatch( UInt8 inStatus,
183 UInt32 inBufferOffset,
186 bool ret_value =
false;
188 if (inStatus == 0x90 && !inData2)
189 inStatus = 0x80 | inChannel;
193 tempMap.mStatus = inStatus | inChannel;
194 tempMap.mData1 = inData1;
196 CompareMIDIMap compareObj;
198 AudioUnitEvent event;
199 event.mEventType = kAudioUnitEvent_ParameterValueChange;
200 event.mArgument.mParameter.mAudioUnit = inAUBase.GetComponentInstance();
202 ParameterMaps::iterator lower_iter =
203 std::lower_bound(mParameterMaps.begin(), mParameterMaps.end(), tempMap, compareObj);
205 while (lower_iter < mParameterMaps.end())
207 CAAUMIDIMap & map = (*lower_iter);
208 if (compareObj.Finish(map, tempMap))
212 if (map.MIDI_Matches(inChannel, inData1, inData2, value))
214 inAUBase.SetParameter ( map.mParameterID, map.mScope, map.mElement,
215 map.ParamValueFromMIDILinear(value), inBufferOffset);
217 event.mArgument.mParameter.mParameterID = map.mParameterID;
218 event.mArgument.mParameter.mScope = map.mScope;
219 event.mArgument.mParameter.mElement = map.mElement;
221 AUEventListenerNotify(NULL, NULL, &event);