VocalEasel/Sources/VLGrooveController.mm

129 lines
3.0 KiB
Plaintext
Raw Permalink Normal View History

2007-04-15 05:22:30 +00:00
//
2007-04-27 06:41:34 +00:00
// File: VLGrooveController.mm - Control groove selection sheet
2007-04-15 05:22:30 +00:00
//
2007-04-27 06:41:34 +00:00
// Author(s):
//
// (MN) Matthias Neeracher
//
2011-09-04 19:48:57 +00:00
// Copyright © 2007-2011 Matthias Neeracher
2007-04-15 05:22:30 +00:00
//
#import "VLGrooveController.h"
#import "VLSheetView.h"
2011-09-04 19:48:57 +00:00
#import "VLSheetWindow.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 matches[c] '.*(Intro|End)\\\\d*$')"]
2007-04-15 05:22:30 +00:00
retain];
2008-01-24 01:29:18 +00:00
fView = view;
2011-09-04 23:38:01 +00:00
fSheetWin = [[view window] windowController];
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])
2008-01-24 01:29:18 +00:00
[fView playWithGroove:[[fBrowser selectedCellInColumn:1] stringValue]];
2007-04-23 05:46:37 +00:00
else
2011-09-04 19:48:57 +00:00
[fSheetWin stop:self];
2007-04-23 05:46:37 +00:00
}
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
{
2011-09-04 19:48:57 +00:00
[fSheetWin stop:self];
2007-04-15 05:22:30 +00:00
if (returnCode == NSAlertFirstButtonReturn)
2008-01-24 01:29:18 +00:00
[fView setGroove:[[fBrowser selectedCellInColumn:1] stringValue]];
2007-04-23 05:46:37 +00:00
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 objectForKey:@".ORDER"]
2007-04-15 05:22:30 +00:00
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]]]];
2011-09-04 19:48:57 +00:00
[fSheetWin stop:self];
2007-04-23 05:46:37 +00:00
[self togglePlay:fPlayButton];
} else
2007-04-15 05:22:30 +00:00
[fDescription setStringValue:[fSubStyles objectForKey:@".DESC"]];
}
@end