alternative new version of the AppleUtility library
[ardour.git] / libs / appleutility / CoreAudio / AudioUnits / AUPublic / AUCarbonViewBase / AUCarbonViewBase.h
1 /*
2      File: AUCarbonViewBase.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 __AUCarbonViewBase_h__
48 #define __AUCarbonViewBase_h__
49
50 #include <vector>
51 #include "AUCarbonViewControl.h"
52 #include "ComponentBase.h"
53
54 static const Float32 kDefaultNotificationInterval = 0.100;
55
56         /*! @class AUCarbonViewBase */
57 class AUCarbonViewBase : public ComponentBase, public CarbonEventHandler
58 {
59 public:
60     /*! @ctor AUCarbonViewBase */
61     AUCarbonViewBase (  AudioUnitCarbonView inInstance,
62                                                 Float32 inNotificationInterval = kDefaultNotificationInterval /* in seconds */);
63         /*! @dtor ~AUCarbonViewBase */
64         virtual ~AUCarbonViewBase();
65         
66         // AUViewBase overrides
67         /*! @method CreateCarbonView */
68         virtual OSStatus                        CreateCarbonView (AudioUnit inAudioUnit, WindowRef inWindow, ControlRef inParentControl, const Float32Point &inLocation, const Float32Point &inSize, ControlRef &outParentControl);
69
70         // our own virtual methods
71         /*! @method CreateUI */
72         virtual OSStatus                        CreateUI (Float32       inXOffset, Float32      inYOffset);
73
74         /*! @method HandleEvent */
75         virtual bool                            HandleEvent (EventHandlerCallRef inHandlerRef, EventRef event);
76         
77         /*! @method GetEditAudioUnit */
78         const AudioUnit                         GetEditAudioUnit () const { return mEditAudioUnit; }
79         //
80         /*! @method ComponentEntryDispatch */
81         static OSStatus                 ComponentEntryDispatch (
82                                                                         ComponentParameters *                   params,
83                                                                         AUCarbonViewBase *                              This);
84
85         /*! @method AddCarbonControl */
86         void                                            AddCarbonControl (
87                                                                         AUCarbonViewControl::ControlType        type, 
88                                                                         const CAAUParameter &                           param, 
89                                                                         ControlRef                                                      control);
90
91         /*! @method GetCarbonWindow */
92         WindowRef                                       GetCarbonWindow () { return mCarbonWindow; }
93         /*! @method GetCarbonPane */
94         ControlRef                                      GetCarbonPane () { return mCarbonPane; }
95         /*! @method EmbedControl */
96         OSStatus                                        EmbedControl (ControlRef ctl);
97         
98         /*! @method TellListener */
99         void                                            TellListener (const CAAUParameter &auvp, AudioUnitCarbonViewEventID event, void *evpar);
100         
101         // pass in true if wanting an update to the view and you're calling this from a thread
102         // that is safe to do UI in.
103         // If you don't know, pass in false!
104         /*! @method Update */
105         void                                            Update (bool inUIThread);
106         
107         /*! @method GetXOffset */
108         Float32                                         GetXOffset () { return mXOffset; }
109         /*! @method GetYOffset */
110         Float32                                         GetYOffset () { return mYOffset; }
111         
112         /*! @method ClearControls */
113         void                                            ClearControls ();
114         
115         /*! @method IsCompositWindow */
116         bool                                            IsCompositWindow () const { return mCompositWindow; }
117         
118 protected:
119 #if !__LP64__
120         /*! @method SetEventListener */
121         void                                            SetEventListener (AudioUnitCarbonViewEventListener listener, void *userData)
122                                                                 {
123                                                                         mEventListener = listener;
124                                                                         mEventListenerUserData = userData;
125                                                                 }
126 #endif
127
128         /*! @method AddControl */
129         void                                            AddControl (AUCarbonViewControl *control);
130         /*! @method RemoveControl */
131         void                                            RemoveControl (AUCarbonViewControl *control);
132
133         OSStatus                                        CreateEventLoopTimer (Float32 inDelay, Float32 inInterval);
134         
135         /*! @method ParameterListener */
136         static void ParameterListener (void *                                           inCallbackRefCon,
137                                                                         void *                                          inObject,
138                                                                         const AudioUnitEvent *          inEvent,
139                                                                         UInt64                                          inEventHostTime,
140                                                                         Float32                                         inParameterValue);
141                                                                         
142         static pascal void TheTimerProc (       EventLoopTimerRef               inTimer, 
143                                                                                 void *                                  inUserData);
144
145         virtual void                            RespondToEventTimer (EventLoopTimerRef inTimer);
146
147         /*! @var mEditAudioUnit */
148         AudioUnit                                       mEditAudioUnit; // the AU we're controlling
149         /*! @var mParameterListener */
150         AUEventListenerRef                      mParameterListener;
151
152 #if !__LP64__
153         /*! @var mEventListener */
154         AudioUnitCarbonViewEventListener
155                                                                 mEventListener;
156 #endif
157
158         /*! @var mEventListenerUserData */
159         void *                                          mEventListenerUserData;
160
161 private:
162         typedef std::vector<AUCarbonViewControl *> ControlList;
163         /*! @var mControlList */
164         ControlList                                     mControlList;
165
166         EventLoopTimerRef                       mTimerRef;
167
168         EventLoopTimerUPP                       mTimerUPP;
169
170 protected:
171         /*! @var mCarbonWindow */
172         WindowRef                       mCarbonWindow;
173         /*! @var mCarbonPane */
174         ControlRef                      mCarbonPane;    // user pane, contains all other controls
175         /*! @var mBottomRight */
176         Point                           mBottomRight;   // largest width and height of child controls
177         /*! @var mXOffset */
178         Float32                         mXOffset;
179         /*! @var mYOffset */
180         Float32                         mYOffset;
181         /*! @var mCompositWindow */
182         bool                            mCompositWindow;
183         /*! @var mCurrentScrollPoint */
184         HIPoint                         mCurrentScrollPoint;            // needed for scrolling
185 };
186
187
188 #endif // __AUCarbonViewBase_h__