when tabbing between track/bus name fields, skip rec-enabled tracks to avoid an annoy...
[ardour2.git] / libs / appleutility / CAAudioChannelLayoutObject.cpp
blob8c4030048db52435b356bdf655d9766adf60aa87
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 CAAudioChannelLayoutObject.cpp
41 =============================================================================*/
43 #include "CAAudioChannelLayout.h"
44 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
45 #include <CoreServices/CoreServices.h>
46 #include <AudioToolbox/AudioFormat.h>
47 #else
48 #include <CoreServices.h>
49 #include <AudioFormat.h>
50 #endif
53 CAAudioChannelLayout::CAAudioChannelLayout ()
55 mLayoutHolder = new ACLRefCounter (offsetof(AudioChannelLayout, mChannelDescriptions));
58 //=============================================================================
59 // CAAudioChannelLayout::CAAudioChannelLayout
60 //=============================================================================
61 CAAudioChannelLayout::CAAudioChannelLayout (UInt32 inNumberChannels, bool inChooseSurround)
63 // this chooses default layouts based on the number of channels...
64 UInt32 theSize = CalculateByteSize (inNumberChannels);
66 mLayoutHolder = new ACLRefCounter (theSize);
68 AudioChannelLayout* layout = mLayoutHolder->GetLayout();
70 layout->mNumberChannelDescriptions = inNumberChannels;
72 switch (inNumberChannels)
74 case 1:
75 layout->mChannelLayoutTag = kAudioChannelLayoutTag_Mono;
76 break;
77 case 2:
78 layout->mChannelLayoutTag = inChooseSurround ? kAudioChannelLayoutTag_Binaural : kAudioChannelLayoutTag_Stereo;
79 break;
80 case 4:
81 layout->mChannelLayoutTag = inChooseSurround ? kAudioChannelLayoutTag_Ambisonic_B_Format : kAudioChannelLayoutTag_AudioUnit_4;
82 break;
83 case 5:
84 layout->mChannelLayoutTag = inChooseSurround ? kAudioChannelLayoutTag_AudioUnit_5_0 : kAudioChannelLayoutTag_AudioUnit_5;
85 break;
86 case 6:
87 layout->mChannelLayoutTag = inChooseSurround ? kAudioChannelLayoutTag_AudioUnit_6_0 : kAudioChannelLayoutTag_AudioUnit_6;
88 break;
89 case 7:
90 layout->mChannelLayoutTag = kAudioChannelLayoutTag_AudioUnit_7_0;
91 break;
92 case 8:
93 layout->mChannelLayoutTag = kAudioChannelLayoutTag_AudioUnit_8;
94 break;
95 default:
96 // here we have a "broken" layout, in the sense that we haven't any idea how to lay this out
97 // the layout itself is all set to zeros
98 // ### no longer true ###
99 SetAllToUnknown(*layout, inNumberChannels);
100 break;
104 //=============================================================================
105 // CAAudioChannelLayout::CAAudioChannelLayout
106 //=============================================================================
107 CAAudioChannelLayout::CAAudioChannelLayout (AudioChannelLayoutTag inLayoutTag)
108 : mLayoutHolder(NULL)
110 SetWithTag(inLayoutTag);
113 //=============================================================================
114 // CAAudioChannelLayout::CAAudioChannelLayout
115 //=============================================================================
116 CAAudioChannelLayout::CAAudioChannelLayout (const CAAudioChannelLayout &c)
117 : mLayoutHolder(NULL)
119 *this = c;
123 //=============================================================================
124 // CAAudioChannelLayout::AudioChannelLayout
125 //=============================================================================
126 CAAudioChannelLayout::CAAudioChannelLayout (const AudioChannelLayout* inChannelLayout)
127 : mLayoutHolder(NULL)
129 *this = inChannelLayout;
132 //=============================================================================
133 // CAAudioChannelLayout::~CAAudioChannelLayout
134 //=============================================================================
135 CAAudioChannelLayout::~CAAudioChannelLayout ()
137 if (mLayoutHolder) {
138 mLayoutHolder->release();
139 mLayoutHolder = NULL;
143 //=============================================================================
144 // CAAudioChannelLayout::CAAudioChannelLayout
145 //=============================================================================
146 CAAudioChannelLayout& CAAudioChannelLayout::operator= (const CAAudioChannelLayout &c)
148 if (mLayoutHolder != c.mLayoutHolder) {
149 if (mLayoutHolder)
150 mLayoutHolder->release();
152 if ((mLayoutHolder = c.mLayoutHolder) != NULL)
153 mLayoutHolder->retain();
156 return *this;
159 CAAudioChannelLayout& CAAudioChannelLayout::operator= (const AudioChannelLayout* inChannelLayout)
161 if (mLayoutHolder)
162 mLayoutHolder->release();
164 UInt32 theSize = CalculateByteSize (inChannelLayout->mNumberChannelDescriptions);
166 mLayoutHolder = new ACLRefCounter (theSize);
168 memcpy(mLayoutHolder->mLayout, inChannelLayout, theSize);
169 return *this;
172 void CAAudioChannelLayout::SetWithTag(AudioChannelLayoutTag inTag)
174 if (mLayoutHolder)
175 mLayoutHolder->release();
177 mLayoutHolder = new ACLRefCounter(offsetof(AudioChannelLayout, mChannelDescriptions[0]));
178 AudioChannelLayout* layout = mLayoutHolder->GetLayout();
179 layout->mChannelLayoutTag = inTag;
182 //=============================================================================
183 // CAAudioChannelLayout::operator==
184 //=============================================================================
185 bool CAAudioChannelLayout::operator== (const CAAudioChannelLayout &c) const
187 if (mLayoutHolder == c.mLayoutHolder)
188 return true;
189 return Layout() == c.Layout();
192 //=============================================================================
193 // CAAudioChannelLayout::Print
194 //=============================================================================
195 void CAAudioChannelLayout::Print (FILE* file) const
197 CAShowAudioChannelLayout (file, &Layout());