Merge with 2.0-ongoing R3071.
[ardour.git] / libs / appleutility / CAComponentDescription.h
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         CAComponentDescription.h
40         
41 =============================================================================*/
42
43 #ifndef __CAComponentDescription_h__
44 #define __CAComponentDescription_h__
45
46 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
47         #include <CoreServices/CoreServices.h>
48         #include <AudioUnit/AudioUnit.h>
49 #else
50         #include <ConditionalMacros.h>
51         #include <CoreServices.h>
52         #include <AudioUnit.h>
53 #endif
54
55 #include "CACFDictionary.h"
56 #include <stdio.h>
57 #include <string.h>
58
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62
63 void CAShowComponentDescription(const ComponentDescription *desc);
64
65 #ifdef __cplusplus
66 }
67 #endif
68
69
70 // ____________________________________________________________________________
71 //
72 //      CAComponentDescription
73 class CAComponentDescription : public ComponentDescription {
74 public:
75         CAComponentDescription() { memset (this, 0, sizeof (ComponentDescription)); }
76         
77         CAComponentDescription (OSType inType, OSType inSubtype = 0, OSType inManu = 0);
78
79         CAComponentDescription(const ComponentDescription& desc) { memcpy (this, &desc, sizeof (ComponentDescription)); }
80                 
81         // _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
82         //
83         // interrogation
84         
85         bool    IsAU () const;
86         
87         bool    IsAUFX() const { return componentType == kAudioUnitType_Effect; }
88         bool    IsAUFM() const { return componentType == kAudioUnitType_MusicEffect; }
89         
90         bool    IsEffect () const { return IsAUFX() || IsAUFM() || IsPanner(); }
91         
92         bool    IsOffline () const { return componentType == 'auol'; }
93         
94         bool    IsFConv () const { return componentType == kAudioUnitType_FormatConverter; }
95         
96         bool    IsPanner () const { return componentType == kAudioUnitType_Panner; }
97         
98         bool    IsMusicDevice () const { return componentType == kAudioUnitType_MusicDevice; }
99         
100 #ifndef MAC_OS_X_VERSION_10_4
101         bool    IsGenerator () const { return componentType =='augn'; }
102 #else
103         bool    IsGenerator () const { return componentType ==kAudioUnitType_Generator; }
104 #endif
105         
106         bool    IsOutput () const { return componentType == kAudioUnitType_Output; }
107         
108         bool    IsSource () const { return IsMusicDevice() || IsGenerator(); }
109         
110         OSType  Type () const { return componentType; }
111         OSType  SubType () const { return componentSubType; }
112         OSType  Manu () const { return componentManufacturer; }
113
114         int             Count() const { return CountComponents(const_cast<CAComponentDescription*>(this)); }
115         
116                 // does a semantic match where "wild card" values for type, subtype, manu will match
117         bool    Matches (const ComponentDescription &desc) const;
118         
119         // _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
120         //
121         //      other
122         
123         void    Print(FILE* file = stdout) const        { _CAShowComponentDescription (this, file); }
124
125         OSStatus                        Save (CFPropertyListRef *outData) const;
126         OSStatus                        Restore (CFPropertyListRef &inData);
127
128 private:
129         static void _CAShowComponentDescription (const ComponentDescription *desc, FILE* file);
130         friend void CAShowComponentDescription (const ComponentDescription *desc);
131 };
132
133 inline bool     operator< (const ComponentDescription& x, const ComponentDescription& y)
134 {
135         return memcmp (&x, &y, offsetof (ComponentDescription, componentFlags)) < 0;
136 }
137
138 inline bool     operator== (const ComponentDescription& x, const ComponentDescription& y)
139 {
140         return !memcmp (&x, &y, offsetof (ComponentDescription, componentFlags));
141 }
142
143 inline bool     operator!= (const ComponentDescription& x, const ComponentDescription& y)
144 {
145         return !(x == y);
146 }
147
148 #endif