VocalEasel/Sources/VLSheetWindow.mm

264 lines
5.8 KiB
Plaintext
Raw Normal View History

//
2007-04-27 06:41:34 +00:00
// File: VLSheetWindow.mm - Control lead sheet editing window
//
2007-04-27 06:41:34 +00:00
// Author(s):
//
// (MN) Matthias Neeracher
//
2011-08-29 00:01:49 +00:00
// Copyright <20> 2005-2011 Matthias Neeracher
//
#import "VLSheetWindow.h"
#import "VLDocument.h"
#import "VLPDFWindow.h"
#import "VLLogWindow.h"
2011-09-04 19:48:57 +00:00
#import "VLSoundOut.h"
#import "VLSheetView.h"
#import "VLSheetViewSelection.h"
@implementation VLEditable
- (NSString *) stringValue
{
return @"";
}
- (void) setStringValue:(NSString*)val
{
}
- (BOOL) validValue:(NSString*)val
{
return YES;
}
- (void) moveToNext
{
}
- (void) moveToPrev
{
}
- (void) highlightCursor
{
}
2011-09-10 23:15:21 +00:00
- (BOOL)canExtendSelection:(VLRegion)region
{
return NO;
}
2011-09-11 02:03:22 +00:00
- (void)extendSelection:(VLLocation)at
2011-09-10 23:15:21 +00:00
{
}
2011-09-10 23:54:34 +00:00
- (BOOL)hidden
{
return NO;
}
- (void) deleteAtEndOfPlayback
{
}
@end
@implementation VLSheetWindow
@synthesize logWin;
- (id)initWithWindow:(NSWindow *)window
{
if (self = [super initWithWindow:window]) {
editTarget = nil;
2011-09-04 19:48:57 +00:00
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
NSOperationQueue * oq = [NSOperationQueue mainQueue];
soundStartObserver = [nc addObserverForName:(NSString*)kVLSoundStartedNotification
object:nil queue:oq usingBlock:^(NSNotification *note) {
2011-09-04 21:03:55 +00:00
[[[self window] toolbar] validateVisibleItems];
2011-09-04 19:48:57 +00:00
}];
soundStopObserver = [nc addObserverForName:(NSString*)kVLSoundStoppedNotification
object:nil queue:oq usingBlock:^(NSNotification *note) {
2011-09-04 21:03:55 +00:00
[[[self window] toolbar] validateVisibleItems];
2011-09-11 21:27:53 +00:00
if (VLSoundOut::Instance()->AtBeginning())
[editTarget deleteAtEndOfPlayback]; // Kill note cursor if we ran to end
2011-09-04 19:48:57 +00:00
}];
}
return self;
}
2011-09-04 19:48:57 +00:00
- (void) dealloc
{
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
[nc removeObserver:soundStartObserver];
[nc removeObserver:soundStopObserver];
}
- (VLEditable *)editTarget
{
return editTarget;
}
- (void)setEditTarget:(VLEditable *)editable
{
2011-09-11 21:27:53 +00:00
if (editTarget != editable) {
[editTarget release];
editTarget = editable;
}
}
- (void) startAnimation
{
2011-08-29 00:01:49 +00:00
[progressIndicator startAnimation:self];
}
- (void) stopAnimation
{
2011-08-29 00:01:49 +00:00
[progressIndicator stopAnimation:self];
}
2008-01-29 03:02:25 +00:00
- (IBAction) zoomIn: (id) sender
{
[sheetView zoomIn:sender];
}
- (IBAction) zoomOut: (id) sender
{
[sheetView zoomOut:sender];
}
- (void) mouseMoved:(NSEvent *)event
{
[sheetView mouseMoved:event];
}
2011-09-11 21:27:53 +00:00
- (void (^)()) willPlaySequence:(MusicSequence)music
2008-05-29 18:54:30 +00:00
{
2011-09-11 21:27:53 +00:00
return [sheetView willPlaySequence:music];
2008-05-29 18:54:30 +00:00
}
- (IBAction) togglePlayElements:(id)sender
{
2011-09-11 02:03:22 +00:00
[[self document] setPlayElements:[[self document] playElements] ^ (int)[sender tag]];
}
2011-09-04 19:48:57 +00:00
- (BOOL) validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)item
{
2011-09-04 19:48:57 +00:00
if ([item action] == @selector(togglePlayElements:)) {
NSMenuItem * menuItem = (NSMenuItem *)item;
2011-09-11 02:03:22 +00:00
if (NSInteger tag = [item tag])
[menuItem setState:([[self document] playElements] & tag) != 0];
2011-09-04 19:48:57 +00:00
} else if ([item action] == @selector(playStop:)) {
NSMenuItem * menuItem = [(NSObject *)item isKindOfClass:[NSMenuItem class]] ? (NSMenuItem *)item : nil;
NSToolbarItem * toolItem = menuItem ? nil : (NSToolbarItem *)item;
if (VLSoundOut::Instance()->Playing()) {
[menuItem setTitle:@"Stop"];
[toolItem setLabel:@"Stop"];
[toolItem setImage:[NSImage imageNamed:@"stop.icns"]];
} else {
[menuItem setTitle:@"Play"];
[toolItem setLabel:@"Play"];
[toolItem setImage:[NSImage imageNamed:@"play.icns"]];
}
}
return YES;
}
- (IBAction) showLog:(id)sender
{
[logWin showWindow:sender];
}
- (void) showLogAndBeep
{
[logWin showWindow:self];
NSBeep();
}
- (IBAction) showOutput:(id)sender
{
[[self document] createTmpFileWithExtension:@"pdf" ofType:VLPDFType];
[pdfWin showWindow:self];
[pdfWin reloadPDF];
}
2011-09-04 19:48:57 +00:00
- (IBAction) stop:(id)sender
{
VLSoundOut::Instance()->Stop();
}
- (IBAction) playStop:(id)sender
{
2011-09-11 21:27:53 +00:00
if (VLSoundOut::Instance()->Playing())
2011-09-04 19:48:57 +00:00
[self stop:sender];
else
[[self document] playSong];
}
- (IBAction) playMusic:(id)sender
{
switch ([sender tag]) {
case 1: // Fwd
VLSoundOut::Instance()->Fwd();
break;
2011-09-11 17:20:34 +00:00
case 0: {
float slowDown = 0.5f;
int modifiers=
[NSEvent modifierFlags] & (NSShiftKeyMask|NSAlternateKeyMask|NSCommandKeyMask|NSControlKeyMask);
while (modifiers) {
slowDown *= 0.75f;
modifiers &= modifiers-1;
}
VLSoundOut::Instance()->Slow(slowDown); }
break;
2011-09-04 19:48:57 +00:00
case -1: // Rew
VLSoundOut::Instance()->Bck();
break;
}
}
- (IBAction) adjustTempo:(id)sender
{
[[self document] setSongTempo:[[self document] songTempo]+[sender tag]];
}
- (IBAction)editDisplayOptions:(id)sender
{
NSUndoManager * undoMgr = [[self document] undoManager];
[undoMgr setGroupsByEvent:NO];
[undoMgr beginUndoGrouping];
[NSApp beginSheet:displaySheet modalForWindow:[self window]
modalDelegate:self
didEndSelector:@selector(didEndDisplaySheet:returnCode:contextInfo:)
contextInfo:nil];
}
- (void)didEndDisplaySheet:(NSWindow *)sheet returnCode:(int)returnCode
contextInfo:(void *)ctx
{
NSUndoManager * undoMgr = [[self document] undoManager];
[undoMgr setActionName:@"Display Options"];
[undoMgr endUndoGrouping];
[undoMgr setGroupsByEvent:YES];
switch (returnCode) {
case NSAlertFirstButtonReturn:
[sheetView needsRecalculation];
break;
default:
[undoMgr undo];
break;
}
[sheet orderOut:self];
}
- (NSUndoManager *)windowWillReturnUndoManager:(NSWindow *)window
{
return [[self document] undoManager];
}
2011-09-04 19:48:57 +00:00
@end