feat: add native on-screen grading controls with isolated live parameter gestures

这个提交包含在:
mac 于 2026-11-04 19:36:25 +08:00 提交
1 父节点 61248ab9f5
当前提交 cc037340bf
16 个文件已更改
+594 -20

没有与搜索条件相匹配的文件

+33
查看文件
@@ -22,3 +22,36 @@
悬停、展开、分页、模块选择属于瞬时 UI 状态,不创建调色参数或撤销项。保留现有蒙版工具条、钢笔与跟踪路由。
证据与验证结果将在对应阶段补充;静态研究不能代替真实宿主交互验证。
## 静态证据
# mFilmLook 3.1.4 屏幕控件静态调查
范围:只读用户指定的 mFilmLook XPC Service,未运行插件,未修改原件。Universal 原件 SHA-256 为 6814e428e99256f23d076c8855f918f9692b8b20f6f7ca5fbc37789bb573a88d;供 Ghidra 12.1.4 使用的 arm64 切片为 b1cee1dffd3b490afa0c22db646404b018a0aaadf70d9a6827e95cb178c74357。所有结论是静态观察或由此推导,未声称宿主运行已验证。
## 可独立实现的交互规范
- 展开和效果启用分离。drawOSC 0x100002988 从 inspectorBarParams 的字符串 0/1 恢复面板显隐,从 inspectorCheckboxParams 恢复效果启用。mouseUp 0x100005724 比较状态,只写回变化。证据 ev_be6866f470c930f3239f4678fa9ed11da79a23143297864c6ada4d44c8196fa2、ev_7ba43ef534545c3c16f1633f4ee7911a343b72289a8ad1ba6e6d86a96d1b12c5。
- 坐标由 FxOnScreenControlAPI_v4 convertPointFromSpace 转换,控件逆矩阵还原局部坐标,带边距矩形命中;隐藏父视图时跳过整个子树。方法 mouseAction 0x1000bdd68、OSCView::getHitElementID 0x10005bd7c / 0x10005bea0。证据 ev_73eedf87215a0cf8da178948205e5ab372ccea33f84d43fe5b1d39d7074973b9、ev_0ba4130d5f30564be2f317cb3353a943f93a64ed039859a973d95250740606a0、ev_b80a7bd65444cae316b421dfe459b0d507d42a2d186233af197680a7c0945390。
- 按下保存起点,任意轴超过 2.0 后置拖动标记;松开补算最后位移。mouseDown 0x1000044b4、mouseDrag 0x10000463c、mouseUp 0x100005724。证据 ev_c67c0a4caf048aaec7fd687416ed7ae81110807b606ff4a94b43ece6e699ef08、ev_889e7b4ee2ff8413b326c083dd336e9d602608f2e4d59a35b398412b9ca671ad、ev_7ba43ef534545c3c16f1633f4ee7911a343b72289a8ad1ba6e6d86a96d1b12c5。
- 滑杆按值域线性映射:t=(value-min)/(max-min),knobX=(t-0.5)*trackWidth,两端夹紧。轨道点击可跳转;拖动实时写宿主 float 参数,松开再收尾。OSCMarkedSlider::mouseDownAction 0x100026a6c、setMoveVec 0x1000267fc、getValue 0x1000269d4、setValue 0x100026a14。证据 ev_76c35a7740fa1b938d07c6a50f0ff0bb76dadbb01218b199ec887681507f75fc、ev_ccc485dc8ea1e56ebe1cfabf017612a379758f9a394255be4c387ce26ecdff6f、ev_661e01277328a90c0cefa7d18df4864e37fe83b25e6cdadd2532124502c1268b、ev_0505d73a7f2d30b301c123b2331d7f5a9f1ef5f22422e2673723f070de23d794。
- 按钮保存按下时的启用/按压状态,释放后清按压。OSCButton::mouseDownAction 0x10006c204、mouseUpAction 0x10006c188。证据 ev_a04295adad17a322579d4478039c8c2693882c767696247fb769f0c2491882a4、ev_f3fd7e86b0686b9ca3468648b46f4130e3950789a9f69c32cc25f77c6a689e7b。
- hover 提示延时常量 0.5 秒,mouseExited 隐藏提示并请求重绘。DisplayTooltipIfNeeded 0x100005e04、mouseExited 0x100005f88。提示证据 ev_113c519048990bee9fc99ad832eeefb84bf611d05442919dd22028b098f5d8b2。
## 未知及移植边界
- 此管理器鼠标路径未读取 modifiers,无 Shift 精细拖动的原版证据。
- IPluginOSCManager::doubleClick 0x1000062b0 只检查约 100ms 时间间隔;未发现双击复位默认值。证据 ev_2b22b07404cc104b0d63f0fa9bd7341f4f3ea6017c00ffd3ae7ea3201ada5bc0。
- 有 startUndo/endUndo 的 FxUndoAPI 包装(0x1000c2de0、0x1000c2e48),但间接调用边界未知,不能声明原版拖动撤销分组已完整确认。建议使用接收工程既有撤销契约。证据 ev_f2e3705b55f0d6e7cc1fa284c30b9bf4e909c88b564c27b98f20f7e83f24cdb6、ev_ae0897bf492fb9c9d49f2eb4dc0f5a499c1bf45f0699f1b2cca6adfb71bd3d22。
- Ghidra 的 arm64 C++/ObjC 参数签名存在错误,主要结论已对照 otool 汇编。未观察 FCP 实际交互。
- 独立重写状态机和布局;原版图标、纹理、资源、二进制、伪源码不进入产品或源码仓库。
REA 已关闭。完整证据为同目录 evidence-bundle.json;同目录另有 analysis-snapshot.json 和 arm64.asm。缓存仅用于调查复核。
## 接收项目适配
画面右上角“画面调色”入口默认收起;展开后可从目录选择现有模块和独立层,参数按可用高度分页。复杂曲线/蜘蛛盘继续使用检查器的原生图形编辑,画面面板提供其已有标量调节,未搬入原版渲染或专有资源。基础调整保留独立的影调、颜色两个启停按钮。展开、选择和页码保留为会话 UI 状态;参考插件的展开参数持久化方式未照搬,以免更改本项目参数/预设合同。
本项目显式增加单项 ↺ 复位;不声称参考插件有双击复位或 Shift 精调。默认值标记、既有浅/深主题、独立图层 UUID 路由与冲突保护均属于项目适配。2 像素门槛按实际绘制比例换算。鼠标移出只清悬停,不中断仍被捕获的滑杆;播放头/节点失效或 OSC 释放会结束写入组。
正式构建前 647 项离屏原生检查通过:20 项桥接、16 项界面状态/边界及原有功能,另包含真实 Metal 蒙版跨面板拖动回归。最终正式安装自检及 FCP 实测结果另记 verification。
+4
查看文件
@@ -21,6 +21,8 @@
#include <cstring>
#include <vector>
#include "DYToolTrackingProbe.inc.h"
#import "DYViewerParameterProbe.h"
#import "DYViewerControlsProbe.h"
// Fake host objects implement the real selectors used by the model and renderer.
// They never connect to a host document or enter the FxPrincipal service loop.
@@ -504,6 +506,8 @@ extern "C" int DYRunDiagnostics(void) { @autoreleasepool {
#include "DYManagedDiagnostics.inc.h"
#include "DYPrimaryDiagnostics.inc.h"
#include "DYCompactUIDiagnostics.inc.h"
#include "DYViewerParameterDiagnostics.inc.h"
#include "DYViewerControlsDiagnostics.inc.h"
[gpu release];
} @catch(NSException *exception) {
run.record(@"diagnostic-exception",false,@{@"exception":exception.name?:@"unknown",@"message":exception.reason?:@"unknown"});
+3 -1
查看文件
@@ -12,6 +12,7 @@
#import <os/log.h>
#include "MaskCore/DYTracker.hpp"
#include <atomic>
#include "DYViewerParameterBridge.inc.h"
#include "DYToolHostDeclarations.inc.h"
#include "DYToolFlow.inc.h"
@implementation DYPlugIn {
@@ -29,7 +30,7 @@
- (NSView*)createViewForParameterID:(UInt32)pid{[self scheduleToolCanvasRegistration];return pid==DYInspectorParameterID?[[DYInspector alloc]initWithAPIManager:_apiManager renderer:_renderer]:[[NSView alloc]initWithFrame:NSZeroRect];}
- (BOOL)parameterChanged:(UInt32)pid atTime:(CMTime)t error:(NSError**)e{if(pid==DYToolsParameterID)[self adoptToolCanvasDocument:DYReadTools(_apiManager,t).document];if(pid==DYToolsParameterID||pid==2013||pid==2014||(pid>=2236&&pid<2400)||pid==DYAssetsParameterID)[_renderer invalidatePreview];dispatch_async(dispatch_get_main_queue(),^{[NSNotificationCenter.defaultCenter postNotificationName:DYModelChanged object:self.apiManager];});return YES;}
- (BOOL)pluginState:(NSData**)state atTime:(CMTime)t quality:(FxQuality)q error:(NSError**)e{
DYUniforms u;DYReadUniforms(_apiManager,t,&u);CMTime frameDuration=kCMTimeInvalid,origin=kCMTimeZero;id<FxTimingAPI_v4>timing=[_apiManager apiForProtocol:@protocol(FxTimingAPI_v4)];if([timing respondsToSelector:@selector(frameDuration:)])[timing frameDuration:&frameDuration];if([timing respondsToSelector:@selector(startTimeForEffect:)])[timing startTimeForEffect:&origin];int64_t frame=DYFilmFrameIndex(t,frameDuration,origin);u.filmFrameKey=DYFilmFrameKey(frame,u.film.grainHold,u.film.grainSeed);DYAssetState*a=DYReadAssets(_apiManager,t);DYToolDocument *tools=DYReadTools(_apiManager,t);[self adoptToolCanvasDocument:tools.document];double copyAuto=0;[[_apiManager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)]getFloatValue:&copyAuto fromParameter:8800 atTime:t];NSMutableDictionary *snapshot=DYMutablePlist(DYToolRenderSnapshot(tools.document,t));for(NSMutableDictionary *node in snapshot[@"layers"]){DYUniforms layer=DYToolUniforms(node);if([node[@"type"]isEqual:@"film"])node[@"filmFrameKey"]=@(DYFilmFrameKey(frame,layer.film.grainHold,layer.film.grainSeed));}NSInteger primaries=-1;id<FxColorGamutAPI_v2>gamut=[_apiManager apiForProtocol:@protocol(FxColorGamutAPI_v2)];if([gamut respondsToSelector:@selector(colorPrimaries)])primaries=gamut.colorPrimaries;NSDictionary*s=@{@"colorManagement":a.colorManagement?:@{},@"hostPrimaries":@(primaries),@"schema":@2,@"tools":snapshot,@"copyAuto":@(copyAuto>.5),@"uniforms":[NSData dataWithBytes:&u length:sizeof(u)],@"paths":a.paths?:@{},@"spider":a.spiderMesh?:[NSData data]};*state=[NSPropertyListSerialization dataWithPropertyList:s format:NSPropertyListBinaryFormat_v1_0 options:0 error:e];return *state!=nil;
DYUniforms u;DYReadUniforms(_apiManager,t,&u);CMTime frameDuration=kCMTimeInvalid,origin=kCMTimeZero;id<FxTimingAPI_v4>timing=[_apiManager apiForProtocol:@protocol(FxTimingAPI_v4)];if([timing respondsToSelector:@selector(frameDuration:)])[timing frameDuration:&frameDuration];if([timing respondsToSelector:@selector(startTimeForEffect:)])[timing startTimeForEffect:&origin];int64_t frame=DYFilmFrameIndex(t,frameDuration,origin);u.filmFrameKey=DYFilmFrameKey(frame,u.film.grainHold,u.film.grainSeed);DYAssetState*a=DYReadAssets(_apiManager,t);DYToolDocument *tools=DYReadTools(_apiManager,t);[self adoptToolCanvasDocument:tools.document];[_viewerParameterBridge publishUniforms:&u document:tools.document atTime:t];double copyAuto=0;[[_apiManager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)]getFloatValue:&copyAuto fromParameter:8800 atTime:t];NSMutableDictionary *snapshot=DYMutablePlist(DYToolRenderSnapshot(tools.document,t));for(NSMutableDictionary *node in snapshot[@"layers"]){DYUniforms layer=DYToolUniforms(node);if([node[@"type"]isEqual:@"film"])node[@"filmFrameKey"]=@(DYFilmFrameKey(frame,layer.film.grainHold,layer.film.grainSeed));}NSInteger primaries=-1;id<FxColorGamutAPI_v2>gamut=[_apiManager apiForProtocol:@protocol(FxColorGamutAPI_v2)];if([gamut respondsToSelector:@selector(colorPrimaries)])primaries=gamut.colorPrimaries;NSDictionary*s=@{@"colorManagement":a.colorManagement?:@{},@"hostPrimaries":@(primaries),@"schema":@2,@"tools":snapshot,@"copyAuto":@(copyAuto>.5),@"uniforms":[NSData dataWithBytes:&u length:sizeof(u)],@"paths":a.paths?:@{},@"spider":a.spiderMesh?:[NSData data]};*state=[NSPropertyListSerialization dataWithPropertyList:s format:NSPropertyListBinaryFormat_v1_0 options:0 error:e];return *state!=nil;
}
- (BOOL)destinationImageRect:(FxRect*)rect sourceImages:(NSArray<FxImageTile*>*)src destinationImage:(FxImageTile*)dst pluginState:(NSData*)s atTime:(CMTime)t error:(NSError**)e{if(!src.count)return NO;*rect=src[0].imagePixelBounds;return YES;}
- (BOOL)sourceTileRect:(FxRect*)rect sourceImageIndex:(NSUInteger)i sourceImages:(NSArray<FxImageTile*>*)src destinationTileRect:(FxRect)dstRect destinationImage:(FxImageTile*)dst pluginState:(NSData*)s atTime:(CMTime)t error:(NSError**)e{if(i>=src.count)return NO;*rect=src[i].imagePixelBounds;return YES;}
@@ -44,4 +45,5 @@
- (void)autoRequested:(NSNotification*)n{NSData*frame=[_renderer preview];[self applyValues:[n.name isEqual:@"DYAutoGrade"]?DYAutoGrade(frame):DYAutoWhiteBalance(frame)];}
- (void)whiteBalanceRequested:(NSNotification*)n{NSColor*c=[n.userInfo[@"color"]colorUsingColorSpace:NSColorSpace.sRGBColorSpace];if(!c)return;float temp=0,tint=0;if([DYColorTables neutralizeColor:(vector_float3){(float)c.redComponent,(float)c.greenComponent,(float)c.blueComponent} temperature:&temp tint:&tint])[self applyValues:@{@"temperature":@(temp),@"tint":@(tint)}];else [self alert:@"所选颜色过暗,请选择白色或中性灰区域。"];}
@end
#include "DYViewerControls.inc.h"
#include "DYToolOSC.inc.h"
@@ -10,3 +10,17 @@
int undo=base->_undoStarts;BOOL update=NO;[osc mouseDownAtPositionX:320 positionY:212.5 activePart:1 modifiers:0 forceUpdate:&update atTime:kCMTimeZero];[osc mouseDraggedAtPositionX:348 positionY:196.75 activePart:1 modifiers:0 forceUpdate:&update atTime:kCMTimeZero];[osc mouseUpAtPositionX:348 positionY:196.75 activePart:1 modifiers:0 forceUpdate:&update atTime:kCMTimeZero];drain();NSDictionary *moved=DYReadTools(base,kCMTimeZero).document[@"baseMasks"][@"hsl"][0];DYMaskParameters p=DYMaskAtTime(moved,kCMTimeZero);run.record(@"native-osc-drag-writes-independent-normalized-geometry",fabs(p.centerX-.55)<1e-5&&fabs(p.centerY-.55)<1e-5,@{@"x":@(p.centerX),@"y":@(p.centerY)});run.record(@"native-osc-drag-commits-one-undo-after-callback",base->_undoStarts==undo+1&&base->_undoStarts==base->_undoEnds);
NSDictionary *before=[DYReadTools(base,kCMTimeZero).document copy];[plugin adoptToolCanvasDocument:before];[osc mouseDownAtPositionX:348 positionY:196.75 activePart:1 modifiers:0 forceUpdate:&update atTime:kCMTimeZero];[osc mouseDraggedAtPositionX:370 positionY:180 activePart:1 modifiers:0 forceUpdate:&update atTime:kCMTimeZero];BOOL handled=NO;[osc keyDownAtPositionX:370 positionY:180 keyPressed:27 modifiers:0 forceUpdate:&update didHandle:&handled atTime:kCMTimeZero];drain();run.record(@"native-osc-escape-discards-draft-without-host-edit",[before isEqual:DYReadTools(base,kCMTimeZero).document]&&base->_undoStarts==undo+1);[before release];[osc release];[plugin release];
}
{
DYDiagnosticManager*base=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(base,&error);DYToolCanvasProbe*host=[[[DYToolCanvasProbe alloc]init]autorelease];host->_base=base;host->_time=kCMTimeZero;
NSMutableDictionary*doc=DYMutablePlist(DYReadTools(base,kCMTimeZero).document);NSDictionary*mask=DYNewMask(DYMaskRectangle);doc[@"baseMasks"][@"hsl"]=[NSMutableArray arrayWithObject:mask];DYWriteTools(base,doc,kCMTimeZero);
id<DYToolCanvasHostProbe>plugin=(id)[[NSClassFromString(@"DYPlugIn")alloc]initWithAPIManager:host];[plugin scheduleToolCanvasRegistration];NSData*state=nil;[plugin pluginState:&state atTime:kCMTimeZero quality:(FxQuality)0 error:&error];
auto drain=[](){double end=NSProcessInfo.processInfo.systemUptime+.06;while(NSProcessInfo.processInfo.systemUptime<end)[[NSRunLoop mainRunLoop]runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:.002]];};drain();
id<FxOnScreenControl_v4>osc=(id)[[NSClassFromString(@"DYToolOSC")alloc]initWithAPIManager:host];DYDiagnosticTile*overlay=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:640 height:400]autorelease];[osc drawOSCWithWidth:640 height:400 activePart:0 destinationImage:overlay atTime:kCMTimeZero];BOOL update=NO;NSInteger part=0;
[osc hitTestOSCAtMousePositionX:480 mousePositionY:375 activePart:&part atTime:kCMTimeZero];[osc mouseDownAtPositionX:480 positionY:375 activePart:part modifiers:0 forceUpdate:&update atTime:kCMTimeZero];[osc mouseUpAtPositionX:480 positionY:375 activePart:part modifiers:0 forceUpdate:&update atTime:kCMTimeZero];
[osc drawOSCWithWidth:640 height:400 activePart:0 destinationImage:overlay atTime:kCMTimeZero];int undo=base->_undoStarts;
[osc hitTestOSCAtMousePositionX:320 mousePositionY:212.5 activePart:&part atTime:kCMTimeZero];[osc mouseDownAtPositionX:320 positionY:212.5 activePart:part modifiers:0 forceUpdate:&update atTime:kCMTimeZero];
[osc hitTestOSCAtMousePositionX:450 mousePositionY:200 activePart:&part atTime:kCMTimeZero];BOOL insideViewer=part>=20000;[osc mouseDraggedAtPositionX:450 positionY:200 activePart:part modifiers:0 forceUpdate:&update atTime:kCMTimeZero];[osc mouseUpAtPositionX:450 positionY:200 activePart:part modifiers:0 forceUpdate:&update atTime:kCMTimeZero];drain();
DYMaskParameters p=DYMaskAtTime(DYReadTools(base,kCMTimeZero).document[@"baseMasks"][@"hsl"][0],kCMTimeZero);
run.record(@"native-osc-mask-gesture-keeps-capture-when-crossing-the-open-viewer-panel",insideViewer&&fabs(p.centerX-(.5+130./560))<1e-5&&fabs(p.centerY-(.5+12.5/315))<1e-5&&base->_undoStarts==undo+1&&base->_undoEnds==undo+1);
[osc release];[plugin release];drain();
}
@@ -1,6 +1,7 @@
@class DYPlugIn;
static NSMapTable *DYToolCanvasSessions(void){static NSMapTable *map;static dispatch_once_t once;dispatch_once(&once,^{map=[[NSMapTable strongToWeakObjectsMapTable]retain];});return map;}
@interface DYPlugIn (ToolCanvas)
- (DYViewerParameterBridge*)viewerParameterBridge;
- (NSDictionary*)toolCanvasMaskAtTime:(CMTime)time;
- (void)toolCanvasEvent:(NSEventType)type point:(NSPoint)point part:(NSInteger)part modifiers:(FxModifierKeys)modifiers key:(unichar)key time:(CMTime)time;
- (BOOL)toolCanvasVisible;
@@ -1,4 +1,5 @@
NSString *_toolSession,*_selectedToolNode,*_selectedToolMask;
DYViewerParameterBridge *_viewerParameterBridge;
NSTimer *_toolAnalysisTimer;
BOOL _toolCaptureEnabled,_toolCanvasHidden,_toolDrawingPen,_toolShowCoverage,_toolCanvasCommitPending;
NSMutableDictionary *_toolCanvasDraft,*_toolCanvasOriginal;NSDictionary *_toolCanvasDocument;
@@ -1,8 +1,10 @@
- (void)initializeToolHost {
_viewerParameterBridge=[[DYViewerParameterBridge alloc]initWithAPIManager:_apiManager];
_toolCaptureDevices=[NSMutableDictionary new];_toolCanvasDocument=[[[[DYToolDocument alloc]init]autorelease].document copy];_toolSourceTime=kCMTimeInvalid;_toolCanvasEditTime=kCMTimeInvalid;
NSNotificationCenter *n=NSNotificationCenter.defaultCenter;[n addObserver:self selector:@selector(toolCanvasSelection:) name:@"DYToolCanvasSelection" object:_apiManager];[n addObserver:self selector:@selector(toolCanvasCommand:) name:@"DYToolCanvasCommand" object:_apiManager];[n addObserver:self selector:@selector(toolTrackRequested:) name:@"DYToolTrack" object:_apiManager];
}
- (void)tearDownToolHost {
[_viewerParameterBridge invalidate];[_viewerParameterBridge release];_viewerParameterBridge=nil;
[_toolAnalysisTimer invalidate];[_toolAnalysisTimer release];@synchronized(DYToolCanvasSessions()){if(_toolSession)[DYToolCanvasSessions()removeObjectForKey:_toolSession];}
[_toolCanvasDocument release];[_toolSession release];[_selectedToolNode release];[_selectedToolMask release];[_toolCanvasDraft release];[_toolCanvasOriginal release];[_trackingNode release];[_trackingMaskID release];[_trackingFrozenMask release];[_trackingCandidate release];[_trackingSamples release];[_trackingMessage release];[_toolCaptureDevices release];
}
@@ -28,6 +30,7 @@
@synchronized(self){if(_trackingActive.load()&&(![_trackingNode isEqual:node]||![_trackingMaskID isEqual:mask])){_trackingCancelled.store(true);_trackingDiscard=YES;}[_selectedToolNode release];_selectedToolNode=[node copy];[_selectedToolMask release];_selectedToolMask=[mask copy];_toolCanvasHidden=[notification.userInfo[@"hidden"]boolValue];_toolDrawingPen=[notification.userInfo[@"draw"]boolValue];++_toolCanvasRevision;_toolCanvasEditTime=kCMTimeInvalid;_toolDragPart=0;_toolCanvasHasHover=NO;[_toolCanvasDraft release];_toolCanvasDraft=nil;[_toolCanvasOriginal release];_toolCanvasOriginal=nil;}[self postToolCanvasStatus:_toolDrawingPen?@"钢笔:点击放点,拖出曲柄;点首节点或完成绘制闭合。":@"已选中本层蒙版"];
}
- (BOOL)toolCanvasVisible {@synchronized(self){return _selectedToolNode&&_selectedToolMask&&!_toolCanvasHidden;}}
- (DYViewerParameterBridge*)viewerParameterBridge{return _viewerParameterBridge;}
- (NSDictionary*)toolCanvasMaskAtTime:(CMTime)time {
@synchronized(self){if(_toolCanvasHidden||!_selectedToolMask)return nil;NSDictionary *m=_toolCanvasDraft?:[self toolMask:_selectedToolMask node:_selectedToolNode document:_toolCanvasDocument];if(!m)return nil;DYMaskParameters p=DYMaskAtTime(m,time);return @{@"id":m[@"id"],@"parameters":[NSData dataWithBytes:&p length:sizeof(p)],@"nodes":(_toolDrawingPen&&!_toolCanvasDraft)?[NSData data]:(m[@"nodes"]?:[NSData data]),@"drawing":@(_toolDrawingPen),@"hover":(_toolDrawingPen&&_toolCanvasHasHover)?@[@(_toolCanvasHoverPoint.x),@(_toolCanvasHoverPoint.y)]:@[],@"coverage":@(_toolShowCoverage)};}
}
+19 -14
查看文件
@@ -4,10 +4,10 @@
@end
@implementation DYToolOSC {
id<MTLDevice> _device;id<MTLCommandQueue> _queue;CIContext *_context;
CGFloat _height,_uiScale;NSInteger _toolbarRows;NSRect _imageRect;NSDictionary *_mask;NSMutableArray *_handles;NSBezierPath *_outline;NSInteger _lastRoute;NSUInteger _drawCount,_hitDiagnostics,_eventDiagnostics;
DYViewerControls *_viewerControls;CGFloat _height,_canvasWidth,_uiScale;NSInteger _toolbarRows;NSRect _imageRect;NSDictionary *_mask;NSMutableArray *_handles;NSBezierPath *_outline;NSInteger _lastRoute;NSUInteger _drawCount,_hitDiagnostics,_eventDiagnostics;
}
- (instancetype)initWithAPIManager:(id<PROAPIAccessing>)manager{if((self=[super init])){_apiManager=manager;_handles=[NSMutableArray new];_lastRoute=-1;_uiScale=1;_toolbarRows=9;os_log(OS_LOG_DEFAULT,"dayu_tool_osc_init");}return self;}
- (void)dealloc{[_device release];[_queue release];[_context release];[_mask release];[_handles release];[_outline release];[super dealloc];}
- (instancetype)initWithAPIManager:(id<PROAPIAccessing>)manager{if((self=[super init])){_apiManager=manager;_viewerControls=[DYViewerControls new];_handles=[NSMutableArray new];_lastRoute=-1;_uiScale=1;_toolbarRows=9;os_log(OS_LOG_DEFAULT,"dayu_tool_osc_init");}return self;}
- (void)dealloc{[_viewerControls release];[_device release];[_queue release];[_context release];[_mask release];[_handles release];[_outline release];[super dealloc];}
- (FxDrawingCoordinates)drawingCoordinates{return kFxDrawingCoordinates_CANVAS;}
- (DYPlugIn*)pluginAtTime:(CMTime)time{NSString *value=nil;id<FxParameterRetrievalAPI_v6>get=[_apiManager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];[get getStringParameterValue:&value fromParameter:DYCanvasSessionParameterID];@synchronized(DYToolCanvasSessions()){return [DYToolCanvasSessions()objectForKey:value];}}
- (NSPoint)canvasPoint:(float)x y:(float)y parameters:(DYMaskParameters)p{
@@ -18,14 +18,15 @@
- (void)drawOSCWithWidth:(NSInteger)width height:(NSInteger)height activePart:(NSInteger)activePart destinationImage:(FxImageTile*)destination atTime:(CMTime)time {@synchronized(self){@autoreleasepool{
if(!_device||_device.registryID!=destination.deviceRegistryID){[_device release];_device=nil;NSArray *devices=MTLCopyAllDevices();for(id<MTLDevice>d in devices)if(d.registryID==destination.deviceRegistryID)_device=[d retain];[devices release];[_queue release];_queue=[_device newCommandQueue];[_context release];_context=_device?[[CIContext contextWithMTLDevice:_device options:@{kCIContextWorkingColorSpace:NSNull.null,kCIContextOutputColorSpace:NSNull.null}]retain]:nil;}
id<MTLTexture>texture=[destination metalTextureForDevice:_device];if(!texture||!_queue)return;id<MTLCommandBuffer>commands=[_queue commandBuffer];MTLRenderPassDescriptor *pass=[MTLRenderPassDescriptor renderPassDescriptor];pass.colorAttachments[0].texture=texture;pass.colorAttachments[0].loadAction=MTLLoadActionClear;pass.colorAttachments[0].storeAction=MTLStoreActionStore;pass.colorAttachments[0].clearColor=MTLClearColorMake(0,0,0,0);id<MTLRenderCommandEncoder>encoder=[commands renderCommandEncoderWithDescriptor:pass];[encoder endEncoding];
_height=destination.imagePixelBounds.top-destination.imagePixelBounds.bottom;CGFloat canvasWidth=destination.imagePixelBounds.right-destination.imagePixelBounds.left;
_height=destination.imagePixelBounds.top-destination.imagePixelBounds.bottom;CGFloat canvasWidth=destination.imagePixelBounds.right-destination.imagePixelBounds.left;_canvasWidth=canvasWidth;
id<FxOnScreenControlAPI_v4>api=[_apiManager apiForProtocol:@protocol(FxOnScreenControlAPI_v4)];double lx=0,ly=0,ux=0,uy=0;[api convertPointFromSpace:kFxDrawingCoordinates_OBJECT fromX:0 fromY:0 toSpace:kFxDrawingCoordinates_CANVAS toX:&lx toY:&ly];[api convertPointFromSpace:kFxDrawingCoordinates_OBJECT fromX:1 fromY:1 toSpace:kFxDrawingCoordinates_CANVAS toX:&ux toY:&uy];_imageRect=NSMakeRect(lx,_height-uy,ux-lx,uy-ly);_uiScale=[api respondsToSelector:@selector(backingScaleFactor)]?MAX(1.,MIN(3.,[api backingScaleFactor])):1.;_toolbarRows=MAX(1,MIN(11,(NSInteger)floor((_height-MAX(8*_uiScale,_imageRect.origin.y+12*_uiScale)-8*_uiScale)/(39*_uiScale))));
DYPlugIn *plugin=[self pluginAtTime:time];NSDictionary *mask=[plugin toolCanvasMaskAtTime:time];NSInteger route=(plugin?1:0)+(mask?2:0);if(route!=_lastRoute||_drawCount++<2){_lastRoute=route;os_log(OS_LOG_DEFAULT,"dayu_tool_osc_route plugin=%{public}d mask=%{public}d width=%{public}.2f height=%{public}.2f",plugin!=nil,mask!=nil,_imageRect.size.width,_imageRect.size.height);}[_mask release];_mask=[mask copy];[_handles removeAllObjects];[_outline release];_outline=nil;
if(mask&&canvasWidth>0&&_height>0&&canvasWidth<16384&&_height<16384&&_imageRect.size.width>0&&_imageRect.size.height>0){
[_viewerControls setBridge:[plugin viewerParameterBridge]];[_viewerControls prepareWithSize:NSMakeSize(canvasWidth,_height) scale:_uiScale atTime:time];
if(plugin&&canvasWidth>0&&_height>0&&canvasWidth<16384&&_height<16384&&_imageRect.size.width>0&&_imageRect.size.height>0){
NSBitmapImageRep *bitmap=[[[NSBitmapImageRep alloc]initWithBitmapDataPlanes:NULL pixelsWide:(NSInteger)canvasWidth pixelsHigh:(NSInteger)_height bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:(NSInteger)canvasWidth*4 bitsPerPixel:32]autorelease];memset(bitmap.bitmapData,0,bitmap.bytesPerRow*bitmap.pixelsHigh);[NSGraphicsContext saveGraphicsState];[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:bitmap]];NSAffineTransform *flip=[NSAffineTransform transform];[flip translateXBy:0 yBy:_height];[flip scaleXBy:1 yBy:-1];[flip concat];
// Match AppKit text/image drawing to the top-down canvas CTM.
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithCGContext:NSGraphicsContext.currentContext.CGContext flipped:YES]];
DYMaskParameters p;[mask[@"parameters"]getBytes:&p length:sizeof(p)];p.imageAspect=_imageRect.size.width/_imageRect.size.height;_outline=[[NSBezierPath bezierPath]retain];
if(mask){DYMaskParameters p;[mask[@"parameters"]getBytes:&p length:sizeof(p)];p.imageAspect=_imageRect.size.width/_imageRect.size.height;_outline=[[NSBezierPath bezierPath]retain];
if(p.kind==DYMaskBezier){NSData *data=mask[@"nodes"];auto *nodes=(const DYBezierNode*)data.bytes;NSUInteger count=data.length/sizeof(DYBezierNode);for(NSUInteger i=0;i<count;i++){NSPoint anchor=[self canvasPoint:nodes[i].x y:nodes[i].y parameters:p];if(i==0)[_outline moveToPoint:anchor];else{auto a=nodes[i-1],b=nodes[i];[_outline curveToPoint:anchor controlPoint1:[self canvasPoint:a.outX y:a.outY parameters:p] controlPoint2:[self canvasPoint:b.inX y:b.inY parameters:p]];}[self addHandle:anchor part:1000+i*3];for(int j=0;j<2;j++){NSPoint handle=[self canvasPoint:j?nodes[i].outX:nodes[i].inX y:j?nodes[i].outY:nodes[i].inY parameters:p];if(hypot(handle.x-anchor.x,handle.y-anchor.y)>3){NSBezierPath *line=[NSBezierPath bezierPath];[line moveToPoint:anchor];[line lineToPoint:handle];[[NSColor colorWithWhite:1 alpha:.55]setStroke];[line stroke];[self addHandle:handle part:1000+i*3+j+1];}}}
NSArray *hover=mask[@"hover"];if(count&&[mask[@"drawing"]boolValue]&&hover.count==2){NSPoint target=NSMakePoint(_imageRect.origin.x+[hover[0]doubleValue]*_imageRect.size.width,_imageRect.origin.y+[hover[1]doubleValue]*_imageRect.size.height);[_outline curveToPoint:target controlPoint1:[self canvasPoint:nodes[count-1].outX y:nodes[count-1].outY parameters:p] controlPoint2:target];}
if(count>=3&&![mask[@"drawing"]boolValue]){auto a=nodes[count-1],b=nodes[0];[_outline curveToPoint:[self canvasPoint:b.x y:b.y parameters:p] controlPoint1:[self canvasPoint:a.outX y:a.outY parameters:p] controlPoint2:[self canvasPoint:b.inX y:b.inY parameters:p]];[_outline closePath];}
@@ -39,26 +40,30 @@
NSInteger buttonCount=[mask[@"drawing"]boolValue]?11:9;
for(NSInteger i=0;i<buttonCount;i++){NSRect cell=[self toolbarRectForItem:i];BOOL active=(i==1&&[mask[@"drawing"]boolValue])||(i==0&&![mask[@"drawing"]boolValue]);[[NSColor colorWithCalibratedRed:active?.08:.12 green:active?.34:.12 blue:active?.58:.12 alpha:.94]setFill];[[NSBezierPath bezierPathWithRoundedRect:cell xRadius:5*_uiScale yRadius:5*_uiScale]fill];NSImage *icon=[NSImage imageWithSystemSymbolName:symbols[i] accessibilityDescription:nil];icon=[icon imageWithSymbolConfiguration:[NSImageSymbolConfiguration configurationWithPaletteColors:@[NSColor.whiteColor]]];[icon drawInRect:NSInsetRect(cell,7*_uiScale,7*_uiScale) fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1 respectFlipped:YES hints:nil];}
if([mask[@"drawing"]boolValue]){NSRect hint=NSMakeRect(MAX(12*_uiScale,_imageRect.origin.x+12*_uiScale),MIN(_height-36*_uiScale,NSMaxY(_imageRect)-36*_uiScale),MIN(460*_uiScale,canvasWidth-24*_uiScale),28*_uiScale);[[NSColor colorWithWhite:.08 alpha:.9]setFill];[[NSBezierPath bezierPathWithRoundedRect:hint xRadius:5*_uiScale yRadius:5*_uiScale]fill];[@"钢笔:点击放点,拖出曲柄;点首节点或 ✓ 闭合" drawInRect:NSInsetRect(hint,7*_uiScale,5*_uiScale) withAttributes:@{NSFontAttributeName:[NSFont systemFontOfSize:12*_uiScale],NSForegroundColorAttributeName:NSColor.whiteColor}];}
}[_viewerControls draw];
[NSGraphicsContext restoreGraphicsState];CIImage *overlay=[CIImage imageWithCGImage:bitmap.CGImage options:@{kCIImageColorSpace:NSNull.null}];overlay=[overlay imageByApplyingTransform:CGAffineTransformMakeTranslation(0,texture.height-_height)];[_context render:overlay toMTLTexture:texture commandBuffer:commands bounds:CGRectMake(0,0,texture.width,texture.height) colorSpace:nil];
}[commands commit];[commands waitUntilCompleted];
}}}
- (NSInteger)partAtPoint:(NSPoint)point {
NSInteger viewerHit=[_viewerControls partAtPoint:point];if(viewerHit)return viewerHit;
if(!_mask)return 0;BOOL drawing=[_mask[@"drawing"]boolValue];for(NSInteger i=0;i<(drawing?11:9);i++)if(NSPointInRect(point,[self toolbarRectForItem:i]))return 10000+i;
DYMaskParameters p;[_mask[@"parameters"]getBytes:&p length:sizeof(p)];p.imageAspect=_imageRect.size.width/MAX(1.,_imageRect.size.height);
if(drawing){NSData *data=_mask[@"nodes"];if(data.length>=3*sizeof(DYBezierNode)){const DYBezierNode *nodes=(const DYBezierNode*)data.bytes;NSPoint first=[self canvasPoint:nodes[0].x y:nodes[0].y parameters:p];if(hypot(point.x-first.x,point.y-first.y)<=10*_uiScale)return 1000;}return NSPointInRect(point,_imageRect)?1:0;}
for(NSDictionary *h in _handles){NSPoint q=[h[@"point"]pointValue];if(hypot(q.x-point.x,q.y-point.y)<=9*_uiScale)return [h[@"part"]integerValue];}
if(p.kind==DYMaskBezier||p.kind==DYMaskLinearGradient||[_outline containsPoint:point])return 1;return 0;
}
- (void)hitTestOSCAtMousePositionX:(double)x mousePositionY:(double)y activePart:(NSInteger*)part atTime:(CMTime)time{@synchronized(self){NSDictionary *fresh=[[self pluginAtTime:time]toolCanvasMaskAtTime:time];[_mask release];_mask=[fresh copy];NSInteger hit=[self partAtPoint:NSMakePoint(x,_height-y)];if(part)*part=hit;if(_hitDiagnostics++<16)os_log(OS_LOG_DEFAULT,"dayu_tool_osc_hit x=%{public}.2f y=%{public}.2f height=%{public}.2f rect=%{public}.2f,%{public}.2f,%{public}.2f,%{public}.2f mask=%{public}d hit=%{public}ld",x,y,_height,_imageRect.origin.x,_imageRect.origin.y,_imageRect.size.width,_imageRect.size.height,_mask!=nil,(long)hit);}}
- (void)hitTestOSCAtMousePositionX:(double)x mousePositionY:(double)y activePart:(NSInteger*)part atTime:(CMTime)time{@synchronized(self){DYPlugIn*plugin=[self pluginAtTime:time];[_viewerControls setBridge:[plugin viewerParameterBridge]];[_viewerControls prepareWithSize:NSMakeSize(_canvasWidth,_height) scale:_uiScale atTime:time];NSDictionary *fresh=[plugin toolCanvasMaskAtTime:time];[_mask release];_mask=[fresh copy];NSInteger hit=[self partAtPoint:NSMakePoint(x,_height-y)];if(part)*part=hit;if(_hitDiagnostics++<16)os_log(OS_LOG_DEFAULT,"dayu_tool_osc_hit x=%{public}.2f y=%{public}.2f height=%{public}.2f rect=%{public}.2f,%{public}.2f,%{public}.2f,%{public}.2f mask=%{public}d hit=%{public}ld",x,y,_height,_imageRect.origin.x,_imageRect.origin.y,_imageRect.size.width,_imageRect.size.height,_mask!=nil,(long)hit);}}
- (BOOL)event:(NSEventType)type x:(double)x y:(double)y part:(NSInteger)part modifiers:(FxModifierKeys)modifiers key:(unichar)key time:(CMTime)time {@synchronized(self){
DYPlugIn *plugin=[self pluginAtTime:time];if(_eventDiagnostics++<12)os_log(OS_LOG_DEFAULT,"dayu_tool_osc_event type=%{public}ld part=%{public}ld x=%{public}.2f y=%{public}.2f plugin=%{public}d",(long)type,(long)part,x,y,plugin!=nil);if(!plugin||![plugin toolCanvasVisible]||_imageRect.size.width<=0||_imageRect.size.height<=0)return NO;NSPoint point=NSMakePoint((x-_imageRect.origin.x)/_imageRect.size.width,(_height-y-_imageRect.origin.y)/_imageRect.size.height);[plugin toolCanvasEvent:type point:point part:part modifiers:modifiers key:key time:time];return YES;
DYPlugIn *plugin=[self pluginAtTime:time];if(_eventDiagnostics++<12)os_log(OS_LOG_DEFAULT,"dayu_tool_osc_event type=%{public}ld part=%{public}ld x=%{public}.2f y=%{public}.2f plugin=%{public}d",(long)type,(long)part,x,y,plugin!=nil);[_viewerControls setBridge:[plugin viewerParameterBridge]];[_viewerControls prepareWithSize:NSMakeSize(_canvasWidth,_height) scale:_uiScale atTime:time];NSPoint canvasPoint=NSMakePoint(x,_height-y);if(type==NSEventTypeKeyDown&&key==27&&[_viewerControls capturing])return [_viewerControls finishCapture];if(type!=NSEventTypeKeyDown&&[_viewerControls event:type point:canvasPoint atTime:time])return YES;if(!plugin||![plugin toolCanvasVisible]||_imageRect.size.width<=0||_imageRect.size.height<=0)return NO;NSPoint point=NSMakePoint((x-_imageRect.origin.x)/_imageRect.size.width,(_height-y-_imageRect.origin.y)/_imageRect.size.height);[plugin toolCanvasEvent:type point:point part:part modifiers:modifiers key:key time:time];return YES;
}}
- (void)mouseDownAtPositionX:(double)x positionY:(double)y activePart:(NSInteger)part modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update atTime:(CMTime)t{if(update)*update=[self event:NSEventTypeLeftMouseDown x:x y:y part:part modifiers:m key:0 time:t];}
- (void)mouseDraggedAtPositionX:(double)x positionY:(double)y activePart:(NSInteger)part modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update atTime:(CMTime)t{if(update)*update=[self event:NSEventTypeLeftMouseDragged x:x y:y part:part modifiers:m key:0 time:t];}
- (void)mouseUpAtPositionX:(double)x positionY:(double)y activePart:(NSInteger)part modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update atTime:(CMTime)t{if(update)*update=[self event:NSEventTypeLeftMouseUp x:x y:y part:part modifiers:m key:0 time:t];}
- (void)mouseDownAtPositionX:(double)x positionY:(double)y activePart:(NSInteger)part modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update atTime:(CMTime)t{BOOL result=[self event:NSEventTypeLeftMouseDown x:x y:y part:part modifiers:m key:0 time:t];if(update)*update=result;}
- (void)mouseDraggedAtPositionX:(double)x positionY:(double)y activePart:(NSInteger)part modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update atTime:(CMTime)t{BOOL result=[self event:NSEventTypeLeftMouseDragged x:x y:y part:part modifiers:m key:0 time:t];if(update)*update=result;}
- (void)mouseUpAtPositionX:(double)x positionY:(double)y activePart:(NSInteger)part modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update atTime:(CMTime)t{BOOL result=[self event:NSEventTypeLeftMouseUp x:x y:y part:part modifiers:m key:0 time:t];if(update)*update=result;}
- (void)keyDownAtPositionX:(double)x positionY:(double)y keyPressed:(unsigned short)key modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update didHandle:(BOOL*)handled atTime:(CMTime)t{BOOL result=(key==27||key==13||key==10||key==3||key==8||key==127)&&[self event:NSEventTypeKeyDown x:x y:y part:1 modifiers:m key:key time:t];if(update)*update=result;if(handled)*handled=result;}
- (void)mouseMovedAtPositionX:(double)x positionY:(double)y activePart:(NSInteger)part modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update atTime:(CMTime)t{NSDictionary *mask=[[self pluginAtTime:t]toolCanvasMaskAtTime:t];BOOL drawing=[mask[@"drawing"]boolValue];NSCursor *cursor=part>=10000?NSCursor.pointingHandCursor:(drawing||part>=1000)?NSCursor.crosshairCursor:part?NSCursor.openHandCursor:NSCursor.arrowCursor;[[_apiManager apiForProtocol:@protocol(FxOnScreenControlAPI_v4)]setCursor:cursor];if(drawing)[self event:NSEventTypeMouseMoved x:x y:y part:part modifiers:m key:0 time:t];if(update)*update=drawing;}
- (void)mouseEnteredAtPositionX:(double)x positionY:(double)y modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update atTime:(CMTime)t{if(update)*update=NO;}
- (void)mouseExitedAtPositionX:(double)x positionY:(double)y modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update atTime:(CMTime)t{if(update)*update=NO;}
- (void)mouseMovedAtPositionX:(double)x positionY:(double)y activePart:(NSInteger)part modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update atTime:(CMTime)t{@synchronized(self){
DYPlugIn*plugin=[self pluginAtTime:t];[_viewerControls setBridge:[plugin viewerParameterBridge]];[_viewerControls prepareWithSize:NSMakeSize(_canvasWidth,_height) scale:_uiScale atTime:t];NSPoint point=NSMakePoint(x,_height-y);NSInteger viewerHit=[_viewerControls partAtPoint:point];BOOL redraw=[_viewerControls mouseMoved:point];NSDictionary *mask=[plugin toolCanvasMaskAtTime:t];BOOL drawing=[mask[@"drawing"]boolValue];NSCursor *cursor=viewerHit?NSCursor.pointingHandCursor:part>=10000?NSCursor.pointingHandCursor:(drawing||part>=1000)?NSCursor.crosshairCursor:part?NSCursor.openHandCursor:NSCursor.arrowCursor;[[_apiManager apiForProtocol:@protocol(FxOnScreenControlAPI_v4)]setCursor:cursor];if(drawing&&!viewerHit)[self event:NSEventTypeMouseMoved x:x y:y part:part modifiers:m key:0 time:t];if(update)*update=redraw||drawing;
}}
- (void)mouseEnteredAtPositionX:(double)x positionY:(double)y modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update atTime:(CMTime)t{[self mouseMovedAtPositionX:x positionY:y activePart:0 modifiers:m forceUpdate:update atTime:t];}
- (void)mouseExitedAtPositionX:(double)x positionY:(double)y modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update atTime:(CMTime)t{@synchronized(self){BOOL changed=[_viewerControls mouseExited];if(update)*update=changed;}}
- (void)keyUpAtPositionX:(double)x positionY:(double)y keyPressed:(unsigned short)key modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update didHandle:(BOOL*)handled atTime:(CMTime)t{if(update)*update=NO;if(handled)*handled=NO;}
@end
+135
查看文件
@@ -0,0 +1,135 @@
// Independently authored canvas UI. Hit geometry and drawing share the same layout.
#import "DYTheme.h"
static const NSInteger DYViewerPartBase=20000;
@interface DYViewerControls : NSObject
@property(nonatomic,retain) DYViewerParameterBridge *bridge;
- (void)prepareWithSize:(NSSize)size scale:(CGFloat)scale atTime:(CMTime)time;
- (void)draw;
- (NSInteger)partAtPoint:(NSPoint)point;
- (BOOL)event:(NSEventType)type point:(NSPoint)point atTime:(CMTime)time;
- (BOOL)mouseMoved:(NSPoint)point;
- (BOOL)mouseExited;
- (BOOL)capturing;
- (BOOL)finishCapture;
@end
@implementation DYViewerControls {
DYViewerParameterBridge *_bridge;NSDictionary *_snapshot;NSArray *_nodes,*_rows;NSMutableArray *_areas;
NSString *_nodeID;NSSize _size;NSRect _panel;CGFloat _scale;BOOL _open,_catalog,_dragging,_hasDraft;
NSInteger _page,_catalogPage,_capacity,_catalogCapacity,_hover,_pressed;NSPoint _down;NSDictionary *_captured;
double _draftValue,_downValue;CGFloat _knobOffset;CMTime _time,_downTime;
}
@synthesize bridge=_bridge;
- (instancetype)init{if((self=[super init])){_areas=[NSMutableArray new];_nodeID=[@"base:base" copy];_scale=1;_time=_downTime=kCMTimeInvalid;}return self;}
- (void)dealloc{[_bridge endGesture];[_bridge release];[_snapshot release];[_nodes release];[_rows release];[_areas release];[_nodeID release];[_captured release];[super dealloc];}
- (void)setBridge:(DYViewerParameterBridge*)bridge{if(bridge==_bridge)return;[_bridge endGesture];[_bridge release];_bridge=[bridge retain];_pressed=0;_dragging=NO;[_captured release];_captured=nil;}
- (BOOL)capturing{return _pressed!=0;}
- (BOOL)finishCapture{BOOL had=_pressed!=0;[_bridge endGesture];_pressed=0;_hasDraft=NO;[_captured release];_captured=nil;return had;}
- (NSDictionary*)descriptorForKey:(NSString*)key{for(NSDictionary*d in DYDescriptors())if([d[@"key"]isEqual:key])return d;return nil;}
- (NSDictionary*)node{for(NSDictionary*n in _nodes)if([n[@"id"]isEqual:_nodeID])return n;return nil;}
- (double)valueForDescriptor:(NSDictionary*)d{
if(_hasDraft&&_captured&&[_captured[@"descriptor"][@"pid"]isEqual:d[@"pid"]]&&_pressed)return _draftValue;
NSDictionary*n=[self node];DYUniforms u;NSData*raw=_snapshot[@"uniforms"];if(raw.length!=sizeof(u))return [d[@"default"]doubleValue];
if([_nodeID hasPrefix:@"base:"])[raw getBytes:&u length:sizeof(u)];else u=DYToolUniforms(n[@"layer"]);
NSInteger offset=[d[@"offset"]integerValue];return offset>=0&&offset+sizeof(float)<=sizeof(u)?*(float*)((uint8_t*)&u+offset):[d[@"default"]doubleValue];
}
- (void)addArea:(NSRect)rect part:(NSInteger)part kind:(NSString*)kind title:(NSString*)title descriptor:(NSDictionary*)d index:(NSInteger)index{
NSMutableDictionary*a=[NSMutableDictionary dictionaryWithDictionary:@{@"rect":[NSValue valueWithRect:rect],@"part":@(part),@"kind":kind,@"title":title?:@"",@"index":@(index)}];if(d)a[@"descriptor"]=d;if([kind isEqual:@"module"]&&index<(NSInteger)_nodes.count)a[@"nodeID"]=_nodes[index][@"id"];[_areas addObject:a];
}
- (void)prepareWithSize:(NSSize)size scale:(CGFloat)scale atTime:(CMTime)time{
_size=size;_scale=MAX(.6,MIN(MAX(1.,scale),MIN(size.width/360.,size.height/230.)));_time=time;
if(_pressed&&(!CMTIME_IS_NUMERIC(time)||CMTimeCompare(time,_downTime)!=0)){[_bridge endGesture];_pressed=0;[_captured release];_captured=nil;}
[_snapshot release];_snapshot=[[_bridge snapshotAtTime:time]retain];NSDictionary*doc=_snapshot[@"document"];
NSMutableArray*nodes=[NSMutableArray array];NSMutableDictionary*counts=[NSMutableDictionary dictionary];
for(NSString*ID in DYToolDisplayOrder(doc?:@{})){
BOOL base=[ID hasPrefix:@"base:"];NSDictionary*layer=base?nil:DYToolWithID(doc,ID);NSString*type=base?[ID substringFromIndex:5]:layer[@"type"];if(!type||(base&&DYBaseToolRemoved(doc,type)))continue;
NSString*title=DYToolSection(type)[@"title"]?:type;if([type isEqual:@"base"])title=@"基础调整";
NSInteger count=[counts[type]integerValue];counts[type]=@(count+1);if(!base)title=[title stringByAppendingFormat:@" · %ld",(long)(count+1)];
[nodes addObject:@{@"id":ID,@"type":type,@"title":title,@"layer":layer?:@{}}];
}[_nodes release];_nodes=[nodes copy];
if(![self node]&&_nodes.count){[_bridge endGesture];_pressed=0;[_captured release];_captured=nil;[_nodeID release];_nodeID=[_nodes[0][@"id"]copy];_page=0;}
NSString*type=[self node][@"type"];NSMutableArray*rows=[NSMutableArray array];
// These are the existing public scalar controls, never hidden curve-slot metadata.
NSArray*sections=[type isEqual:@"base"]?@[@"color",@"base"]:type?@[type]:@[];
for(NSString*part in sections)for(NSDictionary*d in DYToolSection(part)[@"rows"]){NSString*k=d[@"key"];if(!d[@"pid"]||[k hasPrefix:@"cmbypass"]||[k isEqual:@"copyAutoGrade"]||([type isEqual:@"curve"]&&![k hasPrefix:@"curveY"]))continue;[rows addObject:d];}
[_rows release];_rows=[rows copy];[_areas removeAllObjects];if(!_bridge||size.width<120||size.height<80)return;
CGFloat s=_scale,margin=10*s,w=MIN(286*s,size.width-2*margin),x=MAX(margin,size.width-w-margin);_capacity=MAX(1,MIN(5,(NSInteger)floor((size.height-128*s)/(46*s))));
_catalogCapacity=MAX(2,MIN(8,2*(NSInteger)floor((size.height-2*margin-100*s)/(35*s))));if(size.width<200*s||size.height<166*s)_open=NO;
_page=MIN(MAX(0,_page),MAX(0,((NSInteger)_rows.count-1)/_capacity));_catalogPage=MIN(MAX(0,_catalogPage),MAX(0,((NSInteger)_nodes.count-1)/_catalogCapacity));
CGFloat h=!_open?30*s:_catalog?(100+35*ceil(MIN((double)_catalogCapacity,MAX(0.,(double)_nodes.count-_catalogPage*_catalogCapacity))/2))*s:(100+46*MIN(_capacity,(NSInteger)_rows.count))*s;
_panel=NSMakeRect(x,margin,w,MIN(h,size.height-2*margin));
[self addArea:NSMakeRect(x,margin,w,30*s) part:20000 kind:@"open" title:_open?@"画面调色 ▴":@"画面调色 ▾" descriptor:nil index:0];if(!_open)return;
CGFloat y=margin+36*s;
[self addArea:NSMakeRect(x+8*s,y,w-([type isEqual:@"base"]?126:84)*s,28*s) part:20002 kind:@"catalog" title:[self node][@"title"]?:@"等待画面" descriptor:nil index:0];
NSDictionary*enabled=[self descriptorForKey:[type isEqual:@"primary"]?@"primaryMasterEnabled":[type stringByAppendingString:@"Enabled"]];
if(enabled&&_snapshot)[self addArea:NSMakeRect(NSMaxX(_panel)-68*s,y,27*s,28*s) part:20003 kind:@"headerBool" title:[type isEqual:@"base"]?@"调":@"" descriptor:enabled index:0];
if([type isEqual:@"base"]&&_snapshot)[self addArea:NSMakeRect(NSMaxX(_panel)-108*s,y,36*s,28*s) part:20007 kind:@"headerBool" title:@"色" descriptor:[self descriptorForKey:@"colorEnabled"] index:0];
[self addArea:NSMakeRect(NSMaxX(_panel)-36*s,y,27*s,28*s) part:20001 kind:@"close" title:@"×" descriptor:nil index:0];y+=36*s;
if(_catalog){
for(NSInteger i=0;i<_catalogCapacity&&_catalogPage*_catalogCapacity+i<(NSInteger)_nodes.count;i++){NSDictionary*n=_nodes[_catalogPage*_catalogCapacity+i];CGFloat cell=(w-24*s)/2;[self addArea:NSMakeRect(x+8*s+(i%2)*(cell+8*s),y+(i/2)*35*s,cell,29*s) part:20100+i kind:@"module" title:n[@"title"] descriptor:nil index:_catalogPage*_catalogCapacity+i];}
y+=ceil(MIN((double)_catalogCapacity,MAX(0.,(double)_nodes.count-_catalogPage*_catalogCapacity))/2)*35*s;
}else{
for(NSInteger i=0;i<_capacity&&_page*_capacity+i<(NSInteger)_rows.count;i++){NSDictionary*d=_rows[_page*_capacity+i];NSString*kind=d[@"kind"]?:@"float";NSString*valueKind=[kind isEqual:@"bool"]?@"bool":[kind isEqual:@"popup"]?@"choice":@"slider";
[self addArea:NSMakeRect(x+10*s,y+i*46*s,w-46*s,40*s) part:21000+i*3 kind:valueKind title:d[@"title"] descriptor:d index:i];
[self addArea:NSMakeRect(NSMaxX(_panel)-31*s,y+i*46*s+5*s,23*s,29*s) part:21001+i*3 kind:@"reset" title:@"↺" descriptor:d index:i];}
y+=MIN(_capacity,(NSInteger)_rows.count)*46*s;
}
NSInteger total=_catalog?_nodes.count:_rows.count,cap=_catalog?_catalogCapacity:_capacity,page=_catalog?_catalogPage:_page;
if(total>cap){[self addArea:NSMakeRect(x+8*s,y,29*s,23*s) part:20004 kind:@"previous" title:@"‹" descriptor:nil index:0];[self addArea:NSMakeRect(NSMaxX(_panel)-37*s,y,29*s,23*s) part:20005 kind:@"next" title:@"›" descriptor:nil index:0];}
}
- (NSRect)trackForArea:(NSDictionary*)area{NSRect r=[area[@"rect"]rectValue];return NSMakeRect(r.origin.x+5*_scale,r.origin.y+28*_scale,r.size.width-10*_scale,4*_scale);}
- (void)text:(NSString*)text rect:(NSRect)rect size:(CGFloat)size color:(NSColor*)color alignment:(NSTextAlignment)alignment{
NSMutableParagraphStyle*p=[[[NSMutableParagraphStyle alloc]init]autorelease];p.lineBreakMode=NSLineBreakByTruncatingTail;p.alignment=alignment;
[text drawInRect:rect withAttributes:@{NSFontAttributeName:[NSFont systemFontOfSize:size*_scale weight:NSFontWeightMedium],NSForegroundColorAttributeName:color,NSParagraphStyleAttributeName:p}];
}
- (NSString*)valueText:(NSDictionary*)d value:(double)v{
if([d[@"kind"]isEqual:@"bool"])return v>.5?@"开启":@"关闭";
if([d[@"kind"]isEqual:@"popup"]){NSArray*values=d[@"values"],*options=d[@"options"];NSInteger i=values?[values indexOfObject:@((NSInteger)llround(v))]:(NSInteger)llround(v);return i>=0&&i<(NSInteger)options.count?options[i]:@"—";}
return [NSString stringWithFormat:[d[@"max"]doubleValue]-[d[@"min"]doubleValue]>20?@"%.1f":@"%.2f",v];
}
- (void)draw{
if(!_areas.count)return;[NSGraphicsContext saveGraphicsState];NSRectClip(NSIntersectionRect(_panel,NSMakeRect(0,0,_size.width,_size.height)));CGFloat s=_scale;NSColor*ink=DYThemeColor(@"ink")?:NSColor.whiteColor,*accent=DYThemeColor(@"accent")?:NSColor.systemCyanColor;
NSBezierPath*panel=[NSBezierPath bezierPathWithRoundedRect:_panel xRadius:9*s yRadius:9*s];DYDrawThemeSurface(panel,YES);
for(NSDictionary*a in _areas){NSRect r=[a[@"rect"]rectValue];NSInteger part=[a[@"part"]integerValue];NSString*kind=a[@"kind"];BOOL pressed=_pressed==part,hover=_hover==part;NSDictionary*d=a[@"descriptor"];
if([kind isEqual:@"slider"]){double v=[self valueForDescriptor:d],lo=[d[@"min"]doubleValue],hi=[d[@"max"]doubleValue];CGFloat ratio=hi>lo?MAX(0.,MIN(1.,(v-lo)/(hi-lo))):0;NSRect track=[self trackForArea:a];
[self text:a[@"title"] rect:NSMakeRect(r.origin.x,r.origin.y,r.size.width-68*s,18*s) size:11 color:ink alignment:NSTextAlignmentLeft];[self text:[self valueText:d value:v] rect:NSMakeRect(NSMaxX(r)-68*s,r.origin.y,68*s,18*s) size:11 color:hover||pressed?accent:ink alignment:NSTextAlignmentRight];
DYDrawSoftControl(NSInsetRect(track,-2*s,-3*s),5*s,YES,NO,NO);[accent setFill];[[NSBezierPath bezierPathWithRoundedRect:NSMakeRect(track.origin.x,track.origin.y,MAX(2*s,track.size.width*ratio),track.size.height) xRadius:2*s yRadius:2*s]fill];
CGFloat marker=MAX(0.,MIN(1.,([d[@"default"]doubleValue]-lo)/(hi-lo)));[ink setStroke];NSBezierPath*tick=[NSBezierPath bezierPath];[tick moveToPoint:NSMakePoint(track.origin.x+marker*track.size.width,NSMidY(track)-5*s)];[tick lineToPoint:NSMakePoint(track.origin.x+marker*track.size.width,NSMidY(track)+5*s)];tick.lineWidth=.7*s;[tick stroke];
DYDrawSoftControl(NSMakeRect(track.origin.x+ratio*track.size.width-6*s,NSMidY(track)-6*s,12*s,12*s),6*s,NO,hover||pressed,pressed);
}else{
BOOL selected=[kind isEqual:@"module"]&&[a[@"nodeID"]isEqual:_nodeID];BOOL on=([kind isEqual:@"bool"]||[kind isEqual:@"headerBool"])&&[self valueForDescriptor:d]>.5;
DYDrawSoftControl(r,5*s,NO,hover||selected||on,pressed);NSString*title=a[@"title"];
if(d&&![kind isEqual:@"reset"]){NSString*value=[self valueText:d value:[self valueForDescriptor:d]];title=[kind isEqual:@"headerBool"]?[title stringByAppendingString:[self valueForDescriptor:d]>.5?@"●":@"○"]:[NSString stringWithFormat:@"%@ %@%@",title,value,[kind isEqual:@"choice"]?@" ›":@""];}
[self text:title rect:NSInsetRect(r,5*s,5*s) size:[kind isEqual:@"open"]?12:11 color:ink alignment:NSTextAlignmentCenter];
}
}
if(_open){NSInteger cap=_catalog?_catalogCapacity:_capacity,total=_catalog?_nodes.count:_rows.count,page=_catalog?_catalogPage:_page;NSString*hint=total>cap?[NSString stringWithFormat:@"%ld / %ld",(long)(page+1),(long)((total+cap-1)/cap)]:(_snapshot?@"拖动调节 · ↺ 还原此项":@"请移动播放头以读取画面");[self text:hint rect:NSMakeRect(_panel.origin.x+40*s,NSMaxY(_panel)-23*s,_panel.size.width-80*s,18*s) size:10 color:ink alignment:NSTextAlignmentCenter];}
[NSGraphicsContext restoreGraphicsState];
}
- (NSInteger)partAtPoint:(NSPoint)p{if(!std::isfinite(p.x)||!std::isfinite(p.y)||!_bridge||!NSPointInRect(p,NSIntersectionRect(_panel,NSMakeRect(0,0,_size.width,_size.height))))return 0;for(NSDictionary*a in [_areas reverseObjectEnumerator])if(NSPointInRect(p,[a[@"rect"]rectValue]))return [a[@"part"]integerValue];return _open&&NSPointInRect(p,_panel)?20006:0;}
- (NSDictionary*)areaForPart:(NSInteger)part{for(NSDictionary*a in _areas)if([a[@"part"]integerValue]==part)return a;return nil;}
- (void)applySliderPoint:(NSPoint)p{
NSRect t=[self trackForArea:_captured];NSDictionary*d=_captured[@"descriptor"];double ratio=MAX(0.,MIN(1.,(p.x-_knobOffset-t.origin.x)/MAX(1.,t.size.width)));_draftValue=[d[@"min"]doubleValue]+ratio*([d[@"max"]doubleValue]-[d[@"min"]doubleValue]);[_bridge changeValue:_draftValue];
}
- (void)clickArea:(NSDictionary*)a{
NSString*kind=a[@"kind"];if([kind isEqual:@"open"]||[kind isEqual:@"close"]){_open=!_open;_catalog=NO;return;}if([kind isEqual:@"catalog"]){_catalog=!_catalog;return;}
if([kind isEqual:@"module"]){for(NSDictionary*n in _nodes)if([n[@"id"]isEqual:a[@"nodeID"]]){[_nodeID release];_nodeID=[a[@"nodeID"]copy];_catalog=NO;_page=0;break;}return;}
if([kind isEqual:@"previous"]||[kind isEqual:@"next"]){NSInteger total=_catalog?_nodes.count:_rows.count,cap=_catalog?_catalogCapacity:_capacity,count=MAX(1,(total+cap-1)/cap),delta=[kind isEqual:@"next"]?1:-1;if(_catalog)_catalogPage=(_catalogPage+delta+count)%count;else _page=(_page+delta+count)%count;return;}
NSDictionary*d=a[@"descriptor"];if(!d||!_snapshot)return;double old=[self valueForDescriptor:d],v=old;
if([kind isEqual:@"reset"])v=[d[@"default"]doubleValue];else if([kind isEqual:@"bool"]||[kind isEqual:@"headerBool"])v=old>.5?0:1;else if([kind isEqual:@"choice"]){NSArray*values=d[@"values"],*options=d[@"options"];NSInteger i=values?[values indexOfObject:@((NSInteger)llround(old))]:(NSInteger)llround(old);if(!options.count)return;i=(i+1)%options.count;v=values?[values[i]doubleValue]:i;}
[_bridge beginParameter:d node:_nodeID value:old atTime:_time];[_bridge changeValue:v];[_bridge endGesture];
}
- (BOOL)event:(NSEventType)type point:(NSPoint)p atTime:(CMTime)time{
if(!std::isfinite(p.x)||!std::isfinite(p.y))return NO;[self prepareWithSize:_size scale:_scale atTime:time];NSInteger hit=[self partAtPoint:p];
if(type==NSEventTypeLeftMouseDown){if(!hit)return NO;[_bridge endGesture];_hasDraft=NO;_pressed=hit;_down=p;_downTime=time;_dragging=NO;[_captured release];_captured=[[self areaForPart:hit]copy];NSDictionary*d=_captured[@"descriptor"];
if([_captured[@"kind"]isEqual:@"slider"]&&_snapshot){NSRect t=[self trackForArea:_captured];if(NSPointInRect(p,NSInsetRect(t,-8*_scale,-8*_scale))){_downValue=[self valueForDescriptor:d];_draftValue=_downValue;_hasDraft=YES;[_bridge beginParameter:d node:_nodeID value:_downValue atTime:time];CGFloat knob=t.origin.x+(_downValue-[d[@"min"]doubleValue])/([d[@"max"]doubleValue]-[d[@"min"]doubleValue])*t.size.width;_knobOffset=fabs(p.x-knob)<=8*_scale?p.x-knob:0;if(fabs(p.x-knob)>8*_scale)[self applySliderPoint:p];}}return YES;
}
if(!_pressed)return NO;
if(type==NSEventTypeLeftMouseDragged){if(fabs(p.x-_down.x)>2*_scale||fabs(p.y-_down.y)>2*_scale)_dragging=YES;if(_dragging&&_hasDraft&&[_captured[@"kind"]isEqual:@"slider"]&&_snapshot)[self applySliderPoint:p];return YES;}
if(type==NSEventTypeLeftMouseUp){BOOL slider=[_captured[@"kind"]isEqual:@"slider"];NSDictionary*a=[_captured retain];NSInteger pressed=_pressed;
if(slider){if(_hasDraft&&(_dragging||fabs(p.x-_down.x)>2*_scale||fabs(p.y-_down.y)>2*_scale))[self applySliderPoint:p];[_bridge endGesture];}
_pressed=0;_dragging=NO;_hasDraft=NO;[_captured release];_captured=nil;if(!slider&&hit==pressed&&(!a[@"nodeID"]||[a[@"nodeID"]isEqual:[self areaForPart:hit][@"nodeID"]]))[self clickArea:a];[a release];[self prepareWithSize:_size scale:_scale atTime:time];return YES;}
return NO;
}
- (BOOL)mouseMoved:(NSPoint)p{NSInteger part=[self partAtPoint:p];BOOL changed=part!=_hover;_hover=part;return changed;}
- (BOOL)mouseExited{BOOL changed=_hover!=0;_hover=0;return changed;}
@end
@@ -0,0 +1,52 @@
{
DYDiagnosticManager*base=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(base,&error);
DYToolCanvasProbe*host=[[[DYToolCanvasProbe alloc]init]autorelease];host->_base=base;host->_time=kCMTimeZero;
id<DYViewerParameterProbe>bridge=(id)[[NSClassFromString(@"DYViewerParameterBridge")alloc]initWithAPIManager:host];
id<DYViewerControlsProbe>controls=(id)[NSClassFromString(@"DYViewerControls")new];controls.bridge=bridge;
auto drain=[](){double end=NSProcessInfo.processInfo.systemUptime+.03;while(NSProcessInfo.processInfo.systemUptime<end)[[NSRunLoop mainRunLoop]runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:.002]];};
auto publish=[&](){DYUniforms u;DYReadUniforms(host,host->_time,&u);[bridge publishUniforms:&u document:DYReadTools(host,host->_time).document atTime:host->_time];[controls prepareWithSize:NSMakeSize(640,400) scale:1 atTime:host->_time];};
auto areaFor=[&](NSString*kind,NSString*key)->NSDictionary*{for(NSDictionary*a in [controls valueForKey:@"areas"])if([a[@"kind"]isEqual:kind]&&(!key||[a[@"descriptor"][@"key"]isEqual:key]))return [[a copy]autorelease];return nil;};
auto click=[&](NSDictionary*a){NSRect r=[a[@"rect"]rectValue];NSPoint p=NSMakePoint(NSMidX(r),NSMidY(r));[controls event:NSEventTypeLeftMouseDown point:p atTime:host->_time];[controls event:NSEventTypeLeftMouseUp point:p atTime:host->_time];};
auto value=[&](NSString*key)->double{for(NSDictionary*d in DYDescriptors())if([d[@"key"]isEqual:key])return [base->_values[d[@"pid"]]doubleValue];return NAN;};
publish();int undo=base->_undoStarts;NSDictionary*initial=[[base->_values copy]autorelease];
run.record(@"viewer-controls-start-collapsed-without-hidden-slider-hit",[[controls valueForKey:@"areas"]count]==1&&[controls partAtPoint:NSMakePoint(450,200)]==0);
NSRect header=[areaFor(@"open",nil)[@"rect"]rectValue];NSPoint hp=NSMakePoint(NSMidX(header),NSMidY(header));
[controls event:NSEventTypeLeftMouseDown point:hp atTime:host->_time];[controls event:NSEventTypeLeftMouseUp point:NSMakePoint(10,390) atTime:host->_time];
run.record(@"viewer-controls-button-release-outside-cancels-activation",[[controls valueForKey:@"areas"]count]==1&&![controls capturing]);
click(areaFor(@"open",nil));
run.record(@"viewer-controls-expand-is-separate-from-effect-enabling",areaFor(@"slider",@"exposure")!=nil&&[initial isEqual:base->_values]&&base->_undoStarts==undo);
click(areaFor(@"headerBool",@"baseEnabled"));drain();publish();
run.record(@"viewer-controls-tone-eye-does-not-misrepresent-the-separate-color-eye",value(@"baseEnabled")==0&&value(@"colorEnabled")==1&&areaFor(@"headerBool",@"colorEnabled")!=nil);
click(areaFor(@"headerBool",@"baseEnabled"));drain();publish();undo=base->_undoStarts;
NSDictionary*exposure=areaFor(@"slider",@"exposure");NSRect row=[exposure[@"rect"]rectValue];NSPoint label=NSMakePoint(row.origin.x+10,row.origin.y+5);
[controls event:NSEventTypeLeftMouseDown point:label atTime:host->_time];[controls event:NSEventTypeLeftMouseUp point:label atTime:host->_time];drain();
run.record(@"viewer-controls-clicking-a-label-does-not-change-the-grade",value(@"exposure")==0&&base->_undoStarts==undo);
NSRect track=NSMakeRect(row.origin.x+5,row.origin.y+28,row.size.width-10,4);NSPoint knob=NSMakePoint(NSMidX(track),NSMidY(track));
[controls event:NSEventTypeLeftMouseDown point:knob atTime:host->_time];[controls event:NSEventTypeLeftMouseDragged point:NSMakePoint(knob.x+1,knob.y+1) atTime:host->_time];[controls event:NSEventTypeLeftMouseUp point:NSMakePoint(knob.x+1,knob.y+1) atTime:host->_time];drain();
run.record(@"viewer-controls-slider-deadzone-does-not-create-an-edit",value(@"exposure")==0&&base->_undoStarts==undo);
[controls event:NSEventTypeLeftMouseDown point:NSMakePoint(knob.x+5,knob.y) atTime:host->_time];[controls event:NSEventTypeLeftMouseDragged point:NSMakePoint(knob.x+5+track.size.width*.1,knob.y) atTime:host->_time];drain();
run.record(@"viewer-controls-knob-grab-preserves-offset-and-writes-live",fabs(value(@"exposure")-1)<1e-5&&[controls capturing]&&base->_undoStarts==undo+1&&base->_undoEnds==undo);
[controls event:NSEventTypeLeftMouseDragged point:NSMakePoint(1000,500) atTime:host->_time];drain();
run.record(@"viewer-controls-drag-remains-captured-outside-the-panel-and-clamps",value(@"exposure")==5&&[controls capturing]);
[controls event:NSEventTypeLeftMouseUp point:NSMakePoint(-100,500) atTime:host->_time];drain();
run.record(@"viewer-controls-mouse-up-applies-final-position-and-closes-one-undo",value(@"exposure")==-5&&![controls capturing]&&base->_undoStarts==undo+1&&base->_undoEnds==undo+1);publish();
click(areaFor(@"reset",@"exposure"));drain();publish();run.record(@"viewer-controls-explicit-reset-uses-existing-parameter-default",value(@"exposure")==0);
click(areaFor(@"catalog",nil));BOOL catalog=areaFor(@"module",nil)!=nil;
run.record(@"viewer-controls-hidden-parameter-subtree-has-no-hit-areas",catalog&&!areaFor(@"slider",@"exposure"));
initial=[[base->_values copy]autorelease];undo=base->_undoStarts;click(areaFor(@"module",nil));drain();
run.record(@"viewer-controls-module-selection-does-not-write-grade-or-undo",[initial isEqual:base->_values]&&base->_undoStarts==undo);
NSMutableDictionary*doc=DYMutablePlist(DYReadTools(host,host->_time).document);NSDictionary*layer=DYInsertTool(doc,@"base",@"base:base");NSString*layerID=[[layer[@"id"]copy]autorelease];DYWriteTools(host,doc,host->_time);publish();click(areaFor(@"catalog",nil));
NSDictionary*module=nil;for(NSDictionary*a in [controls valueForKey:@"areas"])if([a[@"nodeID"]isEqual:layerID])module=[[a copy]autorelease];NSString*selected=[[[controls valueForKey:@"nodeID"]copy]autorelease];NSRect mr=[module[@"rect"]rectValue];NSPoint mp=NSMakePoint(NSMidX(mr),NSMidY(mr));
[controls event:NSEventTypeLeftMouseDown point:mp atTime:host->_time];doc=DYMutablePlist(DYReadTools(host,host->_time).document);DYRemoveTool(doc,layerID);DYWriteTools(host,doc,host->_time);publish();[controls event:NSEventTypeLeftMouseUp point:mp atTime:host->_time];
run.record(@"viewer-controls-module-button-retains-identity-when-a-layer-is-deleted-during-press",module&&[[controls valueForKey:@"nodeID"]isEqual:selected]);click(areaFor(@"catalog",nil));
NSDictionary*open=areaFor(@"open",nil);NSRect openRect=[open[@"rect"]rectValue];NSPoint hover=NSMakePoint(NSMidX(openRect),NSMidY(openRect));
run.record(@"viewer-controls-hover-and-exit-request-redraw-only-when-state-changes",[controls mouseMoved:hover]&&![controls mouseMoved:hover]&&[controls mouseExited]&&![controls mouseExited]);
click(open);run.record(@"viewer-controls-collapse-hides-the-entire-interactive-subtree",[[controls valueForKey:@"areas"]count]==1&&[controls partAtPoint:NSMakePoint(450,200)]==0);
BOOL bounded=YES;for(NSSize size:{NSMakeSize(120,80),NSMakeSize(200,130),NSMakeSize(320,240),NSMakeSize(1280,720)})for(CGFloat scale:{1.,2.}){
[controls prepareWithSize:size scale:scale atTime:host->_time];click(areaFor(@"open",nil));
bounded&=[controls partAtPoint:NSMakePoint(-1,20)]==0&&[controls partAtPoint:NSMakePoint(size.width+1,20)]==0&&[controls partAtPoint:NSMakePoint(50,size.height+1)]==0;
for(NSDictionary*a in [controls valueForKey:@"areas"]){NSRect r=[a[@"rect"]rectValue];NSPoint center=NSMakePoint(NSMidX(r),NSMidY(r));if(center.x<0||center.y<0||center.x>=size.width||center.y>=size.height)bounded&=[controls partAtPoint:center]==0;}
}
run.record(@"viewer-controls-small-and-retina-canvases-never-hit-outside-visible-bounds",bounded);
[controls finishCapture];controls.bridge=nil;[bridge invalidate];drain();[controls release];[bridge release];
}
@@ -0,0 +1,12 @@
#pragma once
@protocol DYViewerControlsProbe
@property(nonatomic,retain) id<DYViewerParameterProbe> bridge;
- (void)prepareWithSize:(NSSize)size scale:(CGFloat)scale atTime:(CMTime)time;
- (NSInteger)partAtPoint:(NSPoint)point;
- (BOOL)event:(NSEventType)type point:(NSPoint)point atTime:(CMTime)time;
- (BOOL)mouseMoved:(NSPoint)point;
- (BOOL)mouseExited;
- (BOOL)capturing;
- (BOOL)finishCapture;
- (id)valueForKey:(NSString*)key;
@end
@@ -0,0 +1,219 @@
// The OSC side publishes values and enqueues intent. Only the main queue enters
// host actions; no OSC/render callback waits for AppKit or a host model write.
@interface DYViewerParameterBridge : NSObject
- (instancetype)initWithAPIManager:(id<PROAPIAccessing>)manager;
- (void)publishUniforms:(const DYUniforms*)uniforms document:(NSDictionary*)document atTime:(CMTime)time;
- (NSDictionary*)snapshotAtTime:(CMTime)time;
- (void)beginParameter:(NSDictionary*)descriptor node:(NSString*)nodeID value:(double)value atTime:(CMTime)time;
- (void)changeValue:(double)value;
- (void)endGesture;
// Call before the owning plug-in releases this object during teardown.
- (void)invalidate;
@end
static BOOL DYViewerSameValue(double a,double b) {
return std::isfinite(a)&&std::isfinite(b)&&fabs(a-b)<=1e-6*MAX(1.,MAX(fabs(a),fabs(b)));
}
static NSDictionary *DYViewerCanonicalDescriptor(NSDictionary *candidate) {
if(![candidate isKindOfClass:NSDictionary.class])return nil;
for(NSDictionary *d in DYDescriptors())if([d[@"pid"]isEqual:candidate[@"pid"]]&&[d[@"key"]isEqual:candidate[@"key"]])return d;
return nil;
}
static BOOL DYViewerDescriptorBelongsToType(NSDictionary *d,NSString *type) {
if(!type.length)return NO;
for(NSDictionary *owned in DYBaseToolDescriptors(type))if([owned[@"pid"]isEqual:d[@"pid"]])return YES;
return NO;
}
static BOOL DYViewerSanitizeValue(NSDictionary *d,double input,double *output) {
if(!d||!std::isfinite(input))return NO;
double lo=[d[@"min"]doubleValue],hi=[d[@"max"]doubleValue],v=MAX(lo,MIN(hi,input));
if(!std::isfinite(lo)||!std::isfinite(hi)||hi<lo)return NO;
if([d[@"kind"]isEqual:@"bool"])v=v>=.5?1:0;
else if([d[@"kind"]isEqual:@"popup"]){
// A popup is an enum, not a continuous range. Unknown choices must not
// silently turn into the first/last item when a stale event is received.
v=round(input);NSArray *values=d[@"values"];
if(values){BOOL found=NO;for(NSNumber *number in values)if(DYViewerSameValue(v,number.doubleValue)){v=number.doubleValue;found=YES;break;}if(!found)return NO;}
else if(v<0||v>=(double)[d[@"options"]count])return NO;
if(v<lo||v>hi)return NO;
}
if(output)*output=v;return YES;
}
@implementation DYViewerParameterBridge {
id<PROAPIAccessing> _apiManager;
NSDictionary *_snapshot,*_sourceDocument;
CMTime _snapshotTime;
BOOL _invalidated,_validationScheduled;
uint64_t _requestSequence,_requestedGesture;
// The fields below are confined to the main queue.
id<PROAPIAccessing> _writerHost,_writerTarget;
NSDictionary *_writerDescriptor,*_writerCompanions;
NSString *_writerNode,*_writerType;
CMTime _writerTime;
double _writerLastValue;
uint64_t _writerGesture;
BOOL _writerUndoOpen;
}
- (instancetype)initWithAPIManager:(id<PROAPIAccessing>)manager {
if((self=[super init])){_apiManager=manager;_snapshotTime=kCMTimeInvalid;_writerTime=kCMTimeInvalid;}return self;
}
- (void)dealloc {
// invalidate enqueues closure before the owner releases its final reference;
// the queued block keeps the bridge alive until its host group is closed.
NSCAssert(!_writerUndoOpen,@"Viewer parameter group must be closed before teardown");
[_snapshot release];[_sourceDocument release];[_writerHost release];[_writerTarget release];
[_writerDescriptor release];[_writerCompanions release];[_writerNode release];[_writerType release];[super dealloc];
}
- (void)publishUniforms:(const DYUniforms*)uniforms document:(NSDictionary*)document atTime:(CMTime)time {
if(!uniforms||!document||!CMTIME_IS_NUMERIC(time))return;
NSDictionary *frozen=nil;
@synchronized(self){
if(_invalidated)return;
if(document==_sourceDocument&&![document isKindOfClass:NSMutableDictionary.class])frozen=[_snapshot[@"document"]retain];
}
if(!frozen){
DYToolDocument *copy=[[[DYToolDocument alloc]init]autorelease];
if(!DYValidToolDocument(document))return;copy.document=document;frozen=[copy.document retain];
}
NSData *bytes=[NSData dataWithBytes:uniforms length:sizeof(*uniforms)];BOOL validate=NO;
@synchronized(self){
if(!_invalidated){
[_snapshot release];_snapshot=[@{@"uniforms":bytes,@"document":frozen,@"timeValue":@(time.value),@"timeScale":@(time.timescale),@"timeEpoch":@(time.epoch)}copy];
[_sourceDocument release];_sourceDocument=[document retain];_snapshotTime=time;
if(_requestedGesture&&!_validationScheduled){_validationScheduled=YES;validate=YES;}
}
}
[frozen release];
if(validate)dispatch_async(dispatch_get_main_queue(),^{
@synchronized(self){self->_validationScheduled=NO;}
if(self->_writerGesture&&![self writerStillValid])[self closeWriter];
});
}
- (NSDictionary*)snapshotAtTime:(CMTime)time {
@synchronized(self){
if(_invalidated||!CMTIME_IS_NUMERIC(time)||!CMTIME_IS_NUMERIC(_snapshotTime)||CMTimeCompare(time,_snapshotTime)!=0)return nil;
return [[_snapshot retain]autorelease];
}
}
- (void)closeWriter {
NSCAssert(NSThread.isMainThread,@"Host writes require the main queue");
if(_writerUndoOpen){
id<FxCustomParameterActionAPI_v4>action=[_writerHost apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)];
[action startAction:self];@try{[[_writerHost apiForProtocol:@protocol(FxUndoAPI)]endUndoGroup];}@finally{[action endAction:self];}
}
_writerUndoOpen=NO;_writerGesture=0;_writerTime=kCMTimeInvalid;
[_writerHost release];_writerHost=nil;[_writerTarget release];_writerTarget=nil;
[_writerDescriptor release];_writerDescriptor=nil;[_writerCompanions release];_writerCompanions=nil;
[_writerNode release];_writerNode=nil;[_writerType release];_writerType=nil;
}
- (BOOL)writerNodeExists {
NSDictionary *doc=DYReadTools(_writerHost,_writerTime).document;
if([_writerNode hasPrefix:@"base:"])return !DYBaseToolRemoved(doc,_writerType);
NSDictionary *node=DYToolWithID(doc,_writerNode);return node&&[node[@"type"]isEqual:_writerType];
}
- (BOOL)writerValueMatches {
if(![self writerNodeExists])return NO;
double value=NAN;
BOOL read=[[_writerTarget apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)]getFloatValue:&value fromParameter:[_writerDescriptor[@"pid"]unsignedIntValue] atTime:_writerTime];
if(!read||!DYViewerSameValue(value,_writerLastValue))return NO;
// Primary scalar edits also touch configuration/bypass switches. A later
// external change to any of those switches must win over this live drag.
id<FxParameterRetrievalAPI_v6>get=[_writerTarget apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];
for(NSNumber *pid in _writerCompanions){double companion=NAN;if(![get getFloatValue:&companion fromParameter:pid.unsignedIntValue atTime:_writerTime]||!DYViewerSameValue(companion,[_writerCompanions[pid]doubleValue]))return NO;}
return YES;
}
- (BOOL)writerStillValid {
if(!_writerGesture)return NO;BOOL active;
@synchronized(self){active=!_invalidated;}
if(!active)return NO;
id<FxCustomParameterActionAPI_v4>action=[_writerTarget apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)];if(!action)return NO;
BOOL valid=NO;[action startAction:self];@try{
valid=CMTIME_IS_NUMERIC(action.currentTime)&&CMTimeCompare(action.currentTime,_writerTime)==0&&[self writerValueMatches];
}@finally{[action endAction:self];}return valid;
}
- (void)beginParameter:(NSDictionary*)descriptor node:(NSString*)nodeID value:(double)value atTime:(CMTime)time {
NSDictionary *canonical=DYViewerCanonicalDescriptor(descriptor);double sanitized=0;
if(!canonical||![nodeID isKindOfClass:NSString.class]||!CMTIME_IS_NUMERIC(time)||!DYViewerSanitizeValue(canonical,value,&sanitized))return;
NSString *node=[nodeID copy];NSDictionary *d=[canonical retain];uint64_t gesture;
@synchronized(self){if(_invalidated){[node release];[d release];return;}_requestedGesture=gesture=++_requestSequence;}
dispatch_async(dispatch_get_main_queue(),^{
[self closeWriter];id<PROAPIAccessing>host=nil;
@synchronized(self){if(!self->_invalidated)host=[self->_apiManager retain];}
if(!host)return;
id<FxCustomParameterActionAPI_v4>action=[host apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)];
if(!action){[host release];return;}
id<PROAPIAccessing>target=nil;NSString *type=nil;
[action startAction:self];@try{
if(CMTIME_IS_NUMERIC(action.currentTime)&&CMTimeCompare(action.currentTime,time)==0){
NSDictionary *doc=DYReadTools(host,time).document;
if([node hasPrefix:@"base:"]){type=[node substringFromIndex:5];if([DYToolTypes()containsObject:type]&&!DYBaseToolRemoved(doc,type))target=[host retain];}
else{NSDictionary *layer=DYToolWithID(doc,node);if(layer){type=layer[@"type"];target=[[DYToolManager alloc]initWithHost:host node:layer];}}
if(!DYViewerDescriptorBelongsToType(d,type)){[target release];target=nil;}
type=[type copy];
}
}@finally{[action endAction:self];}
if(target){
self->_writerHost=host;self->_writerTarget=target;self->_writerDescriptor=[d retain];self->_writerNode=[node copy];self->_writerType=type;
self->_writerTime=time;self->_writerGesture=gesture;self->_writerLastValue=sanitized;
if(![self writerStillValid])[self closeWriter];
}else{[type release];[host release];}
});
[node release];[d release];
}
- (void)writeValue:(double)value gesture:(uint64_t)gesture {
NSCAssert(NSThread.isMainThread,@"Host writes require the main queue");
if(!_writerGesture||gesture!=_writerGesture)return;double v=0;
if(!DYViewerSanitizeValue(_writerDescriptor,value,&v))return;
BOOL active;@synchronized(self){active=!_invalidated;}if(!active){[self closeWriter];return;}
id<FxCustomParameterActionAPI_v4>action=[_writerTarget apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)];
if(!action){[self closeWriter];return;}BOOL conflict=NO,changed=NO;
[action startAction:self];@try{
conflict=!CMTIME_IS_NUMERIC(action.currentTime)||CMTimeCompare(action.currentTime,_writerTime)!=0||![self writerValueMatches];
if(!conflict&&!DYViewerSameValue(v,_writerLastValue)){
id<FxUndoAPI>undo=[_writerHost apiForProtocol:@protocol(FxUndoAPI)];
if(!_writerUndoOpen)_writerUndoOpen=[undo startUndoGroup:[@"画面调整 · " stringByAppendingString:_writerDescriptor[@"title"]?:@"调色"]];
if(_writerUndoOpen){
id<FxParameterSettingAPI_v6>set=[_writerTarget apiForProtocol:@protocol(FxParameterSettingAPI_v6)];
NSString *key=_writerDescriptor[@"key"];
changed=[set setFloatValue:v toParameter:[_writerDescriptor[@"pid"]unsignedIntValue] atTime:_writerTime];
if(changed){
// Mirror scalarChanged in the inspector. Eye/bypass switches remain
// literal switches and are never cleared by their own click.
BOOL primaryValue=[key hasPrefix:@"cm"]&&![key hasPrefix:@"cmbypass"]&&![key isEqual:@"cmConfigured"]&&![key hasSuffix:@"Enabled"];
if(primaryValue||[key isEqual:@"blackWhiteMix"]){
id<FxParameterRetrievalAPI_v6>get=[_writerTarget apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];DYInspectorToken *old=nil;
[get getCustomParameterValue:&old fromParameter:DYInspectorParameterID atTime:_writerTime];
if(primaryValue){[set setFloatValue:1 toParameter:2236 atTime:_writerTime];for(NSDictionary *r in DYDescriptors())if([r[@"key"]hasPrefix:@"cmbypass"])[set setFloatValue:0 toParameter:[r[@"pid"]unsignedIntValue] atTime:_writerTime];}
else if(old.schema<2){double configured=0;[get getFloatValue:&configured fromParameter:2236 atTime:_writerTime];if(configured<.5)[set setFloatValue:-1 toParameter:2236 atTime:_writerTime];}
if(old&&old.schema<2){DYInspectorToken *token=[[old copy]autorelease];token.schema=2;[set setCustomParameterValue:token toParameter:DYInspectorParameterID atTime:_writerTime];}
}
DYPrimaryControlChanged(_writerTarget,_writerTime,key);
double actual=v;[[_writerTarget apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)]getFloatValue:&actual fromParameter:[_writerDescriptor[@"pid"]unsignedIntValue] atTime:_writerTime];_writerLastValue=actual;
if(primaryValue||[key isEqual:@"blackWhiteMix"]){
NSMutableDictionary *companions=[NSMutableDictionary dictionary];id<FxParameterRetrievalAPI_v6>get=[_writerTarget apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];
for(NSDictionary *r in DYDescriptors())if([r[@"key"]isEqual:@"cmConfigured"]||(primaryValue&&[r[@"key"]hasPrefix:@"cmbypass"])){double related=NAN;if([get getFloatValue:&related fromParameter:[r[@"pid"]unsignedIntValue] atTime:_writerTime]&&std::isfinite(related))companions[r[@"pid"]]=@(related);}
[_writerCompanions release];_writerCompanions=[companions copy];
}
}
}
}
}@finally{[action endAction:self];}
if(conflict)[self closeWriter];
if(changed)[NSNotificationCenter.defaultCenter postNotificationName:DYModelChanged object:_apiManager];
}
- (void)changeValue:(double)value {
if(!std::isfinite(value))return;uint64_t gesture;
@synchronized(self){if(_invalidated)return;gesture=_requestedGesture;}
if(gesture)dispatch_async(dispatch_get_main_queue(),^{[self writeValue:value gesture:gesture];});
}
- (void)endGesture {
uint64_t gesture;@synchronized(self){gesture=_requestedGesture;_requestedGesture=0;}
if(gesture)dispatch_async(dispatch_get_main_queue(),^{if(self->_writerGesture==gesture)[self closeWriter];});
}
- (void)invalidate {
@synchronized(self){if(_invalidated)return;_invalidated=YES;_requestedGesture=0;_apiManager=nil;}
dispatch_async(dispatch_get_main_queue(),^{[self closeWriter];});
}
@end
@@ -0,0 +1,83 @@
{
// Exercise the real bridge on a fake host; the values pass through the same
// float IDs and immutable independent-layer document used by the product.
DYDiagnosticManager *base=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(base,&error);
DYToolCanvasProbe *host=[[[DYToolCanvasProbe alloc]init]autorelease];host->_base=base;host->_time=kCMTimeZero;
id<DYViewerParameterProbe>bridge=(id)[[NSClassFromString(@"DYViewerParameterBridge")alloc]initWithAPIManager:host];
auto drain=[](){double end=NSProcessInfo.processInfo.systemUptime+.025;while(NSProcessInfo.processInfo.systemUptime<end)[[NSRunLoop mainRunLoop]runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:.002]];};
auto descriptor=[](NSString *key)->NSDictionary*{for(NSDictionary *d in DYDescriptors())if([d[@"key"]isEqual:key])return d;return nil;};
auto value=[&](NSDictionary *d)->double{double v=NAN;[base getFloatValue:&v fromParameter:[d[@"pid"]unsignedIntValue] atTime:host->_time];return v;};
NSDictionary *exposure=descriptor(@"exposure"),*grainHold=descriptor(@"filmGrainHold"),*primaryExposure=descriptor(@"cmexposure"),*primaryEye=descriptor(@"primaryMasterEnabled");
DYUniforms u;DYReadUniforms(host,kCMTimeZero,&u);NSMutableDictionary *document=DYMutablePlist(DYReadTools(base,kCMTimeZero).document);
[bridge publishUniforms:&u document:document atTime:kCMTimeZero];NSDictionary *snapshot=[bridge snapshotAtTime:kCMTimeZero];
[document setObject:@[@"base"] forKey:@"removedBase"];
run.record(@"viewer-bridge-published-snapshot-is-immutable-and-frame-bound",[snapshot[@"uniforms"]length]==sizeof(DYUniforms)&&![snapshot[@"document"][@"removedBase"]count]&&![bridge snapshotAtTime:CMTimeMake(1,24)]);
int undo=base->_undoStarts;
[bridge beginParameter:exposure node:@"base:base" value:0 atTime:kCMTimeZero];[bridge changeValue:.4];drain();
run.record(@"viewer-bridge-drag-writes-before-mouse-up-asynchronously",fabs(value(exposure)-.4)<1e-6&&base->_undoStarts==undo+1&&base->_undoEnds==undo);
[bridge changeValue:.8];[bridge endGesture];[bridge endGesture];drain();
run.record(@"viewer-bridge-continuous-drag-closes-one-host-undo-group",fabs(value(exposure)-.8)<1e-6&&base->_undoStarts==undo+1&&base->_undoEnds==undo+1);
undo=base->_undoStarts;
[bridge beginParameter:exposure node:@"base:base" value:.8 atTime:kCMTimeZero];[bridge changeValue:.8];[bridge endGesture];drain();
run.record(@"viewer-bridge-no-op-gesture-does-not-create-an-undo",base->_undoStarts==undo&&base->_undoEnds==undo);
[bridge beginParameter:exposure node:@"base:base" value:.8 atTime:kCMTimeZero];[bridge changeValue:NAN];[bridge changeValue:INFINITY];[bridge endGesture];drain();
run.record(@"viewer-bridge-nonfinite-values-are-rejected",fabs(value(exposure)-.8)<1e-6&&base->_undoStarts==undo);
[bridge beginParameter:exposure node:@"base:base" value:.8 atTime:kCMTimeZero];[bridge changeValue:1000];[bridge endGesture];drain();
run.record(@"viewer-bridge-values-are-clamped-to-the-existing-parameter-domain",value(exposure)==[exposure[@"max"]doubleValue]);
undo=base->_undoStarts;
[bridge beginParameter:exposure node:@"base:base" value:value(exposure) atTime:kCMTimeZero];[bridge changeValue:1.1];drain();
[base setFloatValue:2.1 toParameter:[exposure[@"pid"]unsignedIntValue] atTime:kCMTimeZero];
[bridge changeValue:1.3];[bridge endGesture];drain();
run.record(@"viewer-bridge-external-parameter-edit-wins-and-closes-the-group",fabs(value(exposure)-2.1)<1e-6&&base->_undoStarts==undo+1&&base->_undoEnds==undo+1);
undo=base->_undoStarts;
[bridge beginParameter:exposure node:@"base:base" value:value(exposure) atTime:kCMTimeZero];[bridge changeValue:2.2];drain();
host->_time=CMTimeMake(1,24);[bridge changeValue:2.8];[bridge endGesture];drain();
run.record(@"viewer-bridge-playhead-change-does-not-write-to-a-new-frame",fabs(value(exposure)-2.2)<1e-6&&base->_undoStarts==undo+1&&base->_undoEnds==undo+1);host->_time=kCMTimeZero;
undo=base->_undoStarts;
[bridge beginParameter:exposure node:@"base:base" value:0 atTime:kCMTimeZero];[bridge changeValue:1.2];[bridge endGesture];drain();
run.record(@"viewer-bridge-stale-snapshot-cannot-overwrite-current-values",fabs(value(exposure)-2.2)<1e-6&&base->_undoStarts==undo);
[bridge beginParameter:grainHold node:@"base:film" value:1 atTime:kCMTimeZero];[bridge changeValue:3.4];[bridge endGesture];drain();
run.record(@"viewer-bridge-popup-writes-an-existing-discrete-value",value(grainHold)==3);
NSDictionary *densityMode=descriptor(@"filmDensityMode");undo=base->_undoStarts;
[bridge beginParameter:densityMode node:@"base:film" value:2 atTime:kCMTimeZero];[bridge changeValue:0];[bridge endGesture];drain();
run.record(@"viewer-bridge-popup-values-outside-the-enumeration-are-rejected",value(densityMode)==2&&base->_undoStarts==undo);
[bridge beginParameter:primaryEye node:@"base:primary" value:value(primaryEye) atTime:kCMTimeZero];[bridge changeValue:0];[bridge endGesture];drain();
run.record(@"viewer-bridge-primary-master-eye-is-not-reactivated-by-the-bridge",value(primaryEye)==0);
[bridge beginParameter:primaryExposure node:@"base:primary" value:0 atTime:kCMTimeZero];[bridge changeValue:.3];[bridge endGesture];drain();
run.record(@"viewer-bridge-primary-edit-preserves-master-bypass-and-configures-cst",fabs(value(primaryExposure)-.3)<1e-6&&value(primaryEye)==0&&[base->_values[@2236]doubleValue]==1);
undo=base->_undoStarts;
[bridge beginParameter:primaryExposure node:@"base:primary" value:.3 atTime:kCMTimeZero];[bridge changeValue:.4];drain();
NSDictionary *bypass=descriptor(@"cmbypassExposure");[base setFloatValue:1 toParameter:[bypass[@"pid"]unsignedIntValue] atTime:kCMTimeZero];
[bridge changeValue:.6];[bridge endGesture];drain();
run.record(@"viewer-bridge-external-primary-bypass-is-not-cleared-by-a-later-drag",fabs(value(primaryExposure)-.4)<1e-6&&value(bypass)==1&&base->_undoStarts==undo+1&&base->_undoEnds==undo+1);
undo=base->_undoStarts;
[bridge beginParameter:exposure node:@"base:base" value:value(exposure) atTime:kCMTimeZero];[bridge changeValue:2.3];drain();
host->_time=CMTimeMake(1,24);DYReadUniforms(host,host->_time,&u);[bridge publishUniforms:&u document:DYReadTools(base,host->_time).document atTime:host->_time];drain();
run.record(@"viewer-bridge-new-frame-publication-closes-an-abandoned-gesture",fabs(value(exposure)-2.3)<1e-6&&base->_undoStarts==undo+1&&base->_undoEnds==undo+1);[bridge endGesture];drain();host->_time=kCMTimeZero;
undo=base->_undoStarts;
[bridge beginParameter:exposure node:@"missing-layer" value:value(exposure) atTime:kCMTimeZero];[bridge changeValue:4];[bridge endGesture];
[bridge beginParameter:exposure node:@"base:hsl" value:value(exposure) atTime:kCMTimeZero];[bridge changeValue:4];[bridge endGesture];drain();
run.record(@"viewer-bridge-invalid-node-and-wrong-module-descriptors-do-not-write",fabs(value(exposure)-2.3)<1e-6&&base->_undoStarts==undo);
NSMutableDictionary *doc=DYMutablePlist(DYReadTools(base,kCMTimeZero).document);NSDictionary *layer=DYInsertTool(doc,@"base",@"base:base");NSString *layerID=layer[@"id"];
DYWriteTools(base,doc,kCMTimeZero);double rootExposure=value(exposure);
[bridge beginParameter:exposure node:layerID value:0 atTime:kCMTimeZero];[bridge changeValue:.65];[bridge endGesture];drain();
NSDictionary *savedLayer=DYToolWithID(DYReadTools(base,kCMTimeZero).document,layerID);
run.record(@"viewer-bridge-independent-layer-keeps-root-and-other-layers-isolated",fabs([savedLayer[@"values"][@"exposure"]doubleValue]-.65)<1e-6&&value(exposure)==rootExposure);
undo=base->_undoStarts;
[bridge beginParameter:exposure node:layerID value:.65 atTime:kCMTimeZero];[bridge changeValue:.75];drain();
doc=DYMutablePlist(DYReadTools(base,kCMTimeZero).document);DYRemoveTool(doc,layerID);DYWriteTools(base,doc,kCMTimeZero);
[bridge changeValue:.9];[bridge endGesture];drain();
run.record(@"viewer-bridge-deleted-layer-is-not-recreated-by-a-pending-drag",!DYToolWithID(DYReadTools(base,kCMTimeZero).document,layerID)&&base->_undoStarts==undo+1&&base->_undoEnds==undo+1&&value(exposure)==rootExposure);
undo=base->_undoStarts;
[bridge beginParameter:exposure node:@"base:base" value:rootExposure atTime:kCMTimeZero];[bridge changeValue:2.4];drain();
doc=DYMutablePlist(DYReadTools(base,kCMTimeZero).document);DYSetBaseToolRemoved(doc,@"base",YES);DYWriteTools(base,doc,kCMTimeZero);
[bridge changeValue:2.6];[bridge endGesture];drain();
run.record(@"viewer-bridge-removed-base-is-not-written-after-its-removal",fabs(value(exposure)-2.4)<1e-6&&base->_undoStarts==undo+1&&base->_undoEnds==undo+1);
doc=DYMutablePlist(DYReadTools(base,kCMTimeZero).document);DYSetBaseToolRemoved(doc,@"base",NO);DYWriteTools(base,doc,kCMTimeZero);
undo=base->_undoStarts;
[bridge beginParameter:exposure node:@"base:base" value:value(exposure) atTime:kCMTimeZero];[bridge changeValue:2.5];drain();
[bridge invalidate];[bridge changeValue:3];drain();
run.record(@"viewer-bridge-teardown-closes-a-live-undo-and-rejects-further-writes",fabs(value(exposure)-2.5)<1e-6&&base->_undoStarts==undo+1&&base->_undoEnds==undo+1&&![bridge snapshotAtTime:kCMTimeZero]);
[bridge release];
}
@@ -0,0 +1,10 @@
#pragma once
@protocol DYViewerParameterProbe
- (instancetype)initWithAPIManager:(id<PROAPIAccessing>)manager;
- (void)publishUniforms:(const DYUniforms*)uniforms document:(NSDictionary*)document atTime:(CMTime)time;
- (NSDictionary*)snapshotAtTime:(CMTime)time;
- (void)beginParameter:(NSDictionary*)descriptor node:(NSString*)nodeID value:(double)value atTime:(CMTime)time;
- (void)changeValue:(double)value;
- (void)endGesture;
- (void)invalidate;
@end
+3 -3
查看文件
@@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.8.5</string>
<string>1.9.0</string>
<key>CFBundleVersion</key>
<string>67</string>
<string>68</string>
<key>NSHumanReadableCopyright</key>
<string></string>
<key>PlugInKit</key>
@@ -71,7 +71,7 @@
<key>uuid</key>
<string>1C17B73B-F229-4C09-A434-EAF6DFF5F22A</string>
<key>version</key>
<string>1.8.5</string>
<string>1.9.0</string>
</dict>
<dict>
<key>className</key>
+2 -2
查看文件
@@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.8.5</string>
<string>1.9.0</string>
<key>CFBundleVersion</key>
<string>67</string>
<string>68</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>