45 行
2.9 KiB
Objective-C
45 行
2.9 KiB
Objective-C
#pragma once
|
|
#import <CoreMedia/CoreMedia.h>
|
|
// FCP can expose the exclusive input out point to custom views while its viewer
|
|
// holds the last visible frame. Only that exact boundary has a previous frame.
|
|
static inline CMTime DYScopeDisplayTime(CMTime requested,CMTime start,CMTime duration,CMTime frame){
|
|
if(!CMTIME_IS_NUMERIC(requested)||!CMTIME_IS_NUMERIC(start)||!CMTIME_IS_NUMERIC(duration)||!CMTIME_IS_NUMERIC(frame)||duration.value<=0||frame.value<=0||duration.epoch||frame.epoch)return requested;
|
|
CMTime end=CMTimeAdd(start,duration);if(!CMTIME_IS_NUMERIC(end)||CMTimeCompare(requested,end)!=0)return requested;
|
|
CMTime last=CMTimeSubtract(end,frame);return CMTimeCompare(last,start)<0?start:last;
|
|
}
|
|
|
|
// Custom-view time can land between rendered input frames. A cached frame
|
|
// covers its own interval only; the next frame boundary must get a fresh sample.
|
|
static inline bool DYScopeFrameContainsTime(CMTime captured,CMTime requested,CMTime frame,bool exclusiveEnd){
|
|
if(!CMTIME_IS_NUMERIC(captured)||!CMTIME_IS_NUMERIC(requested)||captured.epoch!=requested.epoch)return false;
|
|
int comparison=CMTimeCompare(captured,requested);
|
|
if(comparison==0)return !exclusiveEnd;
|
|
if(comparison>0||!CMTIME_IS_NUMERIC(frame)||frame.value<=0||frame.epoch)return false;
|
|
CMTime delta=CMTimeSubtract(requested,captured);
|
|
if(exclusiveEnd){
|
|
// FCP holds its last presented project frame at the exclusive clip end.
|
|
// Allow a final project frame as slow as 23.976 even for faster source media.
|
|
return CMTimeCompare(delta,CMTimeMaximum(frame,CMTimeMake(1001,24000)))<=0;
|
|
}
|
|
return CMTimeCompare(delta,frame)<0;
|
|
}
|
|
|
|
#import <FxPlug/FxPlugSDK.h>
|
|
// Caller must already hold a custom parameter action. OSC events keep their
|
|
// provided time; this only normalizes the custom-view clock used to guard them.
|
|
static inline CMTime DYHostDisplayedFrameTime(id<PROAPIAccessing> host,CMTime current,CMTime *frameDuration=nullptr){
|
|
id<FxTimingAPI_v4>timing=[host apiForProtocol:@protocol(FxTimingAPI_v4)];CMTime start=kCMTimeInvalid,duration=kCMTimeInvalid,frame=kCMTimeInvalid;
|
|
if([timing respondsToSelector:@selector(startTimeOfInputToFilter:)]&&[timing respondsToSelector:@selector(durationTimeOfInputToFilter:)]&&[timing respondsToSelector:@selector(frameDuration:)]){[timing startTimeOfInputToFilter:&start];[timing durationTimeOfInputToFilter:&duration];[timing frameDuration:&frame];}
|
|
if(frameDuration)*frameDuration=frame;
|
|
return DYScopeDisplayTime(current,start,duration,frame);
|
|
}
|
|
|
|
// OSC reports the presented frame's start, while a custom view may report a
|
|
// subframe phase inside it (25p footage in a different project timebase, etc.).
|
|
// Accept only that frame's half-open interval; never borrow the next frame.
|
|
static inline bool DYHostDisplaysCanvasFrame(id<PROAPIAccessing> host,CMTime current,CMTime canvas){
|
|
CMTime frame=kCMTimeInvalid;
|
|
CMTime displayed=DYHostDisplayedFrameTime(host,current,&frame);
|
|
return DYScopeFrameContainsTime(canvas,displayed,frame,false);
|
|
}
|