globally remove all trailing whitespace from .cpp and .hpp files missed by previous...
[ardour.git] / libs / appleutility / AUParamInfo.cpp
1 /*      Copyright:      � Copyright 2005 Apple Computer, Inc. All rights reserved.
2
3         Disclaimer:     IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
4                         ("Apple") in consideration of your agreement to the following terms, and your
5                         use, installation, modification or redistribution of this Apple software
6                         constitutes acceptance of these terms.  If you do not agree with these terms,
7                         please do not use, install, modify or redistribute this Apple software.
8
9                         In consideration of your agreement to abide by the following terms, and subject
10                         to these terms, Apple grants you a personal, non-exclusive license, under Apple�s
11                         copyrights in this original Apple software (the "Apple Software"), to use,
12                         reproduce, modify and redistribute the Apple Software, with or without
13                         modifications, in source and/or binary forms; provided that if you redistribute
14                         the Apple Software in its entirety and without modifications, you must retain
15                         this notice and the following text and disclaimers in all such redistributions of
16                         the Apple Software.  Neither the name, trademarks, service marks or logos of
17                         Apple Computer, Inc. may be used to endorse or promote products derived from the
18                         Apple Software without specific prior written permission from Apple.  Except as
19                         expressly stated in this notice, no other rights or licenses, express or implied,
20                         are granted by Apple herein, including but not limited to any patent rights that
21                         may be infringed by your derivative works or by other works in which the Apple
22                         Software may be incorporated.
23
24                         The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
25                         WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
26                         WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27                         PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
28                         COMBINATION WITH YOUR PRODUCTS.
29
30                         IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
31                         CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
32                         GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33                         ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
34                         OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
35                         (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
36                         ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38 /*=============================================================================
39         AUParamInfo.cpp
40         
41 =============================================================================*/
42 #include "AUParamInfo.h"
43 #include "CAXException.h"
44
45 AUParamInfo::AUParamInfo (AudioUnit                             inAU,
46                                                         bool                            inIncludeExpert,
47                                                         bool                            inIncludeReadOnly,
48                                                         AudioUnitScope          inScope,
49                                                         AudioUnitElement        inElement)
50         : mAU (inAU),
51           mNumParams (0),
52           mParamListID(NULL),
53           mScope (inScope),
54           mElement (inElement)
55 {
56         UInt32 size;
57         OSStatus result = AudioUnitGetPropertyInfo(mAU, kAudioUnitProperty_ParameterList, inScope, mElement, &size, NULL);
58                 if (size == 0 || result) return;
59         
60         int nparams = size / sizeof(AudioUnitPropertyID);
61         mParamListID = new AudioUnitParameterID[nparams];
62
63         memset (mParamListID, 0xFF, size);
64
65         AudioUnitParameterID *paramList = new AudioUnitParameterID[nparams];
66         
67         result = AudioUnitGetProperty(mAU, kAudioUnitProperty_ParameterList, mScope, mElement, paramList, &size);
68         if (result) {
69                 delete [] mParamListID;
70                 delete [] paramList;
71                 mParamListID = NULL;
72                 return;
73         }
74         
75         ParameterMap params;
76         for (int i = 0; i < nparams; ++i)
77         {
78                 CAAUParameter auvp (mAU, paramList[i], mScope, mElement); // took out only using global scope in CAAUParameter creation
79                 const AudioUnitParameterInfo &paramInfo = auvp.ParamInfo();
80                         
81                 //      don't include if parameter can't be read or written
82                 if (!(paramInfo.flags & kAudioUnitParameterFlag_IsWritable)
83                         && !(paramInfo.flags & kAudioUnitParameterFlag_IsReadable))
84                         continue;
85
86                 // only include if expert params wanted
87                 if (!inIncludeExpert && auvp.IsExpert())
88                         continue;
89                 
90                 // only include if read only params are wanted
91                 if (!(paramInfo.flags & kAudioUnitParameterFlag_IsWritable)
92                         && (paramInfo.flags & kAudioUnitParameterFlag_IsReadable))
93                 {       
94                         if (!inIncludeReadOnly)
95                                 continue;
96                 }
97                 
98                 mParamListID[mNumParams] = paramList[i];
99                 mNumParams++;
100                 
101                 // ok - if we're here, then we have a parameter we are going to display.
102                 UInt32 clump = 0;
103                 auvp.GetClumpID (clump);
104                 mParams[clump].push_back (auvp);
105         }
106
107         delete [] paramList;
108 }
109
110 AUParamInfo::~AUParamInfo()
111 {
112         delete [] mParamListID;
113 }
114
115 UInt32                  AUParamInfo::NumParamsForClump (UInt32 inClump) const
116 {
117         ParameterMap::const_iterator it = mParams.find(inClump);
118         if (it != mParams.end())
119                 return (*it).second.size();
120         return 0;
121 }
122
123 const CAAUParameter*    AUParamInfo::GetParamInfo (AudioUnitParameterID inParamID) const
124 {
125         for (ParameterMap::const_iterator it = mParams.begin(); it != mParams.end(); ++it) {
126                 const ParameterList &list = (*it).second;
127                 for (ParameterList::const_iterator iter = list.begin(); iter != list.end(); ++iter) {
128                         if (inParamID == (*iter).mParameterID) {
129                                 return &(*iter);
130                         }
131                 }
132         }
133         return NULL;
134 }