Binding "Movie Location" input in IB

gregsamsa's picture

Hi. I'm building a very simple interface in IB to control a composition for an interactive video performance. Without writing any code, I can successfully bind all of my inputs to nice little sliders, knobs, etc. But I thought it would be really nice to be able to bind my "movie location" input, so I could load different clips into my composition directly from my interface. I simply need to create a standard file directory menu, I think? But I can't figure it out? Perhaps some coding is required? Thanks.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

.lov.'s picture
Re: Binding "Movie Location" input in IB

If you happy with a drag-and-drop-only solution, just use a text field as the input, and bind the stringValue.

dust's picture
Re: Binding "Movie Location" input in IB

First you need an app controller. The header file will look something like this.

#import <Cocoa/Cocoa.h>
#import <Quartz/Quartz.h>
 
@interface AppController : NSObject 
{
    IBOutlet QCView* qcView;
}
 
- (IBAction) selectMovieDir:(id)sender;
 
@end

Next you need to implement your app controller in the .m file like this.

#import "AppController.h"
 
@implementation AppController
 
- (void) awakeFromNib
{
   if(![qcView loadCompositionFromFile:[Bad link]) {
      NSLog(@"Could not load composition");
   }
}
 
- (void)windowWillClose:(NSNotification *)notification 
{
   [NSApp terminate:self];
}
 
 
// An example of programmatically setting the value of qc input ports
 
- (IBAction) selectMovieDir:(id)sender
{
   openPanel = [NSOpenPanel openPanel];
   [openPanel setAllowsMultipleSelection:NO];
   [openPanel setCanChooseDirectories:NO];
   [openPanel setCanChooseFiles:YES];
   if([openPanel runModalForDirectory:nil file:nil types:nil] != NSOKButton) 
   {NSLog(@"No file specified");}
 
   [qcView setValue:[openPanel filename] forInputKey:@"MoviePath"];
 
}
 
 
@end

what this will do is present the user with an open file window where the user selects the file. then passes it to the published input port via the qc view class.

this assigns a file path string to a qc input port.

[qcView setValue:[openPanel filename] forInputKey:@"MoviePath"];

in IB you need to add an app controller then control click it and drag the "selectMovieDir" action to open file menu item or button. also you will need to do the same with qcView. ctrl drag the app controller object to the qc view in IB. this will also update a qc parameters view automatically.

vade's picture
Re: Binding "Movie Location" input in IB

Technically, thats not binding at all ;)

gregsamsa's picture
Re: Binding "Movie Location" input in IB

I've been spending the last few days trying to get this to work, and I really appreciate your help, but I can't seem to get it right.

When I try to build the app, it fails, giving me a few error messages:

For the line,

if(![qcView loadCompositionFromFile:NSBundle mainBundle] pathForResource:@"Introduction" ofType:@"qtz") - it says "Expected expression before 'NSBundle' " and also, "Expected ')' before 'pathForResource' "

And for the line,

openPanel = [NSOpenPanel openPanel]; - it says " 'openPanel' undeclared"

Using different code from a Apple Developer document, I was able to get a button to open a menu to load a different quartz composition, but I wasn't able to figure out how to bind that operation (?) to an input.

Any suggestions you may be able to offer would be greatly appreciated. Meanwhile, I guess I better start learning some Objective-C!

dust's picture
Re: Binding "Movie Location" input in IB

to declare something in obj-c you would say id * variable. in this case what was missing was NSOpenPanel your object id and variable openPanel. By saying NSOpenPanel * openPanel it would fix that error. the other error means that the file introduction.qtz needs to exist in your xcode file. a easy fix would be to delete that whole method as your using IB to load your qtz files.

although i have no idea what the name of your file is so instead i just made a qtz file with a movie path parameter published it as "MoviePath" made a openFile action and connect the open file to the open file menu. sorry if this is not what you wanted but you said regular menu system so you file>open or apple O to open the movie that gets passed to your qtz movie file parameter.

see attachement for xcode sample.

PreviewAttachmentSize
qcMovieIB.zip29.39 KB

cybero's picture
Re: Binding "Movie Location" input in IB

Neat work. Only thing I sought to change was to flag that Movie Importer patch to run Asynchronously, thus enabling the sound output on the imported movie.

Nice :-)

Wouldn't it be cool to be able to enable .qtz as a 'movie' input too, especially if we could get Audio Tools honoured?

Right now I can get the .qtz graphically rendering as a movie input only, sans sound file input.

Thanks for sharing, dust.

dust's picture
Re: Binding "Movie Location" input in IB

yeah i thought this was a good question as well cybero.

as per the movies asynchronous properties you may need to uncheck vbl sync in qc view via interface builder. if you don't see these options in IB you will need to turn them on in your private qc prefs. i know cybero knows how to do this but for anybody else you would hold option and go to qc prefs to turn on private things. there is an option in there for extra IB settings once it is turned on then you have a bunch of more options in IB.

this would work for an audio path as well. i think the next step would be to make a core data model and set a save action so the application remembers the last movie selected.

franz's picture
Re: Binding "Movie Location" input in IB

has "Show private IB palette" been fixed ? last time i tryied (== 10.6.4), it crashed IB and corrupted the nib.

dust's picture
Re: Binding "Movie Location" input in IB

the private interface builder palette has been working for me. interface builder itself has been a little weird in comparison to leopard. like it will not launch from a xib in xcode. what i have to do some times is quit xcode and open interface builder then open my xcode projects xib file. seeing x-code is closed you need to read in your class files in case anything has been changed. sometimes clicking on a qcview and moving at the same time will give me a corrupt error.

i have no idea if this has anything to do with qc's private IB stuff or not. what i do when given this error is click continue. you are presented with crash IB or continue fatal error type of message. clicking continue will leave the project open but your qc view disappears ? simply hitting undo will bring your qc view back and then IB is stable again. clicking on the qcview again may or may give fatal corruption error. i have found one movement at time helps. click on qc view then hover over view till you get the handles then you can re-size view.

what is best is to simply use your documents window in list view to select the qc view and then you will not have any problems. im wondering now if all my problems have been because i have private IB turned on, either way thanks franz i will have to test this out.

cwright's picture
Re: Binding "Movie Location" input in IB

No -- that's a private undocumented option that's unlikely to get addressed ever (there's no need for it). You should keep that setting off, esp if you plan on using IB.

dust's picture
Re: Binding "Movie Location" input in IB

thanks chris and franz hope this helps my IB issues. i'm re-uploading the example without an of the private settings selected not sure if that will make a difference. i'm assuming if i had private vbl sync set to on , then that might mess with the movie player patch synchronous settings.

PreviewAttachmentSize
qcMovieIB.zip29.39 KB