Permalink
Browse files

Add our own osc in-port type to handle multiple delegates

  • Loading branch information...
1 parent 141de93 commit 5d750a6749b810c1e545a31fb347832ed3703082 Jonathan del Strother committed Sep 16, 2009
Showing with 101 additions and 19 deletions.
  1. +6 −0 BBOSC.xcodeproj/project.pbxproj
  2. +25 −0 BBOSCInPort.h
  3. +47 −0 BBOSCInPort.m
  4. +5 −5 BBOSCManager.h
  5. +12 −9 BBOSCManager.m
  6. +2 −2 BBOSCPluginReceiver.h
  7. +4 −3 BBOSCPluginReceiver.m
@@ -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 = "<group>"; };
FC520E8E1059234900FE3004 /* BBOSCManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BBOSCManager.m; sourceTree = "<group>"; };
FC520F3C105936A500FE3004 /* VVOpenSource.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = VVOpenSource.xcodeproj; path = lib/vvosc/VVOpenSource.xcodeproj; sourceTree = "<group>"; };
+ FCDF33AC1060FDF2001FAA34 /* BBOSCInPort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BBOSCInPort.h; sourceTree = "<group>"; };
+ FCDF33AD1060FDF2001FAA34 /* BBOSCInPort.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BBOSCInPort.m; sourceTree = "<group>"; };
/* 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 = "<group>";
@@ -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;
};
View
@@ -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 <Cocoa/Cocoa.h>
+
+// 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
View
@@ -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
View
@@ -8,16 +8,16 @@
#import <Cocoa/Cocoa.h>
-@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
View
@@ -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];
}
View
@@ -8,7 +8,7 @@
#import <Quartz/Quartz.h>
-@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;
View
@@ -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<QCPlugInContext>)context
{
if (self.oscPort) {
- [[BBOSCManager sharedManager] removeOutput:self.oscPort];
+ [[BBOSCManager sharedManager] removeInput:self.oscPort];
self.oscPort = nil;
}
}

0 comments on commit 5d750a6

Please sign in to comment.