Create temp files on demand, show progress animation

This commit is contained in:
Matthias Neeracher 2007-04-18 07:05:04 +00:00
parent 7cbbe5e050
commit 3312d2ecc0
15 changed files with 190 additions and 92 deletions

Binary file not shown.

View File

@ -55,7 +55,7 @@
logToolItem = id;
outputToolItem = id;
playToolItem = id;
runToolItem = id;
progressToolItem = id;
stopToolItem = id;
zoomInToolItem = id;
zoomOutToolItem = id;

View File

@ -8,10 +8,10 @@
<string>460.0</string>
<key>IBOpenObjects</key>
<array>
<integer>216</integer>
<integer>196</integer>
<integer>5</integer>
<integer>144</integer>
<integer>196</integer>
<integer>216</integer>
</array>
<key>IBSystem Version</key>
<string>9A412</string>

Binary file not shown.

View File

@ -1,5 +1,5 @@
<?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">
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
@ -97,11 +97,29 @@
<string>Midi</string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<string>None</string>
<key>LSTypeIsPackage</key>
<false/>
<key>NSPersistentStoreTypeKey</key>
<string>XML</string>
<string>Binary</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>pdf</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>application/pdf</string>
</array>
<key>CFBundleTypeName</key>
<string>VLPDFType</string>
<key>CFBundleTypeRole</key>
<string>None</string>
<key>LSTypeIsPackage</key>
<false/>
<key>NSPersistentStoreTypeKey</key>
<string>Binary</string>
</dict>
</array>
<key>CFBundleExecutable</key>
@ -117,7 +135,7 @@
<key>CFBundleSignature</key>
<string>VçEz</string>
<key>CFBundleVersion</key>
<string>1.0a1</string>
<string>1.0a2</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>

View File

@ -16,24 +16,24 @@
@interface VLDocument : NSDocument
{
VLSong * song;
NSString * lilypondTemplate;
NSString * songTitle;
NSString * songLyricist;
NSString * songComposer;
NSString * songArranger;
NSString * songGroove;
NSNumber * songTempo;
NSString * tmpPath;
NSFileWrapper * vcsWrapper;
NSMutableArray* observers;
int repeatVolta;
bool brandNew;
VLSheetWindow * sheetWin;
VLLogWindow * logWin;
VLPDFWindow * pdfWin;
VLKeyValueUndo* undo;
VLSong * song;
NSString * lilypondTemplate;
NSString * songTitle;
NSString * songLyricist;
NSString * songComposer;
NSString * songArranger;
NSString * songGroove;
NSNumber * songTempo;
NSString * tmpPath;
NSFileWrapper * vcsWrapper;
NSMutableArray* observers;
NSMutableDictionary*validTmpFiles;
int repeatVolta;
bool brandNew;
VLSheetWindow * sheetWin;
VLLogWindow * logWin;
VLPDFWindow * pdfWin;
VLKeyValueUndo* undo;
}
- (VLSong *) song;
@ -48,7 +48,6 @@
- (void) setDivisions:(int)divisions;
- (void) setRepeatVolta:(int)repeatVolta;
- (IBAction) engrave:(id)sender;
- (IBAction) showOutput:(id)sender;
- (IBAction) showLog:(id)sender;
@ -56,11 +55,13 @@
- (NSString *) workPath;
- (NSString *) baseName;
- (NSURL *) fileURLWithExtension:(NSString*)extension;
- (void) createTmpFileWithExtension:(NSString*)ext ofType:(NSString*)type;
- (NSTask *) taskWithLaunchPath:(NSString *)path arguments:(NSArray *)args;
- (void) changedFileWrapper;
- (void) willChangeSong;
- (void) didChangeSong;
- (void) addObserver:(id)observer;
- (VLLogWindow *)logWin;
@end

View File

