Jamoma API  0.6.0.a19
AUParamInfo.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 #include "AUParamInfo.h"
42 #include "CAXException.h"
43 
44 AUParamInfo::AUParamInfo (AudioUnit inAU,
45  bool inIncludeExpert,
46  bool inIncludeReadOnly,
47  AudioUnitScope inScope,
48  AudioUnitElement inElement)
49  : mAU (inAU),
50  mNumParams (0),
51  mParamListID(NULL),
52  mScope (inScope),
53  mElement (inElement)
54 {
55  UInt32 size;
56  OSStatus result = AudioUnitGetPropertyInfo(mAU, kAudioUnitProperty_ParameterList, inScope, mElement, &size, NULL);
57  if (size == 0 || result) return;
58 
59  int nparams = size / sizeof(AudioUnitPropertyID);
60  mParamListID = new AudioUnitParameterID[nparams];
61 
62  memset (mParamListID, 0xFF, size);
63 
64  AudioUnitParameterID *paramList = new AudioUnitParameterID[nparams];
65 
66  result = AudioUnitGetProperty(mAU, kAudioUnitProperty_ParameterList, mScope, mElement, paramList, &size);
67  if (result) {
68  delete [] mParamListID;
69  delete [] paramList;
70  mParamListID = NULL;
71  return;
72  }
73 
74  ParameterMap params;
75  for (int i = 0; i < nparams; ++i)
76  {
77  CAAUParameter auvp (mAU, paramList[i], mScope, mElement); // took out only using global scope in CAAUParameter creation
78  const AudioUnitParameterInfo &paramInfo = auvp.ParamInfo();
79 
80  // don't include if parameter can't be read or written
81  if (!(paramInfo.flags & kAudioUnitParameterFlag_IsWritable)
82  && !(paramInfo.flags & kAudioUnitParameterFlag_IsReadable))
83  continue;
84 
85  // only include if expert params wanted
86  if (!inIncludeExpert && auvp.IsExpert())
87  continue;
88 
89  // only include if read only params are wanted
90  if (!(paramInfo.flags & kAudioUnitParameterFlag_IsWritable)
91  && (paramInfo.flags & kAudioUnitParameterFlag_IsReadable))
92  {
93  if (!inIncludeReadOnly)
94  continue;
95  }
96 
97  mParamListID[mNumParams] = paramList[i];
98  mNumParams++;
99 
100  // ok - if we're here, then we have a parameter we are going to display.
101  UInt32 clump = 0;
102  auvp.GetClumpID (clump);
103  mParams[clump].push_back (auvp);
104  }
105 
106  delete [] paramList;
107 }
108 
109 AUParamInfo::~AUParamInfo()
110 {
111  delete [] mParamListID;
112 }
113 
114 UInt32 AUParamInfo::NumParamsForClump (UInt32 inClump) const
115 {
116  ParameterMap::const_iterator it = mParams.find(inClump);
117  if (it != mParams.end())
118  return (*it).second.size();
119  return 0;
120 }
121 
122 const CAAUParameter* AUParamInfo::GetParamInfo (AudioUnitParameterID inParamID) const
123 {
124  for (ParameterMap::const_iterator it = mParams.begin(); it != mParams.end(); ++it) {
125  const ParameterList &list = (*it).second;
126  for (ParameterList::const_iterator iter = list.begin(); iter != list.end(); ++iter) {
127  if (inParamID == (*iter).mParameterID) {
128  return &(*iter);
129  }
130  }
131  }
132  return NULL;
133 }