I am trying to develop a plug in for motion in Objective-c using the FxPlug template and so far I have been having issues with getting "NSOpenPanel" to be called from a push button in order to get a file dialog window, similar to the "File" generator present in Motion.
[paramAPI addPushButtonWithName: @"MIDI file"
parameterID: 1
selector: @selector(MIDI_func)
parameterFlags: kFxParameterFlag_DEFAULT]
I have tried to call NSOpenPanel through "dispatch_async" so that it would run on the main thread and thus not crash but when I press the button it appears not to work
- (void)MIDI_func {
NSLog(@"Button pressed");
dispatch_async(dispatch_get_main_queue(), ^{
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
[openDlg setCanChooseFiles:YES];
[openDlg setAllowsMultipleSelection:NO];
[openDlg setCanChooseDirectories:NO];
if ([openDlg runModal] == NSModalResponseOK) {
NSArray* urls = [openDlg URLs];
for(NSInteger i = 0; i < [urls count]; i++ ) {
NSString* url = [urls objectAtIndex:i];
NSLog(@"Url: %@", url);
}
}
});
}
How can I achieve this or is there a function in the FxPlug SDK that will let me open a file dialog from the host application?