Cocoa and Quartz Composer Notes to self

Ive been doing a lot of coding recently, porting v001 effects to Core Image/QC, learning Cocoa and making a Quartz Composer VJ application as a project. Some notes to self:

Cocoa widgets will block OpenGL/QCRenderer rendering unless you do the following:

	// set up timers for preview and main renderer
	v001RenderTimer = [[NSTimer scheduledTimerWithTimeInterval:(1.0 /(NSTimeInterval)v001RendererFPS)
                        target:self
                        selector:@selector(_render:)
                        userInfo:nil
                        repeats:YES]
                        retain];
						
	v001PreviewRenderTimer = [[NSTimer scheduledTimerWithTimeInterval:(1.0 /(NSTimeInterval)v001PreviewRendererFPS)
                        target:self
                        selector:@selector(_renderPreview:)
                        userInfo:nil
                        repeats:YES]
                        retain];

	// magic to stop cocoa widgets from blocking drawing. woo.
	[[NSRunLoop currentRunLoop] addTimer:v001RenderTimer forMode:NSDefaultRunLoopMode];
	[[NSRunLoop currentRunLoop] addTimer:v001RenderTimer forMode:NSModalPanelRunLoopMode];
	[[NSRunLoop currentRunLoop] addTimer:v001RenderTimer forMode:NSEventTrackingRunLoopMode];
	[[NSRunLoop currentRunLoop] addTimer:v001PreviewRenderTimer forMode:NSDefaultRunLoopMode];
	[[NSRunLoop currentRunLoop] addTimer:v001PreviewRenderTimer forMode:NSModalPanelRunLoopMode];
	[[NSRunLoop currentRunLoop] addTimer:v001PreviewRenderTimer forMode:NSEventTrackingRunLoopMode];

Also, using a QCCompositionParameterView, to make it not show images, or a background, set up your IBOutlet appropriately, implement the QCCompositionParameterView delegate method and then in awake from nib setBackground:no:

 -(void) awakeFromNib
{
	[v001Effect1ParameterList setDelegate:self];
	[v001Effect2ParameterList setDelegate:self];
	[v001Effect1ParameterList setDrawsBackground:NO];
	[v001Effect2ParameterList setDrawsBackground:NO];
	
}

- (BOOL) compositionParameterView:(QCCompositionParameterView *)parameterView shouldDisplayParameterWithKey:(NSString *)portKey attributes:(NSDictionary *)portAttributes
{
	// we do not want to display images at all. So we return false for QCPortTypeImage keys
	NSLog(@"Delegate: %@", [portAttributes objectForKey:@"QCPortAttributeTypeKey"] );
	if([[portAttributes objectForKey:@"QCPortAttributeTypeKey"] isEqualToString:@"QCPortTypeImage"])
	{
		return false;
	}
	else
	{
		return true;
	}	
}

Should look into Cocoa Syntax highlighting plugin?

2 Responses to “Cocoa and Quartz Composer Notes to self”

  1. David Stolarsky Says:

    What do you mean by Cocoa widgets? Dashboard widgets?

  2. vade Says:

    No, sorry, I mean user interface elements like NSPopUpButton. At least with my previous attempts at using Cocoa + OpenGL + QCRenderer and procedurally connecting Composition published outputs to published inputs, I had blocking whenever trying to use a UI element.

    For whatever reason, this solves it. I think I found this code in the QCTV developer example.

Leave a Reply