when tabbing between track/bus name fields, skip rec-enabled tracks to avoid an annoy...
[ardour2.git] / libs / appleutility / CAAudioChannelLayout.h
blob796f197c3b786f55c2affe1da9e00eb79611b0c8
1 /* Copyright: © Copyright 2005 Apple Computer, Inc. All rights reserved.
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.
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.
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.
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.
38 /*=============================================================================
39 CAAudioChannelLayout.h
41 =============================================================================*/
42 #if !defined(__CAAudioChannelLayout_h__)
43 #define __CAAudioChannelLayout_h__
45 //=============================================================================
46 // Includes
47 //=============================================================================
49 // System Includes
50 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
51 #include <CoreAudio/CoreAudioTypes.h>
52 #include <CoreFoundation/CoreFoundation.h>
53 #else
54 #include <CoreAudioTypes.h>
55 #include <CoreFoundation.h>
56 #endif
57 #include <stdio.h>
58 #include <stdlib.h>
59 #include <string.h>
61 #if !HAL_Build
62 #include "CAReferenceCounted.h"
63 #endif
65 //=============================================================================
66 // CAAudioChannelLayout
67 //=============================================================================
69 bool operator== (const AudioChannelLayout &x, const AudioChannelLayout &y);
71 extern "C" void CAShowAudioChannelLayout (FILE* file, const AudioChannelLayout *layout);
73 class CAAudioChannelLayout
75 // static Construction/Destruction
76 public:
77 static AudioChannelLayout* Create(UInt32 inNumberChannelDescriptions);
78 static void Destroy(AudioChannelLayout* inChannelLayout);
79 static UInt32 CalculateByteSize(UInt32 inNumberChannelDescriptions) {
80 return offsetof(AudioChannelLayout, mChannelDescriptions) + inNumberChannelDescriptions * sizeof(AudioChannelDescription);
82 static void SetAllToUnknown(AudioChannelLayout& outChannelLayout, UInt32 inNumberChannelDescriptions);
83 static UInt32 NumberChannels(const AudioChannelLayout& inLayout);
85 #if !HAL_Build
86 // object methods
87 public:
88 CAAudioChannelLayout ();
90 CAAudioChannelLayout (UInt32 inNumberChannels, bool inChooseSurround);
91 // if inChooseSurround is false, then symmetrical speaker arrangements
92 // are chosen in place of surround layouts if there is a choice
93 // This call chooses layouts based on the expected defaults in
94 // AudioUnit usage
95 CAAudioChannelLayout (AudioChannelLayoutTag inTag);
96 CAAudioChannelLayout (const CAAudioChannelLayout &c);
97 CAAudioChannelLayout (const AudioChannelLayout* inChannelLayout);
98 ~CAAudioChannelLayout();
100 CAAudioChannelLayout& operator= (const AudioChannelLayout* inChannelLayout);
101 CAAudioChannelLayout& operator= (const CAAudioChannelLayout& c);
102 bool operator== (const CAAudioChannelLayout &c) const;
104 void SetWithTag(AudioChannelLayoutTag inTag);
106 bool IsValid() const { return NumberChannels() > 0; }
107 UInt32 Size() const { return mLayoutHolder ? mLayoutHolder->Size() : 0; }
109 UInt32 NumberChannels() const { return NumberChannels(Layout()); }
111 AudioChannelLayoutTag Tag() const { return Layout().mChannelLayoutTag; }
112 const AudioChannelLayout& Layout() const { return mLayoutHolder->Layout(); }
113 operator const AudioChannelLayout *() const { return &Layout(); }
115 void Print () const { Print (stdout); }
116 void Print (FILE* file) const;
118 OSStatus Save (CFPropertyListRef *outData) const;
119 OSStatus Restore (CFPropertyListRef &inData);
121 private:
122 class ACLRefCounter : public CAReferenceCounted {
123 public:
124 ACLRefCounter (UInt32 inDataSize)
126 if (inDataSize < offsetof(AudioChannelLayout, mChannelDescriptions))
127 inDataSize = offsetof(AudioChannelLayout, mChannelDescriptions);
129 mLayout = static_cast<AudioChannelLayout*>(malloc (inDataSize));
130 memset (mLayout, 0, inDataSize);
131 mByteSize = inDataSize;
134 const AudioChannelLayout & Layout() const { return *mLayout; }
136 UInt32 Size () const { return mByteSize; }
138 private:
139 AudioChannelLayout *mLayout;
140 UInt32 mByteSize;
142 // only the constructors can change the actual state of the layout
143 friend CAAudioChannelLayout::CAAudioChannelLayout (UInt32 inNumberChannels, bool inChooseSurround);
144 friend OSStatus CAAudioChannelLayout::Restore (CFPropertyListRef &inData);
145 friend CAAudioChannelLayout& CAAudioChannelLayout::operator= (const AudioChannelLayout* inChannelLayout);
146 friend void CAAudioChannelLayout::SetWithTag(AudioChannelLayoutTag inTag);
148 AudioChannelLayout * GetLayout() { return mLayout; }
149 ~ACLRefCounter() { if (mLayout) { free(mLayout); mLayout = NULL; } }
151 private:
152 ACLRefCounter () : mLayout(NULL) { }
153 ACLRefCounter(const ACLRefCounter&) : mLayout(NULL) { }
154 ACLRefCounter& operator=(const ACLRefCounter&) { return *this; }
157 ACLRefCounter *mLayoutHolder;
158 #endif // HAL_Build
162 #endif