mirror of
https://github.com/microtherion/VocalEasel.git
synced 2024-12-23 03:34:00 +00:00
89 lines
2.3 KiB
Plaintext
89 lines
2.3 KiB
Plaintext
//
|
|
// File: VLXMLDocument.mm - Read and write native (MusicXML) document format
|
|
//
|
|
// Author(s):
|
|
//
|
|
// (MN) Matthias Neeracher
|
|
//
|
|
// Copyright © 2006-2007 Matthias Neeracher
|
|
//
|
|
|
|
#import "VLXMLDocument.h"
|
|
#import "VLPListDocument.h"
|
|
|
|
@implementation VLDocument (XML)
|
|
|
|
|
|
- (NSArray *)propertyKeys
|
|
{
|
|
static NSArray * sPropertyKeys = nil;
|
|
|
|
if (!sPropertyKeys)
|
|
sPropertyKeys = [[NSArray alloc] initWithObjects:
|
|
@"songGroove", @"songTempo", nil];
|
|
|
|
return sPropertyKeys;
|
|
}
|
|
|
|
- (NSFileWrapper *)XMLFileWrapperWithError:(NSError **)outError flat:(BOOL)flat;
|
|
{
|
|
NSFileWrapper * contents = [self fileWrapperWithFilter:@"VLMusicXMLType" error:outError];
|
|
|
|
if (!contents) {
|
|
return nil;
|
|
} else if (flat) {
|
|
return contents;
|
|
} else {
|
|
NSFileWrapper * wrap = [[[NSFileWrapper alloc]
|
|
initDirectoryWithFileWrappers:
|
|
[NSDictionary dictionary]]
|
|
autorelease];
|
|
[contents setPreferredFilename:@"Song"];
|
|
[wrap addFileWrapper:contents];
|
|
NSDictionary * prop =
|
|
[self dictionaryWithValuesForKeys:[self propertyKeys]];
|
|
[wrap addRegularFileWithContents:
|
|
[NSPropertyListSerialization dataFromPropertyList:prop
|
|
format:NSPropertyListXMLFormat_v1_0
|
|
errorDescription:nil]
|
|
preferredFilename:@"Properties"];
|
|
if (vcsWrapper)
|
|
[wrap addFileWrapper:vcsWrapper];
|
|
|
|
return wrap;
|
|
}
|
|
}
|
|
|
|
- (BOOL)readFromXMLFileWrapper:(NSFileWrapper *)wrapper error:(NSError **)outError
|
|
{
|
|
if ([wrapper isDirectory]) {
|
|
NSDictionary * wrappers = [wrapper fileWrappers];
|
|
if ((vcsWrapper = [wrappers objectForKey:@"CVS"])
|
|
|| (vcsWrapper = [wrappers objectForKey:@".svn"])
|
|
)
|
|
[vcsWrapper retain];
|
|
NSFileWrapper * prop = [wrappers objectForKey:@"Properties"];
|
|
if (prop) {
|
|
NSUndoManager * undoMgr = [self undoManager];
|
|
[undoMgr disableUndoRegistration];
|
|
[self setValuesForKeysWithDictionary:
|
|
[NSPropertyListSerialization
|
|
propertyListFromData:[prop regularFileContents]
|
|
mutabilityOption:NSPropertyListImmutable
|
|
format:nil errorDescription:nil]];
|
|
[undoMgr enableUndoRegistration];
|
|
}
|
|
return [self readFromFileWrapper:[wrappers objectForKey:@"Song"] withFilter:@"VLMusicXMLType"
|
|
error:outError];
|
|
} else {
|
|
if ([self readFromFileWrapper:wrapper withFilter:@"VLMusicXMLType" error:outError]) {
|
|
[self setFileURL:nil];
|
|
|
|
return YES;
|
|
} else
|
|
return NO;
|
|
}
|
|
}
|
|
|
|
@end
|