2006-11-12 11:37:36 +00:00
|
|
|
//
|
2007-04-27 06:41:34 +00:00
|
|
|
// File: VLMIDIDocument.mm - Export document in MIDI format
|
2006-11-12 11:37:36 +00:00
|
|
|
//
|
2007-04-27 06:41:34 +00:00
|
|
|
// Author(s):
|
|
|
|
//
|
|
|
|
// (MN) Matthias Neeracher
|
|
|
|
//
|
|
|
|
// Copyright © 2006-2007 Matthias Neeracher
|
2006-11-12 11:37:36 +00:00
|
|
|
//
|
|
|
|
|
2007-04-18 07:05:04 +00:00
|
|
|
#import "VLMIDIDocument.h"
|
2006-11-12 11:37:36 +00:00
|
|
|
|
|
|
|
@implementation VLDocument (MIDI)
|
|
|
|
|
|
|
|
- (NSFileWrapper *)midiFileWrapperWithError:(NSError **)outError
|
|
|
|
{
|
|
|
|
NSBundle * mainBundle = [NSBundle mainBundle];
|
|
|
|
|
2007-04-18 07:05:04 +00:00
|
|
|
[self createTmpFileWithExtension:@"mma" ofType:@"VLMMAType"];
|
2006-11-12 11:37:36 +00:00
|
|
|
|
2007-04-18 07:05:04 +00:00
|
|
|
NSURL * mmaURL = [self fileURLWithExtension:@"mma"];
|
2006-11-12 11:37:36 +00:00
|
|
|
NSString * launch =
|
|
|
|
[mainBundle pathForResource:@"mmaWrapper" ofType:@""
|
|
|
|
inDirectory:@"bin"];
|
|
|
|
NSArray * args = [NSArray arrayWithObject: [mmaURL path]];
|
|
|
|
NSTask * task = [self taskWithLaunchPath:launch arguments:args];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
addObserver:self selector:@selector(mmaDone:)
|
|
|
|
name:NSTaskDidTerminateNotification object:task];
|
|
|
|
|
2007-04-18 07:05:04 +00:00
|
|
|
[sheetWin startAnimation];
|
2006-11-12 11:37:36 +00:00
|
|
|
[task launch];
|
|
|
|
[task waitUntilExit];
|
2007-04-18 07:05:04 +00:00
|
|
|
[sheetWin stopAnimation];
|
2006-11-12 11:37:36 +00:00
|
|
|
int status = [task terminationStatus];
|
|
|
|
if (!status) {
|
|
|
|
return [[[NSFileWrapper alloc]
|
|
|
|
initWithPath:[[self fileURLWithExtension:@"mid"] path]]
|
|
|
|
autorelease];
|
|
|
|
} else {
|
|
|
|
if (outError)
|
|
|
|
*outError = [NSError errorWithDomain:NSCocoaErrorDomain
|
|
|
|
code:NSPersistentStoreSaveError
|
|
|
|
userInfo:nil];
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-12 09:01:19 +00:00
|
|
|
|
|
|
|
- (void)mmaDone:(NSNotification *)notification {
|
2007-04-19 18:23:33 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self
|
|
|
|
name:NSTaskDidTerminateNotification object:[notification object]];
|
2007-01-12 09:01:19 +00:00
|
|
|
int status = [[notification object] terminationStatus];
|
|
|
|
if (!status) {
|
|
|
|
;
|
|
|
|
} else {
|
2007-04-18 07:05:04 +00:00
|
|
|
[logWin showWindow: self];
|
2007-01-12 09:01:19 +00:00
|
|
|
NSBeep();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-12 11:37:36 +00:00
|
|
|
@end
|