1 /*
2      File: CAAUParameter.h
3  Abstract: Part of CoreAudio Utility Classes
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 #ifndef __CAAUParameter_h__
48 #define __CAAUParameter_h__
49 
50 #include <AudioToolbox/AudioUnitUtilities.h>
51 
52 // ____________________________________________________________________________
53 //	CAAUParameter
54 //	complete parameter specification
55 	/*! @class CAAUParameter */
56 class CAAUParameter : public AudioUnitParameter {
57 public:
58 								/*! @ctor CAAUParameter.0 */
59 								CAAUParameter();
60 								/*! @ctor CAAUParameter.1 */
61 								CAAUParameter(AudioUnit au, AudioUnitParameterID param, AudioUnitScope scope, AudioUnitElement element);
62 								/*! @ctor CAAUParameter.2 */
63 								CAAUParameter(AudioUnitParameter &inParam);
64 								/*! @ctor CAAUParameter.3 */
65 								CAAUParameter(const CAAUParameter &a);
66 								/*! @dtor ~CAAUParameter */
67 								~CAAUParameter();
68 
69 	/*! @method operator <@ */
70 	bool						operator < (const CAAUParameter &a) const
71 								{
72 									return memcmp(this, &a, sizeof(AudioUnitParameter)) < 0;
73 								}
74 
75 	/*! @method operator ==@ */
76 	bool						operator == (const CAAUParameter &a) const
77 								{
78 									return !memcmp(this, &a, sizeof(AudioUnitParameter));
79 								}
80 
81 	/*! @method operator =@ */
82 	CAAUParameter &				operator = (const CAAUParameter &a);
83 
84 	/*! @method GetValue */
85 	Float32						GetValue() const;
86 	/*! @method SetValue */
87 	void						SetValue(	AUParameterListenerRef			inListener,
88 											void *							inObject,
89 											Float32							inValue) const;
90 
91 	/*! @method GetName */
GetName()92 	CFStringRef					GetName() const { return mParamName; }
93 										// borrowed reference!
94 
95 	/*! @method GetStringFromValueCopy */
96 	CFStringRef					GetStringFromValueCopy(const Float32 *value = NULL) const;
97 										// returns a copy of the name of the current parameter value
98 										// or null if there is no name associated
99 										// caller must release
100 	/*! @method ValuesHaveStrings */
ValuesHaveStrings()101 	bool						ValuesHaveStrings () const
102 								{
103 									return (mParamInfo.flags & kAudioUnitParameterFlag_ValuesHaveStrings) != 0;
104 								}
105 
106 	/*! @method GetValueFromString */
107 	Float32						GetValueFromString (CFStringRef str) const;
108 									// caller must release
109 
110 	/*! @method ParamInfo */
111 	const AudioUnitParameterInfo &
ParamInfo()112 								ParamInfo()	const { return mParamInfo; }
113 
114 	/*! @method GetParamTag */
GetParamTag()115 	CFStringRef					GetParamTag() const	{ return mParamTag; }
116 									// this may return null! -
117 									// in which case there is no descriptive tag for the parameter
118 
119 	/*! @method GetParamName */
GetParamName(int inIndex)120 	CFStringRef					GetParamName (int inIndex) const
121 									// this can return null if there is no name for the parameter
122 								{
123 									return (mNamedParams && inIndex < mNumIndexedParams)
124 												? (CFStringRef) CFArrayGetValueAtIndex(mNamedParams, inIndex)
125 												: 0;
126 								}
127 
128 	/*! @method GetNumIndexedParams */
GetNumIndexedParams()129 	int							GetNumIndexedParams () const { return mNumIndexedParams; }
130 
131 	/*! @method IsIndexedParam */
IsIndexedParam()132 	bool						IsIndexedParam () const { return mNumIndexedParams != 0; }
133 
134 	/*! @method HasNamedParams */
HasNamedParams()135 	bool						HasNamedParams () const { return IsIndexedParam() && mNamedParams; }
136 
137 	/*! @method GetClumpID */
GetClumpID(UInt32 & outClumpID)138 	bool						GetClumpID (UInt32 &outClumpID) const
139 								{
140 									if (mParamInfo.flags & kAudioUnitParameterFlag_HasClump) {
141 										outClumpID = mParamInfo.clumpID;
142 										return true;
143 									}
144 									return false;
145 								}
146 
147 	/*! @method HasDisplayTransformation */
HasDisplayTransformation()148 	bool						HasDisplayTransformation () const
149 								{
150 									return GetAudioUnitParameterDisplayType (mParamInfo.flags);
151 								}
152 
153 	/*! @method IsExpert */
IsExpert()154 	bool						IsExpert () const
155 								{
156 									return mParamInfo.flags & kAudioUnitParameterFlag_ExpertMode;
157 								}
158 #if DEBUG
159 	void						Print () const;
160 #endif
161 
162 		// these methods are defined in CAPersistence.cpp
163 		// they will persist and restore only the scope, element and param ID's of the AudioUnitParameter
164 		// however, this is sufficient to be able to save/restore a CAAUParameter object
165 	void						Save (CFPropertyListRef &outData) const;
166 
167 	static void					Save (const AudioUnitParameter &inParam, CFPropertyListRef &outData);
168 
169 	static OSStatus				Restore	(const CFPropertyListRef inData, AudioUnitParameter &outParam);
170 
171 protected:
172 	// cached parameter info
173 	/*! @var mParamInfo */
174 	AudioUnitParameterInfo		mParamInfo;
175 	/*! @var mParamName */
176 	CFStringRef					mParamName;
177 	/*! @var mParamTag */
178 	CFStringRef					mParamTag;
179 	/*! @var mNumIndexedParams */
180 	short						mNumIndexedParams;
181 	/*! @var mNamedParams */
182 	CFArrayRef					mNamedParams;
183 
184 private:
185 	void						Init (AudioUnit au, AudioUnitParameterID param, AudioUnitScope scope, AudioUnitElement element);
186 
187 };
188 
189 
190 
191 #endif // __CAAUParameter_h__
192