Difference between revisions of "Movie cocoaqt"

From The Foundry MODO SDK wiki
Jump to: navigation, search
 
Line 9: Line 9:
 
We want our class to create a movie object, so we inherit from [[Movie:_Server_basics#Sample_Methods|CLxImpl_Movie]]. Our class includes all the basic methods of a movie class. To create a movie, our class first calls the mov_BeginMovie class, which initiates the saving and provides the file path and the size of the frame. Next, our mov_SetFrameRate function sets the frame rate. After that, our mov_AddImage appends an image to the movie every time it is called. After that is finished, the mov_AddAudio function adds an audio track to the movie file. Finally, our EndMovie function closes the movies file and cleans up the temp files.
 
We want our class to create a movie object, so we inherit from [[Movie:_Server_basics#Sample_Methods|CLxImpl_Movie]]. Our class includes all the basic methods of a movie class. To create a movie, our class first calls the mov_BeginMovie class, which initiates the saving and provides the file path and the size of the frame. Next, our mov_SetFrameRate function sets the frame rate. After that, our mov_AddImage appends an image to the movie every time it is called. After that is finished, the mov_AddAudio function adds an audio track to the movie file. Finally, our EndMovie function closes the movies file and cleans up the temp files.
  
 +
<syntaxhighlight>
 
  class CCocoaQuickTimeMovie : public CLxImpl_Movie
 
  class CCocoaQuickTimeMovie : public CLxImpl_Movie
 
  {
 
  {
Line 25: Line 26:
 
         NSDictionary *myDict;
 
         NSDictionary *myDict;
 
         NSString *audioFileName;
 
         NSString *audioFileName;
  };
+
  };</syntaxhighlight>
  
 
===[[Server_Tags|Server Tags]]===
 
===[[Server_Tags|Server Tags]]===
Line 31: Line 32:
 
Servers tags are examined when the server is initialized, and give information about the server. We set the tags in this case by taking a descinfo[] array and associating the relevant data with the corresponding flags. The tags here indicate that the main class will be a server of the movie type that will have the extension .mov named Express Quicktime.
 
Servers tags are examined when the server is initialized, and give information about the server. We set the tags in this case by taking a descinfo[] array and associating the relevant data with the corresponding flags. The tags here indicate that the main class will be a server of the movie type that will have the extension .mov named Express Quicktime.
  
 +
<syntaxhighlight>
 
  LXtTagInfoDesc CCocoaQuickTimeMovie::descInfo[] = {
 
  LXtTagInfoDesc CCocoaQuickTimeMovie::descInfo[] = {
 
         { LXsLOD_CLASSLIST, LXa_MOVIE        },
 
         { LXsLOD_CLASSLIST, LXa_MOVIE        },
Line 37: Line 39:
 
         { LXsSRV_USERNAME, "Express Quicktime" },
 
         { LXsSRV_USERNAME, "Express Quicktime" },
 
         { 0 }
 
         { 0 }
  };
+
  };</syntaxhighlight>
  
 
===[[Initialize_(index)|Initialize]]===
 
===[[Initialize_(index)|Initialize]]===
Line 43: Line 45:
 
Servers are extensible set of features that we add to modo, usually through plugins. Intialize is called when we add the plugin to modo, and is the utility that exports the server. The LXx_ADD_SERVER method is simply a wrapper that is identical to normal method of adding a server, with the arguments being (interface_to_be_added, class_you_depend_on, server_name). In this case we add the Movie interface, depend on the CCocoaQuickTimeMove, and name our server "quicktime".
 
Servers are extensible set of features that we add to modo, usually through plugins. Intialize is called when we add the plugin to modo, and is the utility that exports the server. The LXx_ADD_SERVER method is simply a wrapper that is identical to normal method of adding a server, with the arguments being (interface_to_be_added, class_you_depend_on, server_name). In this case we add the Movie interface, depend on the CCocoaQuickTimeMove, and name our server "quicktime".
  
 +
<syntaxhighlight>
 
  void
 
  void
 
  initialize ()
 
  initialize ()
 
  {
 
  {
 
         LXx_ADD_SERVER (Movie, CCocoaQuickTimeMovie, "quicktime");
 
         LXx_ADD_SERVER (Movie, CCocoaQuickTimeMovie, "quicktime");
  }
+
  }</syntaxhighlight>
  
 
===Helper Functions===
 
===Helper Functions===
Line 53: Line 56:
 
Apple uses the NS image format for its movie frames, so we need to have some function to convert our format(CGImage) to NS. This function does exactly that. We call this function in our mov_AddImage function in order to convert the CGImage we have constructed.  
 
Apple uses the NS image format for its movie frames, so we need to have some function to convert our format(CGImage) to NS. This function does exactly that. We call this function in our mov_AddImage function in order to convert the CGImage we have constructed.  
  
 +
<syntaxhighlight>
 
  static NSImage *
 
  static NSImage *
 
  cgImageToNSImage (
 
  cgImageToNSImage (
Line 58: Line 62:
 
  {
 
  {
 
         ...
 
         ...
  }
+
  }</syntaxhighlight>
  
 
This function creates a temporary audio file with the audio object. Most importantly, if the function is unable to read or write the audio object, it returns an error code. This function is called in mov_AddAudio in order to verify that the audio object passed in is valid.
 
This function creates a temporary audio file with the audio object. Most importantly, if the function is unable to read or write the audio object, it returns an error code. This function is called in mov_AddAudio in order to verify that the audio object passed in is valid.
  
 +
<syntaxhighlight>
 
  static LxResult
 
  static LxResult
 
  CreateAudioTempFile (
 
  CreateAudioTempFile (
Line 68: Line 73:
 
  {
 
  {
 
       ...
 
       ...
  }  
+
  }</syntaxhighlight>
  
 
===Implementations===
 
===Implementations===
Line 74: Line 79:
 
Creates a movie file and starts writing to it.
 
Creates a movie file and starts writing to it.
  
 +
<syntaxhighlight>
 
         LxResult
 
         LxResult
 
  CCocoaQuickTimeMovie::mov_BeginMovie (
 
  CCocoaQuickTimeMovie::mov_BeginMovie (
Line 82: Line 88:
 
  {
 
  {
 
     ...
 
     ...
  }
+
  }</syntaxhighlight>
  
 
This function sets the framerate for the movie.
 
This function sets the framerate for the movie.
  
 +
<syntaxhighlight>
 
  LxResult
 
  LxResult
 
  CCocoaQuickTimeMovie::mov_SetFramerate (
 
  CCocoaQuickTimeMovie::mov_SetFramerate (
Line 91: Line 98:
 
  {
 
  {
 
       ...
 
       ...
  }
+
  }</syntaxhighlight>
  
 
This functions adds another frame to the movie.
 
This functions adds another frame to the movie.
  
 +
<syntaxhighlight>
 
  LxResult
 
  LxResult
 
  CCocoaQuickTimeMovie::mov_AddImage (
 
  CCocoaQuickTimeMovie::mov_AddImage (
Line 100: Line 108:
 
  {
 
  {
 
       ...
 
       ...
  }
+
  }</syntaxhighlight>
  
 
This function adds the temp audio file to the movie.
 
This function adds the temp audio file to the movie.
  
 +
<syntaxhighlight>
 
  LxResult
 
  LxResult
 
  CCocoaQuickTimeMovie::mov_AddAudio (
 
  CCocoaQuickTimeMovie::mov_AddAudio (
Line 109: Line 118:
 
  {
 
  {
 
         ...
 
         ...
  }
+
  }</syntaxhighlight>
  
 
This function stops the writing to the movie file and cleans up the temp files.
 
This function stops the writing to the movie file and cleans up the temp files.
  
 +
<syntaxhighlight>
 
  LxResult
 
  LxResult
 
  CCocoaQuickTimeMovie::mov_EndMovie (void)
 
  CCocoaQuickTimeMovie::mov_EndMovie (void)
 
  {
 
  {
 
         ...
 
         ...
  }
+
  }</syntaxhighlight>
  
 
[[Category: SDK Examples]]
 
[[Category: SDK Examples]]

Latest revision as of 18:46, 16 September 2013

Movie_CocoaQT is a basic example plugin. This wiki page is intended as a walkthrough of the code in order to help you better understand the SDK.

When installed, the Movie_CocoaQT plugin adds Cocoa QuickTime saver utility for movies.

Code Walkthrough

Class Declaration

We want our class to create a movie object, so we inherit from CLxImpl_Movie. Our class includes all the basic methods of a movie class. To create a movie, our class first calls the mov_BeginMovie class, which initiates the saving and provides the file path and the size of the frame. Next, our mov_SetFrameRate function sets the frame rate. After that, our mov_AddImage appends an image to the movie every time it is called. After that is finished, the mov_AddAudio function adds an audio track to the movie file. Finally, our EndMovie function closes the movies file and cleans up the temp files.

 class CCocoaQuickTimeMovie : public CLxImpl_Movie
 {
     public:
         LxResult		 mov_BeginMovie (const char*,int, int, int);
         LxResult		 mov_SetFramerate (int);
         LxResult		 mov_AddImage (ILxUnknownID);
         LxResult		 mov_EndMovie (void);
         LxResult		 mov_AddAudio (ILxUnknownID);
 
         static LXtTagInfoDesc	 descInfo[];
 
         int			 frameRate;
         NSString		*nsStringPath;
         QTMovie			*mMovie;
         NSDictionary		*myDict;
         NSString		*audioFileName;
 };

Server Tags

Servers tags are examined when the server is initialized, and give information about the server. We set the tags in this case by taking a descinfo[] array and associating the relevant data with the corresponding flags. The tags here indicate that the main class will be a server of the movie type that will have the extension .mov named Express Quicktime.

 LXtTagInfoDesc	 CCocoaQuickTimeMovie::descInfo[] = {
        { LXsLOD_CLASSLIST,	LXa_MOVIE         },
        { LXsLOD_DOSPATTERN,	"*.mov"           },
        { LXsSAV_DOSTYPE,	"mov"             },
        { LXsSRV_USERNAME,	"Express Quicktime" },
        { 0 }
 };

Initialize

Servers are extensible set of features that we add to modo, usually through plugins. Intialize is called when we add the plugin to modo, and is the utility that exports the server. The LXx_ADD_SERVER method is simply a wrapper that is identical to normal method of adding a server, with the arguments being (interface_to_be_added, class_you_depend_on, server_name). In this case we add the Movie interface, depend on the CCocoaQuickTimeMove, and name our server "quicktime".

 void
 initialize ()
 {
        LXx_ADD_SERVER (Movie, CCocoaQuickTimeMovie, "quicktime");
 }

Helper Functions

Apple uses the NS image format for its movie frames, so we need to have some function to convert our format(CGImage) to NS. This function does exactly that. We call this function in our mov_AddImage function in order to convert the CGImage we have constructed.

 static NSImage *
 cgImageToNSImage (
         CGImageRef	 image)
 {
        ...
 }

This function creates a temporary audio file with the audio object. Most importantly, if the function is unable to read or write the audio object, it returns an error code. This function is called in mov_AddAudio in order to verify that the audio object passed in is valid.

 static LxResult
 CreateAudioTempFile (
        NSString		*filePath,
        CLxUser_Audio		*audio)
 {
       ...
 }

Implementations

Creates a movie file and starts writing to it.

        LxResult
 CCocoaQuickTimeMovie::mov_BeginMovie (
        const char              *fname,
        int                      w,
        int                      h,
        int                      flags)
 {
    ...
 }

This function sets the framerate for the movie.

 LxResult
 CCocoaQuickTimeMovie::mov_SetFramerate (
        int			 frate)
 {
       ...
 }

This functions adds another frame to the movie.

 LxResult
 CCocoaQuickTimeMovie::mov_AddImage (
        ILxUnknownID		 img)
 {
       ...
 }

This function adds the temp audio file to the movie.

 LxResult
 CCocoaQuickTimeMovie::mov_AddAudio (
        ILxUnknownID		 au)
 {
        ...
 }

This function stops the writing to the movie file and cleans up the temp files.

 LxResult
 CCocoaQuickTimeMovie::mov_EndMovie (void)
 {
        ...
 }