QuickTime and Cross-Platform Multimedia 
by Mark Carolan

Example 1:
BatchPack *bPack = (BatchPack *) handlerRefCon;


Example 2:
void InitStrings()
{   
    LoadString(hInstance, IDS_VIDEO, THA_MOOFIE, MOVIENAME_SIZE);
    LoadString(hInstance, IDS_AUDIO, THA_SOUND, MOVIENAME_SIZE);        
}


Example 3:
comment = "<string>"
audio path = "<string>"
delay = <number>


Example 4:
char *ReadStrParam(char *buff, char *param_name)
bool ReadNumParam(char *buff, char *param_name, float *theNum)


Listing One
struct BatchPack {
    Rect            rect, originalPictFrame;
    Boolean     batching, batchFileOpened, scale_set;
    int         batchFileElements;
    Cruncher        *cruncher;
    FSSpec      *batchFileList;
    OSType      type;
    
                BatchPack() :
                rect(),
                originalPictFrame(),
                batching(false),
                batchFileOpened(false),
                scale_set(false),
                batchFileElements(0),
                cruncher(NULL),
                batchFileList(NULL) 
                { 
                    rect.right = 320; rect.bottom = 240;
                    originalPictFrame.right = 320;
                    originalPictFrame.bottom = 240;
                }
                ~BatchPack() 
                {
                    Reset();
                }                           
    void            PartialReset() 
               {
                    if (cruncher)
                            delete cruncher;
                        cruncher = NULL;    
                        batching= false;
                }                       
    void            Reset() 
                {
                    PartialReset();
                    if (batchFileList)
                            delete batchFileList;
                        batchFileList = NULL;   
                        batchFileElements = 0;  
                    batchFileOpened = false;            
                }                       
};

