Movie cocoaqt¶
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 Movie:_Server_basics#Sample_Methods. 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_(index)¶
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)
{
...
}</syntaxhighlight>
This function sets the framerate for the movie.
<syntaxhighlight>
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)
{
...
}