Skip to content

Commit

Permalink
Merging Custom Drop Zone Experiment
Browse files Browse the repository at this point in the history
- This is just work-in-progress code, that I'm going to merge in, then revert a whole bunch of stuff.
  • Loading branch information
latenitefilms committed Jul 11, 2023
1 parent 37a3091 commit df8de24
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Source/Gyroflow.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
2239AB792945979800028B77 /* libgyroflow_toolbox.dylib in Embed Libraries */ = {isa = PBXBuildFile; fileRef = 2239AB772945979800028B77 /* libgyroflow_toolbox.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
224321B629615B0C00EA591A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 224321B529615B0C00EA591A /* Assets.xcassets */; };
224321B829615C4400EA591A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 224321B729615C4400EA591A /* Assets.xcassets */; };
22442A1B29C5A097006A56D6 /* CustomDropZoneView.m in Sources */ = {isa = PBXBuildFile; fileRef = 22442A1929C5A097006A56D6 /* CustomDropZoneView.m */; };
2264334F29864BDF002C0F9E /* CustomButtonView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2264334D29864BDF002C0F9E /* CustomButtonView.m */; };
22DAC75F2953B1A7001F2E06 /* GyroflowDocument.icns in Resources */ = {isa = PBXBuildFile; fileRef = 22DAC75E2953B1A7001F2E06 /* GyroflowDocument.icns */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -108,6 +109,8 @@
2239AB7C2945A69100028B77 /* lib.rs */ = {isa = PBXFileReference; lastKnownFileType = text; name = lib.rs; path = Frameworks/gyroflow/src/lib.rs; sourceTree = SOURCE_ROOT; };
224321B529615B0C00EA591A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
224321B729615C4400EA591A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
22442A1929C5A097006A56D6 /* CustomDropZoneView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomDropZoneView.m; sourceTree = "<group>"; };
22442A1A29C5A097006A56D6 /* CustomDropZoneView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomDropZoneView.h; sourceTree = "<group>"; };
2264334D29864BDF002C0F9E /* CustomButtonView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomButtonView.m; sourceTree = "<group>"; };
2264334E29864BDF002C0F9E /* CustomButtonView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomButtonView.h; sourceTree = "<group>"; };
228E9E1929517DDA00B2571E /* GyroflowConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GyroflowConstants.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -272,6 +275,8 @@
228E9E13294E815E00B2571E /* Code */ = {
isa = PBXGroup;
children = (
22442A1A29C5A097006A56D6 /* CustomDropZoneView.h */,
22442A1929C5A097006A56D6 /* CustomDropZoneView.m */,
2264334E29864BDF002C0F9E /* CustomButtonView.h */,
2264334D29864BDF002C0F9E /* CustomButtonView.m */,
228E9E1929517DDA00B2571E /* GyroflowConstants.h */,
Expand Down Expand Up @@ -456,6 +461,7 @@
files = (
2239AB392943F8F600028B77 /* MetalDeviceCache.m in Sources */,
2264334F29864BDF002C0F9E /* CustomButtonView.m in Sources */,
22442A1B29C5A097006A56D6 /* CustomDropZoneView.m in Sources */,
2239AB452943F8F600028B77 /* main.m in Sources */,
2239AB57294400B500028B77 /* GyroflowParameters.m in Sources */,
2239AB322943F8F600028B77 /* GyroflowPlugIn.m in Sources */,
Expand Down
22 changes: 22 additions & 0 deletions Source/Gyroflow/Plugin/CustomDropZoneView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// CustomButtonView.h
// Gyroflow Toolbox Renderer
//
// Created by Chris Hocking on 29/01/2023.
//

#import <Cocoa/Cocoa.h>
#import <FxPlug/FxPlugSDK.h>

@interface CustomDropZoneView : NSView <NSDraggingDestination>
{
id<PROAPIAccessing> _apiManager;
id _parentPlugin;
int _buttonID;
}

- (instancetype)initWithAPIManager:(id<PROAPIAccessing>)apiManager
parentPlugin:(id)parentPlugin
buttonID:(UInt32)buttonID
buttonTitle:(NSString*)buttonTitle;
@end
166 changes: 166 additions & 0 deletions Source/Gyroflow/Plugin/CustomDropZoneView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
//
// CustomButtonView.m
// Gyroflow Toolbox Renderer
//
// Created by Chris Hocking on 29/01/2023.
//

#import "CustomDropZoneView.h"
#import <FxPlug/FxPlugSDK.h>

static NSString *const kFinalCutProUTI = @"com.apple.flexo.proFFPasteboardUTI";

@interface CustomDropZoneView ()

@property (nonatomic) bool dragIsOver;

@end

@implementation CustomDropZoneView {
NSButton* _button;
}

//---------------------------------------------------------
// Initialize:
//---------------------------------------------------------
- (instancetype)initWithAPIManager:(id<PROAPIAccessing>)apiManager
parentPlugin:(id)parentPlugin
buttonID:(UInt32)buttonID
buttonTitle:(NSString*)buttonTitle
{
int buttonWidth = 200;
int buttonHeight = 32;

NSRect frameRect = NSMakeRect(0, 0, buttonWidth, buttonHeight); // x y w h
self = [super initWithFrame:frameRect];

if (self != nil)
{
_apiManager = apiManager;

[self registerForDraggedTypes:@[kFinalCutProUTI]];

self.wantsLayer = YES;
self.layer.backgroundColor = [[NSColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0] CGColor];
self.layer.borderColor = [[NSColor grayColor] CGColor];
self.layer.borderWidth = 2.0;

//---------------------------------------------------------
// Cache the parent plugin & button ID:
//---------------------------------------------------------
_parentPlugin = parentPlugin;
_buttonID = buttonID;

//---------------------------------------------------------
// Add the button:
//---------------------------------------------------------
/*
NSButton *button = [[NSButton alloc]initWithFrame:NSMakeRect(0, 0, buttonWidth, buttonHeight)]; // x y w h
[button setButtonType:NSButtonTypeMomentaryPushIn];
[button setBezelStyle: NSBezelStyleRounded];
button.layer.backgroundColor = [NSColor colorWithCalibratedRed:66 green:66 blue:66 alpha:1].CGColor;
button.layer.shadowColor = [NSColor blackColor].CGColor;
[button setBordered:YES];
[button setTitle:buttonTitle];
[button setTarget:self];
[button setAction:@selector(buttonPressed)];
_button = button;
[self addSubview:_button];
*/
}

return self;
}

//---------------------------------------------------------
// Awake From NIB:
//---------------------------------------------------------
- (void) awakeFromNib {
NSArray *sortedPasteboardTypes = @[@"com.apple.finalcutpro.xml.v1-10", @"com.apple.finalcutpro.xml.v1-9", @"com.apple.finalcutpro.xml"];
[self registerForDraggedTypes:sortedPasteboardTypes];

}

//---------------------------------------------------------
// Dragging Entered:
//---------------------------------------------------------
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
NSArray *sortedPasteboardTypes = @[@"com.apple.finalcutpro.xml.v1-10", @"com.apple.finalcutpro.xml.v1-9", @"com.apple.finalcutpro.xml"];
for (NSPasteboardType pasteboardType in sortedPasteboardTypes) {
if ( [[[sender draggingPasteboard] types] containsObject:pasteboardType] ) {
_dragIsOver = true;
[self needsDisplay];
return NSDragOperationCopy;
}
}
return NSDragOperationNone;
}

- (BOOL)prepareForDragOperation:(id<NSDraggingInfo>)sender {
return YES;
}

- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
NSPasteboard *pasteboard = [sender draggingPasteboard];
NSString *finalCutProData = [pasteboard stringForType:kFinalCutProUTI];

// Handle the dropped Final Cut Pro data
if (finalCutProData) {
NSLog(@"Dropped Final Cut Pro data: %@", finalCutProData);
}

return YES;
}

//---------------------------------------------------------
// Dragging Exited:
//---------------------------------------------------------
- (void)draggingExited:(nullable id <NSDraggingInfo>)sender {
_dragIsOver = false;
[self needsDisplay];
}

//---------------------------------------------------------
// Deallocates the memory occupied by the receiver:
//---------------------------------------------------------
- (void)dealloc
{
if (_button) {
[_button release];
}

[super dealloc];
}

//---------------------------------------------------------
// Draw the NSView:
//---------------------------------------------------------
- (void)drawRect:(NSRect)dirtyRect {
[NSGraphicsContext saveGraphicsState];
[super drawRect:dirtyRect];
if (_dragIsOver)
{
[[[NSColor keyboardFocusIndicatorColor] colorWithAlphaComponent:0.25] set];
NSRectFill(NSInsetRect(self.bounds, 1, 1));
}
[NSGraphicsContext restoreGraphicsState];
}



//---------------------------------------------------------
// Because custom views are hosted in an overlay window,
// the first click on them will normally just make the
// overlay window be the key window, and it will require a
// second click in order to actually tell the view to
// start responding. By returning YES from this method, the
// first click begins user interaction with the view.
//---------------------------------------------------------
- (BOOL)acceptsFirstMouse:(NSEvent *)event
{
return YES;
}

@end

5 changes: 4 additions & 1 deletion Source/Gyroflow/Plugin/GyroflowConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
//---------------------------------------------------------
// Plugin Parameter Constants:
//---------------------------------------------------------
enum {
enum {

kCB_DropZone = 10,

kCB_LaunchGyroflow = 20,
kCB_LoadLastGyroflowProject = 25,
kCB_ImportGyroflowProject = 30,
Expand Down
1 change: 1 addition & 0 deletions Source/Gyroflow/Plugin/GyroflowPlugIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
NSView* importGyroflowProjectView;
NSView* reloadGyroflowProjectView;
NSView* loadLastGyroflowProjectView;
NSView* dropZoneView;
}
@property (assign) id<PROAPIAccessing> apiManager;
@end
65 changes: 61 additions & 4 deletions Source/Gyroflow/Plugin/GyroflowPlugIn.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#import "GyroflowConstants.h"

#import "CustomButtonView.h"
#import "CustomDropZoneView.h"

#import "MetalDeviceCache.h"

Expand Down Expand Up @@ -179,6 +180,13 @@ - (NSView*)createViewForParameterID:(UInt32)parameterID
buttonTitle:@"Import Last Saved Project"];
loadLastGyroflowProjectView = view;
return view;
} else if (parameterID == kCB_DropZone) {
NSView* view = [[CustomDropZoneView alloc] initWithAPIManager:_apiManager
parentPlugin:self
buttonID:kCB_DropZone
buttonTitle:@"Drop Zone"];
dropZoneView = view;
return view;
} else {
NSLog(@"[Gyroflow Toolbox Renderer] BUG - createViewForParameterID requested a parameterID that we haven't allowed for: %u", (unsigned int)parameterID);
return nil;
Expand Down Expand Up @@ -222,6 +230,40 @@ - (BOOL)addParametersWithError:(NSError**)error
}
return NO;
}

