feat: add vertical canvas editors and host-owned scopes LUT workspace; boundary review in progress

这个提交包含在:
mac 于 2026-11-04 21:51:44 +08:00 提交
1 父节点 0dfb838b39
当前提交 031c704f0f
29 个文件已更改
+1062 -234

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

@@ -6,9 +6,14 @@
- (NSDictionary*)snapshotAtTime:(CMTime)time;
- (void)beginParameter:(NSDictionary*)descriptor node:(NSString*)nodeID value:(double)value atTime:(CMTime)time;
- (void)changeValue:(double)value;
- (void)beginParameters:(NSArray<NSDictionary*>*)descriptors node:(NSString*)nodeID values:(NSDictionary<NSString*,NSNumber*>*)values atTime:(CMTime)time;
// Every sample supplies every key selected by beginParameters. Invalid or
// incomplete samples are rejected as a unit, before the first host write.
- (void)changeValues:(NSDictionary<NSString*,NSNumber*>*)values;
- (void)endGesture;
// Call before the owning plug-in releases this object during teardown.
- (void)invalidate;
- (void)requestWorkspace;
@end
static BOOL DYViewerSameValue(double a,double b) {
@@ -49,10 +54,10 @@ static BOOL DYViewerSanitizeValue(NSDictionary *d,double input,double *output) {
// The fields below are confined to the main queue.
id<PROAPIAccessing> _writerHost,_writerTarget;
NSDictionary *_writerDescriptor,*_writerCompanions;
NSArray *_writerDescriptors;
NSDictionary *_writerLastValues,*_writerCompanions;
NSString *_writerNode,*_writerType;
CMTime _writerTime;
double _writerLastValue;
uint64_t _writerGesture;
BOOL _writerUndoOpen;
}
@@ -64,7 +69,10 @@ static BOOL DYViewerSanitizeValue(NSDictionary *d,double input,double *output) {
// 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];
[_writerDescriptors release];[_writerLastValues release];[_writerCompanions release];[_writerNode release];[_writerType release];[super dealloc];
}
- (void)requestWorkspace{
dispatch_async(dispatch_get_main_queue(),^{id manager=nil;@synchronized(self){if(!_invalidated)manager=_apiManager;}if(manager)[NSNotificationCenter.defaultCenter postNotificationName:@"DYColorWorkspaceRequested" object:manager];});
}
- (void)publishUniforms:(const DYUniforms*)uniforms document:(NSDictionary*)document atTime:(CMTime)time {
if(!uniforms||!document||!CMTIME_IS_NUMERIC(time))return;
@@ -105,7 +113,8 @@ static BOOL DYViewerSanitizeValue(NSDictionary *d,double input,double *output) {
}
_writerUndoOpen=NO;_writerGesture=0;_writerTime=kCMTimeInvalid;
[_writerHost release];_writerHost=nil;[_writerTarget release];_writerTarget=nil;
[_writerDescriptor release];_writerDescriptor=nil;[_writerCompanions release];_writerCompanions=nil;
[_writerDescriptors release];_writerDescriptors=nil;[_writerLastValues release];_writerLastValues=nil;
[_writerCompanions release];_writerCompanions=nil;
[_writerNode release];_writerNode=nil;[_writerType release];_writerType=nil;
}
- (BOOL)writerNodeExists {
@@ -115,12 +124,12 @@ static BOOL DYViewerSanitizeValue(NSDictionary *d,double input,double *output) {
}
- (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;
id<FxParameterRetrievalAPI_v6>get=[_writerTarget apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];
for(NSDictionary *d in _writerDescriptors){double value=NAN;
if(![get getFloatValue:&value fromParameter:[d[@"pid"]unsignedIntValue] atTime:_writerTime]||!DYViewerSameValue(value,[_writerLastValues[d[@"key"]]doubleValue]))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;
}
@@ -134,10 +143,19 @@ static BOOL DYViewerSanitizeValue(NSDictionary *d,double input,double *output) {
}@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;}
NSDictionary *d=DYViewerCanonicalDescriptor(descriptor);if(!d)return;
[self beginParameters:@[d] node:nodeID values:@{d[@"key"]:@(value)} atTime:time];
}
- (void)beginParameters:(NSArray<NSDictionary*>*)descriptors node:(NSString*)nodeID values:(NSDictionary<NSString*,NSNumber*>*)values atTime:(CMTime)time {
if(![descriptors isKindOfClass:NSArray.class]||!descriptors.count||descriptors.count>DYDescriptors().count||![values isKindOfClass:NSDictionary.class]||values.count!=descriptors.count||![nodeID isKindOfClass:NSString.class]||!CMTIME_IS_NUMERIC(time))return;
NSMutableArray *canonical=[NSMutableArray array];NSMutableDictionary *original=[NSMutableDictionary dictionary];NSMutableSet *pids=[NSMutableSet set];
for(NSDictionary *candidate in descriptors){
NSDictionary *d=DYViewerCanonicalDescriptor(candidate);NSNumber *number=d?values[d[@"key"]]:nil;double sanitized=0;
if(!d||original[d[@"key"]]||[pids containsObject:d[@"pid"]]||![number isKindOfClass:NSNumber.class]||!DYViewerSanitizeValue(d,number.doubleValue,&sanitized))return;
[canonical addObject:d];[pids addObject:d[@"pid"]];original[d[@"key"]]=@(sanitized);
}
NSString *node=[nodeID copy];NSArray *selected=[canonical copy];NSDictionary *initial=[original copy];uint64_t gesture;
@synchronized(self){if(_invalidated){[node release];[selected release];[initial 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];}
@@ -150,49 +168,77 @@ static BOOL DYViewerSanitizeValue(NSDictionary *d,double input,double *output) {
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;}
for(NSDictionary *d in selected)if(!DYViewerDescriptorBelongsToType(d,type)){[target release];target=nil;break;}
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;
self->_writerHost=host;self->_writerTarget=target;self->_writerDescriptors=[selected retain];self->_writerLastValues=[initial retain];self->_writerNode=[node copy];self->_writerType=type;
self->_writerTime=time;self->_writerGesture=gesture;
if(![self writerStillValid])[self closeWriter];
}else{[type release];[host release];}
});
[node release];[d release];
[node release];[selected release];[initial release];
}
- (void)writeValue:(double)value gesture:(uint64_t)gesture {
- (void)writeValues:(NSDictionary<NSString*,NSNumber*>*)values 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;
if(!_writerGesture||gesture!=_writerGesture||values.count!=_writerDescriptors.count)return;
NSMutableDictionary *desired=[NSMutableDictionary dictionary];BOOL anyChanged=NO,primaryValue=NO,blackWhite=NO;NSString *workingKey=nil;
NSMutableSet *explicitPids=[NSMutableSet set];
for(NSDictionary *d in _writerDescriptors){
NSString *key=d[@"key"];NSNumber *number=values[key];double v=0;
if(![number isKindOfClass:NSNumber.class]||!DYViewerSanitizeValue(d,number.doubleValue,&v))return;
desired[key]=@(v);[explicitPids addObject:d[@"pid"]];
if(!DYViewerSameValue(v,[_writerLastValues[key]doubleValue])){
anyChanged=YES;
primaryValue|=[key hasPrefix:@"cm"]&&![key hasPrefix:@"cmbypass"]&&![key isEqual:@"cmConfigured"]&&![key hasSuffix:@"Enabled"];
blackWhite|=[key isEqual:@"blackWhiteMix"];
if([@[@"cmworkingTransfer",@"cmworkingGamut"]containsObject:key])workingKey=key;
}
}
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;
if(!action){[self closeWriter];return;}BOOL conflict=NO,changed=NO,failed=NO;
[action startAction:self];@try{
conflict=!CMTIME_IS_NUMERIC(action.currentTime)||CMTimeCompare(action.currentTime,_writerTime)!=0||![self writerValueMatches];
if(!conflict&&!DYViewerSameValue(v,_writerLastValue)){
if(!conflict&&anyChanged){
id<FxUndoAPI>undo=[_writerHost apiForProtocol:@protocol(FxUndoAPI)];
if(!_writerUndoOpen)_writerUndoOpen=[undo startUndoGroup:[@"画面调整 · " stringByAppendingString:_writerDescriptor[@"title"]?:@"调色"]];
NSString *title=_writerDescriptors.count==1?_writerDescriptors[0][@"title"]:@"图形控件";
if(!_writerUndoOpen)_writerUndoOpen=[undo startUndoGroup:[@"画面调整 · " stringByAppendingString: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)];
id<FxParameterRetrievalAPI_v6>get=[_writerTarget apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];
NSMutableDictionary *before=[NSMutableDictionary dictionary];
for(NSDictionary *d in _writerDescriptors)before[d[@"pid"]]=_writerLastValues[d[@"key"]];
DYInspectorToken *old=nil;
if(primaryValue||blackWhite){
[get getCustomParameterValue:&old fromParameter:DYInspectorParameterID atTime:_writerTime];
for(NSDictionary *r in DYDescriptors())if([r[@"key"]isEqual:@"cmConfigured"]||(primaryValue&&[r[@"key"]hasPrefix:@"cmbypass"])){double previous=NAN;if([get getFloatValue:&previous fromParameter:[r[@"pid"]unsignedIntValue] atTime:_writerTime]&&std::isfinite(previous))before[r[@"pid"]]=@(previous);}
}
// Prevalidation and conflict checks cover the entire batch. Both axes are
// set inside this one action; an independent layer commits one document.
for(NSDictionary *d in _writerDescriptors)if(![set setFloatValue:[desired[d[@"key"]]doubleValue] toParameter:[d[@"pid"]unsignedIntValue] atTime:_writerTime]){failed=YES;break;}
if(!failed&&(primaryValue||blackWhite)){
// Explicit switches in the batch remain literal switches. Automatic CST
// companions never overwrite a requested eye/configuration/bypass value.
if(primaryValue){
if(![explicitPids containsObject:@2236])failed|=![set setFloatValue:1 toParameter:2236 atTime:_writerTime];
for(NSDictionary *r in DYDescriptors())if([r[@"key"]hasPrefix:@"cmbypass"]&&![explicitPids containsObject:r[@"pid"]])failed|=![set setFloatValue:0 toParameter:[r[@"pid"]unsignedIntValue] atTime:_writerTime];
}else if(old.schema<2&&![explicitPids containsObject:@2236]){double configured=0;[get getFloatValue:&configured fromParameter:2236 atTime:_writerTime];if(configured<.5)failed|=![set setFloatValue:-1 toParameter:2236 atTime:_writerTime];}
if(!failed&&old&&old.schema<2){DYInspectorToken *token=[[old copy]autorelease];token.schema=2;failed|=![set setCustomParameterValue:token toParameter:DYInspectorParameterID atTime:_writerTime];}
}
if(failed){
// The host API has no abortAction. Restore all affected fields before
// ending the action rather than leaving half a graphic update behind.
for(NSNumber *pid in before)[set setFloatValue:[before[pid]doubleValue] toParameter:pid.unsignedIntValue atTime:_writerTime];
if(old)[set setCustomParameterValue:old toParameter:DYInspectorParameterID atTime:_writerTime];
}else{
if(workingKey)DYPrimaryControlChanged(_writerTarget,_writerTime,workingKey);
NSMutableDictionary *actual=[NSMutableDictionary dictionary];
for(NSDictionary *d in _writerDescriptors){double v=[desired[d[@"key"]]doubleValue];[get getFloatValue:&v fromParameter:[d[@"pid"]unsignedIntValue] atTime:_writerTime];actual[d[@"key"]]=@(v);}
[_writerLastValues release];_writerLastValues=[actual copy];changed=YES;
if(primaryValue||blackWhite){
NSMutableDictionary *companions=[NSMutableDictionary dictionary];
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];
}
@@ -200,13 +246,23 @@ static BOOL DYViewerSanitizeValue(NSDictionary *d,double input,double *output) {
}
}
}@finally{[action endAction:self];}
if(conflict)[self closeWriter];
if(conflict||failed)[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];});
if(gesture)dispatch_async(dispatch_get_main_queue(),^{if(self->_writerGesture==gesture&&self->_writerDescriptors.count==1)[self writeValues:@{self->_writerDescriptors[0][@"key"]:@(value)} gesture:gesture];});
}
- (void)changeValues:(NSDictionary<NSString*,NSNumber*>*)values {
if(![values isKindOfClass:NSDictionary.class]||!values.count)return;
// Copy only validated primitive input, so callers may reuse mutable samples.
NSMutableDictionary *sample=[NSMutableDictionary dictionary];
for(id key in values){id value=values[key];if(![key isKindOfClass:NSString.class]||![value isKindOfClass:NSNumber.class]||!std::isfinite([value doubleValue]))return;sample[[[key copy]autorelease]]=@([value doubleValue]);}
NSDictionary *frozen=[sample copy];uint64_t gesture;
@synchronized(self){if(_invalidated){[frozen release];return;}gesture=_requestedGesture;}
if(gesture)dispatch_async(dispatch_get_main_queue(),^{[self writeValues:frozen gesture:gesture];});
[frozen release];
}
- (void)endGesture {
uint64_t gesture;@synchronized(self){gesture=_requestedGesture;_requestedGesture=0;}