Listing Two
if (batchPack.batchFileOpened) {
    if (!batchPack.cruncher) {
        if (batchPack.type == 'PICT')
            batchPack.cruncher = new PictCruncher(gSrcWindow, p);
        else if (batchPack.type == 'MooV')
            batchPack.cruncher = new MovieCruncher(gSrcWindow, p);
    }           
    batchPack.cruncher->CreateBatch(batchPack.batchFileList, 
               batchPack.batchFileElements,  &batchPack.rect);
 ...

Listing Three
switch (myEvent->what) {
case nullEvent:
    if (batchPack.cruncher && allow_processing) {
        if (batchPack.cruncher->crunching)
            if (!(batchPack.cruncher->Process(gFilterString))) {
            // means it's just finished
            // reset all process info
            // leave edit list full in case more copies required
            batchPack.PartialReset();                   
            allow_processing = false;
            FixMenus();             
        }
    }
    break;
 ...

Listing Four
TimeScale t = GetMovieTimeScale(newMovie);
TimeValue v = GetMovieDuration(newMovie); // get end time of editee
    
SetMovieSelection (newMovie, v, (TimeValue)0); // set insertion point   
PasteMovieSelection(newMovie, current_movie);
v = GetMovieDuration(newMovie);
if (logFile) {
    sprintf(pBuff, "%d\n", (int)v);
    fwrite(pBuff, strlen(pBuff), sizeof(char), logFile);
}

Listing Five
if (batching) {
    P2Ccpy(batchFilter, headerFile.name);
    Trim2Filter(batchFilter, filterString);
    thisNum = FindNextNumberedFile(&headerFile, lastNum, batchFilter);
}
else
    thisNum = FindNextNumberedFile(&headerFile, lastNum, filterString);
if (thisNum == -1) { // no more numbers for this prefix
    if (!NextInBatch()) {
        finishedProcess = true;
        headerFileOpened = false;
        crunching = 0;
    }
    else {
        set_key = true;     // make beginning of next pict sequence a key frame
        goto keyset;
    }
}
 ...

Listing Six
typedef struct _qtedititem {
    long    start;
    long    end;
} EditItem;
struct EditList
{
        EditList()  {Zero();}
        ~EditList() {Clear();}
    void    Set(int count)  
        {
            total = count; 
            edits = new EditItem[total]; 
            index = 0;
        }
    void    Randy() {index = rand() % total;} // ints are in pairs
    long&   Start() {return edits[index].start;}
    long&   End()       {return edits[index].end;}
    void    Clear()
        {
            if (edits) delete [] edits;                                 
    Zero();
        }
    void    Zero()
        {
            index = mode = total = 0; 
            edits = (EditItem*)NULL;
        }   
    long            index;
    long            mode;
    long            total;
    Movie           mov;
    MovieController mc;
    EditItem        *edits;
    CallBackStuff   cbs;
    
    static bool     noChangeYet;
};
bool EditList::noChangeYet = false; // prevents jumping too early

Listing Seven
void InstallMovies()
{
    if (!SetupMovie(THA_MOOFIE, &editList))
        if (!SetupMovie(DEFAULT_VIDEO, &editList))
            editList.mov = NULL;                
    if (OverrideSoundSource(sndeditList))
        goto end_sound_init;        
    if (SetupMovie(THA_SOUND, &sndeditList))
        goto end_sound_init;
    cdPath = CDPath(THA_SOUND);
    if (*cdPath)
        if (SetupMovie(cdPath, &sndeditList)) 
            goto end_sound_init;
    if (SetupMovie(DEFAULT_SOUND, &sndeditList))
            goto end_sound_init;
    cdPath = CDPath(DEFAULT_SOUND);
    if (*cdPath)
        if (SetupMovie(cdPath, &sndeditList))
            goto end_sound_init;
    sndeditList.mov = NULL;
end_sound_init:         
    if (editList.mov) {
        if (OpenEditListFromFile(DEFAULT_VIDEO_EDITS, editList) == 0)
            if (OpenEditListFromResource(VIDEO_RESOURCE, editList) == 0) {
                    editList.Set(1);
                    editList.Start() = (long) 0;
                    editList.End() = (long) GetMovieDuration(editList.mov);
            }
    }
    if (sndeditList.mov) {
        if (OpenEditListFromFile(DEFAULT_SOUND_EDITS, sndeditList) == 0)
            if (OpenEditListFromResource(AUDIO_RESOURCE, sndeditList) == 0) {
                    sndeditList.Set(1);
                    sndeditList.Start() = (long) 0;
                    sndeditList.End() = (long)                                          GetMovieDuration(sndeditList.mov);          
            }           
    }
}

Listing Eight
void Pump()
{
    static char buff[20];
    static bool disp = false;
    int point_x, point_y;
    
    clock_t thisTime, diffTime;
    if (++gRandCounter & 0x0F) { // minimize frequency of checks
        thisTime = clock();
        if (((diffTime = thisTime - gLastTime)) >= gTime_change) { 
            gLastTime = thisTime;               
            RandomChangeMovie(sndeditList);
            RandomChangeMovie(editList);
            #ifdef WIN32
            GetCursorPos(&gLastMouse);
            #else
            Point mp;
            GetMouse(&mp);
            gLastMouse.x = mp.h;
            gLastMouse.y = mp.v;
            #endif
            EditList::noChangeYet = false;
        }
        else {                  // check for fresh mouse drag
            POINT p;
            #ifdef WIN32
            GetCursorPos(&p);
            #else
            Point mp;
            GetMouse(&mp);
            p.x = mp.h;
            p.y = mp.v;
            #endif
            if ((p.x == gLastMouse.x) && (p.y == gLastMouse.y))
                EditList::noChangeYet = false; // ok for another mouse sweep
            else if ((abs(p.x - gLastMouse.x) > MIN_MOUSE_MOVE) ||
                (abs(p.y - gLastMouse.y) > MIN_MOUSE_MOVE)) {
                if (EditList::noChangeYet == false) {
                    RandomChangeMovie(sndeditList);
                    EditList::noChangeYet = true;
                    RandomChangeMovie(editList);
                    gLastTime = thisTime;               
                }
            }
            gLastMouse = p; // keep pointer up to date
        }   
    }
    if (editList.mc)
        MCDoAction(editList.mc, mcActionIdle, NULL);
    if (sndeditList.mc)
        MCDoAction(sndeditList.mc, mcActionIdle, NULL);
}


5