//---------------------------------------------------------
// ADD PARAMETER: Drop Zone
//---------------------------------------------------------
if (![paramAPI addCustomParameterWithName:@"Drop Zone"
parameterID:kCB_DropZone
defaultValue:@0
parameterFlags:kFxParameterFlag_CUSTOM_UI | kFxParameterFlag_NOT_ANIMATABLE])
{
if (error != NULL) {
NSDictionary* userInfo = @{NSLocalizedDescriptionKey : @"[Gyroflow Toolbox Renderer] Unable to add parameter: kCB_DropZone"};
*error = [NSError errorWithDomain:FxPlugErrorDomain
code:kFxError_InvalidParameter
userInfo:userInfo];
}
return NO;
}

//---------------------------------------------------------
// ADD PARAMETER: 'Loaded Gyroflow Project' Text Box
//---------------------------------------------------------
if (![paramAPI addStringParameterWithName:@"Loaded Gyroflow Project"
parameterID:kCB_LoadedGyroflowProject
defaultValue:@"NOTHING LOADED"
parameterFlags:kFxParameterFlag_DISABLED | kFxParameterFlag_NOT_ANIMATABLE])
{
if (error != NULL) {
NSDictionary* userInfo = @{NSLocalizedDescriptionKey : @"[Gyroflow Toolbox Renderer] Unable to add parameter: kCB_LoadedGyroflowProject"};
*error = [NSError errorWithDomain:FxPlugErrorDomain
code:kFxError_InvalidParameter
userInfo:userInfo];
}
return NO;
}

