Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

CAUGui.cpp

Go to the documentation of this file.
00001 /*
00002  *  CAUGui.cpp
00003  *  CoreGraphics AudioUnit GUI framework
00004  *
00005  *  Created by Urs Heckmann on Sat Oct 19 2002.
00006  *  Copyright (c) 2002 __MyCompanyName__. All rights reserved.
00007  *
00008  */
00009 
00010 #include "CAUGui.h"
00011 
00012 
00013 
00014 /***********************************************************************
00015 
00016     CAUGuiMan
00017     
00018     the manager class that does all the admin for you
00019 
00020 ***********************************************************************/
00021 
00022 static UInt32 numConstructions = 0;
00023 
00024 CAUGuiMan::CAUGuiMan (AUCarbonViewBase* theAUCarbonViewBase, UInt32 x, UInt32 y )
00025 {
00026     itemCount = 0;
00027     Images = NULL;
00028     Controls = NULL;
00029     
00030     relaxed = false;
00031     
00032     myAUCarbonViewBase = theAUCarbonViewBase;
00033     X = x;
00034     Y = y;
00035     
00036     
00037     internalParameters = NULL;
00038     
00039     ControlClass            = NULL;
00040     ControlSpec.defType     = kControlDefObjectClass;
00041     ControlSpec.u.classRef  = NULL;
00042     
00043     
00044     
00045     numConstructions++;
00046     
00047     //printf ("ctor CAUGuiMan %d\n", (int) numConstructions);
00048 
00049 }
00050 
00051 CAUGuiMan::~CAUGuiMan()
00052 {
00053 
00054     //printf ("dtor CAUGuiMan\n");
00055     
00056     RemoveEventLoopTimer(timer);
00057     
00058     if ( Controls != NULL ) delete Controls;
00059     Controls = NULL;
00060 
00061     if ( Images != NULL ) delete Images;
00062     Images = NULL;
00063     
00064     
00065     
00066     //UnregisterToolboxObjectClass(ControlClass);
00067     
00068     
00069 
00070 }
00071     
00072 void CAUGuiMan::initialize()
00073 {
00074     
00075     UInt32 myAddress= (UInt32)this;
00076     
00077     bool found = false;
00078     
00079     
00080     EventTypeSpec CEventList[] = {{kEventClassControl, kEventControlDraw},
00081                                    {kEventClassControl, kEventControlHit},
00082                                     {kEventClassControl, kEventControlTrack},
00083                                     {kEventClassControl, kEventControlClick}};
00084 
00085     //CFStringCreateWithCString(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding)
00086 
00087 
00088     while ( !found )
00089     {
00090 
00091         sprintf ( defString, "com.CAUGui.zoyd%d.cntrl", (int)myAddress );
00092 
00093         if ( noErr == RegisterToolboxObjectClass (  CFStringCreateWithCString(NULL, defString, kCFStringEncodingISOLatin1 ),
00094                                                 NULL,
00095                                                 4,
00096                                                 CEventList,
00097                                                 NewEventHandlerUPP (CAUGuiControlHandler),
00098                                                 this,
00099                                                 &ControlClass)) found = true;
00100         myAddress++;
00101     }
00102     
00103     ControlSpec.u.classRef  = ControlClass;
00104 
00105     InstallEventLoopTimer(
00106         GetCurrentEventLoop(),
00107         0,
00108         kEventDurationMillisecond * 50,
00109         NewEventLoopTimerUPP( TimerProc ),
00110         this,
00111         &timer );
00112 }
00113 
00114 void CAUGuiMan::requestInternalParameters()
00115 {
00116 /*
00117     EXTERN_API( ComponentResult )
00118 AudioUnitGetProperty(
00119   AudioUnit             ci,
00120   AudioUnitPropertyID   inID,
00121   AudioUnitScope        inScope,
00122   AudioUnitElement      inElement,
00123   void *                outData,
00124   UInt32 *              ioDataSize)                           FIVEWORDINLINE(0x2F3C, 0x0014, 0x0004, 0x7000, 0xA82A);
00125 */
00126 
00127     UInt32 numParamsPassed = kNumInternalParameters * sizeof( float* );
00128     ComponentResult result;
00129     
00130     result = AudioUnitGetProperty( myAUCarbonViewBase->GetEditAudioUnit(), kInternalParameterProperyID, kAudioUnitScope_Global, 1, &internalParameters, &numParamsPassed );
00131 
00132     //printf ( "result: %d\n", (int)result );
00133 
00134 }
00135 
00136 float CAUGuiMan::getInternalParameter ( int index )
00137 {
00138 
00139     if ( internalParameters == NULL )
00140         requestInternalParameters();
00141         
00142     if ( internalParameters != NULL )   
00143         return internalParameters[ index ];
00144     
00145     return 0.f;
00146 }
00147 
00148 
00149 void CAUGuiMan::idle()
00150 {
00151 /*
00152     if ( kNumInternalParameters != 0 )
00153     {
00154         requestInternalParameters();
00155     }
00156 */  
00157     setRelaxed ( true ); // Dunno if this makes sense (Draw1Control interrupts the thread)...
00158     
00159     if ( Controls != NULL )
00160         Controls->idle();
00161         
00162     setRelaxed ( false );
00163 
00164 }
00165 
00166 void TimerProc ( EventLoopTimerRef inTimer, void *inUserData )
00167 {
00168     if ( inUserData != NULL )
00169     {
00170 
00171         if ( ((CAUGuiMan*)inUserData) != NULL )
00172             ((CAUGuiMan*)inUserData)->idle();
00173     }
00174     
00175 }
00176 
00177 void CAUGuiMan::addImage ( CAUGuiGraphic* theImage )
00178 {
00179     UInt32 nextID = requestID();
00180     
00181     theImage->setID ( nextID );
00182         
00183     if ( Images == NULL )
00184         Images = theImage;
00185     else
00186         Images->append( theImage );
00187         
00188 }
00189 
00190 CAUGuiGraphic* CAUGuiMan::getImageByID ( UInt32 theID )
00191 {
00192     if ( Images == NULL ) return NULL;
00193     return (CAUGuiGraphic*)Images->getByID( theID );
00194 
00195 }
00196 
00197 
00198 
00199 void CAUGuiMan::addCtrl( CAUGuiCtrl* theCtrl )
00200 {
00201     UInt32 nextID = requestID();
00202     
00203     theCtrl->setID ( nextID );
00204     
00205     if ( theCtrl->getDaddy() == NULL )
00206     {
00207         if ( Controls == NULL )
00208             Controls = theCtrl;
00209         else
00210             Controls->append( theCtrl );
00211             
00212         theCtrl->setOffset ( X, Y );
00213     }
00214     
00215     
00216     if ( theCtrl->providesForeignControls () )
00217     {
00218         theCtrl->initForeignControls (ControlSpec);
00219     }
00220     else
00221     {
00222         ControlRef newControl;
00223     
00224         Rect r;
00225     
00226         theCtrl->getBounds ( &r );
00227     
00228         verify_noerr(CreateCustomControl( myAUCarbonViewBase->GetCarbonWindow(), &r, &ControlSpec, NULL, &newControl));
00229     
00230         float factor = (float) theCtrl->getResolution();
00231         
00232         UInt32 theMax = (UInt32)( theCtrl->getRange() * factor );
00233         
00234         SetControl32BitMaximum( newControl, theMax);
00235         
00236         SetControl32BitMinimum( newControl, 0);
00237         
00238         if ( theCtrl->isAUVPattached() )
00239         {
00240         
00241             CAAUParameter myParam = theCtrl->getAUVP();
00242             
00243             float value = myParam.GetValue();
00244             
00245             float maxf = myParam.ParamInfo().maxValue;
00246             
00247             float minf = myParam.ParamInfo().minValue;
00248             
00249             value = (value - minf) / (maxf - minf );
00250             
00251             SInt32 initValue = (SInt32)( value * (float) theMax );
00252             
00253             SetControl32BitValue( newControl, initValue);
00254             
00255         
00256             myAUCarbonViewBase->AddCarbonControl(AUCarbonViewControl::kTypeContinuous, myParam, newControl);
00257             
00258             
00259         }
00260         else
00261         {
00262             myAUCarbonViewBase->EmbedControl( newControl );
00263         }
00264         
00265         
00266         theCtrl->setCarbonControl( newControl );
00267     }
00268 }
00269 
00270 CAUGuiCtrl* CAUGuiMan::getCtrlByID( UInt32 theID )
00271 {
00272 
00273     if ( Controls == NULL ) return NULL;
00274     return (CAUGuiCtrl*)Controls->getByID( theID );
00275 
00276 }
00277 
00278 CAUGuiCtrl* CAUGuiMan::getCtrlByControlRef ( ControlRef theControl )
00279 {
00280     
00281     CAUGuiCtrl* current = Controls;
00282     
00283     while ( current != NULL )
00284     {
00285         if ( current->isControlRef( theControl ) )
00286         {
00287             current = current->getChild(theControl);
00288             break;
00289         }
00290         current = (CAUGuiCtrl*)current->getNext();
00291     
00292     }
00293     
00294     return current;
00295 
00296 }
00297 
00298 UInt32 CAUGuiMan::requestID ( void )
00299 {
00300     itemCount++;
00301     return ( itemCount );
00302 
00303 }
00304 
00305 
00306 
00307 
00308 
00309 
00310 
00311 

(c) 2002 - 2003 by Urs Heckmann www.u-he.com
Generated on Thu May 6 15:13:13 2004 for CAUGui by doxygen 1.3.6