Skip to content

Commit

Permalink
Can now load files from commandline @Danne!
Browse files Browse the repository at this point in the history
Drag app on to terminal, then MLV. No changes to MLV code, only to Mac code.
  • Loading branch information
ilia3101 authored Jul 15, 2017
1 parent 042dd7c commit 93c8604
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 72 deletions.
21 changes: 20 additions & 1 deletion platform/cocoa/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>

/* Host name */
#include <unistd.h>

Expand Down Expand Up @@ -254,6 +254,25 @@ int NSApplicationMain(int argc, const char * argv[])
[[window contentView] addSubview: timelineSlider];


/* If commandline arguments were used load clip... */
if (argc > 1)
{
/* Hardcoded for now as 1st argument is clip */
char * mlvPath = (char *)argv[1];
char * mlvName = mlvPath;
int clipNameStart = strlen(mlvPath) - 1;

/* Point to just name */
while (mlvPath[clipNameStart] != '/')
{
mlvName = mlvPath + clipNameStart;
clipNameStart--;
}

setAppNewMlvClip(mlvPath, mlvName);
}


/* Start the FPS timer on background thread */
beginFrameDrawing();

Expand Down
4 changes: 2 additions & 2 deletions platform/cocoa/main_methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

/* Methods that actually do stuff related to MLV on user interface interactions */

/* This is a function as it may be used in more than one place */
void setAppNewMlvClip(char * mlvPathString, char * mlvFileName);

/* Button methods */

@interface NSButton (mainMethods)

/* Opens a dialog to select MLV file + sets MLV file to that */
Expand All @@ -16,7 +17,6 @@
@end

/* Slider methods */

@interface NSSlider (mainMethods)

/* I think its clear what these do... */
Expand Down
142 changes: 73 additions & 69 deletions platform/cocoa/main_methods.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,77 @@
/* We always set MLV object to this amount of cache */
extern int cacheSizeMB;


/* This is now a function so that it can be accessedd from any part of the app, not just a button press */
void setAppNewMlvClip(char * mlvPathString, char * mlvFileName)
{
/* Set app name to include MLV clip's name */
[window setTitle: [NSString stringWithFormat: @ APP_NAME " | %s", mlvFileName]];

/* Don't allow drawing frames, incase of adjustments during loading */
dontDraw = 1;

/* Destroy it just for simplicity... and make a new one */
freeMlvObject(videoMLV);

/* Create a NEW object with a NEW MLV clip! */
videoMLV = initMlvObjectWithClip( (char *)mlvPathString );

/* This funtion really SHOULD be integrated with the one above */
mapMlvFrames(videoMLV, 0);

/* If use has terminal this is useful */
printMlvInfo(videoMLV);

/* This needs to be joined (or segmentation fault 11 :D) */
setMlvProcessing(videoMLV, processingSettings);

/* Limit frame cache to 38% of RAM size (its fast anyway) */
setMlvRawCacheLimitMegaBytes(videoMLV, (uint64_t)(cacheSizeMB));
/* Tell it how many cores we habe so it can be optimal */
setMlvCpuCores(videoMLV, MAC_CORES);

/* Adjust image size(probably) */
[previewWindow setImage: nil];

/* I think this is like free() */
[rawImageObject release];
[rawBitmap release];

/* Size may need changing */
free(rawImage);
rawImage = malloc( sizeof(uint8_t) * 3 * getMlvWidth(videoMLV) * getMlvHeight(videoMLV) );

/* Now reallocate and set up all imagey-objecty things */
rawBitmap = [ [NSBitmapImageRep alloc]
initWithBitmapDataPlanes: (unsigned char * _Nullable * _Nullable)&rawImage
/* initWithBitmapDataPlanes: NULL */
pixelsWide: getMlvWidth(videoMLV)
pixelsHigh: getMlvHeight(videoMLV)
bitsPerSample: 8
samplesPerPixel: 3
hasAlpha: NO
isPlanar: NO
colorSpaceName: @"NSDeviceRGBColorSpace"
bitmapFormat: 0
bytesPerRow: getMlvWidth(videoMLV) * 3
bitsPerPixel: 24 ];

rawImageObject = [[NSImage alloc] initWithSize: NSMakeSize(getMlvWidth(videoMLV),getMlvHeight(videoMLV)) ];
[rawImageObject addRepresentation:rawBitmap];

[previewWindow setImage: rawImageObject];

/* Allow drawing frames */
dontDraw = 0;
/* Set current frame where slider is at */
currentFrameIndex = (int)( frameSliderPosition * (getMlvFrames(videoMLV)-1) );
/* So view updates and shows new clip */
frameChanged++;

/* End of MLV opening stuff */
}