//---------------------------------------------------------
// ADD PARAMETER: 'Loaded Gyroflow Project' Text Box
Expand Down Expand Up @@ -681,18 +723,18 @@ - (BOOL)pluginState:(NSData**)pluginState

CMTime timelineTime = kCMTimeZero;
[timingAPI timelineTime:&timelineTime fromInputTime:renderTime];

CMTime startTimeOfInputToFilter = kCMTimeZero;
[timingAPI startTimeForEffect:&startTimeOfInputToFilter];

CMTime startTimeOfInputToFilterInTimelineTime = kCMTimeZero;
[timingAPI timelineTime:&startTimeOfInputToFilterInTimelineTime fromInputTime:startTimeOfInputToFilter];

Float64 timelineTimeMinusStartTimeOfInputToFilterNumerator = (Float64)timelineTime.value * (Float64)startTimeOfInputToFilterInTimelineTime.timescale - (Float64)startTimeOfInputToFilterInTimelineTime.value * (Float64)timelineTime.timescale;
Float64 timelineTimeMinusStartTimeOfInputToFilterDenominator = (Float64)timelineTime.timescale * (Float64)startTimeOfInputToFilterInTimelineTime.timescale;

Float64 frame = ( ((Float64)timelineTimeMinusStartTimeOfInputToFilterNumerator / (Float64)timelineTimeMinusStartTimeOfInputToFilterDenominator) / ((Float64)timelineFrameDuration.value / (Float64)timelineFrameDuration.timescale) );

