PDA

View Full Version : Accessing port values during init, in custom patches




SW::Lango
Mar 17, 2008, 07:10 AM
G'day Everyone

This is my first time here, sorry if this has already been answered but i'll be buggered if i can find it.

I'm writing a custom consumer patch for Quartz Composer. It is a simple land generator, nothing fancy, simply a GL_QUAD_STRIP.

My question is that i want to be able to access my default input port variables when the patch gets initialised.

For example i have (this has been shortend for ease of reading)

+ (NSDictionary*) attributesForPropertyPortWithKey:(NSString*)key
{
if([key isEqualToString:@"inputWidth"])
return [NSDictionary dictionaryWithObjectsAndKeys:
@"Width", QCPortAttributeNameKey,
@"2", QCPortAttributeDefaultValueKey,
nil];
return nil;
}


This works fine and i can use this value (by self.inputWidth)in -(void)execute:, but in either -(id)init or - (BOOL) startExecution: it returns 0, instead of 2. I'm assuming 0 is the default default, and the value 2 gets added after.

I'm pretty tired so i'm not sure if i've worded my problem correctly or not. If not sorry about that.

I just want to be able to use the properties when the object gets initialised. I know i can't 'set' them in init: because they are read only.

Is there a way i can use it, or have i just made a simple mistake somewhere

Any help would be super.

Cheers

Lango



SW::Lango
Mar 18, 2008, 04:17 AM
hmmm, 56 views and no replies.

Did i write the question incorrectly, did it not make sense? I'm not really a forum poster so i apologise if my question was not to etiquette.

Anywho, i was unable to findout how to access the port variables (that had my default values), it seems to use the default i set with QCPortAttributeDefaultValueKey after both the init: and the startExecution: methods.

So as a workaround, in case anyone else gets this issue, was i just used a static variable after the @implementation line such as

@implementation SW_SimpleLandGeneratorPlugIn
static double DEFAULTINPUTWIDTH = 2;

Then to use this value as the default value for the input port, you need to change it to a string such as The Iraq...

+ (NSDictionary*) attributesForPropertyPortWithKey:(NSString*)key
{
if([key isEqualToString:@"inputWidth"])
return [NSDictionary dictionaryWithObjectsAndKeys:
@"Width", QCPortAttributeNameKey,
[NSString stringWithFormat:@"%f", DEFAULTINPUTWIDTH],
QCPortAttributeDefaultValueKey,
nil];
return nil;
}

And of course in init: you can use it like any other variable
- (id) init
{
if(self = [super init]) {
NSLog(@"DEFAULTINPUTWIDTH: %f", DEFAULTINPUTWIDTH);
}

return self;
}

In execute: you can and should use self.inputWidth (the input port), as it is will reflect changes, whereas DEFAULTINPUTWIDTH wouldn't.

This now allows you to simply change one variable (DEFAULTINPUTWIDTH) and that default value will be used throughout the initialisation of your class.

If you have any questions or if you have seen anything i have done wrong just reply and i'll see it... i see everything.

Cheers

Lango

robbieduncan
Mar 18, 2008, 05:00 AM
hmmm, 56 views and no replies.

Did i write the question incorrectly, did it not make sense? I'm not really a forum poster so i apologise if my question was not to etiquette.

No, I think the question is fine: lots of detail and code to get on with. Unfortunately I've never written a Quartz Composer patch. I imagine the same is true for a lot of the other views.

I imagine that this problem is similar to views waking from nibs: in that case you cannot assume your nib provided connections/values are there in init so a different awakeFromNib method is available that is called after init once all the connections are made. Perhaps there is something similar here?

SW::Lango
Mar 18, 2008, 05:12 AM
Fair enough, Thanks for the reply robbieduncan.

I had a quick read up on awakeFromNib: and i can understand what it does. Looking through the api for QCPlugIn (the class you extend to make a custom patch) it doesn't seem to have a similar method.

Thanks for your help

Lango