Complete Example

#import <MusicKit/MusicKit.h>
#import <MKUnitGenerators/MKUnitGenerators.h>

@implementation MySynthPatch : MKSynthPatch { }

static int osc, patchPoint, out;  /* Used as indexes into synthElements array */
+ patchTemplateFor: aNote
{	
	static PatchTemplate *t = nil;

	if (!t)  {             /* Only create template the first time. */
	        t = [[PatchTemplate alloc] init];  
  	 	osc = [t addUnitGenerator: [OscgUGxy class]];
 	 	patchPoint = [t addPatchpoint: MK_xPatch];
 	 	out = [t addUnitGenerator: [Out2sumUGx class]]; 	
	}
	return t;   
}

#define OSC [self synthElementAt: osc]
#define OUT [self synthElementAt: out]
#define PATCHPOINT [self synthElementAt: patchpoint]

+ init /* Sent once when object is created */
{ 	
	[OSC setOutput: PATCHPOINT];
  	[OUT setInput: PATCHPOINT];  	
	return self;
}  

+noteOnSelf: aNote
{	
	[OSC setFreq: [aNote freq]];
  	[OSC setAmp: [aNote parAsDouble: MK_amp]];              
 	[OUT setBearing: [aNote parAsDouble: MK_bearing]]; 	
	[synthElements makeObjectsPerform: @selector(run)];	
	return self;
}

+ noteEndSelf
{
	[OSC setAmp: 0.0];   
	return self;  
}