diff --git a/BBOSC.xcodeproj/project.pbxproj b/BBOSC.xcodeproj/project.pbxproj index 06b6dfb..ea955c0 100644 --- a/BBOSC.xcodeproj/project.pbxproj +++ b/BBOSC.xcodeproj/project.pbxproj @@ -36,6 +36,7 @@ FC520F6B105936B000FE3004 /* VVOSC.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FC520F58105936A500FE3004 /* VVOSC.framework */; }; FC520F75105936CA00FE3004 /* VVOSC.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = FC520F58105936A500FE3004 /* VVOSC.framework */; }; FCC290EA1059440700B73F44 /* VVBasics.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = FC520F52105936A500FE3004 /* VVBasics.framework */; }; + FCDF33AE1060FDF2001FAA34 /* BBOSCInPort.m in Sources */ = {isa = PBXBuildFile; fileRef = FCDF33AD1060FDF2001FAA34 /* BBOSCInPort.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -194,6 +195,8 @@ FC520E8D1059234900FE3004 /* BBOSCManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BBOSCManager.h; sourceTree = ""; }; FC520E8E1059234900FE3004 /* BBOSCManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BBOSCManager.m; sourceTree = ""; }; FC520F3C105936A500FE3004 /* VVOpenSource.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = VVOpenSource.xcodeproj; path = lib/vvosc/VVOpenSource.xcodeproj; sourceTree = ""; }; + FCDF33AC1060FDF2001FAA34 /* BBOSCInPort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BBOSCInPort.h; sourceTree = ""; }; + FCDF33AD1060FDF2001FAA34 /* BBOSCInPort.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BBOSCInPort.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -259,6 +262,8 @@ FC520D2F1058137600FE3004 /* OSCExtensions.m */, FC520E8D1059234900FE3004 /* BBOSCManager.h */, FC520E8E1059234900FE3004 /* BBOSCManager.m */, + FCDF33AC1060FDF2001FAA34 /* BBOSCInPort.h */, + FCDF33AD1060FDF2001FAA34 /* BBOSCInPort.m */, ); name = Classes; sourceTree = ""; @@ -491,6 +496,7 @@ FC520CFB1058085100FE3004 /* BBOSCViewController.m in Sources */, FC520D301058137600FE3004 /* OSCExtensions.m in Sources */, FC520E8F1059234900FE3004 /* BBOSCManager.m in Sources */, + FCDF33AE1060FDF2001FAA34 /* BBOSCInPort.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/BBOSCInPort.h b/BBOSCInPort.h new file mode 100644 index 0000000..6a5fc6b --- /dev/null +++ b/BBOSCInPort.h @@ -0,0 +1,25 @@ +// +// BBOSCInPort.h +// BBOSC +// +// Created by Jonathan del Strother on 16/09/2009. +// Copyright 2009 Best Before Media Ltd. All rights reserved. +// + +#import + +// This is a basic wrapper around OSCInPort, with the addition of handling multiple delegates + +@class OSCInPort, OSCManager; +@interface BBOSCInPort : NSObject { + OSCManager* oscManager; + OSCInPort* oscPort; + NSMutableSet* delegates; +} +-(id)initWithManager:(OSCManager*)manager withPort:(unsigned int)p label:(NSString*)l; +-(void)addDelegate:(id)delegate; +-(void)removeDelegate:(id)delegate; +-(unsigned short)port; +-(NSString*)portLabel; +-(void)remove; +@end diff --git a/BBOSCInPort.m b/BBOSCInPort.m new file mode 100644 index 0000000..ffabf74 --- /dev/null +++ b/BBOSCInPort.m @@ -0,0 +1,47 @@ +// +// BBOSCInPort.m +// BBOSC +// +// Created by Jonathan del Strother on 16/09/2009. +// Copyright 2009 Best Before Media Ltd. All rights reserved. +// + +#import "BBOSCInPort.h" +#import "OSCExtensions.h" + +@implementation BBOSCInPort +-(id)initWithManager:(OSCManager*)manager withPort:(unsigned int)p label:(NSString*)l { + if (self = [super init]) { + oscManager = [manager retain]; + oscPort = [[oscManager createNewInputForPort:p withLabel:l] retain]; + oscPort.delegate = self; + delegates = [[NSMutableSet alloc] init]; + } + return self; +} +-(void)dealloc { + [oscManager release]; + [oscPort release]; + [delegates release]; + [super dealloc]; +} +-(void)addDelegate:(id)delegate { + [delegates addObject:delegate]; +} +-(void)removeDelegate:(id)delegate { + [delegates removeObject:delegate]; +} +- (unsigned short) port { + return [oscPort port]; +} +- (NSString *) portLabel { + return [oscPort portLabel]; +} +-(void)remove { + [oscManager removeInput:oscPort]; +} + +- (void) receivedOSCMessage:(OSCMessage *)m { + [delegates makeObjectsPerformSelector:@selector(receivedOSCMessage:) withObject:m]; +} +@end diff --git a/BBOSCManager.h b/BBOSCManager.h index 182479d..1f3d083 100644 --- a/BBOSCManager.h +++ b/BBOSCManager.h @@ -8,16 +8,16 @@ #import -@class OSCManager, OSCInPort, OSCOutPort; +@class OSCManager, BBOSCInPort, OSCOutPort; @interface BBOSCManager : NSObject { OSCManager* oscManager; NSCountedSet* inputPorts; } -+(id)sharedManager; ++(BBOSCManager*)sharedManager; -- (OSCInPort*)createNewInputForPort:(int)p withLabel:(NSString *)l; +- (BBOSCInPort*)createNewInputForPort:(int)p withLabel:(NSString *)l; - (OSCOutPort*)createNewOutputToAddress:(NSString *)a atPort:(int)p withLabel:(NSString *)l; -- (void)removeInput:(id)p; -- (void)removeOutput:(id)p; +- (void)removeInput:(BBOSCInPort*)p; +- (void)removeOutput:(OSCOutPort*)p; @end diff --git a/BBOSCManager.m b/BBOSCManager.m index 2788b3b..3739448 100644 --- a/BBOSCManager.m +++ b/BBOSCManager.m @@ -9,6 +9,7 @@ #import "BBOSCManager.h" #import "OSCExtensions.h" #import "NSArrayExtensions.h" +#import "BBOSCInPort.h" @interface BBOSCBroadcastPort : NSObject { OSCManager* oscManager; @@ -45,7 +46,7 @@ -(void)sendThisMessage:(OSCMessage*)message { @implementation BBOSCManager static id sharedManager=nil; -+(id)sharedManager { ++(BBOSCManager*)sharedManager { if (!sharedManager) sharedManager = [[self alloc] init]; return sharedManager; @@ -59,19 +60,21 @@ -(id)init { return self; } -- (OSCInPort *) createNewInputForPort:(int)p withLabel:(NSString *)l { +- (BBOSCInPort *) createNewInputForPort:(int)p withLabel:(NSString *)l { // Search for any existing oscPorts with the same port number, and re-use them when possible - OSCInPort* resultingPort = nil; - for(OSCInPort* oscPort in inputPorts) { + BBOSCInPort* resultingPort = nil; + for(BBOSCInPort* oscPort in inputPorts) { if (oscPort.port == p) { NSAssert([oscPort.portLabel isEqualToString:l], @"Need to be using the same label"); resultingPort = oscPort; break; } } - if (!resultingPort) - resultingPort = [oscManager createNewInputForPort:p withLabel:l]; + if (!resultingPort) { + resultingPort = [[[BBOSCInPort alloc] initWithManager:oscManager withPort:p label:l] autorelease]; + } + // This is a counted set, so we always add the port, so we can keep track of how many people are using it. [inputPorts addObject:resultingPort]; return resultingPort; @@ -81,13 +84,13 @@ - (OSCOutPort *) createNewOutputToAddress:(NSString *)a atPort:(int)p withLabel: return [[[BBOSCBroadcastPort alloc] initWithManager:oscManager atPort:p] autorelease]; return [oscManager createNewOutputToAddress:a atPort:p withLabel:l]; } -- (void) removeInput:(id)p { +- (void) removeInput:(BBOSCInPort*)p { [inputPorts removeObject:p]; // Once noone is using that input any more, remove it from the oscManager. if ([inputPorts countForObject:p] == 0) - [oscManager removeInput:p]; + [p remove]; } -- (void) removeOutput:(id)p { +- (void) removeOutput:(OSCOutPort*)p { [oscManager removeOutput:p]; } diff --git a/BBOSCPluginReceiver.h b/BBOSCPluginReceiver.h index a00435c..942d7d8 100644 --- a/BBOSCPluginReceiver.h +++ b/BBOSCPluginReceiver.h @@ -8,7 +8,7 @@ #import -@class OSCInPort; +@class BBOSCInPort; @interface BBOSCPluginReceiver : QCPlugIn { NSMutableArray* messages; NSLock* messageLock; @@ -17,7 +17,7 @@ @property (nonatomic, readonly, retain) NSArray* oscParameters; -@property (nonatomic, readonly, retain) OSCInPort *oscPort; +@property (nonatomic, readonly, retain) BBOSCInPort *oscPort; @property (nonatomic, readwrite, assign) BOOL inputDiscardExcessMessages; @property (nonatomic, readwrite, assign) NSUInteger inputReceivingPort; diff --git a/BBOSCPluginReceiver.m b/BBOSCPluginReceiver.m index a56327a..69136f3 100644 --- a/BBOSCPluginReceiver.m +++ b/BBOSCPluginReceiver.m @@ -13,12 +13,13 @@ #import "NSArrayExtensions.h" #import "OSCExtensions.h" #import "BBOSCManager.h" +#import "BBOSCInPort.h" #define kQCPlugIn_Name @"BBOSC Receiver" #define kQCPlugIn_Description @"Best Before Open Sound Control receiver plugin" @interface BBOSCPluginReceiver () -@property (nonatomic, readwrite, retain) OSCOutPort *oscPort; +@property (nonatomic, readwrite, retain) BBOSCInPort *oscPort; @property (nonatomic, readwrite, retain) NSArray* oscParameters; @property (nonatomic, readwrite, retain) NSString* listeningPath; @end @@ -192,7 +193,7 @@ Return NO in case of failure during the execution (this will prevent rendering o if (self.oscPort) [[BBOSCManager sharedManager] removeInput:self.oscPort]; self.oscPort = [[BBOSCManager sharedManager] createNewInputForPort:self.inputReceivingPort withLabel:@"BB OSC"]; - self.oscPort.delegate = self; + [self.oscPort addDelegate:self]; if (!self.oscPort) NSLog(@"Failed to created input port"); } @@ -235,7 +236,7 @@ Return NO in case of failure during the execution (this will prevent rendering o - (void) disableExecution:(id)context { if (self.oscPort) { - [[BBOSCManager sharedManager] removeOutput:self.oscPort]; + [[BBOSCManager sharedManager] removeInput:self.oscPort]; self.oscPort = nil; } }