alternative new version of the AppleUtility library
[ardour.git] / libs / appleutility / CoreAudio / AudioUnits / AUPublic / OtherBases / AUMIDIEffectBase.cpp
1 /*
2      File: AUMIDIEffectBase.cpp
3  Abstract: AUMIDIEffectBase.h
4   Version: 1.1
5  
6  Disclaimer: IMPORTANT:  This Apple software is supplied to you by Apple
7  Inc. ("Apple") in consideration of your agreement to the following
8  terms, and your use, installation, modification or redistribution of
9  this Apple software constitutes acceptance of these terms.  If you do
10  not agree with these terms, please do not use, install, modify or
11  redistribute this Apple software.
12  
13  In consideration of your agreement to abide by the following terms, and
14  subject to these terms, Apple grants you a personal, non-exclusive
15  license, under Apple's copyrights in this original Apple software (the
16  "Apple Software"), to use, reproduce, modify and redistribute the Apple
17  Software, with or without modifications, in source and/or binary forms;
18  provided that if you redistribute the Apple Software in its entirety and
19  without modifications, you must retain this notice and the following
20  text and disclaimers in all such redistributions of the Apple Software.
21  Neither the name, trademarks, service marks or logos of Apple Inc. may
22  be used to endorse or promote products derived from the Apple Software
23  without specific prior written permission from Apple.  Except as
24  expressly stated in this notice, no other rights or licenses, express or
25  implied, are granted by Apple herein, including but not limited to any
26  patent rights that may be infringed by your derivative works or by other
27  works in which the Apple Software may be incorporated.
28  
29  The Apple Software is provided by Apple on an "AS IS" basis.  APPLE
30  MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
31  THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
32  FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
33  OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
34  
35  IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
36  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
39  MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
40  AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
41  STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
42  POSSIBILITY OF SUCH DAMAGE.
43  
44  Copyright (C) 2014 Apple Inc. All Rights Reserved.
45  
46 */
47 #include "AUMIDIEffectBase.h"
48
49 // compatibility with older OS SDK releases
50 typedef OSStatus
51 (*TEMP_MusicDeviceMIDIEventProc)(       void *                          inComponentStorage,
52                                 UInt32                                  inStatus,
53                                 UInt32                                  inData1,
54                                 UInt32                                  inData2,
55                                 UInt32                                  inOffsetSampleFrame);
56
57 static OSStatus         AUMIDIEffectBaseMIDIEvent(void *                                inComponentStorage,
58                                                 UInt32                                  inStatus,
59                                                 UInt32                                  inData1,
60                                                 UInt32                                  inData2,
61                                                 UInt32                                  inOffsetSampleFrame);
62
63 AUMIDIEffectBase::AUMIDIEffectBase(             AudioComponentInstance                          inInstance,
64                                                 bool                                            inProcessesInPlace ) 
65         : AUEffectBase(inInstance, inProcessesInPlace),
66           AUMIDIBase(this)
67 {
68 }
69
70 OSStatus                        AUMIDIEffectBase::GetPropertyInfo(AudioUnitPropertyID                   inID,
71                                                         AudioUnitScope                          inScope,
72                                                         AudioUnitElement                        inElement,
73                                                         UInt32 &                                outDataSize,
74                                                         Boolean &                               outWritable)
75 {
76         OSStatus result;
77         
78         result = AUEffectBase::GetPropertyInfo (inID, inScope, inElement, outDataSize, outWritable);
79         
80         if (result == kAudioUnitErr_InvalidProperty)
81                 result = AUMIDIBase::DelegateGetPropertyInfo (inID, inScope, inElement, outDataSize, outWritable);
82         
83         return result;
84 }
85
86 OSStatus                        AUMIDIEffectBase::GetProperty(  AudioUnitPropertyID             inID,
87                                                                                                         AudioUnitScope                  inScope,
88                                                                                                         AudioUnitElement                inElement,
89                                                                                                         void *                                  outData)
90 {
91         OSStatus result;
92
93 #if !CA_USE_AUDIO_PLUGIN_ONLY
94         if (inID == kAudioUnitProperty_FastDispatch) {
95                 if (inElement == kMusicDeviceMIDIEventSelect) {
96                         *(TEMP_MusicDeviceMIDIEventProc *)outData = AUMIDIEffectBaseMIDIEvent;
97                         return noErr;
98                 }
99                 return kAudioUnitErr_InvalidElement;
100         }
101 #endif
102         
103         result = AUEffectBase::GetProperty (inID, inScope, inElement, outData);
104         
105         if (result == kAudioUnitErr_InvalidProperty)
106                 result = AUMIDIBase::DelegateGetProperty (inID, inScope, inElement, outData);
107         
108         return result;
109 }
110
111 OSStatus                        AUMIDIEffectBase::SetProperty(  AudioUnitPropertyID                     inID,
112                                                         AudioUnitScope                          inScope,
113                                                         AudioUnitElement                        inElement,
114                                                         const void *                            inData,
115                                                         UInt32                                  inDataSize)
116 {
117
118         OSStatus result = AUEffectBase::SetProperty (inID, inScope, inElement, inData, inDataSize);
119                 
120         if (result == kAudioUnitErr_InvalidProperty)
121                 result = AUMIDIBase::DelegateSetProperty (inID, inScope, inElement, inData, inDataSize);
122                 
123         return result;
124 }
125
126
127 #if !TARGET_OS_IPHONE
128 OSStatus                        AUMIDIEffectBase::ComponentEntryDispatch(ComponentParameters *                  params,
129                                                                 AUMIDIEffectBase *                      This)
130 {
131         if (This == NULL) return paramErr;
132
133         OSStatus result;
134         
135         switch (params->what) {
136         case kMusicDeviceMIDIEventSelect:
137         case kMusicDeviceSysExSelect:
138                 result = AUMIDIBase::ComponentEntryDispatch (params, This);
139                 break;
140         default:
141                 result = AUEffectBase::ComponentEntryDispatch(params, This);
142                 break;
143         }
144         
145         return result;
146 }
147 #endif
148
149 // fast dispatch
150 static OSStatus         AUMIDIEffectBaseMIDIEvent(void *                                inComponentStorage,
151                                                 UInt32                                  inStatus,
152                                                 UInt32                                  inData1,
153                                                 UInt32                                  inData2,
154                                                 UInt32                                  inOffsetSampleFrame)
155 {
156         OSStatus result = noErr;
157         try {
158                 AUMIDIEffectBase *This = static_cast<AUMIDIEffectBase *>(inComponentStorage);
159                 if (This == NULL) return paramErr;
160                 result = This->AUMIDIBase::MIDIEvent(inStatus, inData1, inData2, inOffsetSampleFrame);
161         }
162         COMPONENT_CATCH
163         return result;
164 }