home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 July / macformat-026.iso / mac / Shareware City / Developers / SoundMate Plug-In Kit / SoundEffect.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-21  |  4.4 KB  |  231 lines  |  [TEXT/KAHL]

  1. /*****
  2.  * SoundEffect.c
  3.  *
  4.  *    SoundEditor: Copyright (c) 1993 by
  5.  *
  6.  *    Motion Works Corp.
  7.  *    #130 - 1020 Mainland Street
  8.  *    Vancouver, BC
  9.  *    (604) 685-9975
  10.  *
  11.  *  Author:    DMS        (13SEP93)
  12.  *
  13.  *    generic sound effect (SE) component source for Marvin's Modulator
  14.  *
  15.  *****/
  16.  
  17. #include <MacHeaders>
  18. #include <QuickTimeComponents.h>
  19.  
  20. #include "SoundEffect.h"
  21.  
  22. #define    kVersionNumber    1
  23.  
  24.     // prototypes
  25.  
  26. pascal ComponentResult _SEOpen( Handle storage, ComponentInstance self );
  27. pascal ComponentResult _SEClose( Handle storage, ComponentInstance self );
  28. pascal ComponentResult _SECanDo( short selector );
  29. pascal ComponentResult _SEVersion( void );
  30. pascal ComponentResult _SETarget( ComponentInstance capturingComponent );
  31.  
  32. pascal ComponentResult _SEDoEffect(    Handle theSound,
  33.                                     Size *newSelectionStart, Size *newSelectionEnd,
  34.                                     Handle *newSound,
  35.                                     Size *insertStart, Size *deleteEnd
  36.                                    );
  37.  
  38. pascal ComponentResult _SEWorksOnSelectionOnly(    Boolean *answer );
  39.  
  40.  
  41.  
  42. /***
  43.  * main
  44.  *
  45.  ***/
  46.  
  47. #ifdef DEBUG_SOUND_EFFECT
  48.  
  49.     // use this declaration when we're running linked
  50.     
  51. pascal ComponentResult SoundEffectDispatcher( ComponentParameters *params, Handle storage )
  52.  
  53. #else
  54.  
  55.     // use this declaration when we're building a standalone component
  56.     // (be sure to comment out the define of DEBUG_SOUND_EFFECT in SoundEffect.h 
  57.     //  before using this source file to build a standalone component)
  58.     
  59. pascal ComponentResult main( ComponentParameters *params, Handle storage )
  60.  
  61. #endif DEBUG_SOUND_EFFECT
  62. {
  63.     ComponentResult result = noErr;
  64.  
  65.          // Did we get a Component Manager request code (< 0)?
  66.          
  67.     if ( params->what < 0 )
  68.     {
  69.         switch ( params->what )
  70.         {
  71.                 // Open request
  72.             case kComponentOpenSelect:
  73.                 result = CallComponentFunctionWithStorage( storage, 
  74.                                                     params, (ComponentFunction)_SEOpen );
  75.                 break;
  76.  
  77.                 // Close request
  78.             case kComponentCloseSelect:
  79.                 result = CallComponentFunctionWithStorage( storage, 
  80.                                                     params, (ComponentFunction)_SEClose );
  81.                 break;
  82.  
  83.                 // Can Do request
  84.             case kComponentCanDoSelect:
  85.                 result = CallComponentFunction( params, (ComponentFunction)_SECanDo );
  86.                 break;
  87.  
  88.                 // Version request
  89.             case kComponentVersionSelect:
  90.                 result = CallComponentFunction( params, (ComponentFunction)_SEVersion );
  91.                 break;
  92.  
  93.                 // Target request
  94.             case kComponentTargetSelect:
  95.                 result = CallComponentFunction( params, (ComponentFunction)_SETarget );
  96.                 break;
  97.  
  98.                 // Register request not supported
  99.             case kComponentRegisterSelect:
  100.                 // Unknown request
  101.             default:
  102.                 result = paramErr;
  103.                 break;
  104.         }
  105.     }
  106.     else    // Was it one of our request codes?
  107.     {
  108.         switch ( params->what )
  109.         {
  110.             case kDoEffect:
  111.                 result = CallComponentFunction( params, (ComponentFunction)_SEDoEffect );
  112.                 break;
  113.  
  114.             case kWorksOnSelectionOnly:
  115.                 result = CallComponentFunction( params, (ComponentFunction)_SEWorksOnSelectionOnly );
  116.                 break;
  117.  
  118.             default:
  119.                 result = paramErr;
  120.                 break;
  121.         }
  122.     }
  123.  
  124.     return result;
  125. }
  126.  
  127.  
  128.  
  129. /***
  130.  * _SEOpen
  131.  *
  132.  ***/
  133.  
  134. pascal ComponentResult _SEOpen( Handle storage, ComponentInstance self )
  135. {
  136.     ComponentResult        result = noErr;
  137.     PrivateGlobals**    globals;
  138.  
  139.         // Did we get our storage?
  140.     if ( globals = (PrivateGlobals**)NewHandleClear( sizeof( PrivateGlobals ) ) )
  141.     {
  142.             // Keep a reference to self
  143.         (*globals)->self = (Component)self;
  144.  
  145.             // Set storage ref
  146.         SetComponentInstanceStorage( self, (Handle)globals );
  147.     }
  148.     else    // NewHandleClear failed
  149.     {
  150.         result = MemError();
  151.     }
  152.  
  153.     return result;
  154. }
  155.  
  156.  
  157.  
  158. /***
  159.  * _SEClose
  160.  *
  161.  ***/
  162.  
  163. pascal ComponentResult _SEClose( Handle storage, ComponentInstance self )
  164. {
  165.     ComponentResult        result = noErr;
  166.     
  167.         // Do we have any clean up to do?
  168.     if ( storage )
  169.     {
  170.             // Dispose globals
  171.         DisposHandle( storage );
  172.     }
  173.  
  174.     return result;
  175. }
  176.  
  177.  
  178.  
  179. /***
  180.  * _SECanDo
  181.  *
  182.  ***/
  183.  
  184. pascal ComponentResult _SECanDo( short selector )
  185. {
  186.     switch (selector)
  187.     {
  188.             // Component Manager request codes
  189.         case kComponentOpenSelect:
  190.         case kComponentCloseSelect:
  191.         case kComponentCanDoSelect:
  192.         case kComponentVersionSelect:
  193.         case kComponentTargetSelect:
  194.         
  195.             // SE component request codes
  196.         case kDoEffect:
  197.             return TRUE;
  198.  
  199.         case kComponentRegisterSelect:    // Register request not supported
  200.         default:                        // Not a request code we recognize
  201.             return FALSE;
  202.     }
  203. }
  204.  
  205.  
  206.  
  207. /***
  208.  * _SEVersion
  209.  *
  210.  ***/
  211.  
  212. pascal ComponentResult _SEVersion()
  213. {
  214.         // Return the version info
  215.     return kVersionNumber;
  216. }
  217.  
  218.  
  219.  
  220. /***
  221.  * _SETarget
  222.  *
  223.  ***/
  224.  
  225. pascal ComponentResult _SETarget( ComponentInstance capturingComponent )
  226. {
  227.     ComponentResult result = noErr;
  228.     
  229.     return result;
  230. }
  231.