home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Snippets / MMapp / MMapp.cp next >
Encoding:
Text File  |  1996-10-27  |  7.4 KB  |  235 lines  |  [TEXT/CWIE]

  1. //  This project was made using Code Warrior 10
  2.  
  3. //    This project shows a way to play a movie in a pane by specifying just the file name.
  4. //  No movie controller is used.  The project also uses a custom type CPPb resource in
  5. //  Constructor.  I modified some code from the book "Ultimate Mac Programming" by Dave Mark,
  6. //  from the program "Very Simple Player" by Peter Hoddie.
  7. //  The main goal of this program is to build a library of classes for Multi-Media use.
  8. //  As soon as I have better code, I will release it.
  9.  
  10. //  I am not a professional programmer.  I am a photographer, trying to learn programming.
  11. //  I want nothing for this source code except the hope that it may help someone like me
  12. //  who is trying to learn this endless maze of languages, styles, and class libraries that
  13. //  is Macintosh Programming.  This is my first full-fledged Power Plant App.  I started with
  14. //  the basic Power Plant project and using code from some of the examples provided on the disk
  15. //  and from the above mentioned book.
  16.  
  17. //  I want to thank John Daub at MetroWerks for his help on this project.
  18. //  The amount of personal help that is available for Macintosh programmers is way out
  19. //  of balance in comparison to what is available to Dos and Windows programmers, at least
  20. //  for us beginners.  If Apple doesn't realize this and start providing better local
  21. //  support, like Macintosh programming classes at colleges etc., it won't matter how good
  22. //  of a machine Apple makes, if no one is writing software for it anymore.  The only hope
  23. //  we have right now is companies like MetroWerks who provide such good support and tools 
  24. //  and people like John Daub who are willing to take the time to share thier experience.
  25. //  O.K. I'll get off my soap box now! :)
  26.  
  27.  
  28. //  What I am happy about in this program:
  29. // 1.) The program successfully gets the movie's file name from the CPPb resource and opens 
  30. //     the movie from the file name.
  31. // 2.) The program uses ::ShowMoviePoster() to display the first frame of the movie before
  32. //     actually playing the movie.
  33. // 3.) The program successfully sends a message from the braodcaster ( the play button )
  34. //     to a listener ( MMovieView ) to play the movie.
  35.  
  36. //  What I am not happy about in this program:
  37. // 1.) The movie does not play as smooothly as I would like, and the movie poster image
  38. //     is not stable enough, as the poster flashes onto the screen annoyingly during 
  39. //     separate play cycles.
  40. // 2.) The program's memory keeps getting filled even though I call ::DisposeMovie()
  41. //     several times in the program.  After a few plays, the app asks to close some 
  42. //     windows or other apps.
  43. // 3.) The MMovieView pane resizes itself, but does not center itself in it's immediate
  44. //     surroundings.
  45.  
  46.  
  47. //  Program by: Earl Schellhous
  48. //  e-mail as of 10/26/96 : szschell@peseta.ucdavis.edu OR monkey@calweb.com
  49. //  If you write a better version, I would appreciate a copy! =)
  50.  
  51.  
  52. // ===========================================================================
  53. // MMapp.cp
  54.  
  55.  
  56. #include "MMapp.h"
  57. #include "MMovieView.h"
  58. #include "MMappConstants.h"
  59.  
  60. #include <LGrowZone.h>
  61. #include <LWindow.h>
  62. #include <PP_Messages.h>
  63. #include <PP_Resources.h>
  64. #include <PPobClasses.h>
  65. #include <UDrawingState.h>
  66. #include <UMemoryMgr.h>
  67. #include <URegistrar.h>
  68. #include <LEditField.h>
  69. #include <UReanimator.h>
  70. #include <LGADefaultPushButton.h>
  71. #include <UGALibRegistry.h>
  72.  
  73.  
  74.  
  75. // ===========================================================================
  76. //        • Main Program
  77. // ===========================================================================
  78.  
  79. void main(void)
  80. {
  81.                                     // Set Debugging options
  82.     SetDebugThrow_(debugAction_Alert);
  83.     SetDebugSignal_(debugAction_Alert);
  84.  
  85.     InitializeHeap(3);                // Initialize Memory Manager
  86.                                     // Parameter is number of Master Pointer
  87.                                     //   blocks to allocate
  88.     
  89.                                     // Initialize standard Toolbox managers
  90.     UQDGlobals::InitializeToolbox(&qd);
  91.     
  92.     new LGrowZone(20000);            // Install a GrowZone function to catch
  93.                                     //    low memory situations.
  94.  
  95.     MMapp    theApp;            // replace this with your App type
  96.     theApp.Run();
  97. }
  98.  
  99.  
  100. // ---------------------------------------------------------------------------
  101. //        • MMapp             // replace this with your App type
  102. // ---------------------------------------------------------------------------
  103. //    Constructor
  104.  
  105. MMapp::MMapp()
  106. {
  107.     // Register functions to create core PowerPlant classes
  108.     
  109.     RegisterAllPPClasses();
  110.     RegisterGALibraryClasses();
  111.     URegistrar::RegisterClass( MMovieView::class_ID, 
  112.                                (ClassCreatorFunc) MMovieView::CreateMoviePaneStream );
  113. }
  114.  
  115.  
  116. // ---------------------------------------------------------------------------
  117. //        • ~MMapp            // replace this with your App type
  118. // ---------------------------------------------------------------------------
  119. //    Destructor
  120. //
  121.  
  122. MMapp::~MMapp()
  123. {
  124. }
  125.  
  126. // ---------------------------------------------------------------------------
  127. //        • StartUp
  128. // ---------------------------------------------------------------------------
  129. //    This function lets you do something when the application starts up
  130. //    without a document. For example, you could issue your own new command.
  131.  
  132. void
  133. MMapp::StartUp()
  134. {
  135.     ObeyCommand(cmd_New, nil);        // EXAMPLE, create a new window
  136. }
  137.  
  138. // ---------------------------------------------------------------------------
  139. //        • ObeyCommand
  140. // ---------------------------------------------------------------------------
  141. //    Respond to commands
  142.  
  143. Boolean
  144. MMapp::ObeyCommand(
  145.     CommandT    inCommand,
  146.     void        *ioParam)
  147. {
  148.     Boolean        cmdHandled = true;
  149.  
  150.     switch (inCommand) {
  151.     
  152.         // Deal with command messages (defined in PP_Messages.h).
  153.         // Any that you don't handle will be passed to LApplication
  154.              
  155.         case cmd_New:
  156.         {
  157.                                         // EXAMPLE, create a new window
  158.             
  159.             MM_Window = LWindow::CreateWindow( kPPob_Main_Window, this );
  160.             
  161.             // link the listener to the controls
  162.             UReanimator::LinkListenerToControls( this, MM_Window, kRidL_Main_Window );    
  163.             
  164.             // Get the button.
  165.             LGADefaultPushButton    *thePlayButton;
  166.             thePlayButton = (LGADefaultPushButton *) MM_Window->FindPaneByID( kPlayButton );
  167.             
  168.             // Get the Movie View Pane and make it listen to the button
  169.             MMovieView    *theMoviePane;
  170.             theMoviePane = (MMovieView *) MM_Window->FindPaneByID( kMoviePane );
  171.             thePlayButton->AddListener( theMoviePane );
  172.             
  173.             MM_Window->Show();
  174.             break;
  175.         }
  176.  
  177.         default:
  178.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  179.             break;
  180.     }
  181.     
  182.     return cmdHandled;
  183. }
  184.  
  185. // ---------------------------------------------------------------------------
  186. //        • FindCommandStatus
  187. // ---------------------------------------------------------------------------
  188. //    This function enables menu commands.
  189. //
  190.  
  191. void
  192. MMapp::FindCommandStatus(
  193.     CommandT    inCommand,
  194.     Boolean        &outEnabled,
  195.     Boolean        &outUsesMark,
  196.     Char16        &outMark,
  197.     Str255        outName)
  198. {
  199.  
  200.     switch (inCommand) {
  201.     
  202.         // Return menu item status according to command messages.
  203.         // Any that you don't handle will be passed to LApplication
  204.  
  205.         case cmd_New:                    // EXAMPLE
  206.             outEnabled = true;            // enable the New command
  207.             break;
  208.  
  209.         default:
  210.             LApplication::FindCommandStatus(inCommand, outEnabled,
  211.                                                 outUsesMark, outMark, outName);
  212.             break;
  213.     }
  214. }
  215.  
  216. void
  217. MMapp::ListenToMessage(MessageT theMessage, void *ioParam)
  218. {
  219.     #pragma unused (ioParam )
  220.     
  221.     MMovieView *moviePane;
  222.     
  223.     switch( theMessage )
  224.     {
  225.         case msg_PlayMovie:
  226.         {
  227.         /* I'm not really sure if this does anything at all here =) */
  228.             moviePane = (MMovieView *)MM_Window->FindPaneByID( kMoviePane );
  229.             moviePane->Show();
  230.             moviePane->Activate();
  231.             break;
  232.         }
  233.     }
  234. }
  235.