@ -75,6 +75,7 @@
repeatVolta = 2;
brandNew = true;
observers = [[NSMutableArray alloc] init];
validTmpFiles = [[NSMutableDictionary alloc] initWithCapacity:10];
[self setHasUndoManager:YES];
undo =
[[VLKeyValueUndo alloc] initWithOwner:self
@ -90,6 +91,12 @@
return self;
}
- (void)updateChangeCount:(NSDocumentChangeType)changeType
{
[validTmpFiles removeAllObjects];
[super updateChangeCount:changeType];
}
- (void) addObserver:(id)observer
{
[observers addObject:observer];
@ -299,6 +306,8 @@
forSaveOperation:saveOperation error:outError];
if (!vcsWrapper)
vcsWrapper = preservedVCSWrapper;
if ([typeName isEqual:@"VLNativeType"])
[validTmpFiles removeAllObjects];
return res;
}
@ -315,6 +324,8 @@
return [self mmaFileWrapperWithError:outError];
} else if ([typeName isEqual:@"VLMIDIType"]) {
return [self midiFileWrapperWithError:outError];
} else if ([typeName isEqual:@"VLPDFType"]) {
return [self pdfFileWrapperWithError:outError];
} else {
if (outError)
*outError = [NSError errorWithDomain:NSCocoaErrorDomain
@ -358,6 +369,19 @@
[self setFileModificationDate:modDate];
}
- (void) createTmpFileWithExtension:(NSString*)ext ofType:(NSString*)type
{
if (![validTmpFiles objectForKey:ext]) {
NSError * err;
if ([self writeToURL:[self fileURLWithExtension:ext]
ofType:type error:&err]
) {
[validTmpFiles setObject:type forKey:ext];
[self changedFileWrapper];
}
}
}
- (NSTask *) taskWithLaunchPath:(NSString *)launch arguments:(NSArray *)args;
{
NSTask * task = [[NSTask alloc] init];
@ -377,52 +401,9 @@
return task;
}
- (IBAction) engrave:(id)sender
{
NSString * base = [self baseName];
NSBundle * mainBundle = [NSBundle mainBundle];
//
// Convert to Lilypond format
//
NSError * err;
[self writeToURL:[self fileURLWithExtension:@"ly"]
ofType:@"VLLilypondType" error:&err];
NSString * launch =
[mainBundle pathForResource:@"lilyWrapper" ofType:@""
inDirectory:@"bin"];
NSString * tool =
[[NSUserDefaults standardUserDefaults]
stringForKey:@"VLLilypondPath"];
NSArray * args = [NSArray arrayWithObjects:tool, base, nil];
NSTask * task = [self taskWithLaunchPath:launch arguments:args];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(engraveDone:)
name:NSTaskDidTerminateNotification object:task];
[task launch];
}
- (void)engraveDone:(NSNotification *)notification {
[[NSNotificationCenter defaultCenter] removeObserver: self];
int status = [[notification object] terminationStatus];
if (!status) {
[[self pdfWin] showWindow: self];
[pdfWin reloadPDF];
} else {
[[self logWin] showWindow: self];
NSBeep();
}
[self changedFileWrapper];
}
- (IBAction) play:(id)sender
{
NSError * err;
[self writeToURL:[self fileURLWithExtension:@"mid"]
ofType:@"VLMIDIType" error:&err];
[self changedFileWrapper];
[self createTmpFileWithExtension:@"mid" ofType:@"VLMIDIType"];
VLSoundOut::Instance()->PlayFile(
CFDataRef([NSData dataWithContentsOfURL:
[self fileURLWithExtension:@"mid"]]));
@ -435,7 +416,9 @@
- (IBAction) showOutput:(id)sender
{
[self createTmpFileWithExtension:@"pdf" ofType:@"VLPDFType"];
[[self pdfWin] showWindow:sender];
[pdfWin reloadPDF];
}
- (IBAction) showLog:(id)sender

View File

@ -1,5 +1,5 @@
//
// VLMMADocument.h
// VLMIDIDocument.h
// Vocalese
//
// Created by Matthias Neeracher on 10/20/06.

View File

@ -1,12 +1,12 @@
//
// VLLilypondDocument.mm
// VLMIDIDocument.mm
// Vocalese
//
// Created by Matthias Neeracher on 10/20/06.
// Copyright 2006 __MyCompanyName__. All rights reserved.
//
#import "VLMMADocument.h"
#import "VLMIDIDocument.h"
@implementation VLDocument (MIDI)
@ -14,14 +14,9 @@
{
NSBundle * mainBundle = [NSBundle mainBundle];
//
// Convert to MMA format
//
NSError * err;
NSURL * mmaURL = [self fileURLWithExtension:@"mma"];
[self writeToURL: mmaURL ofType:@"VLMMAType" error:&err];
[self changedFileWrapper];
[self createTmpFileWithExtension:@"mma" ofType:@"VLMMAType"];
NSURL * mmaURL = [self fileURLWithExtension:@"mma"];
NSString * launch =
[mainBundle pathForResource:@"mmaWrapper" ofType:@""
inDirectory:@"bin"];
@ -32,16 +27,16 @@
addObserver:self selector:@selector(mmaDone:)
name:NSTaskDidTerminateNotification object:task];
[sheetWin startAnimation];
[task launch];
[task waitUntilExit];
[sheetWin stopAnimation];
int status = [task terminationStatus];
if (!status) {
return [[[NSFileWrapper alloc]
initWithPath:[[self fileURLWithExtension:@"mid"] path]]
autorelease];
} else {
NSBeep();
if (outError)
*outError = [NSError errorWithDomain:NSCocoaErrorDomain
code:NSPersistentStoreSaveError
@ -58,7 +53,7 @@
if (!status) {
;
} else {
[[self logWin] showWindow: self];
[logWin showWindow: self];
NSBeep();
}
}

View File

@ -1,5 +1,5 @@
//
// VLLilypondDocument.mm
// VLMMADocument.mm
// Vocalese
//
// Created by Matthias Neeracher on 10/20/06.

16
Sources/VLPDFDocument.h Normal file
View File

@ -0,0 +1,16 @@
//
// VLPDFDocument.h
// Vocalese
//
// Created by Matthias Neeracher on 10/20/06.
// Copyright 2006 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "VLDocument.h"
@interface VLDocument (PDF)
- (NSFileWrapper *)pdfFileWrapperWithError:(NSError **)outError;
@end

64
Sources/VLPDFDocument.mm Normal file
View File

@ -0,0 +1,64 @@
//
// VLPDFDocument.mm
// Vocalese
//
// Created by Matthias Neeracher on 10/20/06.
// Copyright 2006 __MyCompanyName__. All rights reserved.
//
#import "VLPDFDocument.h"
@implementation VLDocument (PDF)
- (NSFileWrapper *)pdfFileWrapperWithError:(NSError **)outError
{
NSString * base = [self baseName];
NSBundle * mainBundle = [NSBundle mainBundle];
[self createTmpFileWithExtension:@"ly" ofType:@"VLLilypondType"];
NSString * launch =
[mainBundle pathForResource:@"lilyWrapper" ofType:@""
inDirectory:@"bin"];
NSString * tool =
[[NSUserDefaults standardUserDefaults]
stringForKey:@"VLLilypondPath"];
NSArray * args = [NSArray arrayWithObjects:tool, base, nil];
NSTask * task = [self taskWithLaunchPath:launch arguments:args];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(pdfDone:)
name:NSTaskDidTerminateNotification object:task];
[sheetWin startAnimation];
[task launch];
[task waitUntilExit];
[sheetWin stopAnimation];
int status = [task terminationStatus];
if (!status) {
return [[[NSFileWrapper alloc]
initWithPath:[[self fileURLWithExtension:@"pdf"] path]]
autorelease];
} else {
if (outError)
*outError = [NSError errorWithDomain:NSCocoaErrorDomain
code:NSPersistentStoreSaveError
userInfo:nil];
return nil;
}
}
- (void)pdfDone:(NSNotification *)notification {
[[NSNotificationCenter defaultCenter] removeObserver: self];
int status = [[notification object] terminationStatus];
if (!status) {
;
} else {
[[self logWin] showWindow: self];
NSBeep();
}
}
@end

View File

@ -24,16 +24,18 @@
@interface VLSheetWindow : NSWindowController {
VLEditable * editTarget;
IBOutlet id runToolItem;
IBOutlet id outputToolItem;
IBOutlet id logToolItem;
IBOutlet id playToolItem;
IBOutlet id stopToolItem;
IBOutlet id zoomInToolItem;
IBOutlet id zoomOutToolItem;
IBOutlet id progressToolItem;
}
- (VLEditable *) editTarget;
- (void) setEditTarget:(VLEditable *)editable;
- (void) startAnimation;
- (void) stopAnimation;
@end

View File

@ -45,11 +45,11 @@
static NSString* sInputToolbarIdentifier = @"Vocalese Sheet Window Toolbar Identifier";
static NSString* sOutputToolbarItemIdentifier = @"Output Toolbar Item Identifier";
static NSString* sLogToolbarItemIdentifier = @"Log Toolbar Item Identifier";
static NSString* sRunToolbarItemIdentifier = @"Run Toolbar Item Identifier";
static NSString* sPlayToolbarItemIdentifier = @"Play Toolbar Item Identifier";
static NSString* sStopToolbarItemIdentifier = @"Stop Toolbar Item Identifier";
static NSString* sZoomInToolbarItemIdentifier = @"Zoom In Toolbar Item Identifier";
static NSString* sZoomOutToolbarItemIdentifier = @"Zoom Out Toolbar Item Identifier";
static NSString* sProgressToolbarItemIdentifier = @"Progress Toolbar Item Identifier";
- (id)initWithWindow:(NSWindow *)window
{
@ -89,8 +89,6 @@ static NSString* sZoomOutToolbarItemIdentifier = @"Zoom Out Toolbar Item Identif
prototype = outputToolItem;
else if ([itemIdent isEqual: sLogToolbarItemIdentifier])
prototype = logToolItem;
else if ([itemIdent isEqual: sRunToolbarItemIdentifier])
prototype = runToolItem;
else if ([itemIdent isEqual: sPlayToolbarItemIdentifier])
prototype = playToolItem;
else if ([itemIdent isEqual: sStopToolbarItemIdentifier])
@ -109,6 +107,10 @@ static NSString* sZoomOutToolbarItemIdentifier = @"Zoom Out Toolbar Item Identif
[toolbarItem setImage: [prototype image]];
[toolbarItem setTarget: [prototype target]];
[toolbarItem setAction: [prototype action]];
} else if ([itemIdent isEqual: sProgressToolbarItemIdentifier]) {
toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
[toolbarItem setView: progressToolItem];
} else {
toolbarItem = nil;
}
@ -117,7 +119,7 @@ static NSString* sZoomOutToolbarItemIdentifier = @"Zoom Out Toolbar Item Identif
- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar {
return [NSArray arrayWithObjects:
sRunToolbarItemIdentifier,
sOutputToolbarItemIdentifier,
NSToolbarSeparatorItemIdentifier,
sPlayToolbarItemIdentifier,
sStopToolbarItemIdentifier,
@ -125,23 +127,34 @@ static NSString* sZoomOutToolbarItemIdentifier = @"Zoom Out Toolbar Item Identif
sZoomInToolbarItemIdentifier,
sZoomOutToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
sOutputToolbarItemIdentifier,
sLogToolbarItemIdentifier, nil];
sLogToolbarItemIdentifier,
sProgressToolbarItemIdentifier,
nil];
}
- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar {
return [NSArray arrayWithObjects:
sRunToolbarItemIdentifier,
sPlayToolbarItemIdentifier,
sStopToolbarItemIdentifier,
sZoomInToolbarItemIdentifier,
sZoomOutToolbarItemIdentifier,
sOutputToolbarItemIdentifier,
sLogToolbarItemIdentifier,
sProgressToolbarItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarSeparatorItemIdentifier, nil];
}
- (void) startAnimation
{
[progressToolItem startAnimation:self];
}
- (void) stopAnimation
{
[progressToolItem stopAnimation:self];
}
@end

