#pragma once #import // 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){ if(!CMTIME_IS_NUMERIC(captured)||!CMTIME_IS_NUMERIC(requested)||captured.epoch!=requested.epoch)return false; int comparison=CMTimeCompare(captured,requested); if(comparison==0)return true; return comparison<0&&CMTIME_IS_NUMERIC(frame)&&frame.value>0&&!frame.epoch&& CMTimeCompare(CMTimeSubtract(requested,captured),frame)<0; } #import // 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 host,CMTime current,CMTime *frameDuration=nullptr){ idtiming=[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); }