void QTApp_SetupController (MovieController theMC) { long myControllerFlags; // CLUT table use MCDoAction(theMC, mcActionGetFlags, &myControllerFlags); MCDoAction(theMC, mcActionSetFlags, (void *)(myControllerFlags | mcFlagsUseWindowPalette)); // enable keyboard event handling MCDoAction(theMC, mcActionSetKeysEnabled, (void *)true); // disable drag support MCDoAction(theMC, mcActionSetDragEnabled, (void *)false); }
OSErr QTInfo_GoToPosterFrame (Movie theMovie, MovieController theMC) { TimeRecord myTimeRecord; ComponentResult myErr = noErr; // stop the movie from playing myErr = MCDoAction(theMC, mcActionPlay, (void *)0L); if (myErr != noErr) goto bail; // set up a time record with the desired movie time, scale, and base myTimeRecord.value.hi = 0; myTimeRecord.value.lo = GetMoviePosterTime(theMovie); myTimeRecord.base = GetMovieTimeBase(theMovie); myTimeRecord.scale = GetMovieTimeScale(theMovie); myErr = MCDoAction(theMC, mcActionGoToTime, &myTimeRecord); bail: return((OSErr)myErr); }
//////////////////////////////////////////////////////////////////////////////// // virtual bool LLMediaImplQuickTime::setVolume( float volume ) { mCurVolume = (short)(volume * ( double ) 0x100 ); if ( mMovieController ) { MCDoAction( mMovieController, mcActionSetVolume, (void*)mCurVolume ); return true; } return false; }
//////////////////////////////////////////////////////////////////////////////// // virtual bool LLMediaImplQuickTime::updateMedia() { if ( ! mMovieHandle ) return false; if ( ! mMovieController ) return false; if ( ! mGWorldHandle ) return false; // service QuickTime MoviesTask( mMovieHandle, 0 ); MCIdle( mMovieController ); // update state machine (deals with transport controls for example) processState(); // special code for looping - need to rewind at the end of the movie if ( isLooping() ) { // QT call to see if we are at the end - can't do with controller if ( IsMovieDone( mMovieHandle ) ) { // go back to start rewind(); // kick off new play MCDoAction( mMovieController, mcActionPrerollAndPlay, (void*)GetMoviePreferredRate( mMovieHandle ) ); // set the volume MCDoAction( mMovieController, mcActionSetVolume, (void*)mCurVolume ); } } return true; }
//////////////////////////////////////////////////////////////////////////////////////////////// // Function: // MovieDisplay_SetVolume // Description: // // Inputs: // 1. Movie Object // 2. Volume // Outputs: // None //////////////////////////////////////////////////////////////////////////////////////////////// extern "C" void ALMAPI _export MovieDisplay_SetVolume(pAEvtInfo, pAObjMessage theSystem) { OBJECTID oiMovie; //ID of the Input Parameter OBJECTID oiVolume; MOVIERUNPTR lpMovieRunRec; MOVIEDEVPTR lpMovieDevRec; SFIXED sfxVolume; long double Volume; double VolInt, VolFrac; long how; MovieController mController; oiMovie = AFuncGetTypedParameter(1,OTYPE_MOVIE); oiVolume = AFuncGetParameter(2); ONmbrGetReal(oiVolume,&Volume); VolFrac = modf(Volume,&VolInt); sfxVolume = MAKESFIXED(VolInt,VolFrac); lpMovieDevRec = (MOVIEDEVPTR) AObjLockData(oiMovie,MovieDev); mController = lpMovieDevRec->mController; AObjUnlockData(oiMovie,MovieDev); if (!mController) { theSystem->message1 = 2; //Failed return; } // Get the movie's volume MCDoAction (mController, mcActionSetVolume,(LPVOID) &sfxVolume); lpMovieRunRec = (MOVIERUNPTR) AObjLockData(oiMovie,MovieRun); if (lpMovieRunRec->bIsMoviePlaying) how = AEVT_ATMARK | AEVT_KILLDUPLICATES; else how = AEVT_ATTAIL | AEVT_KILLDUPLICATES; AObjUnlockData(oiMovie, MovieRun); AEvtPostStandard(oiMovie, AEVENT_OBJECTCHANGED, 0, AEvtGetObjectChangedPriority(how)); theSystem->message1 = 1; return; }
OSErr DoPlayMovie(Boolean useOverlay) { Rect movieBounds; OSErr err; BailErr((err = GetAMovieFile(&mMovie))); GetMovieBox(mMovie, &movieBounds); mMovieController = NewMovieController(mMovie, &movieBounds, mcTopLeftMovie | mcNotVisible); NormalizeMovieRect(mMovie); GetMovieBox(mMovie, &movieBounds); BailErr((err = InitializeMungData(movieBounds, FrontWindow(), useOverlay, /* overlay */ true, /* clamp */ false /* draw with QT Effect */ ))); // This is key, as we need to draw all frames in our // offscreen gworld first. Once there, our custom // decompressor component can perform overlay drawing // or color clamping SetMovieGWorld(mMovie, GetMungDataOffscreen(), nil); // Our DrawCompleteProc calls BlitOneMungData which SetupMovieDrawCompleteProc(); // --------- SetMovieActive(mMovie, true); #ifndef __APPLE_CC__ // Due to a bug in Jaguar, some QT functions are missing from // /System/Library/CFMSupport/CarbonLib, so we must manually // grab the function pointers from the QuickTime.framework // for CFM Carbon applications. MachO Carbon applications do not // have the problem. GetMissingQTFunctionPointers(); #endif InstallMovieIdlingEventLoopTimer(&mMovieTimerState); // start the movie playing MCDoAction(mMovieController, mcActionPrerollAndPlay, (void*)Long2Fix(1)); bail: return err; }
OSErr QTInfo_SetPosterToFrame (Movie theMovie, MovieController theMC) { TimeValue myTime; ComponentResult myErr = noErr; // stop the movie from playing myErr = MCDoAction(theMC, mcActionPlay, (void *)0L); if (myErr != noErr) goto bail; myTime = GetMovieTime(theMovie, NULL); SetMoviePosterTime(theMovie, myTime); myErr = MCMovieChanged(theMC, theMovie); bail: return((OSErr)myErr); }
boolean playerplaymovie (void) { /* 7.0b4 PBS: play the movie that's loaded. */ if (currentmovie == nil) return (false); GoToBeginningOfMovie (currentmovie); SetMovieActive (currentmovie, true); MCDoAction (currentcontroller, mcActionPlay, (void *) true); /*Start playing.*/ MoviesTask (nil, 0); return (true); } /*playerplaymovie*/
void DoKillMovie() { if (mMovieController && mMovie) { OSErr err = noErr; /* stop movie */ MCDoAction(mMovieController, mcActionPlay, (void*)Long2Fix(0)); #ifdef __APPLE_CC__ err = QTUninstallNextTaskNeededSoonerCallback(mTaskNeededSoonerCallback,mMovieTimerState.theEventTimer); #else err = mQTUninstallNextTaskPtr(mTaskNeededSoonerCallback,mMovieTimerState.theEventTimer); #endif RemoveEventLoopTimer(mMovieTimerState.theEventTimer); /* remove draw complete proc. */ SetMovieDrawingCompleteProc(mMovie, movieDrawingCallWhenChanged, nil, NULL); DisposeMovieDrawingCompleteUPP(mMyDrawCompleteProc); DisposeMungData(); DisposeMovieController(mMovieController); DisposeMovie(mMovie); DisposeEventLoopTimerUPP(mEventLoopTimer); #ifdef __APPLE_CC__ DisposeQTNextTaskNeededSoonerCallbackUPP(mTaskNeededSoonerCallback); #else mDisposeQTNextTaskPtr(mTaskNeededSoonerCallback); #endif mMovieController = nil; mMovie = nil; } }
//////////////////////////////////////////////////////////////////////////////////////////////// // Function: // MovieDisplay_GetVolume // Description: // // Inputs: // 1. Movie Object // Outputs: // 2. Volume - Whole number //////////////////////////////////////////////////////////////////////////////////////////////// extern "C" void ALMAPI _export MovieDisplay_GetVolume(pAEvtInfo, pAObjMessage theSystem) { OBJECTID oiMovie; //ID of the Input Parameter OBJECTID oiVolume; MOVIEDEVPTR lpMovieDevRec; SFIXED sfxVolume; long Volume; MovieController mController; oiMovie = AFuncGetTypedParameter(1,OTYPE_MOVIE); if (!oiMovie) //Invalid parameter { theSystem->message1 = 2; //Failed return; } oiVolume = AObjCreate(OTYPE_NUMBER); lpMovieDevRec = (MOVIEDEVPTR) AObjLockData(oiMovie,MovieDev); mController = lpMovieDevRec->mController; AObjUnlockData(oiMovie,MovieDev); if (!mController) { theSystem->message1 = 2; //Failed return; } // Get the movie's volume MCDoAction (mController, mcActionGetVolume,(LPVOID) &sfxVolume); Volume = (LONG) HIBYTE(sfxVolume); ONmbrSetInteger(oiVolume,(LONG)Volume,TRUE); AFuncSetParameter(1,oiVolume); theSystem->message1 = 1; return; }
//////////////////////////////////////////////////////////////////////////////// // virtual bool LLMediaImplQuickTime::seek( double time ) { if ( mMovieController ) { TimeRecord when; when.scale = GetMovieTimeScale( mMovieHandle ); when.base = 0; // 'time' is in (floating point) seconds. The timebase time will be in 'units', where // there are 'scale' units per second. SInt64 raw_time = ( SInt64 )( time * (double)( when.scale ) ); when.value.hi = ( SInt32 )( raw_time >> 32 ); when.value.lo = ( SInt32 )( ( raw_time & 0x00000000FFFFFFFF ) ); MCDoAction( mMovieController, mcActionGoToTime, &when ); return true; } return false; }
bool LLMediaImplQuickTime::processState() { // start stream if ( nextCommand() == LLMediaBase::COMMAND_START ) { // valid when we are in these states if ( getStatus() == LLMediaBase::STATUS_NAVIGATING|| getStatus() == LLMediaBase::STATUS_STOPPED || getStatus() == LLMediaBase::STATUS_PAUSED ) { // it appears that the movie must be in a loaded state before we do this command if ( GetMovieLoadState( mMovieHandle ) >= kMovieLoadStatePlaythroughOK ) { MCDoAction( mMovieController, mcActionPrerollAndPlay, (void*)GetMoviePreferredRate( mMovieHandle ) ); MCDoAction( mMovieController, mcActionSetVolume, (void*)mCurVolume ); setStatus( LLMediaBase::STATUS_STARTED ); clearCommand(); } } } else if ( nextCommand() == LLMediaBase::COMMAND_STOP ) { // valid when we are in these states if ( getStatus() == LLMediaBase::STATUS_NAVIGATING || getStatus() == LLMediaBase::STATUS_STARTED || getStatus() == LLMediaBase::STATUS_PAUSED ) { // it appears that the movie must be in a loaded state before we do this command if ( GetMovieLoadState( mMovieHandle ) >= kMovieLoadStatePlaythroughOK ) { // stop playing Fixed rate = X2Fix( 0.0 ); MCDoAction( mMovieController, mcActionPlay, (void*)rate ); // go back to start rewind(); setStatus( LLMediaBase::STATUS_STOPPED ); clearCommand(); }; }; } else if ( nextCommand() == LLMediaBase::COMMAND_PAUSE ) { // valid when we are in these states if ( getStatus() == LLMediaBase::STATUS_NAVIGATING || getStatus() == LLMediaBase::STATUS_STARTED || getStatus() == LLMediaBase::STATUS_STOPPED ) { // it appears that the movie must be in a loaded state before we do this command if ( GetMovieLoadState( mMovieHandle ) >= kMovieLoadStatePlaythroughOK ) { // stop playing Fixed rate = X2Fix( 0.0 ); MCDoAction( mMovieController, mcActionPlay, (void*)rate ); setStatus( LLMediaBase::STATUS_PAUSED ); clearCommand(); }; }; }; return true; }
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) { if (nlhs < 0) { mexErrMsgTxt("Too few output arguments."); return; } if (nlhs > 1) { mexErrMsgTxt("Too many output arguments."); return; } if (nrhs < 1) { mexErrMsgTxt("Too few input arguments."); return; } if (nrhs > 3) { mexErrMsgTxt("Too many input arguments."); return; } TimeValue duration; TimeRecord myTimeRecord; Rect bounds; OSErr result = 0; short resRefNum = -1; short actualResId = DoTheRightThing; FSSpec theFSSpec; GWorldPtr offWorld; Movie theMovie = nil; MovieController thePlayer = nil; MovieDrawingCompleteUPP myDrawCompleteProc; long frame_end; long myStep = 1; char location[PATH_BUFFER_SIZE]; long frame_count; mwSize cdims[2]; mxGetString(prhs[0], location, PATH_BUFFER_SIZE); if (nrhs > 2) { frame_start = rint(mxGetScalar(prhs[1])); frame_end = rint(mxGetScalar(prhs[2])); } else if (nrhs > 1) { frame_start = 1; frame_end = rint(mxGetScalar(prhs[1])); } else { frame_start = 1; frame_end = 0; } if (frame_start < 1) { mexErrMsgTxt("Error: the starting frame must be positive\n"); return; } if (frame_end < 0) { mexErrMsgTxt("Error: the ending frame must be positive\n"); return; } if (frame_end != 0 && frame_end < frame_start) { mexErrMsgTxt("Error: the ending frame must not be less than the starting frame\n"); return; } myDrawCompleteProc = NewMovieDrawingCompleteUPP(DrawCompleteProc); EnterMovies(); if (NativePathNameToFSSpec(location, &theFSSpec, 0) || OpenMovieFile(&theFSSpec, &resRefNum, 0) || NewMovieFromFile(&theMovie, resRefNum, &actualResId, 0, 0, 0)) { mexErrMsgTxt("Error: failed to open movie\n"); return; } if (resRefNum != -1) CloseMovieFile(resRefNum); GetMovieBox(theMovie, &bounds); QTNewGWorld(&offWorld, k32ARGBPixelFormat, &bounds, NULL, NULL, 0); LockPixels(GetGWorldPixMap(offWorld)); SetGWorld(offWorld, NULL); thePlayer = NewMovieController(theMovie, &bounds, mcTopLeftMovie | mcNotVisible); SetMovieGWorld(theMovie, offWorld, NULL); SetMovieActive(theMovie, true); SetMovieDrawingCompleteProc(theMovie, movieDrawingCallWhenChanged, myDrawCompleteProc, (long) offWorld); GetMovieTime(theMovie, &myTimeRecord); duration = GetMovieDuration(theMovie); // Compute the number of frames for allocation of output structure frame_count = 0; while ((frame_end == 0 || frame_count < frame_end) && GetMovieTime(theMovie, NULL) < duration) { frame_count++; MCDoAction(thePlayer, mcActionStep, (Ptr) myStep); } SetMovieTime(theMovie, &myTimeRecord); // Ignore frames greater than those in the file if (frame_end == 0 || frame_count < frame_end) frame_end = frame_count; cdims[0] = frame_end - frame_start + 1; // Indices are one-based cdims[1] = 1; plhs[0] = mxCreateCellArray(2, cdims); // Step through the movie and save the frame when in the chosen interval // Note: the step size seems to be handled as a short internally. // Using anything greater than 32758 will seek to an incorrect frame frame_num = 1; while (frame_num <= frame_end) { MCDoAction(thePlayer, mcActionStep, (Ptr) myStep); if (frame_num >= frame_start) { MCIdle(thePlayer); mxSetCell(plhs[0], frame_num - frame_start, framedata); } frame_num++; } UnlockPixels(GetGWorldPixMap (offWorld)); DisposeGWorld(offWorld); DisposeMovieController (thePlayer); DisposeMovie(theMovie); DisposeMovieDrawingCompleteUPP(myDrawCompleteProc); ExitMovies(); return; }
OSStatus HIRevolutionStackViewHandler(EventHandlerCallRef p_call_ref, EventRef p_event, void *p_data) { OSStatus t_status; t_status = eventNotHandledErr; UInt32 t_event_class; t_event_class = GetEventClass(p_event); UInt32 t_event_kind; t_event_kind = GetEventKind(p_event); HIRevolutionStackViewData *t_context; t_context = (HIRevolutionStackViewData *)p_data; switch(t_event_class) { case 'revo': switch(t_event_kind) { case 'rlnk': GetEventParameter(p_event, 'Stak', typeVoidPtr, NULL, sizeof(void *), NULL, &t_context -> stack); break; } break; case kEventClassHIObject: switch(t_event_kind) { case kEventHIObjectConstruct: { HIRevolutionStackViewData *t_data; t_data = new HIRevolutionStackViewData; t_data -> stack = NULL; GetEventParameter(p_event, kEventParamHIObjectInstance, typeHIObjectRef, NULL, sizeof(HIObjectRef), NULL, (HIObjectRef *)&t_data -> view); SetEventParameter(p_event, kEventParamHIObjectInstance, typeVoidPtr, sizeof(HIRevolutionStackViewData *), &t_data); t_status = noErr; } break; case kEventHIObjectInitialize: { GetEventParameter(p_event, 'Stak', typeVoidPtr, NULL, sizeof(void *), NULL, &t_context -> stack); Rect t_bounds; t_bounds . left = 0; // MW-2011-09-12: [[ MacScroll ]] Make sure the top of the HIView takes into // account the scroll. t_bounds . top = -t_context -> stack -> getscroll(); t_bounds . right = t_context -> stack -> getrect() . width; t_bounds . bottom = t_context -> stack -> getrect() . height; SetControlBounds((ControlRef)t_context -> view, &t_bounds); t_status = noErr; } break; case kEventHIObjectDestruct: { delete t_context; t_status = noErr; } break; } break; case kEventClassControl: switch(t_event_kind) { case kEventControlInitialize: { t_status = noErr; } break; case kEventControlDraw: { CGContextRef t_graphics; GetEventParameter(p_event, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(CGContextRef), NULL, &t_graphics); RgnHandle t_dirty_rgn; GetEventParameter(p_event, kEventParamRgnHandle, typeQDRgnHandle, NULL, sizeof(RgnHandle), NULL, &t_dirty_rgn); if (t_context -> stack != NULL) { // Compute the clip region for players. RgnHandle t_clip_rgn, t_rect_rgn; t_clip_rgn = NULL; t_rect_rgn = NULL; for(MCPlayer *t_player = MCplayers; t_player != NULL; t_player = t_player -> getnextplayer()) if (t_player -> isvisible() && t_player -> getcard() == t_context -> stack -> getcurcard() && !t_player -> isbuffering()) { MCRectangle t_rect; Rect t_mac_rect; t_rect = t_player -> getactiverect(); if (t_clip_rgn == NULL) { t_clip_rgn = NewRgn(); CopyRgn((RgnHandle)t_dirty_rgn, t_clip_rgn); t_rect_rgn = NewRgn(); } SetRect(&t_mac_rect, t_rect . x, t_rect . y, t_rect . x + t_rect . width, t_rect . y + t_rect . height); RectRgn(t_rect_rgn, &t_mac_rect); DiffRgn(t_clip_rgn, t_rect_rgn, t_clip_rgn); } // We don't need the rect rgn anymore. if (t_rect_rgn != NULL) DisposeRgn(t_rect_rgn); // If the clip region is non-nil, then apply it. if (t_clip_rgn != NULL) { // As we can't clip to empty path, if the region is empty, we set the context // to nil. if (!EmptyRgn(t_clip_rgn)) { HIShapeRef t_shape; t_shape = HIShapeCreateWithQDRgn(t_clip_rgn); HIShapeReplacePathInCGContext(t_shape, t_graphics); CGContextClip(t_graphics); CFRelease(t_shape); } else t_graphics = nil; DisposeRgn(t_clip_rgn); } // If the graphics context is non-nil (i.e. we aren't completely occluded) then // draw something. if (t_graphics != nil) { // HIView gives us a context in top-left origin mode which isn't so good // for our CG rendering so, revert back to bottom-left. CGContextScaleCTM(t_graphics, 1.0, -1.0); CGContextTranslateCTM(t_graphics, 0.0, -t_context -> stack -> getcurcard() -> getrect() . height); // Save the context state CGContextSaveGState(t_graphics); // If we don't have an update pixmap, then use redrawwindow. if (s_update_pixmap == nil) { MCMacStackSurface t_surface(t_context -> stack, (MCRegionRef)t_dirty_rgn, t_graphics); t_context -> stack -> redrawwindow(&t_surface, (MCRegionRef)t_dirty_rgn); } else { int32_t t_height; t_height = t_context -> stack -> getcurcard() -> getrect() . height; MCRectangle t_rect; t_rect = MCRegionGetBoundingBox((MCRegionRef)t_dirty_rgn); CGRect t_area; t_area = CGRectMake(t_rect . x, t_height - (t_rect . y + t_rect . height), t_rect . width, t_rect . height); CGContextClearRect(t_graphics, t_area); void *t_bits; uint32_t t_stride; MCscreen -> lockpixmap(s_update_pixmap, t_bits, t_stride); MCMacRenderBitsToCG(t_graphics, t_area, t_bits, t_stride, t_context -> stack -> getwindowshape() != nil ? true : false); MCscreen -> unlockpixmap(s_update_pixmap, t_bits, t_stride); } // Restore the context state CGContextRestoreGState(t_graphics); } // MW-2011-11-23: [[ Bug ]] Force a redraw of the players on the stack // after we've drawn the rest of the content. This ensures players // which are just appearing don't disappear behind said content. for(MCPlayer *t_player = MCplayers; t_player != NULL; t_player = t_player -> getnextplayer()) if (t_player -> isvisible() && t_player -> getcard() == t_context -> stack -> getcurcard() && !t_player -> isbuffering()) MCDoAction((MovieController)t_player -> getMovieController(), mcActionDraw, t_context -> stack -> getqtwindow()); } t_status = noErr; } break; case kEventControlHitTest: break; case kEventControlGetPartRegion: { ControlPartCode t_part; GetEventParameter(p_event, kEventParamControlPart, typeControlPartCode, NULL, sizeof(ControlPartCode), NULL, &t_part); RgnHandle t_region; GetEventParameter(p_event, kEventParamControlRegion, typeQDRgnHandle, NULL, sizeof(RgnHandle), NULL, &t_region); } break; case kEventControlHiliteChanged: break; case kEventControlActivate: break; case kEventControlDeactivate: break; } break; } return t_status; }