Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use a shared OSC Manager, allows for multiple patches on one port

  • Loading branch information...
commit 9eee89efb6ab58104c6dbd0dc7be7bb4c338f7ff 1 parent 38ce122
Jonathan del Strother authored
View
6 BBOSC.xcodeproj/project.pbxproj
@@ -34,6 +34,7 @@
FC520BFC1057E69B00FE3004 /* NSArrayExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = FC520BFB1057E69B00FE3004 /* NSArrayExtensions.m */; };
FC520CFB1058085100FE3004 /* BBOSCViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FC520CFA1058085100FE3004 /* BBOSCViewController.m */; };
FC520D301058137600FE3004 /* OSCExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = FC520D2F1058137600FE3004 /* OSCExtensions.m */; };
+ FC520E8F1059234900FE3004 /* BBOSCManager.m in Sources */ = {isa = PBXBuildFile; fileRef = FC520E8E1059234900FE3004 /* BBOSCManager.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -126,6 +127,8 @@
FC520CFA1058085100FE3004 /* BBOSCViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BBOSCViewController.m; sourceTree = "<group>"; };
FC520D2E1058137600FE3004 /* OSCExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSCExtensions.h; sourceTree = "<group>"; };
FC520D2F1058137600FE3004 /* OSCExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSCExtensions.m; sourceTree = "<group>"; };
+ 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>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -189,6 +192,8 @@
FC520CFA1058085100FE3004 /* BBOSCViewController.m */,
FC520D2E1058137600FE3004 /* OSCExtensions.h */,
FC520D2F1058137600FE3004 /* OSCExtensions.m */,
+ FC520E8D1059234900FE3004 /* BBOSCManager.h */,
+ FC520E8E1059234900FE3004 /* BBOSCManager.m */,
);
name = Classes;
sourceTree = "<group>";
@@ -355,6 +360,7 @@
FC520BFC1057E69B00FE3004 /* NSArrayExtensions.m in Sources */,
FC520CFB1058085100FE3004 /* BBOSCViewController.m in Sources */,
FC520D301058137600FE3004 /* OSCExtensions.m in Sources */,
+ FC520E8F1059234900FE3004 /* BBOSCManager.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
25 BBOSCManager.h
@@ -0,0 +1,25 @@
+//
+// BBOSCManager.h
+// BBOSC
+//
+// Created by Jonathan del Strother on 10/09/2009.
+// Copyright 2009 Best Before Media Ltd. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+@class OSCManager, OSCInPort, OSCOutPort;
+@interface BBOSCManager : NSObject {
+ NSMutableArray* delegates;
+ OSCManager* oscManager;
+ NSLock* delegateLock;
+}
++(id)sharedManager;
+-(void)addDelegate:(id)delegate;
+-(void)removeDelegate:(id)delegate;
+
+- (OSCInPort*)createNewInputForPort:(int)p withLabel:(NSString *)l;
+- (OSCOutPort*)createNewOutputToAddress:(NSString *)a atPort:(int)p withLabel:(NSString *)l;
+- (void)removeInput:(id)p;
+- (void)removeOutput:(id)p;
+@end
View
61 BBOSCManager.m
@@ -0,0 +1,61 @@
+//
+// BBOSCManager.m
+// BBOSC
+//
+// Created by Jonathan del Strother on 10/09/2009.
+// Copyright 2009 Best Before Media Ltd. All rights reserved.
+//
+
+#import "BBOSCManager.h"
+#import "OSCExtensions.h"
+
+
+@implementation BBOSCManager
+
+static id sharedManager=nil;
++(id)sharedManager {
+ if (!sharedManager)
+ sharedManager = [[self alloc] init];
+ return sharedManager;
+}
+-(id)init {
+ if (self = [super init]) {
+ oscManager = [[OSCManager alloc] init];
+ oscManager.delegate = self;
+ delegates = [[NSMutableArray alloc] init];
+ delegateLock = [[NSLock alloc] init];
+ }
+ return self;
+}
+
+-(void)addDelegate:(id)delegate {
+ [delegateLock lock];
+ [delegates addObject:delegate];
+ [delegateLock unlock];
+}
+-(void)removeDelegate:(id)delegate {
+ [delegateLock lock];
+ [delegates removeObject:delegate];
+ [delegateLock unlock];
+}
+
+- (void) receivedOSCMessage:(OSCMessage *)m {
+ [delegateLock lock];
+ [delegates makeObjectsPerformSelector:@selector(receivedOSCMessage:) withObject:m];
+ [delegateLock unlock];
+}
+
+- (OSCInPort *) createNewInputForPort:(int)p withLabel:(NSString *)l {
+ return [oscManager createNewInputForPort:p withLabel:l];
+}
+- (OSCOutPort *) createNewOutputToAddress:(NSString *)a atPort:(int)p withLabel:(NSString *)l {
+ return [oscManager createNewOutputToAddress:a atPort:p withLabel:l];
+}
+- (void) removeInput:(id)p {
+ [oscManager removeInput:p];
+}
+- (void) removeOutput:(id)p {
+ [oscManager removeOutput:p];
+}
+
+@end
View
1  BBOSCPlugInSender.h
@@ -12,7 +12,6 @@
@interface BBOSCPlugInSender : QCPlugIn {
}
-@property (nonatomic, readonly, retain) OSCManager *oscManager;
@property (nonatomic, readonly, retain) OSCOutPort *oscPort;
@property (nonatomic, readonly, retain) NSArray* oscParameters;
View
16 BBOSCPlugInSender.m
@@ -12,19 +12,18 @@
#import "BBOSCViewController.h"
#import "BBOSCPlugInSender.h"
#import "NSArrayExtensions.h"
-
+#import "BBOSCManager.h"
#define kQCPlugIn_Name @"BBOSC Sender"
#define kQCPlugIn_Description @"Best Before Open Sound Control sender plugin"
@interface BBOSCPlugInSender ()
-@property (nonatomic, readwrite, retain) OSCManager *oscManager;
@property (nonatomic, readwrite, retain) OSCOutPort *oscPort;
@property (nonatomic, readwrite, retain) NSArray* oscParameters;
@end
@implementation BBOSCPlugInSender
-@synthesize oscManager, oscPort, oscParameters;
+@synthesize oscPort, oscParameters;
@dynamic inputBroadcastPort, inputBroadcastPath;
+ (NSDictionary*) attributes
@@ -73,8 +72,6 @@ - (id) init
/*
Allocate any permanent resource required by the plug-in.
*/
- self.oscManager = [[[OSCManager alloc] init] autorelease];
-
self.oscParameters = [NSArray array];
}
@@ -93,7 +90,6 @@ - (void) finalize
- (void) dealloc
{
[oscPort release];
- [oscManager release];
[super dealloc];
}
@@ -166,8 +162,10 @@ Return NO in case of failure during the execution (this will prevent rendering o
if ([self didValueForInputKeyChange:@"inputBroadcastPort"]) {
if (self.oscPort)
- [self.oscManager removeOutput:self.oscPort];
- self.oscPort = [self.oscManager createNewOutputToAddress:@"0.0.0.0" atPort:self.inputBroadcastPort withLabel:@"BB OSC"];
+ [[BBOSCManager sharedManager] removeOutput:self.oscPort];
+ self.oscPort = [[BBOSCManager sharedManager] createNewOutputToAddress:@"0.0.0.0" atPort:self.inputBroadcastPort withLabel:@"BB OSC"];
+ if (!self.oscPort)
+ NSLog(@"Failed to created output port");
inputsChanged = YES;
}
@@ -202,7 +200,7 @@ Return NO in case of failure during the execution (this will prevent rendering o
- (void) disableExecution:(id<QCPlugInContext>)context
{
if (self.oscPort) {
- [self.oscManager removeOutput:self.oscPort];
+ [[BBOSCManager sharedManager] removeOutput:self.oscPort];
self.oscPort = nil;
}
}
View
3  BBOSCPluginReceiver.h
@@ -8,7 +8,7 @@
#import <Quartz/Quartz.h>
-@class OSCManager, OSCInPort;
+@class OSCInPort;
@interface BBOSCPluginReceiver : QCPlugIn {
NSMutableArray* messages;
NSLock* messageLock;
@@ -17,7 +17,6 @@
@property (nonatomic, readonly, retain) NSArray* oscParameters;
-@property (nonatomic, readonly, retain) OSCManager *oscManager;
@property (nonatomic, readonly, retain) OSCInPort *oscPort;
@property (nonatomic, readwrite, assign) NSUInteger inputReceivingPort;
View
28 BBOSCPluginReceiver.m
@@ -12,12 +12,12 @@
#import "BBOSCViewController.h"
#import "NSArrayExtensions.h"
#import "OSCExtensions.h"
+#import "BBOSCManager.h"
#define kQCPlugIn_Name @"BBOSC Receiver"
#define kQCPlugIn_Description @"Best Before Open Sound Control receiver plugin"
@interface BBOSCPluginReceiver ()
-@property (nonatomic, readwrite, retain) OSCManager *oscManager;
@property (nonatomic, readwrite, retain) OSCOutPort *oscPort;
@property (nonatomic, readwrite, retain) NSArray* oscParameters;
@property (nonatomic, readwrite, retain) NSString* listeningPath;
@@ -25,7 +25,7 @@ @interface BBOSCPluginReceiver ()
@implementation BBOSCPluginReceiver
@dynamic inputReceivingPort, inputReceivingPath, outputMessageReceived, outputMessagePath;
-@synthesize oscManager, oscPort, oscParameters, listeningPath;
+@synthesize oscPort, oscParameters, listeningPath;
+ (NSDictionary*) attributes
{
@@ -77,8 +77,7 @@ + (QCPlugInTimeMode) timeMode
- (id) init
{
if(self = [super init]) {
- self.oscManager = [[[OSCManager alloc] init] autorelease];
- self.oscManager.delegate = self;
+ [[BBOSCManager sharedManager] addDelegate:self];
self.oscParameters = [NSArray array];
messages = [[NSMutableArray alloc] init];
messageLock = [[NSLock alloc] init];
@@ -98,9 +97,8 @@ - (void) finalize
- (void) dealloc
{
+ [[BBOSCManager sharedManager] removeDelegate:self];
[oscPort release];
- oscManager.delegate = nil;
- [oscManager release];
[messages release];
[messageLock release];
[listeningPath release];
@@ -182,8 +180,10 @@ Return NO in case of failure during the execution (this will prevent rendering o
if ([self didValueForInputKeyChange:@"inputReceivingPort"]) {
if (self.oscPort)
- [self.oscManager removeInput:self.oscPort];
- self.oscPort = [self.oscManager createNewInputForPort:self.inputReceivingPort withLabel:@"BB OSC"];
+ [[BBOSCManager sharedManager] removeInput:self.oscPort];
+ self.oscPort = [[BBOSCManager sharedManager] createNewInputForPort:self.inputReceivingPort withLabel:@"BB OSC"];
+ if (!self.oscPort)
+ NSLog(@"Failed to created input port");
}
if ([self didValueForInputKeyChange:@"inputReceivingPath"]) {
@@ -226,19 +226,13 @@ Return NO in case of failure during the execution (this will prevent rendering o
- (void) disableExecution:(id<QCPlugInContext>)context
{
if (self.oscPort) {
- [self.oscManager removeOutput:self.oscPort];
+ [[BBOSCManager sharedManager] removeOutput:self.oscPort];
self.oscPort = nil;
}
}
-- (void) stopExecution:(id<QCPlugInContext>)context
-{
- /*
- Called by Quartz Composer when rendering of the composition stops: perform any required cleanup for the plug-in.
- */
- [oscManager removeOutput:oscPort];
- [oscPort release];
- oscPort = nil;
+- (void) stopExecution:(id<QCPlugInContext>)context {
+
}
@end
Please sign in to comment.
Something went wrong with that request. Please try again.