VocalEasel/Sources/VLGrooveController.mm

128 lines
3.1 KiB
Plaintext
Raw Normal View History

2007-04-15 05:22:30 +00:00
//
// VLGrooveController.mm
// Vocalese
//
// Created by Matthias Neeracher on 2/1/07.
// Copyright 2007 __MyCompanyName__. All rights reserved.
//
#import "VLGrooveController.h"
#import "VLSheetView.h"
2007-04-23 05:46:37 +00:00
#import "VLDocument.h"
2007-04-15 05:22:30 +00:00
@implementation VLGrooveController
- (id) initWithSheetView:(VLSheetView *)view;
{
self = [super initWithWindowNibName:@"VLGroove"];
fGrooves = [[NSDictionary alloc] initWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"Grooves" ofType:@"plist"]];
fSubStyleFilter =
[[NSPredicate predicateWithFormat:
@"!(SELF like[c] '.DESC') AND !(SELF matches[c] '.*(Intro|End)\\\\d*$')"]
retain];
2007-04-23 05:46:37 +00:00
fDocument = [view document];
2007-04-15 05:22:30 +00:00
[NSApp beginSheet: [self window]
modalForWindow: [view window]
modalDelegate: self
didEndSelector: @selector(didEndSheet:returnCode:contextInfo:)
contextInfo: view];
return self;
}
- (void) dealloc
{
[fGrooves release];
[super dealloc];
}
2007-04-23 05:46:37 +00:00
- (IBAction) togglePlay:(id)sender
{
if ([sender state])
[fDocument playWithGroove:[[fBrowser selectedCellInColumn:1] stringValue]];
else
[fDocument stop:sender];
}
2007-04-15 05:22:30 +00:00
- (IBAction)endSheet:(id)sender
{
[NSApp endSheet:[self window] returnCode:[sender tag]];
}
- (void)didEndSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
2007-04-23 05:46:37 +00:00
[fDocument stop:self];
2007-04-15 05:22:30 +00:00
if (returnCode == NSAlertFirstButtonReturn)
[(VLSheetView *)contextInfo setGroove:[[fBrowser selectedCellInColumn:1] stringValue]];
2007-04-23 05:46:37 +00:00
else
[(VLSheetView *)contextInfo setGroove:nil];
2007-04-15 05:22:30 +00:00
[[self window] orderOut:self];
}
2007-04-24 18:32:32 +00:00
- (NSString *)browser:(NSBrowser *)sender titleOfColumn:(int)column
2007-04-15 05:22:30 +00:00
{
if (!column)
return @"Style";
else
return @"Substyle";
}
- (void)updateStyle
{
[fStyle autorelease];
[fSubStyleList release];
fStyle = [[[fBrowser selectedCellInColumn:0] stringValue] retain];
fSubStyles = [fGrooves objectForKey:fStyle];
fSubStyleList = [[[fSubStyles allKeys]
filteredArrayUsingPredicate:fSubStyleFilter]
retain];
}
2007-04-24 18:32:32 +00:00
- (int)browser:(NSBrowser *)sender numberOfRowsInColumn:(int)column
2007-04-15 05:22:30 +00:00
{
[fBrowser setTakesTitleFromPreviousColumn:NO];
[fBrowser setDoubleAction:@selector(endSheet:)];
if (!column) {
return [fGrooves count];
} else {
[self updateStyle];
return [fSubStyleList count];
}
}
2007-04-24 18:32:32 +00:00
- (void)browser:(NSBrowser *)sender willDisplayCell:(id)cell atRow:(int)row column:(int)column
2007-04-15 05:22:30 +00:00
{
if (!column) {
[cell setStringValue:
[[[fGrooves allKeys]
sortedArrayUsingSelector:@selector(compare:)]
objectAtIndex:row]];
} else {
[cell setStringValue:[fSubStyleList objectAtIndex:row]];
[cell setLeaf:YES];
}
}
- (IBAction)updateDescription:(id)sender
{
BOOL validStyle = [fBrowser selectedColumn];
[fOKButton setEnabled:validStyle];
2007-04-23 05:46:37 +00:00
[fPlayButton setEnabled:validStyle];
if (validStyle) {
2007-04-15 05:22:30 +00:00
[fDescription setStringValue:
[NSString stringWithFormat:@"%@\n\n%@",
[fSubStyles objectForKey:@".DESC"],
[fSubStyles objectForKey:
[[fBrowser selectedCellInColumn:1] stringValue]]]];
2007-04-23 05:46:37 +00:00
[fDocument stop:self];
[self togglePlay:fPlayButton];
} else
2007-04-15 05:22:30 +00:00
[fDescription setStringValue:[fSubStyles objectForKey:@".DESC"]];
}
@end