//---------------------------------------------------------
// Calculate the Timestamp:
//---------------------------------------------------------
Expand All @@ -702,6 +744,21 @@ - (BOOL)pluginState:(NSData**)pluginState
Float64 timestamp = (frame / frameRate) * 1000000.0;
params.timestamp = [[[NSNumber alloc] initWithFloat:timestamp] autorelease];


NSLog(@"---------------------------------");
NSLog(@"timelineFrameDuration: %.2f seconds", CMTimeGetSeconds(timelineFrameDuration));
NSLog(@"timelineTime: %.2f seconds", CMTimeGetSeconds(timelineTime));
NSLog(@"startTimeOfInputToFilter: %.2f seconds", CMTimeGetSeconds(startTimeOfInputToFilter));
NSLog(@"startTimeOfInputToFilterInTimelineTime: %.2f seconds", CMTimeGetSeconds(startTimeOfInputToFilterInTimelineTime));
NSLog(@"timelineTimeMinusStartTimeOfInputToFilterNumerator: %f", timelineTimeMinusStartTimeOfInputToFilterNumerator);
NSLog(@"timelineTimeMinusStartTimeOfInputToFilterDenominator: %f", timelineTimeMinusStartTimeOfInputToFilterDenominator);
NSLog(@"frame: %f", frame);
NSLog(@"timelineFpsNumerator: %f", timelineFpsNumerator);
NSLog(@"timelineFpsDenominator: %f", timelineFpsDenominator);
NSLog(@"frameRate: %f", frameRate);
NSLog(@"timestamp: %f", timestamp);
NSLog(@"---------------------------------");

//---------------------------------------------------------
// Gyroflow Path:
//---------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
</sceneSettings>
<publishSettings>
<version>2</version>
<target object="10036" channel="./10" name="Drop Zone"/>
<target object="10036" channel="./40" name="Loaded Gyroflow Project"/>
<target object="10036" channel="./30" name="Import Gyroflow Project"/>
<target object="10036" channel="./25" name="Import Last Saved Project"/>
Expand Down

0 comments on commit df8de24

Please sign in to comment.