diff --git a/CocoaSplit/CSAnimationRunner/cocoasplit.js b/CocoaSplit/CSAnimationRunner/cocoasplit.js index f71cc792..d122e95e 100644 --- a/CocoaSplit/CSAnimationRunner/cocoasplit.js +++ b/CocoaSplit/CSAnimationRunner/cocoasplit.js @@ -114,6 +114,22 @@ var setAudioInputVolume = function(name_regex, volume, duration) { } +var runTriggerScriptInput = function(input, scriptType) { + if (input["script_"+scriptType]) + { + + var inputSelf = null; + if (input.animationLayer) + { + inputSelf = new CSAnimationInput(input); + } + (new Function("self", input["script_"+scriptType]))(inputSelf); + inputSelf = null; + } + +} + + var runTriggerScript = function(layout, scriptType) { var s_inputs = layout.sourceList; s_inputs.forEach(function (r_inp) { @@ -173,7 +189,7 @@ var switchToLayout = function(layout, kwargs) { } } }); - runTriggerScript(target_layout, "beforeReplace"); + //runTriggerScript(target_layout, "beforeReplace"); } @@ -186,7 +202,7 @@ var switchToLayout = function(layout, kwargs) { eval(layout_replacing_script); } - runTriggerScript(target_layout, "afterReplace"); + //runTriggerScript(target_layout, "afterReplace"); } } @@ -205,10 +221,6 @@ var mergeLayout = function(layout, kwargs) { CSAnimationBlock.currentFrame().add_animation(dummy_animation, null, null); } - if (!kwargs['noscripts']) - { - runTriggerScript(target_layout, "beforeMerge"); - } target_layout.mergeSourceLayout(layout); var layout_transition_scripts = layout.transitionScripts; if (layout_transition_scripts['merged'] && !kwargs['noscripts']) @@ -217,10 +229,6 @@ var mergeLayout = function(layout, kwargs) { eval(layout_merged_script); } - if (!kwargs['noscripts']) - { - runTriggerScript(target_layout, "afterMerge"); - } } } diff --git a/CocoaSplit/CSInputSourceBase.m b/CocoaSplit/CSInputSourceBase.m index 714f1d80..17b0d2d5 100644 --- a/CocoaSplit/CSInputSourceBase.m +++ b/CocoaSplit/CSInputSourceBase.m @@ -16,14 +16,21 @@ { if (self = [super init]) { - self.attachedInputs = [NSMutableArray array]; - self.active = YES; + + [self basecommonInit]; } return self; } + +-(void)basecommonInit +{ + self.attachedInputs = [NSMutableArray array]; + self.active = YES; + +} -(void)createUUID { CFUUIDRef tmpUUID = CFUUIDCreate(NULL); @@ -120,8 +127,8 @@ -(instancetype)initWithCoder:(NSCoder *)aDecoder { - if (self = [self init]) - { + [self basecommonInit]; + self.name = [aDecoder decodeObjectForKey:@"name"]; self.uuid = [aDecoder decodeObjectForKey:@"uuid"]; self.depth = [aDecoder decodeFloatForKey:@"CAdepth"]; @@ -134,9 +141,6 @@ self.script_beforeReplace = [aDecoder decodeObjectForKey:@"script_beforeReplace"]; self.script_afterReplace = [aDecoder decodeObjectForKey:@"script_afterReplace"]; - } - - return self; } diff --git a/CocoaSplit/InputSource.m b/CocoaSplit/InputSource.m index 07e2a807..7642f1c2 100644 --- a/CocoaSplit/InputSource.m +++ b/CocoaSplit/InputSource.m @@ -1328,6 +1328,7 @@ static NSArray *_sourceTypes = nil; -(void)dealloc { + NSLog(@"DEALLOC GOD DAMNIT %@", self); [self deregisterVideoInput:self.videoInput]; for(id vInput in self.videoSources) { diff --git a/CocoaSplit/Interface/InputPopupControllerViewController.xib b/CocoaSplit/Interface/InputPopupControllerViewController.xib index e35f5ce6..f9562cea 100644 --- a/CocoaSplit/Interface/InputPopupControllerViewController.xib +++ b/CocoaSplit/Interface/InputPopupControllerViewController.xib @@ -1,8 +1,8 @@ - + - + @@ -12,6 +12,8 @@ + + @@ -28,7 +30,7 @@ - + @@ -37,7 +39,7 @@ - + @@ -46,7 +48,7 @@ - + @@ -62,7 +64,7 @@ - + @@ -98,7 +100,7 @@ - + @@ -107,7 +109,7 @@ - + @@ -128,7 +130,7 @@ - + @@ -137,7 +139,7 @@ - + @@ -158,7 +160,7 @@ - + @@ -167,7 +169,7 @@ - + @@ -188,7 +190,7 @@ - + @@ -205,7 +207,7 @@ - + @@ -214,7 +216,7 @@ - + @@ -226,7 +228,7 @@ - + @@ -235,7 +237,7 @@ - + @@ -247,7 +249,7 @@ - + @@ -279,7 +281,7 @@ - + @@ -288,7 +290,7 @@ - + @@ -300,7 +302,7 @@ - + @@ -312,7 +314,7 @@ - + @@ -324,7 +326,7 @@ - + @@ -368,7 +370,7 @@ - + @@ -377,7 +379,7 @@ - + @@ -386,7 +388,7 @@ - + @@ -395,7 +397,7 @@ - + @@ -404,7 +406,7 @@ - + @@ -475,7 +477,7 @@ - + @@ -513,7 +515,7 @@ - + @@ -560,7 +562,7 @@ - + @@ -569,7 +571,7 @@ - + @@ -578,7 +580,7 @@ - + @@ -603,7 +605,7 @@ - + @@ -612,7 +614,7 @@ - + @@ -621,7 +623,7 @@ - + @@ -633,7 +635,7 @@ - + @@ -672,7 +674,7 @@ - + @@ -681,7 +683,7 @@ - + @@ -706,7 +708,7 @@ - + @@ -715,7 +717,7 @@ - + @@ -724,7 +726,7 @@ - + @@ -733,7 +735,7 @@ - + @@ -742,7 +744,7 @@ - + @@ -754,7 +756,7 @@ - + @@ -766,7 +768,7 @@ - + @@ -789,7 +791,7 @@ - + @@ -809,7 +811,7 @@ - + @@ -818,7 +820,7 @@ - + @@ -830,7 +832,7 @@ - + @@ -857,7 +859,7 @@ - + @@ -866,7 +868,7 @@ - + @@ -906,7 +908,7 @@ - + @@ -929,7 +931,7 @@ - + @@ -1058,7 +1060,7 @@ - + - + @@ -1931,7 +1933,7 @@ - + @@ -1973,7 +1975,7 @@ - + @@ -1987,7 +1989,7 @@ - + @@ -2028,7 +2030,7 @@ - + @@ -2037,7 +2039,7 @@ - + @@ -2132,6 +2134,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CocoaSplit/PreviewView.m b/CocoaSplit/PreviewView.m index 05502421..d586640c 100644 --- a/CocoaSplit/PreviewView.m +++ b/CocoaSplit/PreviewView.m @@ -1081,13 +1081,13 @@ NSString *srcUUID = source.uuid; - InputSource *realSrc = (InputSource *)[self.sourceLayout inputForUUID:srcUUID]; - if (!_highlightedSourceMap[srcUUID] && realSrc) + NSObject *realSrc = (InputSource *)[self.sourceLayout inputForUUID:srcUUID]; + if (!_highlightedSourceMap[srcUUID] && realSrc && realSrc.layer) { CSPreviewOverlayView *oview = [[CSPreviewOverlayView alloc] init]; oview.renderControls = NO; oview.previewView = self; - oview.parentSource = realSrc; + oview.parentSource = (InputSource *)realSrc; _highlightedSourceMap[srcUUID] = oview; } } @@ -1460,7 +1460,7 @@ - (IBAction)deleteInput:(id)sender { - InputSource *toDelete = nil; + NSObject *toDelete = nil; if ([sender isKindOfClass:[NSMenuItem class]]) { @@ -1469,8 +1469,8 @@ { toDelete = item.representedObject; } - } else if ([sender isKindOfClass:[InputSource class]]) { - toDelete = (InputSource *)sender; + } else if ([sender conformsToProtocol:@protocol(CSInputSourceProtocol)]) { + toDelete = (NSObject *)sender; } if (!toDelete) @@ -1485,10 +1485,14 @@ self.mousedSource = nil; NSString *pUUID = nil; - if (toDelete.parentInput) + if (toDelete.layer) { - pUUID = toDelete.parentInput.uuid; - [toDelete.parentInput detachInput:toDelete]; + InputSource *cInput = (InputSource *)toDelete; + if (cInput.parentInput) + { + pUUID = cInput.parentInput.uuid; + [cInput.parentInput detachInput:cInput]; + } } NSData *saveData = [NSKeyedArchiver archivedDataWithRootObject:toDelete]; diff --git a/CocoaSplit/SourceLayout.m b/CocoaSplit/SourceLayout.m index ada9d079..4e284678 100644 --- a/CocoaSplit/SourceLayout.m +++ b/CocoaSplit/SourceLayout.m @@ -762,11 +762,25 @@ NSArray *newInputs = diffResult[@"new"]; NSNumber *aStart = nil; + JSContext *jCtx = [JSContext currentContext]; + NSString *blockUUID = [CATransaction valueForKey:@"__CS_BLOCK_UUID__"]; + + if (jCtx) + { + JSValue *scriptFunc = jCtx[@"runTriggerScriptInput"]; + + if (scriptFunc) + { + for (InputSource *src in self.sourceListPresentation) + { + [scriptFunc callWithArguments:@[src, @"beforeReplace"]]; + } + } + } if (blockUUID) { - JSContext *jCtx = [JSContext currentContext]; if (jCtx) { JSValue *mapValue = jCtx[@"block_uuid_map"]; @@ -908,7 +922,18 @@ - + if (jCtx) + { + JSValue *scriptFunc = jCtx[@"runTriggerScriptInput"]; + + if (scriptFunc) + { + for (InputSource *src in self.sourceListPresentation) + { + [scriptFunc callWithArguments:@[src, @"afterReplace"]]; + } + } + } [CATransaction commit]; [CATransaction flush]; @@ -994,16 +1019,51 @@ NSNumber *aStart = nil; - NSDictionary *blockObj = [CATransaction valueForKey:@"__CS_BLOCK_OBJECT__"]; - if (blockObj) + + + JSContext *jCtx = [JSContext currentContext]; + + NSString *blockUUID = [CATransaction valueForKey:@"__CS_BLOCK_UUID__"]; + + if (jCtx) { - aStart = blockObj[@"current_begin_time"]; - if ([aStart isEqual:[NSNull null]]) + JSValue *scriptFunc = jCtx[@"runTriggerScriptInput"]; + + if (scriptFunc) { - aStart = [NSNumber numberWithDouble:CACurrentMediaTime()]; + for (InputSource *src in self.sourceListPresentation) + { + [scriptFunc callWithArguments:@[src, @"beforeMerge"]]; + } } } + if (blockUUID) + { + if (jCtx) + { + JSValue *mapValue = jCtx[@"block_uuid_map"]; + if (mapValue) + { + NSDictionary *blockMap = mapValue.toDictionary; + NSDictionary *blockObj = blockMap[blockUUID]; + if (blockMap && blockObj) + { + aStart = blockObj[@"current_begin_time"]; + if ([aStart isEqual:[NSNull null]]) + { + aStart = nil; + } + } + } + } + } + + if (!aStart) + { + aStart = [NSNumber numberWithDouble:CACurrentMediaTime()]; + } + CATransition *rTrans = nil; CABasicAnimation *bTrans = nil; @@ -1132,6 +1192,19 @@ } transitionDelegate.changeremoveInputs = changedRemove; + if (jCtx) + { + JSValue *scriptFunc = jCtx[@"runTriggerScriptInput"]; + + if (scriptFunc) + { + for (InputSource *src in self.sourceListPresentation) + { + [scriptFunc callWithArguments:@[src, @"afterMerge"]]; + } + } + } + [CATransaction commit]; [CATransaction flush]; diff --git a/InputPopupControllerViewController.h b/InputPopupControllerViewController.h index 15381d7c..1651cd45 100644 --- a/InputPopupControllerViewController.h +++ b/InputPopupControllerViewController.h @@ -48,6 +48,7 @@ -(void)openTransitionFilterPanel:(CIFilter *)forFilter; -(IBAction) configureInputTransition:(NSButton *)sender; +- (IBAction)scriptSaveAll:(id)sender; - (IBAction)addFilterAction:(NSSegmentedControl *)sender; @@ -59,5 +60,10 @@ @property (weak) IBOutlet NSView *sourceConfigView; @property (strong) IBOutlet NSObjectController *inputobjctrl; @property (strong) NSViewController *inputConfigViewController; +@property (strong) NSArray *scriptTypes; +@property (strong) NSArray *scriptKeys; +@property (unsafe_unretained) IBOutlet NSTextView *scriptTextView; +@property (weak) IBOutlet NSTableView *scriptTableView; + @end diff --git a/InputPopupControllerViewController.m b/InputPopupControllerViewController.m index 34c9a0a8..c1a8a688 100644 --- a/InputPopupControllerViewController.m +++ b/InputPopupControllerViewController.m @@ -19,6 +19,7 @@ @synthesize inputSource = _inputSource; + -(instancetype) init { if (self = [super init]) @@ -53,6 +54,10 @@ self.compositionFilterNames = [CIFilter filterNamesInCategory:kCICategoryCompositeOperation]; + self.scriptTypes = @[@"After Add", @"Before Delete", @"FrameTick", @"Before Merge", @"After Merge", @"Before Remove", @"Before Replace", @"After Replace"]; + self.scriptKeys = @[@"selection.script_afterAdd", @"selection.script_beforeDelete", @"selection.script_frameTick", @"selection.script_beforeMerge", @"selection.script_afterMerge", @"selection.script_beforeRemove", @"selection.script_beforeReplace", @"selection.script_afterReplace"]; + + } @@ -94,6 +99,12 @@ } } +- (IBAction)scriptSaveAll:(id)sender +{ + [self.inputobjctrl commitEditing]; +} + + - (IBAction)configureFilter:(NSSegmentedControl *)sender { @@ -384,6 +395,7 @@ } + -(void)tableViewSelectionDidChange:(NSNotification *)notification { NSTableView *tableView = notification.object; @@ -411,6 +423,10 @@ } else { self.layerTableHasSelection = NO; } + } else if (tableView == self.scriptTableView) { + NSString *scriptKey = self.scriptKeys[tableView.selectedRow]; + [self.scriptTextView bind:@"value" toObject:self.inputobjctrl withKeyPath:scriptKey options:nil]; + } }