View File

@ -51,6 +51,7 @@
9599ED9D0B731CC500A6A2F7 /* VLGrooveController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9599ED9B0B731CC500A6A2F7 /* VLGrooveController.mm */; };
95A1C37C0AF1D4370076597D /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95A1C37B0AF1D4370076597D /* Quartz.framework */; };
95A1C3860AF2ACE20076597D /* VLSheetWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = 95A1C3850AF2ACE20076597D /* VLSheetWindow.mm */; };
95A55C540BD5E5770068A203 /* VLPDFDocument.mm in Sources */ = {isa = PBXBuildFile; fileRef = 95A55C530BD5E5770068A203 /* VLPDFDocument.mm */; };
95B3E1A70960E58B000E9C0D /* Music in Resources */ = {isa = PBXBuildFile; fileRef = 95B3E1980960E58B000E9C0D /* Music */; };
95B66658096BCA1F00FE18C9 /* VLSheetViewNotes.mm in Sources */ = {isa = PBXBuildFile; fileRef = 95B66657096BCA1F00FE18C9 /* VLSheetViewNotes.mm */; };
95BDA15909540BF1009F9D65 /* VLSheetView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 95BDA15809540BF1009F9D65 /* VLSheetView.mm */; };
@ -179,6 +180,8 @@
95A1C37B0AF1D4370076597D /* Quartz.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quartz.framework; path = /System/Library/Frameworks/Quartz.framework; sourceTree = "<absolute>"; };
95A1C3840AF2ACE20076597D /* VLSheetWindow.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = VLSheetWindow.h; path = Sources/VLSheetWindow.h; sourceTree = "<group>"; };
95A1C3850AF2ACE20076597D /* VLSheetWindow.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; name = VLSheetWindow.mm; path = Sources/VLSheetWindow.mm; sourceTree = "<group>"; };
95A55C520BD5E5760068A203 /* VLPDFDocument.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = VLPDFDocument.h; path = Sources/VLPDFDocument.h; sourceTree = "<group>"; };
95A55C530BD5E5770068A203 /* VLPDFDocument.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; name = VLPDFDocument.mm; path = Sources/VLPDFDocument.mm; sourceTree = "<group>"; };
95B3E1980960E58B000E9C0D /* Music */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Music; path = Resources/Music; sourceTree = "<group>"; };
95B66653096BC6A100FE18C9 /* VLSheetViewInternal.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = VLSheetViewInternal.h; path = Sources/VLSheetViewInternal.h; sourceTree = "<group>"; };
95B66656096BCA1F00FE18C9 /* VLSheetViewNotes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLSheetViewNotes.h; path = Sources/VLSheetViewNotes.h; sourceTree = "<group>"; };
@ -321,6 +324,8 @@
2A37F4ABFDCFA73011CA2CEA /* Classes */ = {
isa = PBXGroup;
children = (
95A55C520BD5E5760068A203 /* VLPDFDocument.h */,
95A55C530BD5E5770068A203 /* VLPDFDocument.mm */,
95EDA5A80B06DE46004D8D6E /* VLMIDIDocument.h */,
95EDA5A90B06DE46004D8D6E /* VLMIDIDocument.mm */,
95F820A90AF884A30010963D /* VLMMADocument.h */,
@ -650,6 +655,7 @@
955CBA4F0B2366DD001CF4A1 /* VLKeyValueUndo.mm in Sources */,
954DD4E60B44E67F0056C504 /* VLSheetViewSelection.mm in Sources */,
9599ED9D0B731CC500A6A2F7 /* VLGrooveController.mm in Sources */,
95A55C540BD5E5770068A203 /* VLPDFDocument.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};