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