/* Button methods */

@implementation NSButton (mainMethods)
Expand All @@ -66,7 +137,7 @@ -(void)openMlvDialog
/* Can only choose MLV files */
[panel setAllowedFileTypes: [NSArray arrayWithObject: @"mlv"]];

[panel beginWithCompletionHandler: ^ (NSInteger result)
[panel beginWithCompletionHandler: ^ (NSInteger result)
{
if (result == NSFileHandlingPanelOKButton)
{
Expand All @@ -76,74 +147,7 @@ -(void)openMlvDialog
const char * mlvPathString = [fileURL.path UTF8String];
const char * mlvFileName = [[[fileURL.path lastPathComponent] stringByDeletingPathExtension] UTF8String];

int pathLength = strlen(mlvPathString);
NSLog(@"New MLV file: %s, strlen: %i", mlvPathString, pathLength);

/* Set app name to include MLV clip's name */
[window setTitle: [NSString stringWithFormat: @ APP_NAME " | %s", mlvFileName]];

/* Don't allow drawing frames, incase of adjustments during loading */
dontDraw = 1;

/* Destroy it just for simplicity... and make a new one */
freeMlvObject(videoMLV);

/* Create a NEW object with a NEW MLV clip! */
videoMLV = initMlvObjectWithClip( (char *)mlvPathString );

/* This funtion really SHOULD be integrated with the one above */
mapMlvFrames(videoMLV, 0);

/* If use has terminal this is useful */
printMlvInfo(videoMLV);

/* This needs to be joined (or segmentation fault 11 :D) */
setMlvProcessing(videoMLV, processingSettings);

/* Limit frame cache to 38% of RAM size (its fast anyway) */
setMlvRawCacheLimitMegaBytes(videoMLV, (uint64_t)(cacheSizeMB));
/* Tell it how many cores we habe so it can be optimal */
setMlvCpuCores(videoMLV, MAC_CORES);

/* Adjust image size(probably) */
[previewWindow setImage: nil];

/* I think this is like free() */
[rawImageObject release];
[rawBitmap release];

/* Size may need changing */
free(rawImage);
rawImage = malloc( sizeof(uint8_t) * 3 * getMlvWidth(videoMLV) * getMlvHeight(videoMLV) );

/* Now reallocate and set up all imagey-objecty things */
rawBitmap = [ [NSBitmapImageRep alloc]
initWithBitmapDataPlanes: (unsigned char * _Nullable * _Nullable)&rawImage
/* initWithBitmapDataPlanes: NULL */
pixelsWide: getMlvWidth(videoMLV)
pixelsHigh: getMlvHeight(videoMLV)
bitsPerSample: 8
samplesPerPixel: 3
hasAlpha: NO
isPlanar: NO
colorSpaceName: @"NSDeviceRGBColorSpace"
bitmapFormat: 0
bytesPerRow: getMlvWidth(videoMLV) * 3
bitsPerPixel: 24 ];

rawImageObject = [[NSImage alloc] initWithSize: NSMakeSize(getMlvWidth(videoMLV),getMlvHeight(videoMLV)) ];
[rawImageObject addRepresentation:rawBitmap];

[previewWindow setImage: rawImageObject];

/* Allow drawing frames */
dontDraw = 0;
/* Set current frame where slider is at */
currentFrameIndex = (int)( frameSliderPosition * (getMlvFrames(videoMLV)-1) );
/* So view updates and shows new clip */
frameChanged++;

/* End of MLV opening stuff */
setAppNewMlvClip((char *)mlvPathString, (char *)mlvFileName);
}
}
[panel release];
Expand Down

0 comments on commit 93c8604

Please sign in to comment.