Commits

Cliff Biffle committed 01e6772

Factored recording out of KVDepthView into the app delegate, using a KVDepthRecorder.

  • Participants
  • Parent commits f7f2adb

Comments (0)

Files changed (4)

File KVDepthView.h

   GLfloat worldRotation[4];
   GLfloat spinY, spinX;
     
-  FILE *depthOutput;
-  
   NSColor *deviceWhite;  
 }
 
 
 - (IBAction) toggleDepthFieldUpdates: sender;
 - (IBAction) toggleLighting: sender;
-- (IBAction) toggleRecording: sender;
 - (IBAction) toggleAnaglyph: sender;
 - (IBAction) toggleTextures: sender;
 @end

File KVDepthView.m

 #import "KVDepthView.h"
 #import "KVSpaceModel.h"
 #import "KVRayFieldSpaceModel.h"
+#import "KVDepthRecorder.h"
 #import "trackball.h"
 #import "utility.h"
 
 #pragma mark --- Properties ---
 
 @synthesize updateQueued;
-
 @synthesize lightsOn;
 
 - (void) setLightsOn: (BOOL)flag {
   [sender setState: lightsOn? NSOnState : NSOffState];
 }
 
-- (IBAction) toggleRecording: sender {
-  if (recording) {
-    @synchronized(self) {
-      fclose(depthOutput);
-      depthOutput = NULL;
-      recording = NO;
-    }
-    [sender setState: NSOffState];
-  } else {
-    @synchronized(self) {
-      depthOutput = fopen("/tmp/depth-recording.bin", "wb");
-      recording = YES;
-    }
-    [sender setState: NSOnState];
-  }
-}
-
 - (IBAction) toggleAnaglyph: sender {
   self.anaglyph = !self.anaglyph;
   [self setNeedsDisplay: YES];
 #pragma mark --- KFKinect Delegate Implementation ---
 
 - (void) setLatestDepthSamples: (NSData *)data {
-  const uint8_t *buffer = [data bytes];
-  @synchronized (self) {
-    if (recording) {
-      fwrite(buffer, sizeof(uint16_t), 640*480, depthOutput);
-    }
-  }
-      
   if (!self.frozen) {
     [spaceModel setDepthSamples: data];
     [self setNeedsDisplay: YES];

File KinectViewerAppDelegate.h

  */
 
 #import <Cocoa/Cocoa.h>
-#import "KVKinectHardware.h"
 
 @class KVDepthView;
+@class KVDepthRecorder;
+@class KVKinectHardware;
 
 // Since this is a single-window application, I'm abusing the
 // application delegate as the controller.
   // Interface to the active Kinect.  If no Kinect is being
   // used (i.e. we're replaying a file) this will be nil.
   KVKinectHardware *kinect;
+  
+  KVDepthRecorder *recorder;
 }
 
 @property (assign) IBOutlet NSWindow *window;
 @property (assign) IBOutlet KVDepthView *depthView;
 
+- (IBAction) toggleRecording: sender;
+
 @end

File KinectViewerAppDelegate.m

 #import "KinectViewerAppDelegate.h"
 #import "KVDepthView.h"
 #import "KVDepthPlayer.h"
+#import "KVDepthRecorder.h"
+#import "KVKinectHardware.h"
 
 @implementation KinectViewerAppDelegate
 
   }
 }
 
+- (IBAction) toggleRecording: sender {
+  if (recorder) {
+    [recorder close];
+    recorder = nil;
+    [sender setState: NSOffState];
+  } else {
+    recorder = [[KVDepthRecorder alloc] init];
+    [recorder open: @"/tmp/depth-recording.bin"];
+    [recorder bind: @"latestDepthSamples" toObject: kinect withKeyPath: @"latestDepthSamples" options: nil];
+    [sender setState: NSOnState];
+  }
+}
+
 @end