Permalink
Browse files

Added 'Data Combine' patch to concatenate data bytes. [#2170]

  • Loading branch information...
1 parent 2d99dd8 commit 0a1360437d0b84bb542a0c0e8c5dd8ecd228681d @jlstrecker jlstrecker committed May 1, 2012
Showing with 141 additions and 0 deletions.
  1. +15 −0 DTDataCombinePatch.h
  2. +49 −0 DTDataCombinePatch.m
  3. +48 −0 DTDataCombinePatch.xml
  4. +12 −0 DataTools.xcodeproj/project.pbxproj
  5. +2 −0 DataToolsPrincipal.m
  6. +15 −0 TestDTConvert.m
View
@@ -0,0 +1,15 @@
+@interface DTDataCombinePatch : QCPatch
+{
+ QCVirtualPort *inputRawData1;
+ QCVirtualPort *inputRawData2;
+ QCVirtualPort *outputRawData;
+}
+
++(BOOL)isSafe;
++(BOOL)allowsSubpatchesWithIdentifier:(id)identifier;
++(QCPatchExecutionMode)executionModeWithIdentifier:(id)identifier;
++(QCPatchTimeMode)timeModeWithIdentifier:(id)identifier;
+-(id)initWithIdentifier:(id)identifier;
+-(BOOL)execute:(QCOpenGLContext*)context time:(double)time arguments:(NSDictionary*)arguments;
+
+@end
View
@@ -0,0 +1,49 @@
+#import "DTDataCombinePatch.h"
+
+@implementation DTDataCombinePatch
+
++(BOOL)isSafe
+{
+ return NO;
+}
+
++(BOOL)allowsSubpatchesWithIdentifier:(id)identifier
+{
+ return NO;
+}
+
++(QCPatchExecutionMode)executionModeWithIdentifier:(id)identifier
+{
+ return kQCPatchExecutionModeProcessor;
+}
+
++(QCPatchTimeMode)timeModeWithIdentifier:(id)identifier
+{
+ return kQCPatchTimeModeNone;
+}
+
+-(id)initWithIdentifier:(id)identifier
+{
+ if(self = [super initWithIdentifier:identifier])
+ {
+ [[self userInfo] setObject:@"Kineme Data Combine" forKey:@"name"];
+ }
+ return self;
+}
+
+-(BOOL)execute:(QCOpenGLContext*)context time:(double)time arguments:(NSDictionary*)arguments
+{
+ if ([inputRawData1 wasUpdated] || [inputRawData2 wasUpdated])
+ {
+ NSData *data1 = [inputRawData1 rawValue];
+ NSData *data2 = [inputRawData2 rawValue];
+ NSMutableData *d = [NSMutableData dataWithCapacity:[data1 length]+[data2 length]];
+ [d appendData:data1];
+ [d appendData:data2];
+ [outputRawData setRawValue:d];
+ }
+
+ return YES;
+}
+
+@end
View
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>nodeAttributes</key>
+ <dict>
+ <key>name</key>
+ <string>Data Combine</string>
+ <key>categories</key>
+ <array>
+ <string>Kineme DataTools</string>
+ </array>
+ <key>copyright</key>
+ <string>Copyright 2011 Kosada Incorporated. All rights reserved.</string>
+ <key>description</key>
+ <string>This patch combines two raw data objects by concatenating them.
+
+http://kineme.net/</string>
+ </dict>
+ <key>inputAttributes</key>
+ <dict>
+ <key>inputRawData1</key>
+ <dict>
+ <key>name</key>
+ <string>Raw Data 1</string>
+ <key>description</key>
+ <string>Raw data bytes</string>
+ </dict>
+ <key>inputRawData2</key>
+ <dict>
+ <key>name</key>
+ <string>Raw Data 2</string>
+ <key>description</key>
+ <string>Raw data bytes</string>
+ </dict>
+ </dict>
+ <key>outputAttributes</key>
+ <dict>
+ <key>outputRawData</key>
+ <dict>
+ <key>name</key>
+ <string>Combined Raw Data</string>
+ <key>description</key>
+ <string>Raw data bytes of the inputs concatenated</string>
+ </dict>
+ </dict>
+</dict>
+</plist>
@@ -90,6 +90,9 @@
E74FE11F15505A7F009E29D6 /* DTImageToDataPatch.m in Sources */ = {isa = PBXBuildFile; fileRef = E74FE11E15505A7F009E29D6 /* DTImageToDataPatch.m */; };
E74FE12015505A7F009E29D6 /* DTImageToDataPatch.m in Sources */ = {isa = PBXBuildFile; fileRef = E74FE11E15505A7F009E29D6 /* DTImageToDataPatch.m */; };
E74FE12215505A8D009E29D6 /* DTImageToDataPatch.xml in Resources */ = {isa = PBXBuildFile; fileRef = E74FE12115505A8D009E29D6 /* DTImageToDataPatch.xml */; };
+ E74FE17C15506B58009E29D6 /* DTDataCombinePatch.m in Sources */ = {isa = PBXBuildFile; fileRef = E74FE17B15506B58009E29D6 /* DTDataCombinePatch.m */; };
+ E74FE17D15506B58009E29D6 /* DTDataCombinePatch.m in Sources */ = {isa = PBXBuildFile; fileRef = E74FE17B15506B58009E29D6 /* DTDataCombinePatch.m */; };
+ E74FE18015506DA0009E29D6 /* DTDataCombinePatch.xml in Resources */ = {isa = PBXBuildFile; fileRef = E74FE17F15506DA0009E29D6 /* DTDataCombinePatch.xml */; };
E78586E913E9F64A000BBF4B /* DTStructureKeyPatch.m in Sources */ = {isa = PBXBuildFile; fileRef = E78586E813E9F64A000BBF4B /* DTStructureKeyPatch.m */; };
E78586EB13E9F7DB000BBF4B /* DTStructureKeyPatch.xml in Resources */ = {isa = PBXBuildFile; fileRef = E78586EA13E9F7DB000BBF4B /* DTStructureKeyPatch.xml */; };
E785870513E9F967000BBF4B /* DTStructureKeyPatch.m in Sources */ = {isa = PBXBuildFile; fileRef = E78586E813E9F64A000BBF4B /* DTStructureKeyPatch.m */; };
@@ -200,6 +203,9 @@
E74FE11D15505A7F009E29D6 /* DTImageToDataPatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTImageToDataPatch.h; sourceTree = "<group>"; };
E74FE11E15505A7F009E29D6 /* DTImageToDataPatch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DTImageToDataPatch.m; sourceTree = "<group>"; };
E74FE12115505A8D009E29D6 /* DTImageToDataPatch.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = DTImageToDataPatch.xml; sourceTree = "<group>"; };
+ E74FE17A15506B58009E29D6 /* DTDataCombinePatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTDataCombinePatch.h; sourceTree = "<group>"; };
+ E74FE17B15506B58009E29D6 /* DTDataCombinePatch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DTDataCombinePatch.m; sourceTree = "<group>"; };
+ E74FE17F15506DA0009E29D6 /* DTDataCombinePatch.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = DTDataCombinePatch.xml; sourceTree = "<group>"; };
E78586E713E9F64A000BBF4B /* DTStructureKeyPatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTStructureKeyPatch.h; sourceTree = "<group>"; };
E78586E813E9F64A000BBF4B /* DTStructureKeyPatch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DTStructureKeyPatch.m; sourceTree = "<group>"; };
E78586EA13E9F7DB000BBF4B /* DTStructureKeyPatch.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = DTStructureKeyPatch.xml; sourceTree = "<group>"; };
@@ -378,6 +384,7 @@
E7DC1664134E13E600DBDFC8 /* DTConvertFromDataPatch.xml */,
E74FE0CA15502E3F009E29D6 /* DTStringToDataPatch.xml */,
E74FE12115505A8D009E29D6 /* DTImageToDataPatch.xml */,
+ E74FE17F15506DA0009E29D6 /* DTDataCombinePatch.xml */,
);
name = XML;
sourceTree = "<group>";
@@ -476,6 +483,8 @@
E74FE09F15502957009E29D6 /* DTStringToDataPatch.m */,
E74FE11D15505A7F009E29D6 /* DTImageToDataPatch.h */,
E74FE11E15505A7F009E29D6 /* DTImageToDataPatch.m */,
+ E74FE17A15506B58009E29D6 /* DTDataCombinePatch.h */,
+ E74FE17B15506B58009E29D6 /* DTDataCombinePatch.m */,
);
name = Convert;
sourceTree = "<group>";
@@ -582,6 +591,7 @@
E78586EB13E9F7DB000BBF4B /* DTStructureKeyPatch.xml in Resources */,
E74FE0CB15502E3F009E29D6 /* DTStringToDataPatch.xml in Resources */,
E74FE12215505A8D009E29D6 /* DTImageToDataPatch.xml in Resources */,
+ E74FE18015506DA0009E29D6 /* DTDataCombinePatch.xml in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -641,6 +651,7 @@
E785870513E9F967000BBF4B /* DTStructureKeyPatch.m in Sources */,
E74FE0A115502957009E29D6 /* DTStringToDataPatch.m in Sources */,
E74FE12015505A7F009E29D6 /* DTImageToDataPatch.m in Sources */,
+ E74FE17D15506B58009E29D6 /* DTDataCombinePatch.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -676,6 +687,7 @@
E78586E913E9F64A000BBF4B /* DTStructureKeyPatch.m in Sources */,
E74FE0A015502957009E29D6 /* DTStringToDataPatch.m in Sources */,
E74FE11F15505A7F009E29D6 /* DTImageToDataPatch.m in Sources */,
+ E74FE17C15506B58009E29D6 /* DTDataCombinePatch.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -18,6 +18,7 @@
#import "DTConvertFromDataPatch.h"
#import "DTStringToDataPatch.h"
#import "DTImageToDataPatch.h"
+#import "DTDataCombinePatch.h"
#import "SpookySendPatch.h"
#import "SpookyReceivePatch.h"
@@ -81,6 +82,7 @@ +(void)registerNodesWithManager:(QCNodeManager*)manager
KIRegisterPatch(DTConvertFromDataPatch);
KIRegisterPatch(DTStringToDataPatch);
KIRegisterPatch(DTImageToDataPatch);
+ KIRegisterPatch(DTDataCombinePatch);
/* disabled for now, since this hack results in input splitters that require DataTools (which is kinda misleading)
{
View
@@ -3,6 +3,7 @@
#import "DTConvertFromDataPatch.h"
#import "DTStringToDataPatch.h"
#import "DTImageToDataPatch.h"
+#import "DTDataCombinePatch.h"
@interface TestDTConvert : SkankySDK_TestCase
@@ -87,4 +88,18 @@ - (void)testImageToData
GHAssertEqualObjects(expectedPngData, [outPngData subdataWithRange:NSMakeRange(0, 4)], @"");
}
+- (void)testDataCombine
+{
+ DTDataCombinePatch *patch = [[DTDataCombinePatch alloc] initWithIdentifier:nil];
+
+ NSData *inData1 = [@"first" dataUsingEncoding:NSUTF8StringEncoding];
+ NSData *inData2 = [@"second" dataUsingEncoding:NSUTF8StringEncoding];
+ [self setInputValue:inData1 forPort:@"inputRawData1" onPatch:patch];
+ [self setInputValue:inData2 forPort:@"inputRawData2" onPatch:patch];
+ [self executePatch:patch];
+ NSData *outData = [self getOutputForPort:@"outputRawData" onPatch:patch];
+ NSString *outString = [[NSString alloc] initWithData:outData encoding:NSUTF8StringEncoding];
+ GHAssertEqualStrings(@"firstsecond", outString, @"");
+}
+
@end

0 comments on commit 0a13604

Please sign in to comment.