2006-09-11 02:49:56 +00:00
|
|
|
//
|
|
|
|
// MyDocument.m
|
|
|
|
// Vocalese
|
|
|
|
//
|
|
|
|
// Created by Matthias Neeracher on 12/17/05.
|
|
|
|
// Copyright __MyCompanyName__ 2005 . All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "VLDocument.h"
|
2006-10-22 07:16:29 +00:00
|
|
|
#import "VLXMLDocument.h"
|
|
|
|
#import "VLLilypondDocument.h"
|
2006-09-11 02:49:56 +00:00
|
|
|
|
2006-10-03 17:52:54 +00:00
|
|
|
@implementation VLEditable
|
|
|
|
|
|
|
|
- (NSString *) stringValue
|
|
|
|
{
|
|
|
|
return @"";
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setStringValue:(NSString*)val
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) validValue:(NSString*)val
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2006-10-08 05:56:25 +00:00
|
|
|
- (void) moveToNext
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) moveToPrev
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) highlightCursor
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-10-03 17:52:54 +00:00
|
|
|
@end
|
|
|
|
|
2006-09-11 02:49:56 +00:00
|
|
|
@implementation VLDocument
|
|
|
|
|
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self) {
|
|
|
|
|
|
|
|
// Add your subclass-specific initialization here.
|
|
|
|
// If an error occurs here, send a [self release] message and return nil.
|
|
|
|
|
2006-10-22 07:16:29 +00:00
|
|
|
song = new VLSong;
|
|
|
|
editTarget = nil;
|
|
|
|
lilypondTemplate = @"default";
|
2006-10-23 07:42:53 +00:00
|
|
|
songTitle = @"";
|
|
|
|
songLyricist = @"";
|
|
|
|
songComposer = @"";
|
|
|
|
songArranger = @"";
|
2006-09-11 02:49:56 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
delete song;
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (VLSong *) song
|
|
|
|
{
|
|
|
|
return song;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumber *) songKey
|
|
|
|
{
|
|
|
|
const VLProperties & prop = song->fProperties.front();
|
|
|
|
|
|
|
|
return [NSNumber numberWithInt: (prop.fKey << 8) | (prop.fMode & 0xFF)];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setKey:(int)key transpose:(BOOL)transpose
|
|
|
|
{
|
|
|
|
VLProperties & prop = song->fProperties.front();
|
|
|
|
|
2006-10-14 10:10:19 +00:00
|
|
|
if (transpose)
|
|
|
|
song->Transpose((7*((key>>8)-prop.fKey) % 12));
|
|
|
|
|
2006-09-11 02:49:56 +00:00
|
|
|
prop.fKey = key >> 8;
|
|
|
|
prop.fMode= key & 0xFF;
|
2006-10-14 10:10:19 +00:00
|
|
|
|
|
|
|
[self updateChangeCount:NSChangeDone];
|
2006-09-11 02:49:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumber *) songTime
|
|
|
|
{
|
|
|
|
const VLProperties & prop = song->fProperties.front();
|
|
|
|
|
|
|
|
return [NSNumber numberWithInt: (prop.fTime.fNum << 8) | prop.fTime.fDenom];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setTimeNum:(int)num denom:(int)denom
|
|
|
|
{
|
|
|
|
VLProperties & prop = song->fProperties.front();
|
|
|
|
|
|
|
|
prop.fTime = VLFraction(num, denom);
|
2006-10-14 10:10:19 +00:00
|
|
|
|
|
|
|
[self updateChangeCount:NSChangeDone];
|
2006-09-11 02:49:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumber *) songDivisions
|
|
|
|
{
|
|
|
|
const VLProperties & prop = song->fProperties.front();
|
|
|
|
|
|
|
|
return [NSNumber numberWithInt: prop.fDivisions];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setDivisions:(int)divisions
|
|
|
|
{
|
|
|
|
VLProperties & prop = song->fProperties.front();
|
|
|
|
|
|
|
|
prop.fDivisions = divisions;
|
2006-10-14 10:10:19 +00:00
|
|
|
|
|
|
|
[self updateChangeCount:NSChangeDone];
|
2006-09-11 02:49:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)windowNibName
|
|
|
|
{
|
|
|
|
return @"VLDocument";
|
|
|
|
}
|
|
|
|
|
2006-10-14 10:10:19 +00:00
|
|
|
- (void)windowControllerDidLoadNib:(NSWindowController *) controller
|
2006-09-11 02:49:56 +00:00
|
|
|
{
|
2006-10-14 10:10:19 +00:00
|
|
|
[super windowControllerDidLoadNib:controller];
|
|
|
|
[controller setShouldCloseDocument:YES];
|
2006-09-11 02:49:56 +00:00
|
|
|
}
|
|
|
|
|
2006-10-22 07:16:29 +00:00
|
|
|
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
|
|
|
|
{
|
2006-10-23 07:42:53 +00:00
|
|
|
if ([typeName isEqual:@"VLNativeType"]) {
|
2006-10-22 07:16:29 +00:00
|
|
|
return [self XMLDataWithError:outError];
|
2006-10-23 07:42:53 +00:00
|
|
|
} else if ([typeName isEqual:@"VLLilypondType"]) {
|
2006-10-22 07:16:29 +00:00
|
|
|
return [self lilypondDataWithError:outError];
|
2006-10-23 07:42:53 +00:00
|
|
|
} else {
|
|
|
|
if (outError)
|
|
|
|
*outError = [NSError errorWithDomain:NSCocoaErrorDomain
|
|
|
|
code:NSPersistentStoreInvalidTypeError
|
|
|
|
userInfo:nil];
|
2006-10-22 07:16:29 +00:00
|
|
|
return nil;
|
2006-10-23 07:42:53 +00:00
|
|
|
}
|
2006-10-22 07:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
|
|
|
|
{
|
2006-10-23 07:42:53 +00:00
|
|
|
if ([typeName isEqual:@"VLNativeType"]) {
|
2006-10-22 07:16:29 +00:00
|
|
|
return [self readFromXMLData:data error:outError];
|
2006-10-23 07:42:53 +00:00
|
|
|
} else {
|
|
|
|
if (outError)
|
|
|
|
*outError = [NSError errorWithDomain:NSCocoaErrorDomain
|
|
|
|
code:NSPersistentStoreInvalidTypeError
|
|
|
|
userInfo:nil];
|
2006-10-22 07:16:29 +00:00
|
|
|
return NO;
|
2006-10-23 07:42:53 +00:00
|
|
|
}
|
2006-10-22 07:16:29 +00:00
|
|
|
}
|
|
|
|
|
2006-09-11 02:49:56 +00:00
|
|
|
@end
|